Skip to content

Commit

Permalink
Corrections for PR #545
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed Aug 13, 2017
1 parent 2598c2d commit 54ec57b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;

Expand All @@ -22,7 +21,6 @@
*/
public class ApexQualifiedName implements QualifiedName {

private static final Pattern FORMAT = Pattern.compile("(\\w+)__(\\w+)(.(\\w+))?(#(\\w+))?"); // TODO

private final String nameSpace;
private final String[] classes;
Expand All @@ -36,13 +34,11 @@ private ApexQualifiedName(String nameSpace, String[] classes, String operation)
}



public String getOperation() {
return operation;
}



public String[] getClasses() {
return Arrays.copyOf(classes, classes.length);
}
Expand Down Expand Up @@ -117,6 +113,20 @@ public boolean equals(Object obj) {
}


/**
* Parses a string conforming to the format defined below and returns an ApexQualifiedName.
*
* <p>Here are some examples of the format:
* <ul>
* <li> {@code namespace__OuterClass.InnerClass}: name of an inner class
* <li> {@code namespace__Class#method(String, int)}: name of an operation
* </ul>
*
* @param toParse The string to parse
*
* @return An ApexQualifiedName, or null if the string couldn't be parsed
*/
// private static final Pattern FORMAT = Pattern.compile("(\\w+)__(\\w+)(.(\\w+))?(#(\\w+))?"); // TODO
public static ApexQualifiedName ofString(String toParse) {
throw new UnsupportedOperationException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import net.sourceforge.pmd.lang.apex.metrics.impl.visitors.StandardCycloVisitor;
import net.sourceforge.pmd.lang.metrics.MetricVersion;

import apex.jorje.semantic.ast.expression.BooleanExpressionType;
import apex.jorje.data.ast.BooleanOp;

/**
* See the doc for the Java metric.
Expand Down Expand Up @@ -44,8 +44,8 @@ public static int booleanExpressionComplexity(ASTStandardCondition expression) {
int complexity = 0;

for (ASTBooleanExpression sub : subs) {
BooleanExpressionType type = sub.getNode().getBooleanExpressionType();
if (type != null && (type == BooleanExpressionType.OR || type == BooleanExpressionType.AND)) {
BooleanOp op = sub.getNode().getOp();
if (op != null && (op == BooleanOp.AND || op == BooleanOp.OR)) {
complexity++;
}
}
Expand Down
4 changes: 2 additions & 2 deletions pmd-apex/src/main/resources/rulesets/apex/metrics.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

<rule name="CyclomaticComplexity"
message="The {0} ''{1}'' has a{2} cyclomatic complexity of {3}."
since="1.03"
since="6.0.0"
class="net.sourceforge.pmd.lang.apex.metrics.rule.CyclomaticComplexityRule"
metrics="true"
externalInfoUrl="${pmd.website.baseurl}/rules/apex/codesize.html#CyclomaticComplexity">
externalInfoUrl="${pmd.website.baseurl}/rules/apex/metrics.html#CyclomaticComplexity">
<description>
<![CDATA[
The complexity of methods directly affects maintenance costs and readability. Concentrating too much decisional logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.IOException;

import org.apache.commons.io.IOUtils;
import org.junit.Test;

import net.sourceforge.pmd.lang.LanguageRegistry;
Expand All @@ -33,48 +36,9 @@ public void testProjectMirrorNotNull() {


@Test
public void testOperationsAreThere() {
ApexNode<Compilation> acu = parseAndVisitForString("public with sharing class MetadataDeployController \n"
+ "{\n"
+ "\tprivate class Foo {\n"
+ "}\n"
+ "\n"
+ "\tglobal String ZipData { get; set; }\t\n"
+ "\t\n"
+ "\tpublic MetadataService.AsyncResult AsyncResult {get; private set;}\n"
+ "\t\n"
+ "\tpublic String getPackageXml(String page)\n"
+ "\t{\n"
+ "\t\treturn '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' + \n"
+ "\t\t\t'<Package xmlns=\"http://soap.sforce.com/2006/04/metadata\">' + \n"
+ " \t\t\t'<types>' + \n"
+ " \t\t\t'<members>HelloWorld</members>' +\n"
+ " \t\t\t'<name>ApexClass</name>' + \n"
+ " \t\t\t'</types>' + \n"
+ " \t\t\t'<version>26.0</version>' + \n"
+ "\t\t\t'</Package>';\t\t\n"
+ "\t}\n"
+ "\t\n"
+ "\tpublic String getHelloWorldMetadata()\n"
+ "\t{\n"
+ "\t\treturn '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +\n"
+ "\t\t\t'<ApexClass xmlns=\"http://soap.sforce.com/2006/04/metadata\">' +\n"
+ "\t\t\t '<apiVersion>28.0</apiVersion>' + \n"
+ "\t\t\t '<status>Active</status>' +\n"
+ "\t\t\t'</ApexClass>';\t\t\n"
+ "\t}\n"
+ "\t\n"
+ "\tpublic String getHelloWorld()\t\n"
+ "\t{\n"
+ "\t\treturn 'public class HelloWorld' + \n"
+ "\t\t\t'{' + \n"
+ "\t\t\t\t'public static void helloWorld()' +\n"
+ "\t\t\t\t'{' + \n"
+ "\t\t\t\t\t'System.debug(\\' Hello World\\');' +\n"
+ "\t\t\t\t'}' +\n"
+ "\t\t\t'}';\n"
+ "\t}"
+ "}");
public void testOperationsAreThere() throws IOException {
ApexNode<Compilation> acu = parseAndVisitForString(
IOUtils.toString(ApexMetricsVisitorTest.class.getResourceAsStream("MetadataDeployController.cls")));

final ApexSignatureMatcher toplevel = ApexMetrics.getFacade().getProjectMirror();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.apache.commons.io.IOUtils;
import org.junit.Test;

import net.sourceforge.pmd.lang.apex.ast.ASTMethod;
Expand All @@ -34,52 +36,21 @@
*/
public class ApexProjectMirrorTest {

private static ApexNode<Compilation> acu
= parseAndVisitForString("public with sharing class MetadataDeployController \n"
+ "{\n"
+ "\tprivate class Foo {\n"
+ "}\n"
+ "\n"
+ "\tglobal String ZipData { get; set; }\t\n"
+ "\t\n"
+ "\tpublic MetadataService.AsyncResult AsyncResult {get; private set;}\n"
+ "\t\n"
+ "\tpublic String getPackageXml(String page)\n"
+ "\t{\n"
+ "\t\treturn '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' + \n"
+ "\t\t\t'<Package xmlns=\"http://soap.sforce.com/2006/04/metadata\">' + \n"
+ " \t\t\t'<types>' + \n"
+ " \t\t\t'<members>HelloWorld</members>' +\n"
+ " \t\t\t'<name>ApexClass</name>' + \n"
+ " \t\t\t'</types>' + \n"
+ " \t\t\t'<version>26.0</version>' + \n"
+ "\t\t\t'</Package>';\t\t\n"
+ "\t}\n"
+ "\t\n"
+ "\tpublic String getHelloWorldMetadata()\n"
+ "\t{\n"
+ "\t\treturn '<?xml version=\"1.0\" encoding=\"UTF-8\"?>' +\n"
+ "\t\t\t'<ApexClass xmlns=\"http://soap.sforce.com/2006/04/metadata\">' +\n"
+ "\t\t\t '<apiVersion>28.0</apiVersion>' + \n"
+ "\t\t\t '<status>Active</status>' +\n"
+ "\t\t\t'</ApexClass>';\t\t\n"
+ "\t}\n"
+ "\t\n"
+ "\tpublic String getHelloWorld()\t\n"
+ "\t{\n"
+ "\t\treturn 'public class HelloWorld' + \n"
+ "\t\t\t'{' + \n"
+ "\t\t\t\t'public static void helloWorld()' +\n"
+ "\t\t\t\t'{' + \n"
+ "\t\t\t\t\t'System.debug(\\' Hello World\\');' +\n"
+ "\t\t\t\t'}' +\n"
+ "\t\t\t'}';\n"
+ "\t}"
+ "}");
private static ApexNode<Compilation> acu;
private MetricKey<ASTUserClassOrInterface<?>> classMetricKey = MetricKeyUtil.of(new RandomClassMetric(), null);
private MetricKey<ASTMethod> opMetricKey = MetricKeyUtil.of(new RandomOperationMetric(), null);


static {
try {
acu = parseAndVisitForString(
IOUtils.toString(ApexMetricsVisitorTest.class.getResourceAsStream("MetadataDeployController.cls")));
} catch (IOException ioe) {
// Should definitely not happen
}
}


@Test
public void memoizationTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
public with sharing class MetadataDeployController
{
private class Foo {
}

global String ZipData { get; set; }

public MetadataService.AsyncResult AsyncResult {get; private set;}

public String getPackageXml(String page)
{
return '<?xml version="1.0" encoding="UTF-8"?>' +
'<Package xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<types>' +
'<members>HelloWorld</members>' +
'<name>ApexClass</name>' +
'</types>' +
'<version>26.0</version>' +
'</Package>';
}

public String getHelloWorldMetadata()
{
return '<?xml version="1.0" encoding="UTF-8"?>' +
'<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">' +
'<apiVersion>28.0</apiVersion>' +
'<status>Active</status>' +
'</ApexClass>';
}

public String getHelloWorld()
{
return 'public class HelloWorld' +
'{' +
'public static void helloWorld()' +
'{' +
'System.debug(\' Hello World\');' +
'}' +
'}';
}
}

0 comments on commit 54ec57b

Please sign in to comment.