当前位置: 首页>>代码示例>>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;未经允许,请勿转载。