Search in sources :

Example 6 with DFSTBuilder

use of com.intellij.util.graph.DFSTBuilder in project intellij-community by JetBrains.

the class JarsBuilder method sortJars.

@Nullable
private JarInfo[] sortJars() {
    final DFSTBuilder<JarInfo> builder = new DFSTBuilder<>(GraphGenerator.generate(CachingSemiGraph.cache(new JarsGraph())));
    if (!builder.isAcyclic()) {
        final Pair<JarInfo, JarInfo> dependency = builder.getCircularDependency();
        String message = "Cannot build: circular dependency found between '" + dependency.getFirst().getPresentableDestination() + "' and '" + dependency.getSecond().getPresentableDestination() + "'";
        myContext.processMessage(new CompilerMessage(IncArtifactBuilder.BUILDER_NAME, BuildMessage.Kind.ERROR, message));
        return null;
    }
    JarInfo[] jars = myJarsToBuild.toArray(new JarInfo[myJarsToBuild.size()]);
    Arrays.sort(jars, builder.comparator());
    jars = ArrayUtil.reverseArray(jars);
    return jars;
}
Also used : CompilerMessage(org.jetbrains.jps.incremental.messages.CompilerMessage) DFSTBuilder(com.intellij.util.graph.DFSTBuilder) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with DFSTBuilder

use of com.intellij.util.graph.DFSTBuilder 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)

Aggregations

DFSTBuilder (com.intellij.util.graph.DFSTBuilder)7 InboundSemiGraph (com.intellij.util.graph.InboundSemiGraph)3 Nullable (org.jetbrains.annotations.Nullable)3 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 com.intellij.psi (com.intellij.psi)2 ContainerUtil (com.intellij.util.containers.ContainerUtil)2 MultiMap (com.intellij.util.containers.MultiMap)2 GraphGenerator (com.intellij.util.graph.GraphGenerator)2 THashMap (gnu.trove.THashMap)2 java.util (java.util)2 NotNull (org.jetbrains.annotations.NotNull)2 GenerateMembersUtil (com.intellij.codeInsight.generation.GenerateMembersUtil)1 GetterSetterPrototypeProvider (com.intellij.codeInsight.generation.GetterSetterPrototypeProvider)1 ConditionalGotoInstruction (com.intellij.codeInspection.dataFlow.instructions.ConditionalGotoInstruction)1 GotoInstruction (com.intellij.codeInspection.dataFlow.instructions.GotoInstruction)1 Instruction (com.intellij.codeInspection.dataFlow.instructions.Instruction)1 JavaLanguage (com.intellij.lang.java.JavaLanguage)1 ApplicationManager (com.intellij.openapi.application.ApplicationManager)1 Logger (com.intellij.openapi.diagnostic.Logger)1