From 12099b521cddcfdf9d227e657a3eb151b6b6a5db Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Mon, 16 Feb 2015 21:30:15 +0300 Subject: [PATCH] Comments: put unparsable refs calculation back --- .../inject/java/ConcatenationInjector.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/ConcatenationInjector.java b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/ConcatenationInjector.java index cb1911a8a9fd..8218820c2e5c 100644 --- a/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/ConcatenationInjector.java +++ b/plugins/IntelliLang/java-support/org/intellij/plugins/intelliLang/inject/java/ConcatenationInjector.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -134,20 +134,13 @@ public class ConcatenationInjector implements ConcatenationAwareInjector { public void processInjections() { final PsiElement firstOperand = myOperands[0]; - Ref causeRef = Ref.create(); - BaseInjection commentInjection = mySupport.findCommentInjection(firstOperand, causeRef); - if (commentInjection != null) { - processCommentInjectionInner(causeRef.get(), commentInjection); - return; - } - final PsiElement topBlock = PsiUtil.getTopLevelEnclosingCodeBlock(firstOperand, null); final LocalSearchScope searchScope = new LocalSearchScope(new PsiElement[]{topBlock instanceof PsiCodeBlock ? topBlock : firstOperand.getContainingFile()}, "", true); final THashSet visitedVars = new THashSet(); final LinkedList places = new LinkedList(); places.add(firstOperand); - final AnnotationUtilEx.AnnotatedElementVisitor visitor = new AnnotationUtilEx.AnnotatedElementVisitor() { + class MyAnnoVisitor implements AnnotationUtilEx.AnnotatedElementVisitor { public boolean visitMethodParameter(PsiExpression expression, PsiCallExpression psiCallExpression) { final PsiExpressionList list = psiCallExpression.getArgumentList(); assert list != null; @@ -188,7 +181,8 @@ public class ConcatenationInjector implements ConcatenationAwareInjector { return false; } - public boolean visitVariable(PsiVariable variable) { + private void visitVariableUsages(PsiVariable variable) { + if (variable == null) return; if (myConfiguration.getAdvancedConfiguration().getDfaOption() != Configuration.DfaOption.OFF && visitedVars.add(variable)) { ReferencesSearch.search(variable, searchScope).forEach(new Processor() { @Override @@ -205,7 +199,15 @@ public class ConcatenationInjector implements ConcatenationAwareInjector { } }); } - if (!processCommentInjections(variable)) { + } + + public boolean visitVariable(PsiVariable variable) { + visitVariableUsages(variable); + PsiElement anchor = !(variable.getFirstChild() instanceof PsiComment) ? variable : + variable.getModifierList() != null ? variable.getModifierList() : + variable.getTypeElement(); + + if (anchor != null && !processCommentInjection(anchor)) { myShouldStop = true; } else if (areThereInjectionsWithName(variable.getName(), false)) { @@ -247,25 +249,28 @@ public class ConcatenationInjector implements ConcatenationAwareInjector { } return !myShouldStop; } - }; + private boolean processCommentInjection(@NotNull PsiElement anchor) { + Ref causeRef = Ref.create(); + BaseInjection injection = mySupport.findCommentInjection(anchor, causeRef); + if (injection != null) { + PsiVariable variable = PsiTreeUtil.getParentOfType(anchor, PsiVariable.class); + visitVariableUsages(variable); + return processCommentInjectionInner(causeRef.get(), injection); + } + return true; + } + }; + MyAnnoVisitor visitor = new MyAnnoVisitor(); + if (!visitor.processCommentInjection(firstOperand)) { + return; + } while (!places.isEmpty() && !myShouldStop) { final PsiElement curPlace = places.removeFirst(); AnnotationUtilEx.visitAnnotatedElements(curPlace, visitor); } } - private boolean processCommentInjections(PsiVariable owner) { - PsiElement anchor = !(owner.getFirstChild() instanceof PsiComment) ? owner : - owner.getModifierList() != null ? owner.getModifierList() : - owner.getTypeElement(); - if (anchor == null) return true; - - Ref causeRef = Ref.create(); - BaseInjection injection = mySupport.findCommentInjection(anchor, causeRef); - return injection == null || processCommentInjectionInner(causeRef.get(), injection); - } - protected boolean processCommentInjectionInner(PsiElement comment, BaseInjection injection) { processInjectionWithContext(injection, false); return false;