當前位置: 首頁>>代碼示例>>Java>>正文


Java ControlFlowUtil.VariableInfo方法代碼示例

本文整理匯總了Java中com.intellij.psi.controlFlow.ControlFlowUtil.VariableInfo方法的典型用法代碼示例。如果您正苦於以下問題:Java ControlFlowUtil.VariableInfo方法的具體用法?Java ControlFlowUtil.VariableInfo怎麽用?Java ControlFlowUtil.VariableInfo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.controlFlow.ControlFlowUtil的用法示例。


在下文中一共展示了ControlFlowUtil.VariableInfo方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isReassigned

import com.intellij.psi.controlFlow.ControlFlowUtil; //導入方法依賴的package包/類
public static boolean isReassigned(@NotNull PsiVariable variable, @NotNull Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems)
{
	if(variable instanceof PsiLocalVariable)
	{
		final PsiElement parent = variable.getParent();
		if(parent == null)
		{
			return false;
		}
		final PsiElement declarationScope = parent.getParent();
		if(declarationScope == null)
		{
			return false;
		}
		Collection<ControlFlowUtil.VariableInfo> codeBlockProblems = getFinalVariableProblemsInBlock(finalVarProblems, declarationScope);
		return codeBlockProblems.contains(new ControlFlowUtil.VariableInfo(variable, null));
	}
	if(variable instanceof PsiParameter)
	{
		final PsiParameter parameter = (PsiParameter) variable;
		return isAssigned(parameter);
	}
	return false;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:25,代碼來源:HighlightControlFlowUtil.java

示例2: getFinalVariableProblemsInBlock

import com.intellij.psi.controlFlow.ControlFlowUtil; //導入方法依賴的package包/類
@NotNull
private static Collection<ControlFlowUtil.VariableInfo> getFinalVariableProblemsInBlock(@NotNull Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems,
		@NotNull PsiElement codeBlock)
{
	Collection<ControlFlowUtil.VariableInfo> codeBlockProblems = finalVarProblems.get(codeBlock);
	if(codeBlockProblems == null)
	{
		try
		{
			final ControlFlow controlFlow = getControlFlowNoConstantEvaluate(codeBlock);
			codeBlockProblems = ControlFlowUtil.getInitializedTwice(controlFlow);
		}
		catch(AnalysisCanceledException e)
		{
			codeBlockProblems = Collections.emptyList();
		}
		finalVarProblems.put(codeBlock, codeBlockProblems);
	}
	return codeBlockProblems;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:21,代碼來源:HighlightControlFlowUtil.java

示例3: canBeFinal

import com.intellij.psi.controlFlow.ControlFlowUtil; //導入方法依賴的package包/類
private static boolean canBeFinal(@NotNull PsiVariable variable, @NotNull List<PsiReferenceExpression> references) {
  // if there is at least one assignment to this variable, it cannot be final
  Map<PsiElement, Collection<PsiReferenceExpression>> uninitializedVarProblems = new THashMap<PsiElement, Collection<PsiReferenceExpression>>();
  Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems = new THashMap<PsiElement, Collection<ControlFlowUtil.VariableInfo>>();
  for (PsiReferenceExpression expression : references) {
    if (ControlFlowUtil.isVariableAssignedInLoop(expression, variable)) return false;
    HighlightInfo highlightInfo = HighlightControlFlowUtil.checkVariableInitializedBeforeUsage(expression, variable, uninitializedVarProblems,
                                                                                               variable.getContainingFile());
    if (highlightInfo != null) return false;
    highlightInfo = HighlightControlFlowUtil.checkFinalVariableMightAlreadyHaveBeenAssignedTo(variable, expression, finalVarProblems);
    if (highlightInfo != null) return false;
    if (variable instanceof PsiParameter && PsiUtil.isAccessedForWriting(expression)) return false;
  }
  return true;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:16,代碼來源:VariableAccessFromInnerClassFix.java

示例4: canBeFinal

import com.intellij.psi.controlFlow.ControlFlowUtil; //導入方法依賴的package包/類
private static boolean canBeFinal(PsiVariable variable, List<PsiReferenceExpression> references) {
  // if there is at least one assignment to this variable, it cannot be final
  Map<PsiElement, Collection<PsiReferenceExpression>> uninitializedVarProblems = new THashMap<PsiElement, Collection<PsiReferenceExpression>>();
  Map<PsiElement, Collection<ControlFlowUtil.VariableInfo>> finalVarProblems = new THashMap<PsiElement, Collection<ControlFlowUtil.VariableInfo>>();
  for (PsiReferenceExpression expression : references) {
    if (ControlFlowUtil.isVariableAssignedInLoop(expression, variable)) return false;
    HighlightInfo highlightInfo = HighlightControlFlowUtil.checkVariableInitializedBeforeUsage(expression, variable, uninitializedVarProblems,
                                                                                               variable.getContainingFile());
    if (highlightInfo != null) return false;
    highlightInfo = HighlightControlFlowUtil.checkFinalVariableMightAlreadyHaveBeenAssignedTo(variable, expression, finalVarProblems);
    if (highlightInfo != null) return false;
    if (variable instanceof PsiParameter && PsiUtil.isAccessedForWriting(expression)) return false;
  }
  return true;
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:16,代碼來源:VariableAccessFromInnerClassFix.java

示例5: declareLocalVariables

import com.intellij.psi.controlFlow.ControlFlowUtil; //導入方法依賴的package包/類
private void declareLocalVariables() throws IncorrectOperationException {
  final PsiElement codeFragment = ControlFlowUtil.findCodeFragment(getMatchStart());
  try {
    final Project project = getMatchStart().getProject();
    final ControlFlow controlFlow = ControlFlowFactory.getInstance(project)
      .getControlFlow(codeFragment, new LocalsControlFlowPolicy(codeFragment));
    final int endOffset = controlFlow.getEndOffset(getMatchEnd());
    final int startOffset = controlFlow.getStartOffset(getMatchStart());
    final List<PsiVariable> usedVariables = ControlFlowUtil.getUsedVariables(controlFlow, endOffset, controlFlow.getSize());
    Collection<ControlFlowUtil.VariableInfo> reassigned = ControlFlowUtil.getInitializedTwice(controlFlow, endOffset, controlFlow.getSize());
    final Collection<PsiVariable> outVariables = ControlFlowUtil.getWrittenVariables(controlFlow, startOffset, endOffset, false);
    for (PsiVariable variable : usedVariables) {
      if (!outVariables.contains(variable)) {
        final PsiIdentifier identifier = variable.getNameIdentifier();
        if (identifier != null) {
          final TextRange textRange = checkRange(identifier);
          final TextRange startRange = checkRange(getMatchStart());
          final TextRange endRange = checkRange(getMatchEnd());
          if (textRange.getStartOffset() >= startRange.getStartOffset() && textRange.getEndOffset() <= endRange.getEndOffset()) {
            final String name = variable.getName();
            LOG.assertTrue(name != null);
            PsiDeclarationStatement statement =
              JavaPsiFacade.getInstance(project).getElementFactory().createVariableDeclarationStatement(name, variable.getType(), null);
            if (reassigned.contains(new ControlFlowUtil.VariableInfo(variable, null))) {
              final PsiElement[] psiElements = statement.getDeclaredElements();
              final PsiModifierList modifierList = ((PsiVariable)psiElements[0]).getModifierList();
              LOG.assertTrue(modifierList != null);
              modifierList.setModifierProperty(PsiModifier.FINAL, false);
            }
            getMatchStart().getParent().addBefore(statement, getMatchStart());
          }
        }
      }
    }
  }
  catch (AnalysisCanceledException e) {
    //skip match
  }
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:40,代碼來源:Match.java

示例6: isEffectivelyFinal

import com.intellij.psi.controlFlow.ControlFlowUtil; //導入方法依賴的package包/類
public static boolean isEffectivelyFinal(@NotNull PsiVariable variable, @NotNull PsiElement scope, @Nullable PsiJavaCodeReferenceElement context)
{
	boolean effectivelyFinal;
	if(variable instanceof PsiParameter)
	{
		effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(((PsiParameter) variable).getDeclarationScope()));
	}
	else
	{
		final ControlFlow controlFlow;
		try
		{
			PsiElement codeBlock = PsiUtil.getVariableCodeBlock(variable, context);
			if(codeBlock == null)
			{
				return true;
			}
			controlFlow = getControlFlow(codeBlock);
		}
		catch(AnalysisCanceledException e)
		{
			return true;
		}

		final List<PsiReferenceExpression> readBeforeWriteLocals = ControlFlowUtil.getReadBeforeWriteLocals(controlFlow);
		for(PsiReferenceExpression expression : readBeforeWriteLocals)
		{
			if(expression.resolve() == variable)
			{
				return PsiUtil.isAccessedForReading(expression);
			}
		}

		final Collection<ControlFlowUtil.VariableInfo> initializedTwice = ControlFlowUtil.getInitializedTwice(controlFlow);
		effectivelyFinal = !initializedTwice.contains(new ControlFlowUtil.VariableInfo(variable, null));
		if(effectivelyFinal)
		{
			effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(scope));
		}
	}
	return effectivelyFinal;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:43,代碼來源:HighlightControlFlowUtil.java

示例7: getInitializedTwice

import com.intellij.psi.controlFlow.ControlFlowUtil; //導入方法依賴的package包/類
public Collection<ControlFlowUtil.VariableInfo> getInitializedTwice(int start)
{
	return ControlFlowUtil.getInitializedTwice(myControlFlow, start, myControlFlow.getSize());
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:5,代碼來源:ControlFlowWrapper.java


注:本文中的com.intellij.psi.controlFlow.ControlFlowUtil.VariableInfo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。