Search in sources :

Example 76 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class ArrangementMatchingRulesControl method onMouseClicked.

private void onMouseClicked(@NotNull MouseEvent e) {
    final int count = e.getClickCount();
    if (count != 2) {
        return;
    }
    final TIntArrayList rows = getSelectedModelRows();
    if (rows.size() != 1) {
        return;
    }
    final int row = rows.get(0);
    showEditor(row);
    scrollRowToVisible(row);
}
Also used : TIntArrayList(gnu.trove.TIntArrayList)

Example 77 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class EditArrangementRuleAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    ArrangementMatchingRulesControl control = getRulesControl(e);
    if (control == null) {
        return;
    }
    TIntArrayList rows = control.getSelectedModelRows();
    if (rows.size() != 1) {
        return;
    }
    final int row = rows.get(0);
    control.showEditor(row);
    scrollRowToVisible(control, row);
}
Also used : ArrangementMatchingRulesControl(com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl) TIntArrayList(gnu.trove.TIntArrayList)

Example 78 with TIntArrayList

use of gnu.trove.TIntArrayList 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;
}
Also used : TIntProcedure(gnu.trove.TIntProcedure) DFSTBuilder(com.intellij.util.graph.DFSTBuilder) ConditionalGotoInstruction(com.intellij.codeInspection.dataFlow.instructions.ConditionalGotoInstruction) GotoInstruction(com.intellij.codeInspection.dataFlow.instructions.GotoInstruction) Instruction(com.intellij.codeInspection.dataFlow.instructions.Instruction) TIntArrayList(gnu.trove.TIntArrayList)

Example 79 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class OriginsAnalysis method resultOrigins.

/**
   *
   * @param frames fixpoint of frames
   * @param instructions method instructions
   * @param graph method control flow graph
   * @return array, array[i] == true means that the result of a method execution may originate at an i-th instruction
   * @throws AnalyzerException
   */
@NotNull
public static boolean[] resultOrigins(Frame<Value>[] frames, InsnList instructions, ControlFlowGraph graph) throws AnalyzerException {
    TIntArrayList[] backTransitions = new TIntArrayList[instructions.size()];
    for (int i = 0; i < backTransitions.length; i++) {
        backTransitions[i] = new TIntArrayList();
    }
    LinkedList<InsnLocation> queue = new LinkedList<>();
    HashSet<InsnLocation> queued = new HashSet<>();
    for (int from = 0; from < instructions.size(); from++) {
        for (int to : graph.transitions[from]) {
            TIntArrayList froms = backTransitions[to];
            froms.add(from);
            int opcode = instructions.get(to).getOpcode();
            if (opcode >= Opcodes.IRETURN && opcode <= Opcodes.ARETURN) {
                InsnLocation sourceLoc = new InsnLocation(false, from, frames[to].getStackSize() - 1);
                if (queued.add(sourceLoc)) {
                    queue.push(sourceLoc);
                }
            }
        }
    }
    boolean[] result = new boolean[instructions.size()];
    while (!queue.isEmpty()) {
        InsnLocation resultLocation = queue.pop();
        int insnIndex = resultLocation.insnIndex;
        AbstractInsnNode insn = instructions.get(insnIndex);
        int opcode = insn.getOpcode();
        Location preLocation = previousLocation(frames[insnIndex], resultLocation, insn);
        if (preLocation == null) {
            if (opcode != Opcodes.INVOKEINTERFACE && opcode != Opcodes.GETFIELD && !(opcode >= Opcodes.IALOAD && opcode <= Opcodes.SALOAD)) {
                result[insnIndex] = true;
            }
        } else {
            TIntArrayList froms = backTransitions[insnIndex];
            for (int i = 0; i < froms.size(); i++) {
                InsnLocation preILoc = new InsnLocation(preLocation.local, froms.getQuick(i), preLocation.slot);
                if (queued.add(preILoc)) {
                    queue.push(preILoc);
                }
            }
        }
    }
    return result;
}
Also used : AbstractInsnNode(org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode) TIntArrayList(gnu.trove.TIntArrayList) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 80 with TIntArrayList

use of gnu.trove.TIntArrayList in project intellij-community by JetBrains.

the class SliceTreeTest method testTypingDoesNotInterfereWithDuplicates.

public void testTypingDoesNotInterfereWithDuplicates() throws Exception {
    SliceTreeStructure treeStructure = configureTree("DupSlice");
    SliceNode root = (SliceNode) treeStructure.getRootElement();
    List<SliceNode> nodes = new ArrayList<>();
    expandNodesTo(root, nodes);
    TIntArrayList hasDups = new TIntArrayList();
    for (SliceNode node : nodes) {
        if (node.getDuplicate() != null) {
            PsiElement element = node.getValue().getElement();
            hasDups.add(element.getTextRange().getStartOffset());
            assertTrue(element instanceof PsiParameter && "i".equals(((PsiParameter) element).getName()) || element instanceof PsiLiteralExpression);
        }
    }
    type("   xx");
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    backspace();
    backspace();
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    backspace();
    backspace();
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    backspace();
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    nodes.clear();
    expandNodesTo(root, nodes);
    for (SliceNode node : nodes) {
        if (node.getDuplicate() != null) {
            PsiElement element = node.getValue().getElement();
            int offset = element.getTextRange().getStartOffset();
            int i = hasDups.indexOf(offset);
            assertTrue(i != -1);
            hasDups.remove(i);
            assertTrue(element instanceof PsiParameter && "i".equals(((PsiParameter) element).getName()) || element instanceof PsiLiteralExpression);
        }
    }
    assertTrue(hasDups.isEmpty());
}
Also used : TIntArrayList(gnu.trove.TIntArrayList) TIntArrayList(gnu.trove.TIntArrayList)

Aggregations

TIntArrayList (gnu.trove.TIntArrayList)104 NotNull (org.jetbrains.annotations.NotNull)34 ArrayList (java.util.ArrayList)9 List (java.util.List)7 Nullable (org.jetbrains.annotations.Nullable)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ArrangementMatchingRulesControl (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesControl)3 StringSearcher (com.intellij.util.text.StringSearcher)3 TIntHashSet (gnu.trove.TIntHashSet)3 TIntProcedure (gnu.trove.TIntProcedure)3 IOException (java.io.IOException)3 IDevice (com.android.ddmlib.IDevice)2 ArrangementMatchingRulesModel (com.intellij.application.options.codeStyle.arrangement.match.ArrangementMatchingRulesModel)2 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)2 Project (com.intellij.openapi.project.Project)2 TextRange (com.intellij.openapi.util.TextRange)2 ElementToWorkOn (com.intellij.refactoring.introduceField.ElementToWorkOn)2 IntroduceParameterProcessor (com.intellij.refactoring.introduceParameter.IntroduceParameterProcessor)2 RelativePoint (com.intellij.ui.awt.RelativePoint)2 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)2