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