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


Java MethodCallInstruction类代码示例

本文整理汇总了Java中com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction的典型用法代码示例。如果您正苦于以下问题:Java MethodCallInstruction类的具体用法?Java MethodCallInstruction怎么用?Java MethodCallInstruction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MethodCallInstruction类属于com.intellij.codeInspection.dataFlow.instructions包,在下文中一共展示了MethodCallInstruction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reportOptionalOfNullableImprovements

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
private static void reportOptionalOfNullableImprovements(ProblemsHolder holder, Set<PsiElement> reportedAnchors, Map<MethodCallInstruction, ThreeState> nullArgs)
{
	nullArgs.forEach((call, nullArg) ->
	{
		PsiElement arg = call.getArgumentAnchor(0);
		if(reportedAnchors.add(arg))
		{
			switch(nullArg)
			{
				case YES:
					holder.registerProblem(arg, "Passing <code>null</code> argument to <code>Optional</code>", DfaOptionalSupport.createReplaceOptionalOfNullableWithEmptyFix(arg));
					break;
				case NO:
					holder.registerProblem(arg, "Passing a non-null argument to <code>Optional</code>", DfaOptionalSupport.createReplaceOptionalOfNullableWithOfFix(arg));
					break;
				default:
			}
		}
	});
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:21,代码来源:DataFlowInspectionBase.java

示例2: acceptInstruction

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
@Override
protected DfaInstructionState[] acceptInstruction(InstructionVisitor visitor, DfaInstructionState instructionState) {
  DfaMemoryState memState = instructionState.getMemoryState();
  if (memState.isEphemeral()) {
    return DfaInstructionState.EMPTY_ARRAY;
  }
  Instruction instruction = instructionState.getInstruction();
  if (instruction instanceof CheckReturnValueInstruction) {
    PsiElement anchor = ((CheckReturnValueInstruction)instruction).getReturn();
    DfaValue retValue = memState.pop();
    if (breaksContract(retValue, myContract.returnValue, memState)) {
      myViolations.add(anchor);
    } else {
      myNonViolations.add(anchor);
    }
    return InstructionVisitor.nextInstruction(instruction, this, memState);

  }

  if (instruction instanceof ReturnInstruction) {
    if (((ReturnInstruction)instruction).isViaException() && myContract.returnValue != MethodContract.ValueConstraint.NOT_NULL_VALUE) {
      ContainerUtil.addIfNotNull(myFailures, ((ReturnInstruction)instruction).getAnchor());
    }
  }

  if (instruction instanceof MethodCallInstruction &&
      ((MethodCallInstruction)instruction).getMethodType() == MethodCallInstruction.MethodType.REGULAR_METHOD_CALL &&
      myContract.returnValue == MethodContract.ValueConstraint.THROW_EXCEPTION) {
    ContainerUtil.addIfNotNull(myFailures, ((MethodCallInstruction)instruction).getCallExpression());
    return DfaInstructionState.EMPTY_ARRAY;
  }

  return super.acceptInstruction(visitor, instructionState);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:ContractChecker.java

示例3: visitMethodCall

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
@Override
public DfaInstructionState[] visitMethodCall(MethodCallInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
  if (myForPlace == instruction.getCallExpression()) {
    addToResult(((ExpressionTypeMemoryState)memState).getStates());
  }
  return super.visitMethodCall(instruction, runner, memState);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:GuessManagerImpl.java

示例4: find

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
public static CustomMethodHandler find(MethodCallInstruction instruction)
{
	PsiElement context = instruction.getContext();
	if(context instanceof PsiMethodCallExpression)
	{
		return CUSTOM_METHOD_HANDLERS.mapFirst((PsiMethodCallExpression) context);
	}
	else if(context instanceof PsiMethodReferenceExpression)
	{
		return CUSTOM_METHOD_HANDLERS.mapFirst((PsiMethodReferenceExpression) context);
	}
	return null;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:14,代码来源:CustomMethodHandlers.java

示例5: visitMethodCall

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
@Override
public DfaInstructionState[] visitMethodCall(MethodCallInstruction instruction, DataFlowRunner runner, DfaMemoryState memState)
{
	PsiMethodCallExpression call = ObjectUtils.tryCast(instruction.getCallExpression(), PsiMethodCallExpression.class);
	if(call != null)
	{
		String methodName = call.getMethodExpression().getReferenceName();
		PsiExpression qualifier = PsiUtil.skipParenthesizedExprDown(call.getMethodExpression().getQualifierExpression());
		if(qualifier != null && TypeUtils.isOptional(qualifier.getType()))
		{
			if("isPresent".equals(methodName) && qualifier instanceof PsiMethodCallExpression)
			{
				myOptionalQualifiers.add(qualifier);
			}
			else if(DfaOptionalSupport.isOptionalGetMethodName(methodName))
			{
				Boolean fact = memState.getValueFact(DfaFactType.OPTIONAL_PRESENCE, memState.peek());
				ThreeState state = fact == null ? ThreeState.UNSURE : ThreeState.fromBoolean(fact);
				myOptionalCalls.merge(call, state, ThreeState::merge);
			}
		}
	}
	if(instruction.matches(DfaOptionalSupport.OPTIONAL_OF_NULLABLE))
	{
		DfaValue arg = memState.peek();
		ThreeState nullArg = memState.isNull(arg) ? ThreeState.YES : memState.isNotNull(arg) ? ThreeState.NO : ThreeState.UNSURE;
		myOfNullableCalls.merge(instruction, nullArg, ThreeState::merge);
	}
	DfaInstructionState[] states = super.visitMethodCall(instruction, runner, memState);
	if(hasNonTrivialFailingContracts(instruction))
	{
		DfaConstValue fail = runner.getFactory().getConstFactory().getContractFail();
		boolean allFail = Arrays.stream(states).allMatch(s -> s.getMemoryState().peek() == fail);
		myFailingCalls.merge(instruction, allFail, Boolean::logicalAnd);
	}
	handleBooleanCalls(instruction, states);
	return states;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:39,代码来源:DataFlowInspectionBase.java

示例6: handleBooleanCalls

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
void handleBooleanCalls(MethodCallInstruction instruction, DfaInstructionState[] states)
{
	if(!hasNonTrivialBooleanContracts(instruction))
	{
		return;
	}
	PsiMethod method = instruction.getTargetMethod();
	if(method == null || !ControlFlowAnalyzer.isPure(method))
	{
		return;
	}
	PsiMethodCallExpression call = ObjectUtils.tryCast(instruction.getCallExpression(), PsiMethodCallExpression.class);
	if(call == null || myBooleanCalls.get(call) == ThreeState.UNSURE)
	{
		return;
	}
	PsiElement parent = call.getParent();
	if(parent instanceof PsiExpressionStatement)
	{
		return;
	}
	if(parent instanceof PsiLambdaExpression && PsiType.VOID.equals(LambdaUtil.getFunctionalInterfaceReturnType((PsiLambdaExpression) parent)))
	{
		return;
	}
	for(DfaInstructionState s : states)
	{
		DfaValue val = s.getMemoryState().peek();
		ThreeState state = ThreeState.UNSURE;
		if(val instanceof DfaConstValue)
		{
			Object value = ((DfaConstValue) val).getValue();
			if(value instanceof Boolean)
			{
				state = ThreeState.fromBoolean((Boolean) value);
			}
		}
		myBooleanCalls.merge(call, state, ThreeState::merge);
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:41,代码来源:DataFlowInspectionBase.java

示例7: hasNonTrivialBooleanContracts

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
private static boolean hasNonTrivialBooleanContracts(MethodCallInstruction instruction)
{
	if(CustomMethodHandlers.find(instruction) != null)
	{
		return true;
	}
	List<MethodContract> contracts = instruction.getContracts();
	return !contracts.isEmpty() && contracts.stream().anyMatch(contract -> (contract.getReturnValue() == MethodContract.ValueConstraint.FALSE_VALUE || contract.getReturnValue() ==
			MethodContract.ValueConstraint.TRUE_VALUE) && !contract.isTrivial());
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:11,代码来源:DataFlowInspectionBase.java

示例8: toContracts

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
@NotNull
@Override
public List<StandardMethodContract> toContracts(PsiMethod method, Supplier<PsiCodeBlock> body)
{
	PsiMethodCallExpression call = ObjectUtil.tryCast(expression.restoreExpression(body.get()), PsiMethodCallExpression.class);
	if(call == null)
	{
		return Collections.emptyList();
	}

	JavaResolveResult result = call.resolveMethodGenerics();
	PsiMethod targetMethod = ObjectUtil.tryCast(result.getElement(), PsiMethod.class);
	if(targetMethod == null)
	{
		return Collections.emptyList();
	}
	PsiParameter[] parameters = targetMethod.getParameterList().getParameters();
	PsiExpression[] arguments = call.getArgumentList().getExpressions();
	boolean varArgCall = MethodCallInstruction.isVarArgCall(targetMethod, result.getSubstitutor(), arguments, parameters);


	List<StandardMethodContract> fromDelegate = ContainerUtil.mapNotNull(ControlFlowAnalyzer.getMethodContracts(targetMethod), dc -> convertDelegatedMethodContract(method, parameters, arguments,
			varArgCall, dc));

	if(NullableNotNullManager.isNotNull(targetMethod))
	{
		return ContainerUtil.concat(ContainerUtil.map(fromDelegate, DelegationContract::returnNotNull), Collections.singletonList(new StandardMethodContract(emptyConstraints(method),
				MethodContract.ValueConstraint.NOT_NULL_VALUE)));
	}
	return fromDelegate;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:32,代码来源:DelegationContract.java

示例9: visitMethodCall

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
@Override
public DfaInstructionState[] visitMethodCall(MethodCallInstruction instruction, DataFlowRunner runner, DfaMemoryState memState)
{
	if(myForPlace == instruction.getCallExpression())
	{
		addToResult(((ExpressionTypeMemoryState) memState).getStates());
	}
	return super.visitMethodCall(instruction, runner, memState);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:10,代码来源:GuessManagerImpl.java

示例10: isVarArgCall

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
/**
 * Returns true if given method call is a var-arg call
 *
 * @param call a call to test
 * @return true if call is resolved to the var-arg method and var-arg form is actually used
 */
public static boolean isVarArgCall(PsiMethodCallExpression call)
{
	JavaResolveResult result = call.resolveMethodGenerics();
	PsiMethod method = tryCast(result.getElement(), PsiMethod.class);
	if(method == null || !method.isVarArgs())
	{
		return false;
	}
	PsiSubstitutor substitutor = result.getSubstitutor();
	return MethodCallInstruction.isVarArgCall(method, substitutor, call.getArgumentList().getExpressions(), method.getParameterList().getParameters());
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:18,代码来源:MethodCallUtils.java

示例11: visitMethodCall

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
@Override
public DfaInstructionState[] visitMethodCall(MethodCallInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
  checkEnvironment(runner, memState, instruction.getCallExpression());
  return super.visitMethodCall(instruction, runner, memState);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:6,代码来源:DataFlowRunner.java

示例12: acceptInstruction

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
@NotNull
@Override
protected DfaInstructionState[] acceptInstruction(@NotNull InstructionVisitor visitor, @NotNull DfaInstructionState instructionState)
{
	DfaMemoryState memState = instructionState.getMemoryState();
	if(memState.isEphemeral())
	{
		return DfaInstructionState.EMPTY_ARRAY;
	}
	Instruction instruction = instructionState.getInstruction();
	if(instruction instanceof CheckReturnValueInstruction)
	{
		PsiElement anchor = ((CheckReturnValueInstruction) instruction).getReturn();
		DfaValue retValue = memState.pop();
		if(breaksContract(retValue, myContract.returnValue, memState))
		{
			myViolations.add(anchor);
		}
		else
		{
			myNonViolations.add(anchor);
		}
		return InstructionVisitor.nextInstruction(instruction, this, memState);

	}

	if(instruction instanceof ReturnInstruction)
	{
		if(((ReturnInstruction) instruction).isViaException() && myContract.returnValue != MethodContract.ValueConstraint.NOT_NULL_VALUE)
		{
			ContainerUtil.addIfNotNull(myFailures, ((ReturnInstruction) instruction).getAnchor());
		}
	}

	if(instruction instanceof MethodCallInstruction && ((MethodCallInstruction) instruction).getMethodType() == MethodCallInstruction.MethodType.REGULAR_METHOD_CALL && myContract.returnValue ==
			MethodContract.ValueConstraint.THROW_EXCEPTION)
	{
		ContainerUtil.addIfNotNull(myFailures, ((MethodCallInstruction) instruction).getCallExpression());
		return DfaInstructionState.EMPTY_ARRAY;
	}

	if(instruction instanceof ConditionalGotoInstruction && memState.peek() == DfaUnknownValue.getInstance())
	{
		return DfaInstructionState.EMPTY_ARRAY;
	}

	return super.acceptInstruction(visitor, instructionState);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:49,代码来源:ContractChecker.java

示例13: getOfNullableCalls

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
Map<MethodCallInstruction, ThreeState> getOfNullableCalls()
{
	return myOfNullableCalls;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:5,代码来源:DataFlowInspectionBase.java

示例14: getAlwaysFailingCalls

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
Collection<PsiCall> getAlwaysFailingCalls()
{
	return StreamEx.ofKeys(myFailingCalls, v -> v).map(MethodCallInstruction::getCallExpression).toList();
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:5,代码来源:DataFlowInspectionBase.java

示例15: hasNonTrivialFailingContracts

import com.intellij.codeInspection.dataFlow.instructions.MethodCallInstruction; //导入依赖的package包/类
private static boolean hasNonTrivialFailingContracts(MethodCallInstruction instruction)
{
	List<MethodContract> contracts = instruction.getContracts();
	return !contracts.isEmpty() && contracts.stream().anyMatch(contract -> contract.getReturnValue() == MethodContract.ValueConstraint.THROW_EXCEPTION && !contract.isTrivial());
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:6,代码来源:DataFlowInspectionBase.java


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