forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetPhpClassByFQN.java
37 lines (32 loc) · 1.12 KB
/
GetPhpClassByFQN.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin.util;
import com.intellij.openapi.project.Project;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import java.util.Collection;
public class GetPhpClassByFQN {
private static GetPhpClassByFQN INSTANCE = null;
private Project project;
public static GetPhpClassByFQN getInstance(Project project) {
if (null == INSTANCE) {
INSTANCE = new GetPhpClassByFQN();
}
INSTANCE.project = project;
return INSTANCE;
}
public PhpClass execute(String targetClassName) {
PhpIndex phpIndex = PhpIndex.getInstance(project);
Collection<PhpClass> interfaces = phpIndex.getInterfacesByFQN(targetClassName);
if (!interfaces.isEmpty()) {
return interfaces.iterator().next();
}
Collection<PhpClass> classes = phpIndex.getClassesByFQN(targetClassName);
if (classes.isEmpty()) {
return null;
}
return classes.iterator().next();
}
}