本文整理汇总了Java中com.intellij.psi.scope.processor.VariablesProcessor类的典型用法代码示例。如果您正苦于以下问题:Java VariablesProcessor类的具体用法?Java VariablesProcessor怎么用?Java VariablesProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VariablesProcessor类属于com.intellij.psi.scope.processor包,在下文中一共展示了VariablesProcessor类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findVariablesOfType
import com.intellij.psi.scope.processor.VariablesProcessor; //导入依赖的package包/类
static VariablesProcessor findVariablesOfType(final PsiDeclarationStatement declaration, final PsiType type) {
VariablesProcessor proc = new VariablesProcessor(false) {
@Override
protected boolean check(PsiVariable var, ResolveState state) {
for (PsiElement element : declaration.getDeclaredElements()) {
if (element == var) return false;
}
return TypeConversionUtil.isAssignable(var.getType(), type);
}
};
PsiElement scope = declaration;
while (scope != null) {
if (scope instanceof PsiFile ||
scope instanceof PsiMethod ||
scope instanceof PsiLambdaExpression ||
scope instanceof PsiClassInitializer) break;
scope = scope.getParent();
}
if (scope == null) return proc;
PsiScopesUtil.treeWalkUp(proc, declaration, scope);
return proc;
}
示例2: findVariablesOfType
import com.intellij.psi.scope.processor.VariablesProcessor; //导入依赖的package包/类
static VariablesProcessor findVariablesOfType(final PsiDeclarationStatement declaration, final PsiType type) {
VariablesProcessor proc = new VariablesProcessor(false) {
@Override
protected boolean check(PsiVariable var, ResolveState state) {
for (PsiElement element : declaration.getDeclaredElements()) {
if (element == var) return false;
}
return TypeConversionUtil.isAssignable(var.getType(), type);
}
};
PsiElement scope = declaration;
while (scope != null) {
if (scope instanceof PsiFile || scope instanceof PsiMethod || scope instanceof PsiClassInitializer) break;
scope = scope.getParent();
}
if (scope == null) return proc;
PsiScopesUtil.treeWalkUp(proc, declaration, scope);
return proc;
}
示例3: getArtificialOutputVariable
import com.intellij.psi.scope.processor.VariablesProcessor; //导入依赖的package包/类
@Nullable
private PsiVariable getArtificialOutputVariable() {
if (myOutputVariables.length == 0 && myExitStatements.isEmpty()) {
if (myCanBeChainedConstructor) {
final Set<PsiField> fields = new HashSet<PsiField>();
for (PsiElement element : myElements) {
element.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
super.visitReferenceExpression(expression);
final PsiElement resolve = expression.resolve();
if (resolve instanceof PsiField && ((PsiField)resolve).hasModifierProperty(PsiModifier.FINAL) &&
PsiUtil.isAccessedForWriting(expression)) {
fields.add((PsiField)resolve);
}
}
});
}
if (!fields.isEmpty()) {
return fields.size() == 1 ? fields.iterator().next() : null;
}
}
final VariablesProcessor processor = new VariablesProcessor(true) {
@Override
protected boolean check(PsiVariable var, ResolveState state) {
return isDeclaredInside(var);
}
};
PsiScopesUtil.treeWalkUp(processor, myElements[myElements.length - 1], myCodeFragmentMember);
if (processor.size() == 1) {
return processor.getResult(0);
}
}
return null;
}
示例4: createOccurrenceManager
import com.intellij.psi.scope.processor.VariablesProcessor; //导入依赖的package包/类
private static ExpressionOccurrenceManager createOccurrenceManager(PsiExpression expr, PsiElement tempContainer) {
boolean skipForStatement = true;
final PsiForStatement forStatement = PsiTreeUtil.getParentOfType(expr, PsiForStatement.class);
if (forStatement != null) {
final VariablesProcessor variablesProcessor = new VariablesProcessor(false) {
@Override
protected boolean check(PsiVariable var, ResolveState state) {
return PsiTreeUtil.isAncestor(forStatement.getInitialization(), var, true);
}
};
PsiScopesUtil.treeWalkUp(variablesProcessor, expr, null);
skipForStatement = variablesProcessor.size() == 0;
}
PsiElement containerParent = tempContainer;
PsiElement lastScope = tempContainer;
while (true) {
if (containerParent instanceof PsiFile) break;
if (containerParent instanceof PsiMethod) break;
if (containerParent instanceof PsiLambdaExpression) break;
if (!skipForStatement && containerParent instanceof PsiForStatement) break;
containerParent = containerParent.getParent();
if (containerParent instanceof PsiCodeBlock) {
lastScope = containerParent;
}
}
return new ExpressionOccurrenceManager(expr, lastScope, NotInSuperCallOccurrenceFilter.INSTANCE);
}
示例5: createOccurrenceManager
import com.intellij.psi.scope.processor.VariablesProcessor; //导入依赖的package包/类
private static ExpressionOccurrenceManager createOccurrenceManager(PsiExpression expr, PsiElement tempContainer) {
boolean skipForStatement = true;
final PsiForStatement forStatement = PsiTreeUtil.getParentOfType(expr, PsiForStatement.class);
if (forStatement != null) {
final VariablesProcessor variablesProcessor = new VariablesProcessor(false) {
@Override
protected boolean check(PsiVariable var, ResolveState state) {
return PsiTreeUtil.isAncestor(forStatement.getInitialization(), var, true);
}
};
PsiScopesUtil.treeWalkUp(variablesProcessor, expr, null);
skipForStatement = variablesProcessor.size() == 0;
}
PsiElement containerParent = tempContainer;
PsiElement lastScope = tempContainer;
while (true) {
if (containerParent instanceof PsiFile) break;
if (containerParent instanceof PsiMethod) break;
if (!skipForStatement && containerParent instanceof PsiForStatement) break;
containerParent = containerParent.getParent();
if (containerParent instanceof PsiCodeBlock) {
lastScope = containerParent;
}
}
return new ExpressionOccurrenceManager(expr, lastScope, NotInSuperCallOccurrenceFilter.INSTANCE);
}
示例6: getArtificialOutputVariable
import com.intellij.psi.scope.processor.VariablesProcessor; //导入依赖的package包/类
@Nullable
private PsiVariable getArtificialOutputVariable()
{
if(myOutputVariables.length == 0 && myExitStatements.isEmpty())
{
if(myCanBeChainedConstructor)
{
final Set<PsiField> fields = new HashSet<PsiField>();
for(PsiElement element : myElements)
{
element.accept(new JavaRecursiveElementWalkingVisitor()
{
@Override
public void visitReferenceExpression(PsiReferenceExpression expression)
{
super.visitReferenceExpression(expression);
final PsiElement resolve = expression.resolve();
if(resolve instanceof PsiField && ((PsiField) resolve).hasModifierProperty(PsiModifier.FINAL) &&
PsiUtil.isAccessedForWriting(expression))
{
fields.add((PsiField) resolve);
}
}
});
}
if(!fields.isEmpty())
{
return fields.size() == 1 ? fields.iterator().next() : null;
}
}
final VariablesProcessor processor = new VariablesProcessor(true)
{
@Override
protected boolean check(PsiVariable var, ResolveState state)
{
return isDeclaredInside(var);
}
};
PsiScopesUtil.treeWalkUp(processor, myElements[myElements.length - 1], myCodeFragmentMember);
if(processor.size() == 1)
{
return processor.getResult(0);
}
}
return null;
}
示例7: createOccurrenceManager
import com.intellij.psi.scope.processor.VariablesProcessor; //导入依赖的package包/类
private static ExpressionOccurrenceManager createOccurrenceManager(PsiExpression expr, PsiElement tempContainer)
{
boolean skipForStatement = true;
final PsiForStatement forStatement = PsiTreeUtil.getParentOfType(expr, PsiForStatement.class);
if(forStatement != null)
{
final VariablesProcessor variablesProcessor = new VariablesProcessor(false)
{
@Override
protected boolean check(PsiVariable var, ResolveState state)
{
return PsiTreeUtil.isAncestor(forStatement.getInitialization(), var, true);
}
};
PsiScopesUtil.treeWalkUp(variablesProcessor, expr, null);
skipForStatement = variablesProcessor.size() == 0;
}
PsiElement containerParent = tempContainer;
PsiElement lastScope = tempContainer;
while(true)
{
if(containerParent instanceof PsiFile)
{
break;
}
if(containerParent instanceof PsiMethod)
{
break;
}
if(containerParent instanceof PsiLambdaExpression)
{
break;
}
if(!skipForStatement && containerParent instanceof PsiForStatement)
{
break;
}
containerParent = containerParent.getParent();
if(containerParent instanceof PsiCodeBlock)
{
lastScope = containerParent;
}
}
return new ExpressionOccurrenceManager(expr, lastScope, NotInSuperCallOccurrenceFilter.INSTANCE);
}