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


Java Instruction类代码示例

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


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

示例1: MyGraph

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
private MyGraph(@NotNull ControlFlow flow) {
  myFlow = flow;
  myInstructions = flow.getInstructions();
  for (Instruction instruction : myInstructions) {
    int fromIndex = instruction.getIndex();
    int[] to = next(fromIndex, myInstructions);
    for (int toIndex : to) {
      int[] froms = myIns.get(toIndex);
      if (froms == null) {
        froms = new int[]{fromIndex};
        myIns.put(toIndex, froms);
      }
      else {
        froms = ArrayUtil.append(froms, fromIndex);
        myIns.put(toIndex, froms);
      }
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:LoopAnalyzer.java

示例2: calcInLoop

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
static int[] calcInLoop(ControlFlow controlFlow) {
  final int[] loop = new int[controlFlow.getInstructionCount()]; // loop[i] = loop number(strongly connected component number) of i-th instruction or 0 if outside loop

  MyGraph graph = new MyGraph(controlFlow);
  final DFSTBuilder<Instruction> builder = new DFSTBuilder<Instruction>(graph);
  TIntArrayList sccs = builder.getSCCs();
  sccs.forEach(new TIntProcedure() {
    private int myTNumber;
    private int component;

    @Override
    public boolean execute(int size) {
      int value = size > 1 ? ++component : 0;
      for (int i = 0; i < size; i++) {
        Instruction instruction = builder.getNodeByTNumber(myTNumber + i);
        loop[instruction.getIndex()] = value;
      }
      myTNumber += size;
      return true;
    }
  });

  return loop;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:LoopAnalyzer.java

示例3: next

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
@NotNull
private static int[] next(int i, Instruction[] myInstructions) {
  Instruction instruction = myInstructions[i];
  if (instruction instanceof GotoInstruction) {
    return new int[]{((GotoInstruction)instruction).getOffset()};
  }
  if (instruction instanceof ReturnInstruction) {
    return ArrayUtil.EMPTY_INT_ARRAY;
  }
  if (instruction instanceof ConditionalGotoInstruction) {
    int offset = ((ConditionalGotoInstruction)instruction).getOffset();
    if (offset != i+1) {
      return new int[]{i + 1, offset};
    }
  }
  return i == myInstructions.length-1 ? ArrayUtil.EMPTY_INT_ARRAY : new int[]{i + 1};
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:LoopAnalyzer.java

示例4: isNullInferred

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
private boolean isNullInferred(String exprText, boolean trueSet) {
  final PsiCodeBlock block = myElementFactory.createCodeBlockFromText("{}", myElements[0]);
  for (PsiElement element : myElements) {
    block.add(element);
  }
  final PsiIfStatement statementFromText = (PsiIfStatement)myElementFactory.createStatementFromText("if (" + exprText + " == null);", null);
  block.add(statementFromText);

  final StandardDataFlowRunner dfaRunner = new StandardDataFlowRunner();
  final StandardInstructionVisitor visitor = new StandardInstructionVisitor();
  final RunnerResult rc = dfaRunner.analyzeMethod(block, visitor);
  if (rc == RunnerResult.OK) {
    final Pair<Set<Instruction>, Set<Instruction>> expressions = dfaRunner.getConstConditionalExpressions();
    final Set<Instruction> set = trueSet ? expressions.getFirst() : expressions.getSecond();
    for (Instruction instruction : set) {
      if (instruction instanceof BranchingInstruction) {
        if (((BranchingInstruction)instruction).getPsiAnchor().getText().equals(statementFromText.getCondition().getText())) {
          return true;
        }
      }
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:ExtractMethodProcessor.java

示例5: acceptInstruction

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
@NotNull
protected DfaInstructionState[] acceptInstruction(@NotNull InstructionVisitor visitor, @NotNull DfaInstructionState instructionState)
{
	Instruction instruction = instructionState.getInstruction();
	DfaInstructionState[] states = instruction.accept(this, instructionState.getMemoryState(), visitor);

	PsiElement closure = DfaUtil.getClosureInside(instruction);
	if(closure instanceof PsiClass)
	{
		registerNestedClosures(instructionState, (PsiClass) closure);
	}
	else if(closure instanceof PsiLambdaExpression)
	{
		registerNestedClosures(instructionState, (PsiLambdaExpression) closure);
	}

	return states;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:DataFlowRunner.java

示例6: getReadVariables

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
@NotNull
private List<DfaVariableValue> getReadVariables(Instruction instruction)
{
	if(instruction instanceof PushInstruction && !((PushInstruction) instruction).isReferenceWrite())
	{
		DfaValue value = ((PushInstruction) instruction).getValue();
		if(value instanceof DfaVariableValue)
		{
			return Collections.singletonList((DfaVariableValue) value);
		}
	}
	else
	{
		PsiElement closure = DfaUtil.getClosureInside(instruction);
		if(closure != null)
		{
			return myClosureReads.get(closure);
		}
	}
	return Collections.emptyList();
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:LiveVariablesAnalyzer.java

示例7: MyGraph

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
private MyGraph(@NotNull ControlFlow flow)
{
	myFlow = flow;
	myInstructions = flow.getInstructions();
	for(Instruction instruction : myInstructions)
	{
		int fromIndex = instruction.getIndex();
		int[] to = getSuccessorIndices(fromIndex, myInstructions);
		for(int toIndex : to)
		{
			int[] froms = myIns.get(toIndex);
			if(froms == null)
			{
				froms = new int[]{fromIndex};
				myIns.put(toIndex, froms);
			}
			else
			{
				froms = ArrayUtil.append(froms, fromIndex);
				myIns.put(toIndex, froms);
			}
		}
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:25,代码来源:LoopAnalyzer.java

示例8: getSuccessorIndices

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
@NotNull
static int[] getSuccessorIndices(int i, Instruction[] myInstructions)
{
	Instruction instruction = myInstructions[i];
	if(instruction instanceof GotoInstruction)
	{
		return new int[]{((GotoInstruction) instruction).getOffset()};
	}
	if(instruction instanceof ControlTransferInstruction)
	{
		return ArrayUtil.toIntArray(((ControlTransferInstruction) instruction).getPossibleTargetIndices());
	}
	if(instruction instanceof ConditionalGotoInstruction)
	{
		int offset = ((ConditionalGotoInstruction) instruction).getOffset();
		if(offset != i + 1)
		{
			return new int[]{
					i + 1,
					offset
			};
		}
	}
	return i == myInstructions.length - 1 ? ArrayUtil.EMPTY_INT_ARRAY : new int[]{i + 1};
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:26,代码来源:LoopAnalyzer.java

示例9: reportConstantPushes

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
private void reportConstantPushes(StandardDataFlowRunner runner, ProblemsHolder holder, DataFlowInstructionVisitor visitor, Set<PsiElement> reportedAnchors)
{
	for(Instruction instruction : runner.getInstructions())
	{
		if(instruction instanceof PushInstruction)
		{
			PsiExpression place = ((PushInstruction) instruction).getPlace();
			DfaValue value = ((PushInstruction) instruction).getValue();
			Object constant = value instanceof DfaConstValue ? ((DfaConstValue) value).getValue() : null;
			if(place instanceof PsiPolyadicExpression && constant instanceof Boolean && !isFlagCheck(place) && reportedAnchors.add(place))
			{
				reportConstantCondition(holder, visitor, place, (Boolean) constant);
			}
		}
	}
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:17,代码来源:DataFlowInspectionBase.java

示例10: toString

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
public String toString() {
  StringBuilder result = new StringBuilder();
  final List<Instruction> instructions = myInstructions;

  for (int i = 0; i < instructions.size(); i++) {
    Instruction instruction = instructions.get(i);
    result.append(Integer.toString(i)).append(": ").append(instruction.toString());
    result.append("\n");
  }
  return result.toString();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:ControlFlow.java

示例11: acceptInstruction

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的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

示例12: indicesToInstructions

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
@NotNull
private Iterator<Instruction> indicesToInstructions(int[] next) {
  if (next == null) return EmptyIterator.getInstance();
  List<Instruction> out = new ArrayList<Instruction>(next.length);
  for (int i : next) {
    out.add(myInstructions[i]);
  }
  return out.iterator();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:LoopAnalyzer.java

示例13: problemsDetected

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
public boolean problemsDetected(StandardInstructionVisitor visitor) {
  final Pair<Set<Instruction>, Set<Instruction>> constConditions = getConstConditionalExpressions();
  return !constConditions.getFirst().isEmpty()
         || !constConditions.getSecond().isEmpty()
         || !myNPEInstructions.isEmpty()
         || !myCCEInstructions.isEmpty()
         || !getRedundantInstanceofs(this, visitor).isEmpty()
         || !myNullableArguments.isEmpty()
         || !myNullableArgumentsPassedToNonAnnotatedParam.isEmpty()
         || !myNullableAssignments.isEmpty()
         || !myNullableReturns.isEmpty()
         || !myUnboxedNullables.isEmpty();
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:14,代码来源:StandardDataFlowRunner.java

示例14: getRedundantInstanceofs

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
@NotNull public static Set<Instruction> getRedundantInstanceofs(final DataFlowRunner runner, StandardInstructionVisitor visitor) {
  HashSet<Instruction> result = new HashSet<Instruction>(1);
  for (Instruction instruction : runner.getInstructions()) {
    if (instruction instanceof InstanceofInstruction && visitor.isInstanceofRedundant((InstanceofInstruction)instruction)) {
      result.add(instruction);
    }
  }

  return result;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:11,代码来源:StandardDataFlowRunner.java

示例15: visitAssign

import com.intellij.codeInspection.dataFlow.instructions.Instruction; //导入依赖的package包/类
@Override
public DfaInstructionState[] visitAssign(AssignInstruction instruction, DataFlowRunner runner, DfaMemoryState memState) {
  final Instruction nextInstruction = runner.getInstruction(instruction.getIndex() + 1);

  final DfaValue dfaSource = memState.pop();
  final DfaValue dfaDest = memState.pop();

  if (dfaDest instanceof DfaVariableValue) {
    DfaVariableValue var = (DfaVariableValue)dfaDest;
    final PsiExpression rightValue = instruction.getRExpression();
    final PsiElement parent = rightValue == null ? null : rightValue.getParent();
    final IElementType type = parent instanceof PsiAssignmentExpression
                              ? ((PsiAssignmentExpression)parent).getOperationTokenType() : JavaTokenType.EQ;
    // store current value - to use in case of '+='
    final PsiExpression prevValue = ((ValuableDataFlowRunner.ValuableDfaVariableState)((ValuableDataFlowRunner.MyDfaMemoryState)memState).getVariableState(var)).myExpression;
    memState.setVarValue(var, dfaSource);
    // state may have been changed so re-retrieve it
    final ValuableDataFlowRunner.ValuableDfaVariableState curState = (ValuableDataFlowRunner.ValuableDfaVariableState)((ValuableDataFlowRunner.MyDfaMemoryState)memState).getVariableState(var);
    final PsiExpression curValue = curState.myExpression;
    final PsiExpression nextValue;
    if (type == JavaTokenType.PLUSEQ && prevValue != null) {
      PsiExpression tmpExpression;
      try {
        tmpExpression = JavaPsiFacade.getElementFactory(myContext.getProject())
          .createExpressionFromText(prevValue.getText() + "+" + rightValue.getText(), rightValue);
      }
      catch (Exception e) {
        tmpExpression = curValue == null ? rightValue : curValue;
      }
      nextValue = tmpExpression;
    }
    else {
      nextValue = curValue == null ? rightValue : curValue;
    }
    curState.myExpression = nextValue;
  }
  memState.push(dfaDest);
  return new DfaInstructionState[]{new DfaInstructionState(nextInstruction, memState)};
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:40,代码来源:DfaUtil.java


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