mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PsiElement traversal optimized
GitOrigin-RevId: d8b8b9f554c016e9b29560a3174ae6584f4635ec
This commit is contained in:
committed by
intellij-monorepo-bot
parent
896feeaf7c
commit
1986c0f830
+1
-1
@@ -385,7 +385,7 @@ public class HighlightClassUtil {
|
||||
PsiElement context = null;
|
||||
PsiModifierList modifierList = aClass.getModifierList();
|
||||
if (modifierList != null) {
|
||||
for (PsiElement element : modifierList.getChildren()) {
|
||||
for (PsiElement element = modifierList.getFirstChild(); element != null; element = element.getNextSibling()) {
|
||||
if (Comparing.equal(element.getText(), PsiModifier.STATIC)) {
|
||||
context = element;
|
||||
break;
|
||||
|
||||
+5
-2
@@ -306,8 +306,11 @@ public class HighlightNamesUtil {
|
||||
TextRange textRange = element.getTextRange();
|
||||
if (textRange == null) return 0;
|
||||
PsiAnnotation lastAnnotation = null;
|
||||
for (PsiElement child : element.getChildren()) {
|
||||
if (child instanceof PsiAnnotation) lastAnnotation = (PsiAnnotation)child;
|
||||
for (PsiElement child = element.getLastChild(); child != null; child = child.getPrevSibling()) {
|
||||
if (child instanceof PsiAnnotation) {
|
||||
lastAnnotation = (PsiAnnotation)child;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (lastAnnotation == null) {
|
||||
return textRange.getStartOffset();
|
||||
|
||||
+2
-2
@@ -948,7 +948,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
* @return true if the supplied modifier list contains incompatible modifiers
|
||||
*/
|
||||
public static boolean isIllegalModifierCombination(@NotNull PsiModifierList modifierList) {
|
||||
for (PsiElement child : modifierList.getChildren()) {
|
||||
for (PsiElement child = modifierList.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child instanceof PsiKeyword && getIncompatibleModifier(child.getText(), modifierList) != null) {
|
||||
return true;
|
||||
}
|
||||
@@ -1204,7 +1204,7 @@ public class HighlightUtil extends HighlightUtilBase {
|
||||
}
|
||||
else if (type == JavaTokenType.STRING_LITERAL) {
|
||||
if (value == null) {
|
||||
for (PsiElement element : expression.getChildren()) {
|
||||
for (PsiElement element = expression.getFirstChild(); element != null; element = element.getNextSibling()) {
|
||||
if (element instanceof OuterLanguageElement) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+2
-2
@@ -71,7 +71,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
}
|
||||
|
||||
private void buildClassInitializerFlow(PsiClass psiClass, boolean isStatic) {
|
||||
for (PsiElement element : psiClass.getChildren()) {
|
||||
for (PsiElement element = psiClass.getFirstChild(); element != null; element = element.getNextSibling()) {
|
||||
if (element instanceof PsiField &&
|
||||
!((PsiField)element).hasInitializer() &&
|
||||
((PsiField)element).hasModifierProperty(PsiModifier.STATIC) == isStatic) {
|
||||
@@ -83,7 +83,7 @@ public class ControlFlowAnalyzer extends JavaElementVisitor {
|
||||
addInstruction(new EscapeInstruction(Collections.singleton(getFactory().getVarFactory().createThisValue(psiClass))));
|
||||
addInstruction(new FlushFieldsInstruction());
|
||||
}
|
||||
for (PsiElement element : psiClass.getChildren()) {
|
||||
for (PsiElement element = psiClass.getFirstChild(); element != null; element = element.getNextSibling()) {
|
||||
if (((element instanceof PsiField && ((PsiField)element).hasInitializer()) || element instanceof PsiClassInitializer) &&
|
||||
((PsiMember)element).hasModifierProperty(PsiModifier.STATIC) == isStatic) {
|
||||
element.accept(this);
|
||||
|
||||
+1
-1
@@ -300,7 +300,7 @@ public class DfaValueFactory {
|
||||
ClassInitializationInfo(@NotNull PsiClass psiClass) {
|
||||
// Indirect instantiation via other class is still possible, but hopefully unlikely
|
||||
boolean canInstantiateItself = false;
|
||||
for (PsiElement child : psiClass.getChildren()) {
|
||||
for (PsiElement child = psiClass.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child instanceof PsiMember && ((PsiMember)child).hasModifierProperty(PsiModifier.STATIC) &&
|
||||
SyntaxTraverser.psiTraverser(child).filter(PsiNewExpression.class)
|
||||
.filterMap(PsiNewExpression::getClassReference)
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ class DeclarationSearcher {
|
||||
}
|
||||
|
||||
// look self
|
||||
for (PsiElement element : parent.getChildren()) {
|
||||
for (PsiElement element = parent.getFirstChild(); element != null; element = element.getNextSibling()) {
|
||||
if (element == endPositionElement) {
|
||||
break;
|
||||
}
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ public class MakeClassInterfaceFix extends LocalQuickFixAndIntentionActionOnPsiE
|
||||
private static void convertPsiClass(PsiClass aClass, final boolean makeInterface) throws IncorrectOperationException {
|
||||
final IElementType lookFor = makeInterface? JavaTokenType.CLASS_KEYWORD : JavaTokenType.INTERFACE_KEYWORD;
|
||||
final PsiKeyword replaceWith = JavaPsiFacade.getElementFactory(aClass.getProject()).createKeyword(makeInterface? PsiKeyword.INTERFACE : PsiKeyword.CLASS);
|
||||
for (PsiElement psiElement : aClass.getChildren()) {
|
||||
for (PsiElement psiElement = aClass.getFirstChild(); psiElement != null; psiElement = psiElement.getNextSibling()) {
|
||||
if (psiElement instanceof PsiKeyword) {
|
||||
final PsiKeyword psiKeyword = (PsiKeyword)psiElement;
|
||||
if (psiKeyword.getTokenType() == lookFor) {
|
||||
|
||||
+2
-2
@@ -179,11 +179,11 @@ public class VariableAccessFromInnerClassJava10Fix extends BaseIntentionAction {
|
||||
PsiElement rBrace = anonymousClass.getRBrace();
|
||||
if (lBrace == null || rBrace == null) return;
|
||||
StringBuilder expressionText = new StringBuilder();
|
||||
for (PsiElement child : newExpression.getChildren()) {
|
||||
for (PsiElement child = newExpression.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child == anonymousClass) break;
|
||||
expressionText.append(child.getText());
|
||||
}
|
||||
for (PsiElement child : anonymousClass.getChildren()) {
|
||||
for (PsiElement child = anonymousClass.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (!myIsBefore && child == rBrace) expressionText.append(variableText);
|
||||
expressionText.append(child.getText());
|
||||
if (myIsBefore && child == lBrace) expressionText.append(variableText);
|
||||
|
||||
@@ -206,7 +206,7 @@ public class JavadocTypedHandler extends TypedHandlerDelegate {
|
||||
|
||||
@Nullable
|
||||
private static PsiElement getDocumentingParameter(PsiDocTag tag) {
|
||||
for (PsiElement element : tag.getChildren()) {
|
||||
for(PsiElement element = tag.getFirstChild(); element != null; element = element.getNextSibling()) {
|
||||
if (element instanceof PsiDocParamRef) {
|
||||
return element;
|
||||
}
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ public class MissingArrayConstructorBracketFixer implements Fixer {
|
||||
if (!(psiElement instanceof PsiNewExpression)) return;
|
||||
PsiNewExpression expr = (PsiNewExpression)psiElement;
|
||||
int count = 0;
|
||||
for (PsiElement element : expr.getChildren()) {
|
||||
for (PsiElement element = expr.getFirstChild(); element != null; element = element.getNextSibling()) {
|
||||
if (element.getNode().getElementType() == JavaTokenType.LBRACKET) {
|
||||
count++;
|
||||
} else if (element.getNode().getElementType() == JavaTokenType.RBRACKET) {
|
||||
|
||||
@@ -233,7 +233,7 @@ public class GenerateMembersUtil {
|
||||
final PsiClass psiClass = (PsiClass)element;
|
||||
if (psiClass.isEnum()) {
|
||||
PsiElement lastChild = null;
|
||||
for (PsiElement child : psiClass.getChildren()) {
|
||||
for (PsiElement child = psiClass.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child instanceof PsiJavaToken && ";".equals(child.getText())) {
|
||||
lastChild = child;
|
||||
break;
|
||||
|
||||
+1
-1
@@ -208,7 +208,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
for (PsiElement element : owner.getChildren()) {
|
||||
for (PsiElement element = owner.getFirstChild(); element != null; element = element.getNextSibling()) {
|
||||
if (element instanceof PsiErrorElement) return false;
|
||||
}
|
||||
PsiElement parent = owner.getParent();
|
||||
|
||||
@@ -34,7 +34,7 @@ class JavaListUtils {
|
||||
|
||||
static boolean containsEolComments(@NotNull List<? extends PsiElement> elements) {
|
||||
PsiElement parent = elements.get(0).getParent();
|
||||
for (PsiElement child : parent.getChildren()) {
|
||||
for(PsiElement child = parent.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child instanceof PsiComment && ((PsiComment)child).getTokenType() == JavaTokenType.END_OF_LINE_COMMENT) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -259,7 +259,7 @@ public class JavaDocReferenceInspection extends LocalInspectionTool {
|
||||
|
||||
@Override
|
||||
public void visitElement(PsiElement element) {
|
||||
for (PsiElement child : element.getChildren()) {
|
||||
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
child.accept(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -905,10 +905,7 @@ public class ImportHelper{
|
||||
while (!stack.isEmpty()) {
|
||||
final PsiElement child = stack.removeFirst();
|
||||
if (child instanceof PsiImportList) {
|
||||
for (PsiElement element : child.getChildren()) {
|
||||
if (element == null) {
|
||||
continue;
|
||||
}
|
||||
for(PsiElement element = child.getFirstChild(); element != null; element = element.getNextSibling()) {
|
||||
ASTNode node = element.getNode();
|
||||
if (node == null) {
|
||||
continue;
|
||||
|
||||
@@ -556,13 +556,7 @@ public class JavaPullUpHelper implements PullUpHelper<MemberInfo> {
|
||||
}
|
||||
|
||||
private static void collectPsiStatements(PsiElement root, Set<? super PsiStatement> collected) {
|
||||
if (root instanceof PsiStatement){
|
||||
collected.add((PsiStatement)root);
|
||||
}
|
||||
|
||||
for (PsiElement element : root.getChildren()) {
|
||||
collectPsiStatements(element, collected);
|
||||
}
|
||||
SyntaxTraverser.psiTraverser(root).filter(PsiStatement.class).addAllTo(collected);
|
||||
}
|
||||
|
||||
private static class ParametersAndMovedFieldsUsedCollector extends JavaRecursiveElementWalkingVisitor {
|
||||
@@ -651,7 +645,7 @@ public class JavaPullUpHelper implements PullUpHelper<MemberInfo> {
|
||||
// find references
|
||||
for (PsiReference reference : ReferencesSearch.search(constructor, new LocalSearchScope(mySourceClass), false)) {
|
||||
final PsiElement element = reference.getElement();
|
||||
if (element != null && "super".equals(element.getText())) {
|
||||
if ("super".equals(element.getText())) {
|
||||
PsiMethod parentMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
|
||||
if (parentMethod != null && parentMethod.isConstructor()) {
|
||||
referencingSubConstructors.add(parentMethod);
|
||||
|
||||
@@ -184,7 +184,7 @@ public class RefactoringConflictsUtil {
|
||||
}
|
||||
}
|
||||
|
||||
for (PsiElement child : scope.getChildren()) {
|
||||
for (PsiElement child = scope.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child instanceof PsiWhiteSpace || child instanceof PsiComment) continue;
|
||||
checkUsedElements(member, child, membersToMove, abstractMethods, targetClass, child instanceof PsiClass ? (PsiClass)child : accessClass, context, conflicts);
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class DocCommentTokenizer extends Tokenizer<PsiDocComment> {
|
||||
public void tokenize(@NotNull PsiDocComment comment, TokenConsumer consumer) {
|
||||
final CommentSplitter splitter = CommentSplitter.getInstance();
|
||||
|
||||
for (PsiElement el : comment.getChildren()) {
|
||||
for (PsiElement el = comment.getFirstChild(); el != null; el = el.getNextSibling()) {
|
||||
if (el instanceof PsiDocTag) {
|
||||
PsiDocTag tag = (PsiDocTag)el;
|
||||
if (!excludedTags.contains(tag.getName())) {
|
||||
|
||||
+1
-1
@@ -176,7 +176,7 @@ public class PointlessBitwiseExpressionInspection extends BaseInspection {
|
||||
@NotNull @NonNls String replacement, CommentTracker ct) {
|
||||
final StringBuilder result = new StringBuilder();
|
||||
boolean stop = false;
|
||||
for (PsiElement child : expression.getChildren()) {
|
||||
for (PsiElement child = expression.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child == fromTarget) {
|
||||
stop = true;
|
||||
result.append(replacement);
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ public class DanglingJavadocInspection extends BaseInspection {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
final PsiElement docComment = element.getParent();
|
||||
final StringBuilder newCommentText = new StringBuilder();
|
||||
for (PsiElement child : docComment.getChildren()) {
|
||||
for (PsiElement child = docComment.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child instanceof PsiDocToken) {
|
||||
final PsiDocToken docToken = (PsiDocToken)child;
|
||||
final IElementType tokenType = docToken.getTokenType();
|
||||
|
||||
+2
-2
@@ -179,7 +179,7 @@ public class UnclearBinaryExpressionInspection extends BaseInspection {
|
||||
appendText(polyadicExpression, parentheses, out);
|
||||
}
|
||||
else if (expression instanceof PsiParenthesizedExpression) {
|
||||
for (PsiElement child : expression.getChildren()) {
|
||||
for (PsiElement child = expression.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child instanceof PsiExpression) {
|
||||
final PsiExpression unwrappedExpression = (PsiExpression)child;
|
||||
createReplacementText(unwrappedExpression, out);
|
||||
@@ -235,7 +235,7 @@ public class UnclearBinaryExpressionInspection extends BaseInspection {
|
||||
if (parentheses) {
|
||||
out.append('(');
|
||||
}
|
||||
for (PsiElement child : expression.getChildren()) {
|
||||
for (PsiElement child = expression.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child instanceof PsiExpression) {
|
||||
createReplacementText((PsiExpression)child, out);
|
||||
}
|
||||
|
||||
+1
-1
@@ -230,7 +230,7 @@ public class TrivialFunctionalExpressionUsageInspection extends AbstractBaseJava
|
||||
gParent.addBefore(JavaPsiFacade.getElementFactory(element.getProject()).createStatementFromText(ct.text(body), anchor), anchor);
|
||||
}
|
||||
else {
|
||||
for (PsiElement child : body.getChildren()) {
|
||||
for (PsiElement child = body.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child != statement && !(child instanceof PsiJavaToken)) {
|
||||
gParent.addBefore(ct.markUnchanged(child), anchor);
|
||||
}
|
||||
|
||||
+1
-1
@@ -340,7 +340,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
for (PsiElement child : element.getChildren()) {
|
||||
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (child instanceof PsiExpressionList) {
|
||||
continue;
|
||||
}
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ public class CopyConcatenatedStringToClipboardIntention extends Intention {
|
||||
|
||||
public static String buildConcatenationText(PsiPolyadicExpression polyadicExpression) {
|
||||
StringBuilder out = new StringBuilder();
|
||||
for (PsiElement element : polyadicExpression.getChildren()) {
|
||||
for(PsiElement element = polyadicExpression.getFirstChild(); element != null; element = element.getNextSibling()) {
|
||||
if (element instanceof PsiExpression) {
|
||||
final PsiExpression expression = (PsiExpression)element;
|
||||
final Object value = ExpressionUtils.computeConstantExpression(expression);
|
||||
|
||||
@@ -346,7 +346,7 @@ public class ChangeModifierIntention extends BaseElementAtCaretIntentionAction {
|
||||
|
||||
@Nullable
|
||||
private static PsiKeyword getAnchorKeyword(PsiModifierList modifierList) {
|
||||
for (PsiElement child : modifierList.getChildren()) {
|
||||
for (PsiElement child = modifierList.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
if (ALL_MODIFIERS.contains(AccessModifier.fromKeyword(ObjectUtils.tryCast(child, PsiKeyword.class)))) {
|
||||
return (PsiKeyword)child;
|
||||
}
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public class PropertyFoldingEditHandler {
|
||||
private static UCallExpression findCallExpression(PsiElement foldedPsiElement) {
|
||||
UCallExpression expression = UastContextKt.toUElement(foldedPsiElement, UCallExpression.class);
|
||||
if (expression != null) return expression;
|
||||
for (PsiElement child : foldedPsiElement.getChildren()) {
|
||||
for (PsiElement child = foldedPsiElement.getFirstChild(); child != null; child = child.getNextSibling()) {
|
||||
UCallExpression e = UastContextKt.toUElement(child, UCallExpression.class);
|
||||
if (e != null) return e;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user