use of com.intellij.codeInspection.dataFlow.instructions.Instruction in project intellij-community by JetBrains.
the class ControlFlow method toString.
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();
}
use of com.intellij.codeInspection.dataFlow.instructions.Instruction in project intellij-community by JetBrains.
the class ExtractMethodProcessor method isNullInferred.
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;
}
use of com.intellij.codeInspection.dataFlow.instructions.Instruction in project intellij-community by JetBrains.
the class LoopAnalyzer method calcInLoop.
static int[] calcInLoop(ControlFlow controlFlow) {
// loop[i] = loop number(strongly connected component number) of i-th instruction or 0 if outside loop
final int[] loop = new int[controlFlow.getInstructionCount()];
MyGraph graph = new MyGraph(controlFlow);
final DFSTBuilder<Instruction> builder = new DFSTBuilder<>(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;
}
use of com.intellij.codeInspection.dataFlow.instructions.Instruction in project intellij-community by JetBrains.
the class StateQueue method getNextInstructionStates.
@NotNull
List<DfaInstructionState> getNextInstructionStates(Set<Instruction> joinInstructions) {
DfaInstructionState state = myQueue.poll();
final Instruction instruction = state.getInstruction();
mySet.remove(Pair.create(instruction, state.getMemoryState()));
DfaInstructionState next = myQueue.peek();
if (next == null || next.compareTo(state) != 0)
return Collections.singletonList(state);
List<DfaMemoryStateImpl> memoryStates = ContainerUtil.newArrayList();
memoryStates.add((DfaMemoryStateImpl) state.getMemoryState());
while (!myQueue.isEmpty() && myQueue.peek().compareTo(state) == 0) {
DfaMemoryState anotherState = myQueue.poll().getMemoryState();
mySet.remove(Pair.create(instruction, anotherState));
memoryStates.add((DfaMemoryStateImpl) anotherState);
}
if (memoryStates.size() > 1 && joinInstructions.contains(instruction)) {
MultiMap<Object, DfaMemoryStateImpl> groups = MultiMap.create();
for (DfaMemoryStateImpl memoryState : memoryStates) {
groups.putValue(memoryState.getSuperficialKey(), memoryState);
}
memoryStates = ContainerUtil.newArrayList();
for (Map.Entry<Object, Collection<DfaMemoryStateImpl>> entry : groups.entrySet()) {
memoryStates.addAll(mergeGroup((List<DfaMemoryStateImpl>) entry.getValue()));
}
}
return ContainerUtil.map(memoryStates, state1 -> new DfaInstructionState(instruction, state1));
}
Aggregations