Skip to content

Commit

Permalink
Hide factories of MethodProperty, MethodMultiProperty, FileProperty f…
Browse files Browse the repository at this point in the history
…rom XPath rules

refs pmd#762
  • Loading branch information
oowekyala committed Nov 28, 2017
1 parent abdb962 commit 539d541
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 17 deletions.
Expand Up @@ -15,13 +15,14 @@
* @author Clément Fournier
* @since 6.0.0
*/
// TODO make an enum
public class PropertyDescriptorUtil {

private static final Map<String, PropertyDescriptorExternalBuilder<?>> DESCRIPTOR_FACTORIES_BY_TYPE;


static {
Map<String, PropertyDescriptorExternalBuilder<?>> temp = new HashMap<>(18);
Map<String, PropertyDescriptorExternalBuilder<?>> temp = new HashMap<>(16);
temp.put("Boolean", BooleanProperty.extractor());
temp.put("List[Boolean]", BooleanMultiProperty.extractor());

Expand All @@ -30,7 +31,6 @@ public class PropertyDescriptorUtil {
temp.put("Character", CharacterProperty.extractor());
temp.put("List[Character]", CharacterMultiProperty.extractor());


temp.put("Integer", IntegerProperty.extractor());
temp.put("List[Integer]", IntegerMultiProperty.extractor());
temp.put("Long", LongProperty.extractor());
Expand All @@ -44,10 +44,10 @@ public class PropertyDescriptorUtil {

temp.put("Class", TypeProperty.extractor());
temp.put("List[Class]", TypeMultiProperty.extractor());
temp.put("Method", MethodProperty.extractor());
temp.put("List[Method]", MethodMultiProperty.extractor());

temp.put("File", FileProperty.extractor());
// temp.put("Method", MethodProperty.extractor()); // hidden, see #762
// temp.put("List[Method]", MethodMultiProperty.extractor()); // ditto
// temp.put("File", FileProperty.extractor()); // ditto

DESCRIPTOR_FACTORIES_BY_TYPE = Collections.unmodifiableMap(temp);
}
Expand All @@ -56,7 +56,7 @@ public class PropertyDescriptorUtil {
private PropertyDescriptorUtil() {
}


/**
* Returns the full mappings from type ids to extractors.
*
Expand Down
Expand Up @@ -10,12 +10,15 @@
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Assume;
import org.junit.Test;

import net.sourceforge.pmd.properties.modules.MethodPropertyModule;
import net.sourceforge.pmd.util.ClassUtil;


/**
* Evaluates the functionality of the MethodProperty descriptor by testing its
* ability to catch creation errors (illegal args), flag invalid methods per the
Expand All @@ -33,22 +36,32 @@ public class MethodPropertyTest extends AbstractPackagedPropertyDescriptorTester

private static final String[] METHOD_SIGNATURES = {"String#indexOf(int)", "String#substring(int,int)",
"java.lang.String#substring(int,int)", "Integer#parseInt(String)", "java.util.HashMap#put(Object,Object)",
"HashMap#containsKey(Object)", };
"HashMap#containsKey(Object)",};


public MethodPropertyTest() {
super("Method");
}


@Override
@Test
public void testMissingPackageNames() {
Map<PropertyDescriptorField, String> attributes = getPropertyDescriptorValues();
attributes.remove(PropertyDescriptorField.LEGAL_PACKAGES);
new MethodProperty("p", "d", ALL_METHODS[1], null, 1.0f); // no exception, null is ok
new MethodMultiProperty("p", "d", new Method[]{ALL_METHODS[2], ALL_METHODS[3]}, null, 1.0f); // no exception, null is ok
}


@Test
public void testAsStringOn() {

Method method;

for (int i = 0; i < METHOD_SIGNATURES.length; i++) {
method = ValueParserConstants.METHOD_PARSER.valueOf(METHOD_SIGNATURES[i]);
assertNotNull("Unable to identify method: " + METHOD_SIGNATURES[i], method);
for (String methodSignature : METHOD_SIGNATURES) {
method = ValueParserConstants.METHOD_PARSER.valueOf(methodSignature);
assertNotNull("Unable to identify method: " + methodSignature, method);
}
}

Expand Down Expand Up @@ -86,28 +99,50 @@ protected Method createBadValue() {

@Override
protected PropertyDescriptor<Method> createProperty() {
return new MethodProperty("methodProperty", "asdf", ALL_METHODS[1], new String[] {"java.lang", "org.apache"},
1.0f);
return new MethodProperty("methodProperty", "asdf", ALL_METHODS[1], new String[]{"java.lang", "org.apache"},
1.0f);
}


@Override
protected PropertyDescriptor<List<Method>> createMultiProperty() {
return new MethodMultiProperty("methodProperty", "asdf", new Method[] {ALL_METHODS[2], ALL_METHODS[3]},
new String[] {"java.lang"}, 1.0f);
return new MethodMultiProperty("methodProperty", "asdf", new Method[]{ALL_METHODS[2], ALL_METHODS[3]},
new String[]{"java.lang"}, 1.0f);
}


@Override
protected PropertyDescriptor<Method> createBadProperty() {
return new MethodProperty("methodProperty", "asdf", ALL_METHODS[1], new String[] {"java.util"}, 1.0f);
return new MethodProperty("methodProperty", "asdf", ALL_METHODS[1], new String[]{"java.util"}, 1.0f);

}


@Override
protected PropertyDescriptor<List<Method>> createBadMultiProperty() {
return new MethodMultiProperty("methodProperty", "asdf", new Method[] {ALL_METHODS[2], ALL_METHODS[3]},
new String[] {"java.util"}, 1.0f);
return new MethodMultiProperty("methodProperty", "asdf", new Method[]{ALL_METHODS[2], ALL_METHODS[3]},
new String[]{"java.util"}, 1.0f);
}


@Override
@Test
public void testFactorySingleValue() {
Assume.assumeTrue("MethodProperty cannot be built from XPath (#762)", false);
}


@Override
@Test
public void testFactoryMultiValueCustomDelimiter() {
Assume.assumeTrue("MethodProperty cannot be built from XPath (#762)", false);
}


@Override
@Test
public void testFactoryMultiValueDefaultDelimiter() {
Assume.assumeTrue("MethodProperty cannot be built from XPath (#762)", false);
}

}

0 comments on commit 539d541

Please sign in to comment.