Пример #1
0
 private List<Integer> computeSliceProfileIntersectionStatements(
     Set<PlainVariable> enabledVariables) {
   List<Integer> indicesList = new ArrayList<Integer>();
   for (SliceProfileRow row : sliceProfileRows) {
     if (row.statementBelongsToAllSlices(enabledVariables))
       indicesList.add(row.getStatementID() - 1);
   }
   return indicesList;
 }
Пример #2
0
 public void update(ViewerCell cell) {
   SliceProfileRow element = (SliceProfileRow) cell.getElement();
   int index = cell.getColumnIndex();
   String columnText = getColumnText(element, index);
   cell.setText(columnText);
   cell.setImage(getColumnImage(element, index));
   if (sliceProfileIntersectionIndices.contains(element.getStatementID() - 1)) {
     cell.setBackground(highlightColor);
   } else cell.setBackground(null);
   super.update(cell);
 }
Пример #3
0
 private String getColumnText(Object obj, int index) {
   SliceProfileRow entry = (SliceProfileRow) obj;
   int statementID = entry.getStatementID();
   switch (index) {
     case 0:
       return String.valueOf(statementID);
     default:
       PlainVariable variable = columnIndexMap.get(index);
       if (entry.getValue(variable)) return "|";
       else return "";
   }
 }
Пример #4
0
  protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    parent.getShell().setText("Slice-based Cohesion Metrics");
    composite.setLayout(new GridLayout(2, false));

    sliceProfileTableViewer =
        new TableViewer(
            composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    sliceProfileTableViewer.setContentProvider(new SliceProfileViewContentProvider());
    sliceProfileTableViewer.setLabelProvider(new SliceProfileViewLabelProvider());

    Composite resultComposite = new Composite(composite, SWT.NONE);
    resultComposite.setLayout(new GridLayout(1, false));

    Group metricsGroup = new Group(resultComposite, SWT.SHADOW_ETCHED_IN);
    metricsGroup.setLayout(new GridLayout(2, false));
    metricsGroup.setText("Metrics");

    Group enableScopeVariablesGroup = new Group(resultComposite, SWT.SHADOW_ETCHED_IN);
    enableScopeVariablesGroup.setLayout(new GridLayout(1, false));
    Button enableButton = null;
    if (System.getProperty("os.name").toLowerCase().indexOf("win") >= 0) {
      enableButton = new MultilineButton(enableScopeVariablesGroup, SWT.WRAP | SWT.CHECK);
    } else {
      enableButton = new Button(enableScopeVariablesGroup, SWT.WRAP | SWT.CHECK);
    }
    enableButton.setText("Enable only variables\nwith method scope");
    enableButton.addSelectionListener(new MySelectionListener(enableButton));

    enabledVariableTableViewer = CheckboxTableViewer.newCheckList(resultComposite, SWT.BORDER);
    enabledVariableTableViewer.setContentProvider(new EnabledVariableViewContentProvider());
    enabledVariableTableViewer.addCheckStateListener(new EnabledVariableCheckStateListener());

    Label overlapLabel = new Label(metricsGroup, SWT.NONE);
    overlapLabel.setText("Overlap:");
    overlapLabel.pack();
    this.overlapText = new Text(metricsGroup, SWT.NONE);
    overlapText.setEditable(false);

    Label tightnessLabel = new Label(metricsGroup, SWT.NONE);
    tightnessLabel.setText("Tightness:");
    tightnessLabel.pack();
    this.tightnessText = new Text(metricsGroup, SWT.NONE);
    tightnessText.setEditable(false);

    Label coverageLabel = new Label(metricsGroup, SWT.NONE);
    coverageLabel.setText("Coverage:");
    coverageLabel.pack();
    this.coverageText = new Text(metricsGroup, SWT.NONE);
    coverageText.setEditable(false);

    metricsGroup.pack();

    TableColumn statementIDColumn = new TableColumn(sliceProfileTableViewer.getTable(), SWT.CENTER);
    statementIDColumn.setText("id");
    statementIDColumn.setResizable(false);
    statementIDColumn.pack();

    int columnIndex = 1;
    for (PlainVariable plainVariable : pdg.getAllDeclaredVariables()) {
      PDGNode firstDefNode = pdg.getFirstDef(plainVariable);
      PDGNode lastUseNode = pdg.getLastUse(plainVariable);
      if (firstDefNode != null && lastUseNode != null) {
        BasicBlock boundaryBlock = pdg.getBasicBlocks().get(0);
        Map<CompositeVariable, LinkedHashSet<PDGNode>> definedAttributeNodeCriteriaMap =
            pdg.getDefinedAttributesOfReference(plainVariable);
        TreeSet<PDGNode> sliceProfile = new TreeSet<PDGNode>();
        if (definedAttributeNodeCriteriaMap.isEmpty()) {
          Set<PDGNode> nodeCriteria =
              pdg.getAssignmentNodesOfVariableCriterionIncludingDeclaration(plainVariable);
          if (!nodeCriteria.isEmpty()) {
            PDGSliceUnion sliceUnion =
                new PDGSliceUnion(pdg, boundaryBlock, nodeCriteria, plainVariable);
            sliceProfile.addAll(sliceUnion.getSliceNodes());
          }
        } else {
          Set<PDGNode> allNodeCriteria = new LinkedHashSet<PDGNode>();
          for (CompositeVariable compositeVariable : definedAttributeNodeCriteriaMap.keySet()) {
            Set<PDGNode> nodeCriteria = definedAttributeNodeCriteriaMap.get(compositeVariable);
            allNodeCriteria.addAll(nodeCriteria);
          }
          PDGObjectSliceUnion sliceUnion =
              new PDGObjectSliceUnion(pdg, boundaryBlock, allNodeCriteria, plainVariable);
          sliceProfile.addAll(sliceUnion.getSliceNodes());
        }
        sliceProfile.add(lastUseNode);
        sliceProfileMap.put(plainVariable, sliceProfile);
        columnIndexMap.put(columnIndex, plainVariable);
        enabledVariableMap.put(plainVariable, true);
        TableColumn column = new TableColumn(sliceProfileTableViewer.getTable(), SWT.CENTER);
        column.setText(plainVariable.getVariableName());
        column.setResizable(false);
        column.pack();
        columnWidthMap.put(plainVariable, column.getWidth());
        columnIndex++;
      }
    }
    GridData layoutData =
        new GridData(GridData.GRAB_VERTICAL | GridData.GRAB_HORIZONTAL | GridData.FILL_BOTH);
    sliceProfileTableViewer.getTable().setLayoutData(layoutData);
    sliceProfileTableViewer.getTable().setLinesVisible(true);
    sliceProfileTableViewer.getTable().setHeaderVisible(true);

    sliceProfileRows = new SliceProfileRow[pdg.getTotalNumberOfStatements()];

    Iterator<GraphNode> nodeIterator = pdg.getNodeIterator();
    while (nodeIterator.hasNext()) {
      PDGNode node = (PDGNode) nodeIterator.next();
      SliceProfileRow row = new SliceProfileRow(node.getId());
      for (PlainVariable variable : sliceProfileMap.keySet()) {
        Set<PDGNode> slice = sliceProfileMap.get(variable);
        if (slice.contains(node)) row.put(variable, true);
        else row.put(variable, false);
      }
      sliceProfileRows[node.getId() - 1] = row;
    }
    sliceProfileTableViewer.setInput(sliceProfileRows);
    enabledVariableTableViewer.setInput(sliceProfileMap.keySet().toArray());
    enabledVariableTableViewer.setAllChecked(true);
    sliceProfileIntersectionIndices =
        computeSliceProfileIntersectionStatements(sliceProfileMap.keySet());
    sliceProfileTableViewer.refresh();
    overlapText.setText(decimalFormat.format(overlap(sliceProfileMap.keySet())));
    tightnessText.setText(decimalFormat.format(tightness()));
    coverageText.setText(decimalFormat.format(coverage(sliceProfileMap.keySet())));
    return composite;
  }