微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

com.intellij.psi.scope.processor.VariablesProcessor的实例源码

项目:intellij-ce-playground    文件ReassignVariableutil.java   
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;
}
项目:tools-idea    文件ReassignVariableutil.java   
static VariablesProcessor findVariablesOfType(final PsiDeclarationStatement declaration,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,scope);
  return proc;
}
项目:consulo-java    文件ReassignVariableutil.java   
static VariablesProcessor findVariablesOfType(final PsiDeclarationStatement declaration,scope);
  return proc;
}
项目:intellij-ce-playground    文件ExtractMethodProcessor.java   
@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;
}
项目:intellij-ce-playground    文件IntroduceVariableBase.java   
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);
}
项目:tools-idea    文件IntroduceVariableBase.java   
private static ExpressionOccurrenceManager createOccurrenceManager(PsiExpression 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,notinSuperCallOccurrenceFilter.INSTANCE);
}
项目:consulo-java    文件ExtractMethodProcessor.java   
@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,myCodeFragmentMember);
        if(processor.size() == 1)
        {
            return processor.getResult(0);
        }
    }
    return null;
}
项目:consulo-java    文件IntroduceVariableBase.java   
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(),true);
            }
        };
        PsiScopesUtil.treeWalkUp(variablesProcessor,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,notinSuperCallOccurrenceFilter.INSTANCE);
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。