當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。