Comments: put unparsable refs calculation back

This commit is contained in:
Gregory.Shrago
2015-02-16 21:32:29 +03:00
parent d5638c7553
commit 12099b521c
@@ -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<PsiElement> 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<PsiModifierListOwner> visitedVars = new THashSet<PsiModifierListOwner>();
final LinkedList<PsiElement> places = new LinkedList<PsiElement>();
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<PsiReference>() {
@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<PsiElement> 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<PsiElement> 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;