Пример #1
0
  private String createMessage(Map<Pair<Unit, Set<String>>, Set<Unit>> createProvidesConfigMap) {
    StringBuilder stringBuilder = new StringBuilder();
    boolean appendedConfiguration = false;
    for (Entry<Pair<Unit, Set<String>>, Set<Unit>> provideEntry :
        createProvidesConfigMap.entrySet()) {
      Pair<Unit, Set<String>> key = provideEntry.getKey();
      Unit definition = key.getFirst();
      FeatureTag definitionTag = (FeatureTag) definition.getTag("FeatureTag");
      Set<String> configuration = key.getSecond();

      Set<Unit> reachedUses = provideEntry.getValue();
      for (Unit reachedUnit : reachedUses) {
        FeatureTag reachedUnitTag = (FeatureTag) reachedUnit.getTag("FeatureTag");
        Set<String> difference = new HashSet<String>(reachedUnitTag);
        difference.removeAll(definitionTag);

        if (difference.size() == 0) {
          continue;
        }

        if (!appendedConfiguration) {
          stringBuilder.append("\n\n");
          stringBuilder.append(configuration);
          stringBuilder.append('\n');
          appendedConfiguration = true;
        }
        stringBuilder.append("Provides " + definition + " to\n");

        for (String feature : difference) {
          stringBuilder.append("line " + ASTNodeUnitBridge.getLineFromUnit(reachedUnit));
          stringBuilder.append(" [feature " + feature + "]\n");
        }
      }
      appendedConfiguration = false;
    }
    return stringBuilder.toString();
  }
Пример #2
0
  @Override
  public Object execute(ExecutionEvent event) throws ExecutionException {
    // TODO: this wrapping try is for debug only. Remove later.
    final int TIMES = 10;
    List<Long> runsTimer = new ArrayList<Long>(TIMES);
    for (int i = 0; i < TIMES; i++) {
      long startTimer = System.currentTimeMillis();
      try {
        ISelection selection = HandlerUtil.getCurrentSelectionChecked(event);
        Shell shell = HandlerUtil.getActiveShellChecked(event);

        if (!(selection instanceof ITextSelection))
          throw new ExecutionException("Not a text selection");

        IFile textSelectionFile =
            (IFile)
                HandlerUtil.getActiveEditorChecked(event).getEditorInput().getAdapter(IFile.class);

        ITextSelection textSelection = (ITextSelection) selection;
        SelectionNodesVisitor selectionNodesVisitor = new SelectionNodesVisitor(textSelection);

        ICompilationUnit compilationUnit = JavaCore.createCompilationUnitFrom(textSelectionFile);
        ASTParser parser = ASTParser.newParser(AST.JLS3);
        parser.setSource(compilationUnit);
        parser.setKind(ASTParser.K_COMPILATION_UNIT);
        parser.setResolveBindings(true);
        CompilationUnit jdtCompilationUnit = (CompilationUnit) parser.createAST(null);
        jdtCompilationUnit.accept(selectionNodesVisitor);

        Set<ASTNode> selectionNodes = selectionNodesVisitor.getNodes();
        System.out.println("Selection" + selectionNodes);

        IFeatureExtracter extracter = CIDEFeatureExtracterFactory.getInstance().newExtracter();

        String correspondentClasspath =
            MethodDeclarationSootMethodBridge.getCorrespondentClasspath(textSelectionFile);
        SootManager.configure(correspondentClasspath);
        MethodDeclaration methodDeclaration =
            MethodDeclarationSootMethodBridge.getParentMethod(selectionNodes.iterator().next());
        String declaringMethodClass =
            methodDeclaration.resolveBinding().getDeclaringClass().getQualifiedName();
        MethodDeclarationSootMethodBridge mdsm =
            new MethodDeclarationSootMethodBridge(methodDeclaration);
        SootMethod sootMethod =
            SootManager.getMethodBySignature(
                declaringMethodClass, mdsm.getSootMethodSubSignature());
        Body body = sootMethod.retrieveActiveBody();

        Collection<Unit> unitsInSelection =
            ASTNodeUnitBridge.getUnitsFromLines(
                ASTNodeUnitBridge.getLinesFromASTNodes(selectionNodes, jdtCompilationUnit), body);
        if (unitsInSelection.isEmpty()) {
          System.out.println("the selection doesn't map to any Soot Unit");
          return null;
        }

        FeatureModelInstrumentorTransformer instrumentorTransformer =
            new FeatureModelInstrumentorTransformer(extracter, correspondentClasspath);
        instrumentorTransformer.transform2(body, correspondentClasspath);

        FeatureTag<Set<String>> bodyFeatureTag =
            (FeatureTag<Set<String>>) body.getTag("FeatureTag");

        BriefUnitGraph bodyGraph = new BriefUnitGraph(body);
        LiftedReachingDefinitions reachingDefinitions =
            new LiftedReachingDefinitions(bodyGraph, bodyFeatureTag.getFeatures());
        reachingDefinitions.execute();

        Map<Pair<Unit, Set<String>>, Set<Unit>> createProvidesConfigMap =
            createProvidesConfigMap(unitsInSelection, reachingDefinitions, body);
        System.out.println(createProvidesConfigMap);
        String message = createMessage(createProvidesConfigMap);

        // EmergentPopup.pop(shell, message);
      } catch (Exception ex) {
        ex.printStackTrace();
      } finally {
        G.v().reset();
      }
      long estimatedTime = System.currentTimeMillis() - startTimer;
      runsTimer.add(estimatedTime);
    }
    System.out.println(runsTimer);
    return null;
  }