8000 use PhpCodeInsightUtil for collecting use imports, simplify class equ… · Koc/idea-php-symfony2-plugin@91b85af · GitHub
[go: up one dir, main page]

Skip to content

Commit 91b85af

Browse files
committed
use PhpCodeInsightUtil for collecting use imports, simplify class equal name check
1 parent 270a5a8 commit 91b85af

File tree

2 files changed

+6
-31
lines changed

2 files changed

+6
-31
lines changed

src/fr/adrienbrault/idea/symfony2plugin/util/AnnotationBackportUtil.java

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,33 +81,21 @@ public static Map<String, String> getUseImportMap(@NotNull PhpDocComment phpDocC
8181
// search for use alias in local file
8282
final Map<String, String> useImports = new HashMap<>();
8383

84-
PsiElement scope = PsiTreeUtil.getParentOfType(phpDocComment, PhpNamespace.class);
85-
if(scope == null) {
86-
scope = PsiTreeUtil.getParentOfType(phpDocComment, GroupStatement.class);
87-
}
88-
84+
PhpPsiElement scope = PhpCodeInsightUtil.findScopeForUseOperator(phpDocComment);
8985
if(scope == null) {
9086
return useImports;
9187
}
9288

93-
scope.acceptChildren(new PsiRecursiveElementWalkingVisitor() {
94-
@Override
95-
public void visitElement(PsiElement element) {
96-
if (element instanceof PhpUse) {
97-
visitUse((PhpUse) element);
98-
}
99-
super.visitElement(element);
100-
}
101-
102-
private void visitUse(PhpUse phpUse) {
89+
for (PhpUseList phpUseList : PhpCodeInsightUtil.collectImports(scope)) {
90+
for (PhpUse phpUse : phpUseList.getDeclarations()) {
10391
String alias = phpUse.getAliasName();
10492
if (alias != null) {
10593
useImports.put(alias, phpUse.getFQN());
10694
} else {
10795
useImports.put(phpUse.getName(), phpUse.getFQN());
10896
}
10997
}
110-
});
98+
}
11199

112100
return useImports;
113101
}

src/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -825,25 +825,12 @@ public static boolean isEqualClassName(@NotNull PhpClass phpClass, @NotNull PhpC
825825
}
826826

827827
public static boolean isEqualClassName(@Nullable PhpClass phpClass, @Nullable String compareClassName) {
828-
829828
if(phpClass == null || compareClassName == null) {
830829
return false;
831830
}
832831

833-
String phpClassName = phpClass.getPresentableFQN();
834-
if(phpClassName == null) {
835-
return false;
836-
}
837-
838-
if(phpClassName.startsWith("\\")) {
839-
phpClassName = phpClassName.substring(1);
840-
}
841-
842-
if(compareClassName.startsWith("\\")) {
843-
compareClassName = compareClassName.substring(1);
844-
}
845-
846-
return phpClassName.equals(compareClassName);
832+
return StringUtils.stripStart(phpClass.getPresentableFQN(), "\\")
833+
.equals(StringUtils.stripStart(compareClassName, "\\"));
847834
}
848835

849836
@Nullable

0 commit comments

Comments
 (0)
0