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


Java DfaValue類代碼示例

本文整理匯總了Java中com.intellij.codeInspection.dataFlow.value.DfaValue的典型用法代碼示例。如果您正苦於以下問題:Java DfaValue類的具體用法?Java DfaValue怎麽用?Java DfaValue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


DfaValue類屬於com.intellij.codeInspection.dataFlow.value包,在下文中一共展示了DfaValue類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: create

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
@Nullable
@Override
protected List<DfaVariableValue> create(PsiElement closure) {
  final Set<DfaVariableValue> result = ContainerUtil.newLinkedHashSet();
  closure.accept(new PsiRecursiveElementWalkingVisitor() {
    @Override
    public void visitElement(PsiElement element) {
      if (element instanceof PsiReferenceExpression) {
        DfaValue value = myFactory.createValue((PsiReferenceExpression)element);
        if (value instanceof DfaVariableValue) {
          result.add((DfaVariableValue)value);
        }
      }
      super.visitElement(element);
    }
  });
  return ContainerUtil.newArrayList(result);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:LiveVariablesAnalyzer.java

示例2: MethodCallInstruction

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
public MethodCallInstruction(@NotNull PsiCallExpression call, @Nullable DfaValue precalculatedReturnValue, List<MethodContract> contracts) {
  myContext = call;
  myContracts = contracts;
  myMethodType = MethodType.REGULAR_METHOD_CALL;
  myCall = call;
  final PsiExpressionList argList = call.getArgumentList();
  myArgs = argList != null ? argList.getExpressions() : PsiExpression.EMPTY_ARRAY;
  myType = myCall.getType();

  JavaResolveResult result = call.resolveMethodGenerics();
  myTargetMethod = (PsiMethod)result.getElement();

  PsiSubstitutor substitutor = result.getSubstitutor();
  if (argList != null && myTargetMethod != null) {
    PsiParameter[] parameters = myTargetMethod.getParameterList().getParameters();
    myVarArgCall = isVarArgCall(myTargetMethod, substitutor, myArgs, parameters);
    myArgRequiredNullability = calcArgRequiredNullability(substitutor, parameters);
  } else {
    myVarArgCall = false;
    myArgRequiredNullability = Collections.emptyMap();
  }

  myShouldFlushFields = !(call instanceof PsiNewExpression && myType != null && myType.getArrayDimensions() > 0) && !isPureCall();
  myPrecalculatedReturnValue = precalculatedReturnValue;
  myOfNullable = call instanceof PsiMethodCallExpression && DfaOptionalSupport.resolveOfNullable((PsiMethodCallExpression)call) != null;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:27,代碼來源:MethodCallInstruction.java

示例3: accept

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
@Override
public DfaInstructionState[] accept(DataFlowRunner runner, DfaMemoryState memState, InstructionVisitor visitor) {
  if (myDuplicationCount == 1 && myValueCount == 1) {
    memState.push(memState.peek());
  } else {
    List<DfaValue> values = new ArrayList<DfaValue>(myValueCount);
    for (int i = 0; i < myValueCount; i++) {
      values.add(memState.pop());
    }
    for (int j = 0; j < myDuplicationCount + 1; j++) {
      for (int i = values.size() - 1; i >= 0; i--) {
        memState.push(values.get(i));
      }
    }
  }
  Instruction nextInstruction = runner.getInstruction(getIndex() + 1);
  return new DfaInstructionState[]{new DfaInstructionState(nextInstruction, memState)};
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:19,代碼來源:DupInstruction.java

示例4: checkNotNullable

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
@Override
protected boolean checkNotNullable(DfaMemoryState state, DfaValue value, NullabilityProblem problem, PsiElement anchor) {
  boolean ok = super.checkNotNullable(state, value, problem, anchor);
  if (!ok && anchor != null) {
    myProblems.putValue(problem, anchor);
  }
  Pair<NullabilityProblem, PsiElement> key = Pair.create(problem, anchor);
  StateInfo info = myStateInfos.get(key);
  if (info == null) {
    myStateInfos.put(key, info = new StateInfo());
  }
  if (state.isEphemeral() && !ok) {
    info.ephemeralNpe = true;
  } else if (!state.isEphemeral()) {
    if (ok) info.normalOk = true;
    else info.normalNpe = true;
  }
  return ok;
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:20,代碼來源:DataFlowInspectionBase.java

示例5: visitPush

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
@Override
public DfaInstructionState[] visitPush(PushInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
  if (myContext == instruction.getPlace()) {
    final Map<DfaVariableValue,DfaVariableState> map = ((ValuableDataFlowRunner.MyDfaMemoryState)memState).getVariableStates();
    for (Map.Entry<DfaVariableValue, DfaVariableState> entry : map.entrySet()) {
      ValuableDataFlowRunner.ValuableDfaVariableState state = (ValuableDataFlowRunner.ValuableDfaVariableState)entry.getValue();
      DfaVariableValue variableValue = entry.getKey();
      final PsiExpression psiExpression = state.myExpression;
      if (psiExpression != null && variableValue.getQualifier() == null) {
        myValues.put(variableValue.getPsiVariable(), psiExpression);
      }
    }
    DfaValue value = instruction.getValue();
    if (value instanceof DfaVariableValue && ((DfaVariableValue)value).getQualifier() == null) {
      if (memState.isNotNull((DfaVariableValue)value)) {
        myNotNulls.add(((DfaVariableValue)value).getPsiVariable());
      }
      if (memState.isNull(value)) {
        myNulls.add(((DfaVariableValue)value).getPsiVariable());
      }
    }
  }
  return super.visitPush(instruction, runner, memState);
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:25,代碼來源:DfaUtil.java

示例6: accept

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
@Override
public DfaInstructionState[] accept(DataFlowRunner runner, DfaMemoryState memState, InstructionVisitor visitor) {
  if (myDuplicationCount == 1 && myValueCount == 1) {
    memState.push(memState.peek());
  } else {
    List<DfaValue> values = new ArrayList<DfaValue>(myValueCount);
    for (int i = 0; i < myValueCount; i++) {
      values.add(memState.pop());
    }
    for (int j = 0; j < myDuplicationCount; j++) {
      for (int i = values.size() - 1; i >= 0; i--) {
        memState.push(values.get(i));
      }
    }
  }
  Instruction nextInstruction = runner.getInstruction(getIndex() + 1);
  return new DfaInstructionState[]{new DfaInstructionState(nextInstruction, memState)};
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:19,代碼來源:DupInstruction.java

示例7: visitArrayAccessExpression

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
@Override
public void visitArrayAccessExpression(PsiArrayAccessExpression expression)
{
	startElement(expression);
	PsiExpression arrayExpression = expression.getArrayExpression();
	arrayExpression.accept(this);

	PsiExpression indexExpression = expression.getIndexExpression();
	if(indexExpression != null)
	{
		indexExpression.accept(this);
		generateBoxingUnboxingInstructionFor(indexExpression, PsiType.INT);
	}
	else
	{
		addInstruction(new PushInstruction(DfaUnknownValue.getInstance(), null));
	}

	DfaValue toPush = myFactory.createValue(expression);
	if(toPush == null)
	{
		toPush = myFactory.createTypeValue(expression.getType(), Nullness.UNKNOWN);
	}
	addInstruction(new ArrayAccessInstruction(toPush, expression));
	finishElement(expression);
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:27,代碼來源:ControlFlowAnalyzer.java

示例8: getVariables

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
List<DfaVariableValue> getVariables(boolean unwrap)
{
	List<DfaVariableValue> vars = ContainerUtil.newArrayList();
	for(DfaValue value : getMemberValues())
	{
		if(unwrap)
		{
			value = DfaMemoryStateImpl.unwrap(value);
		}
		if(value instanceof DfaVariableValue)
		{
			vars.add((DfaVariableValue) value);
		}
	}
	return vars;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:17,代碼來源:EqClass.java

示例9: fromDfaValue

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
@Nullable
@Override
Boolean fromDfaValue(DfaValue value)
{
	if(value instanceof DfaConstValue)
	{
		return ((DfaConstValue) value).getValue() == null;
	}
	if(value instanceof DfaBoxedValue || value instanceof DfaUnboxedValue || value instanceof DfaRangeValue)
	{
		return false;
	}
	if(value instanceof DfaTypeValue)
	{
		return NullnessUtil.toBoolean(((DfaTypeValue) value).getNullness());
	}
	return null;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:19,代碼來源:DfaFactType.java

示例10: allCaughtTypes

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
@NotNull
private List<DfaTypeValue> allCaughtTypes(PsiParameter param)
{
	List<PsiType> psiTypes;
	PsiType type = param.getType();
	if(type instanceof PsiDisjunctionType)
	{
		psiTypes = ((PsiDisjunctionType) type).getDisjunctions();
	}
	else
	{
		psiTypes = Collections.singletonList(type);
	}
	List<DfaValue> result = psiTypes.stream().map(it -> myRunner.getFactory().createTypeValue(it, Nullness.NOT_NULL)).collect(Collectors.toList());
	return ContainerUtil.<DfaValue, DfaTypeValue>mapNotNull(result, dfaValue -> dfaValue instanceof DfaTypeValue ? (DfaTypeValue) dfaValue : null);
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:17,代碼來源:ControlTransferHandler.java

示例11: stringEquals

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
private static List<DfaMemoryState> stringEquals(DfaCallArguments args, DfaMemoryState memState, DfaValueFactory factory, boolean ignoreCase)
{
	DfaValue arg = ArrayUtil.getFirstElement(args.myArguments);
	if(arg == null)
	{
		return Collections.emptyList();
	}
	String leftConst = ObjectUtils.tryCast(getConstantValue(memState, args.myQualifier), String.class);
	String rightConst = ObjectUtils.tryCast(getConstantValue(memState, arg), String.class);
	if(leftConst != null && rightConst != null)
	{
		return singleResult(memState, factory.getBoolean(ignoreCase ? leftConst.equalsIgnoreCase(rightConst) : leftConst.equals(rightConst)));
	}
	DfaValue leftLength = SpecialField.STRING_LENGTH.createValue(factory, args.myQualifier);
	DfaValue rightLength = SpecialField.STRING_LENGTH.createValue(factory, arg);
	DfaValue trueRelation = factory.createCondition(leftLength, RelationType.EQ, rightLength);
	DfaValue falseRelation = factory.createCondition(leftLength, RelationType.NE, rightLength);
	return applyCondition(memState, trueRelation, DfaUnknownValue.getInstance(), falseRelation, factory.getBoolean(false));
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:20,代碼來源:CustomMethodHandlers.java

示例12: mathMinMax

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
private static List<DfaMemoryState> mathMinMax(DfaValue[] args, DfaMemoryState memState, DfaValueFactory factory, boolean max)
{
	if(args == null || args.length != 2)
	{
		return Collections.emptyList();
	}
	LongRangeSet first = memState.getValueFact(DfaFactType.RANGE, args[0]);
	LongRangeSet second = memState.getValueFact(DfaFactType.RANGE, args[1]);
	if(first == null || second == null || first.isEmpty() || second.isEmpty())
	{
		return Collections.emptyList();
	}
	LongRangeSet domain = max ? LongRangeSet.range(Math.max(first.min(), second.min()), Long.MAX_VALUE) : LongRangeSet.range(Long.MIN_VALUE, Math.min(first.max(), second.max()));
	LongRangeSet result = first.union(second).intersect(domain);
	return singleResult(memState, factory.getRangeFactory().create(result));
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:17,代碼來源:CustomMethodHandlers.java

示例13: applyCondition

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
@NotNull
private static List<DfaMemoryState> applyCondition(DfaMemoryState memState, DfaValue trueCondition, DfaValue trueResult, DfaValue falseCondition, DfaValue falseResult)
{
	DfaMemoryState falseState = memState.createCopy();
	List<DfaMemoryState> result = new ArrayList<>(2);
	if(memState.applyCondition(trueCondition))
	{
		memState.push(trueResult);
		result.add(memState);
	}
	if(falseState.applyCondition(falseCondition))
	{
		falseState.push(falseResult);
		result.add(falseState);
	}
	return result;
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:18,代碼來源:CustomMethodHandlers.java

示例14: getDfaReturnValue

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
/**
 * Returns DfaValue describing the return value of this contract
 *
 * @param factory       factory to create values
 * @param defaultResult default result value for the called method
 * @return a DfaValue describing the return value of this contract
 */
@NotNull
DfaValue getDfaReturnValue(DfaValueFactory factory, DfaValue defaultResult)
{
	switch(getReturnValue())
	{
		case NULL_VALUE:
			return factory.getConstFactory().getNull();
		case NOT_NULL_VALUE:
			return defaultResult instanceof DfaTypeValue ? ((DfaTypeValue) defaultResult).withNullness(Nullness.NOT_NULL) : DfaUnknownValue.getInstance();
		case TRUE_VALUE:
			return factory.getConstFactory().getTrue();
		case FALSE_VALUE:
			return factory.getConstFactory().getFalse();
		case THROW_EXCEPTION:
			return factory.getConstFactory().getContractFail();
		default:
			return defaultResult;
	}
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:27,代碼來源:MethodContract.java

示例15: breaksContract

import com.intellij.codeInspection.dataFlow.value.DfaValue; //導入依賴的package包/類
private boolean breaksContract(DfaValue retValue, MethodContract.ValueConstraint constraint, DfaMemoryState state)
{
	switch(constraint)
	{
		case NULL_VALUE:
			return state.isNotNull(retValue);
		case NOT_NULL_VALUE:
			return state.isNull(retValue);
		case TRUE_VALUE:
			return isEquivalentTo(retValue, getFactory().getConstFactory().getFalse(), state);
		case FALSE_VALUE:
			return isEquivalentTo(retValue, getFactory().getConstFactory().getTrue(), state);
		case THROW_EXCEPTION:
			return true;
		default:
			return false;
	}
}
 
開發者ID:consulo,項目名稱:consulo-java,代碼行數:19,代碼來源:ContractChecker.java


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