当前位置: 首页>>代码示例>>Java>>正文


Java VariablesProcessor类代码示例

本文整理汇总了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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:ReassignVariableUtil.java

示例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;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:20,代码来源:ReassignVariableUtil.java

示例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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:36,代码来源:ExtractMethodProcessor.java

示例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);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:30,代码来源:IntroduceVariableBase.java

示例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);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:29,代码来源:IntroduceVariableBase.java

示例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;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:47,代码来源:ExtractMethodProcessor.java

示例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);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:48,代码来源:IntroduceVariableBase.java


注:本文中的com.intellij.psi.scope.processor.VariablesProcessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。