forked from phoedos/pmd
Plug into the designer
This commit is contained in:
@ -91,7 +91,7 @@ public class ApexProjectMirrorTest {
|
||||
@Override
|
||||
public Object visit(ASTMethod node, Object data) {
|
||||
MetricMemoizer<ASTMethod> op = toplevel.getOperationMemoizer(node.getQualifiedName());
|
||||
result.add((int) ApexMetricsComputer.INSTANCE.computeForOperation(opMetricKey, node, force,
|
||||
result.add((int) ApexMetricsComputer.getInstance().computeForOperation(opMetricKey, node, force,
|
||||
MetricOptions.emptyOptions(), op));
|
||||
return super.visit(node, data);
|
||||
}
|
||||
@ -100,7 +100,7 @@ public class ApexProjectMirrorTest {
|
||||
@Override
|
||||
public Object visit(ASTUserClass node, Object data) {
|
||||
MetricMemoizer<ASTUserClassOrInterface<?>> clazz = toplevel.getClassMemoizer(node.getQualifiedName());
|
||||
result.add((int) ApexMetricsComputer.INSTANCE.computeForType(classMetricKey, node, force,
|
||||
result.add((int) ApexMetricsComputer.getInstance().computeForType(classMetricKey, node, force,
|
||||
MetricOptions.emptyOptions(), clazz));
|
||||
return super.visit(node, data);
|
||||
}
|
||||
|
@ -143,48 +143,56 @@
|
||||
<artifactId>pmd-apex</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-java</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-javascript</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-jsp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-plsql</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-visualforce</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-vm</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.pmd</groupId>
|
||||
<artifactId>pmd-xml</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<optional>true</optional>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
@ -7,16 +7,18 @@ package net.sourceforge.pmd.util.fxdesigner;
|
||||
import java.net.URL;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.reactfx.EventStreams;
|
||||
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.ast.xpath.Attribute;
|
||||
import net.sourceforge.pmd.lang.java.ast.TypeNode;
|
||||
import net.sourceforge.pmd.lang.metrics.MetricKey;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
|
||||
import net.sourceforge.pmd.util.fxdesigner.model.MetricEvaluator;
|
||||
import net.sourceforge.pmd.util.fxdesigner.model.MetricResult;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.controls.ScopeHierarchyTreeCell;
|
||||
import net.sourceforge.pmd.util.fxdesigner.util.controls.ScopeHierarchyTreeItem;
|
||||
@ -58,7 +60,6 @@ public class NodeInfoPanelController implements Initializable {
|
||||
private Label metricsTitleLabel;
|
||||
@FXML
|
||||
private TreeView<Object> scopeHierarchyTreeView;
|
||||
private MetricEvaluator metricEvaluator = new MetricEvaluator();
|
||||
private Node selectedNode;
|
||||
|
||||
public NodeInfoPanelController(MainDesignerController mainController) {
|
||||
@ -125,11 +126,9 @@ public class NodeInfoPanelController implements Initializable {
|
||||
|
||||
|
||||
private ObservableList<MetricResult> evaluateAllMetrics(Node n) {
|
||||
try {
|
||||
return FXCollections.observableArrayList(metricEvaluator.evaluateAllMetrics(n));
|
||||
} catch (UnsupportedOperationException e) {
|
||||
return FXCollections.emptyObservableList();
|
||||
}
|
||||
Map<MetricKey<?>, Double> results = parent.getLanguageVersion().getLanguageVersionHandler().getLanguageMetricsProvider().computeAllMetricsFor(n);
|
||||
List<MetricResult> resultList = results.entrySet().stream().map(e -> new MetricResult(e.getKey(), e.getValue())).collect(Collectors.toList());
|
||||
return FXCollections.observableArrayList(resultList);
|
||||
}
|
||||
|
||||
|
||||
@ -146,9 +145,10 @@ public class NodeInfoPanelController implements Initializable {
|
||||
+ ((attribute.getValue() != null) ? attribute.getStringValue() : "null"));
|
||||
}
|
||||
|
||||
if (node instanceof TypeNode) {
|
||||
result.add("typeIs() = " + ((TypeNode) node).getType());
|
||||
}
|
||||
// TODO maybe put some equivalent to TypeNode inside pmd-core
|
||||
// if (node instanceof TypeNode) {
|
||||
// result.add("typeIs() = " + ((TypeNode) node).getType());
|
||||
// }
|
||||
Collections.sort(result);
|
||||
return result;
|
||||
}
|
||||
|
@ -1,92 +0,0 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.util.fxdesigner.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
|
||||
import net.sourceforge.pmd.lang.apex.ast.ASTUserClass;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.ApexMetrics;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.api.ApexClassMetricKey;
|
||||
import net.sourceforge.pmd.lang.apex.metrics.api.ApexOperationMetricKey;
|
||||
import net.sourceforge.pmd.lang.ast.Node;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTAnyTypeDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.ast.ASTMethodOrConstructorDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.metrics.JavaMetrics;
|
||||
import net.sourceforge.pmd.lang.java.metrics.api.JavaClassMetricKey;
|
||||
import net.sourceforge.pmd.lang.java.metrics.api.JavaOperationMetricKey;
|
||||
|
||||
/**
|
||||
* Evaluates metrics.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public class MetricEvaluator {
|
||||
|
||||
/**
|
||||
* Evaluates all available metrics and returns a list of results.
|
||||
*
|
||||
* @param node Node
|
||||
*
|
||||
* @return List of all metric results (metric key + result), including NaN results
|
||||
*
|
||||
* @throws UnsupportedOperationException If no metrics are available for this node
|
||||
*/
|
||||
public List<MetricResult> evaluateAllMetrics(Node node) throws UnsupportedOperationException {
|
||||
if (ASTAnyTypeDeclaration.class.isInstance(node)) {
|
||||
return evaluateAllMetrics((ASTAnyTypeDeclaration) node);
|
||||
} else if (ASTMethodOrConstructorDeclaration.class.isInstance(node)) {
|
||||
return evaluateAllMetrics((ASTMethodOrConstructorDeclaration) node);
|
||||
} else if (ASTMethod.class.isInstance(node)) {
|
||||
return evaluateAllMetrics((ASTMethod) node);
|
||||
} else if (ASTUserClass.class.isInstance(node)) {
|
||||
return evaluateAllMetrics((ASTUserClass) node);
|
||||
}
|
||||
throw new UnsupportedOperationException("That language does not support metrics");
|
||||
}
|
||||
|
||||
|
||||
private List<MetricResult> evaluateAllMetrics(ASTMethodOrConstructorDeclaration node) {
|
||||
List<MetricResult> metricResults = new ArrayList<>();
|
||||
for (JavaOperationMetricKey key : JavaOperationMetricKey.values()) {
|
||||
metricResults.add(new MetricResult(key, JavaMetrics.get(key, node)));
|
||||
}
|
||||
|
||||
return metricResults;
|
||||
}
|
||||
|
||||
|
||||
private List<MetricResult> evaluateAllMetrics(ASTAnyTypeDeclaration node) {
|
||||
List<MetricResult> metricResults = new ArrayList<>();
|
||||
for (JavaClassMetricKey key : JavaClassMetricKey.values()) {
|
||||
metricResults.add(new MetricResult(key, JavaMetrics.get(key, node)));
|
||||
}
|
||||
|
||||
return metricResults;
|
||||
}
|
||||
|
||||
|
||||
private List<MetricResult> evaluateAllMetrics(ASTMethod node) {
|
||||
List<MetricResult> metricResults = new ArrayList<>();
|
||||
for (ApexOperationMetricKey key : ApexOperationMetricKey.values()) {
|
||||
metricResults.add(new MetricResult(key, ApexMetrics.get(key, node)));
|
||||
}
|
||||
|
||||
return metricResults;
|
||||
}
|
||||
|
||||
|
||||
private List<MetricResult> evaluateAllMetrics(ASTUserClass node) {
|
||||
List<MetricResult> metricResults = new ArrayList<>();
|
||||
for (ApexClassMetricKey key : ApexClassMetricKey.values()) {
|
||||
metricResults.add(new MetricResult(key, ApexMetrics.get(key, node)));
|
||||
}
|
||||
|
||||
return metricResults;
|
||||
}
|
||||
|
||||
}
|
@ -4,10 +4,6 @@
|
||||
|
||||
package net.sourceforge.pmd.util.fxdesigner.util.controls;
|
||||
|
||||
import net.sourceforge.pmd.lang.java.ast.TypeNode;
|
||||
import net.sourceforge.pmd.lang.java.symboltable.ClassNameDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.symboltable.MethodNameDeclaration;
|
||||
import net.sourceforge.pmd.lang.java.symboltable.VariableNameDeclaration;
|
||||
import net.sourceforge.pmd.lang.symboltable.NameDeclaration;
|
||||
import net.sourceforge.pmd.lang.symboltable.Scope;
|
||||
|
||||
@ -42,31 +38,7 @@ public class ScopeHierarchyTreeCell extends TreeCell<Object> {
|
||||
|
||||
|
||||
private String getTextForDeclaration(NameDeclaration declaration) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (declaration instanceof MethodNameDeclaration
|
||||
|| declaration instanceof net.sourceforge.pmd.lang.plsql.symboltable.MethodNameDeclaration) {
|
||||
sb.append("Method ");
|
||||
} else if (declaration instanceof VariableNameDeclaration
|
||||
|| declaration instanceof net.sourceforge.pmd.lang.plsql.symboltable.VariableNameDeclaration) {
|
||||
sb.append("Variable ");
|
||||
} else if (declaration instanceof ClassNameDeclaration
|
||||
|| declaration instanceof net.sourceforge.pmd.lang.plsql.symboltable.ClassNameDeclaration) {
|
||||
sb.append("Class ");
|
||||
}
|
||||
|
||||
Class<?> type = declaration.getNode() instanceof TypeNode ? ((TypeNode) declaration.getNode()).getType()
|
||||
: null;
|
||||
|
||||
sb.append(declaration.getName());
|
||||
|
||||
if (type != null) {
|
||||
sb.append(" : ").append(type.getSimpleName());
|
||||
}
|
||||
|
||||
sb.append(" (l. ").append(declaration.getNode().getBeginLine()).append(")");
|
||||
|
||||
return sb.toString();
|
||||
return declaration.toString(); // that's nice enough for now
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user