Corrections for PR #602
This commit is contained in:
@ -129,7 +129,7 @@ public final class JavaQualifiedName implements QualifiedName {
|
||||
|
||||
String name = clazz.getName();
|
||||
if (name.indexOf('.') < 0) {
|
||||
name = '.' + name;
|
||||
name = '.' + name; // unnamed package, marked by a full stop. See ofString's format below
|
||||
}
|
||||
|
||||
return ofString(name);
|
||||
|
@ -7,7 +7,7 @@ package net.sourceforge.pmd.lang.java.multifile;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import net.sourceforge.pmd.lang.LanguageVersionHandler;
|
||||
@ -20,9 +20,10 @@ import net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSigMask;
|
||||
import net.sourceforge.pmd.lang.java.multifile.signature.JavaOperationSigMask;
|
||||
import net.sourceforge.pmd.lang.java.multifile.signature.JavaSignature.Visibility;
|
||||
import net.sourceforge.pmd.lang.java.multifile.testdata.MultifileVisitorTestData;
|
||||
import net.sourceforge.pmd.lang.java.multifile.testdata.MultifileVisitorTestData2;
|
||||
|
||||
/**
|
||||
* Tests of the metrics visitor.
|
||||
* Tests of the multifile visitor.
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
@ -35,7 +36,7 @@ public class JavaMultifileVisitorTest {
|
||||
}
|
||||
|
||||
|
||||
@After
|
||||
@Before
|
||||
public void resetMultifile() {
|
||||
PackageStats.INSTANCE.reset();
|
||||
}
|
||||
@ -80,6 +81,31 @@ public class JavaMultifileVisitorTest {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testBothClassesFieldsAreThere() {
|
||||
parseAndVisitForClass(MultifileVisitorTestData.class);
|
||||
parseAndVisitForClass(MultifileVisitorTestData2.class);
|
||||
|
||||
final ProjectMirror toplevel = PackageStats.INSTANCE;
|
||||
|
||||
final JavaFieldSigMask fieldSigMask = new JavaFieldSigMask();
|
||||
|
||||
JavaQualifiedName clazz = JavaQualifiedName.ofClass(MultifileVisitorTestData.class);
|
||||
JavaQualifiedName clazz2 = JavaQualifiedName.ofClass(MultifileVisitorTestData2.class);
|
||||
|
||||
String[] fieldNames1 = {"x", "y", "z", "t"};
|
||||
String[] fieldNames2 = {"x2", "y2", "z2", "t2"};
|
||||
Visibility[] visibilities = {Visibility.PUBLIC, Visibility.PRIVATE, Visibility.PROTECTED, Visibility.PACKAGE};
|
||||
|
||||
|
||||
for (int i = 0; i < fieldNames1.length; i++) {
|
||||
fieldSigMask.restrictVisibilitiesTo(visibilities[i]);
|
||||
assertTrue(toplevel.hasMatchingSig(clazz, fieldNames1[i], fieldSigMask));
|
||||
assertTrue(toplevel.hasMatchingSig(clazz2, fieldNames2[i], fieldSigMask));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static ASTCompilationUnit parseAndVisitForClass(Class<?> clazz) {
|
||||
ASTCompilationUnit acu = ParserTstUtil.parseJavaDefaultVersion(clazz);
|
||||
LanguageVersionHandler handler = ParserTstUtil.getDefaultLanguageVersionHandler();
|
||||
|
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||
*/
|
||||
|
||||
package net.sourceforge.pmd.lang.java.multifile.testdata;
|
||||
|
||||
/**
|
||||
* Test data for the metrics visitor
|
||||
*
|
||||
* @author Clément Fournier
|
||||
*/
|
||||
public class MultifileVisitorTestData2 {
|
||||
|
||||
public String x2;
|
||||
protected String z2;
|
||||
String t2;
|
||||
private String y2;
|
||||
|
||||
|
||||
public MultifileVisitorTestData2() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private MultifileVisitorTestData2(String x) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getX2() {
|
||||
return x2;
|
||||
}
|
||||
|
||||
|
||||
public String getY2() {
|
||||
return y2;
|
||||
}
|
||||
|
||||
|
||||
public void setX2(String n) {
|
||||
x2 = n;
|
||||
}
|
||||
|
||||
|
||||
public void setY2(String n) {
|
||||
y2 = n;
|
||||
}
|
||||
|
||||
|
||||
public void mymethod12() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void mymethod22() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
protected static void mystatic12() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void mystatic22(String k) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void mystatic22(String k, String l) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static class NestedClass2 {
|
||||
|
||||
public NestedClass2() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void nestedMethod12() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -4,12 +4,22 @@
|
||||
|
||||
package net.sourceforge.pmd.lang.java.rule.codesize;
|
||||
|
||||
import net.sourceforge.pmd.Rule;
|
||||
import net.sourceforge.pmd.lang.java.metrics.MetricsHook;
|
||||
import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||
|
||||
public class CodesizeRulesTest extends SimpleAggregatorTst {
|
||||
|
||||
private static final String RULESET = "java-codesize";
|
||||
|
||||
|
||||
@Override
|
||||
protected Rule reinitializeRule(Rule rule) {
|
||||
MetricsHook.reset();
|
||||
return rule;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
addRule(RULESET, "CyclomaticComplexity");
|
||||
|
@ -184,7 +184,7 @@ public class Foo {
|
||||
</test-code>
|
||||
|
||||
<code-fragment id="complicated-method"><![CDATA[
|
||||
public class Boo {
|
||||
public class Foo {
|
||||
public static void main(String args[]) {
|
||||
Random r = new Random();
|
||||
label: for (int j = -12; i < z; i++) {
|
||||
|
Reference in New Issue
Block a user