1
votes

In the eclipse documentation I've seen the following snippet (http://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fcore%2Fexpressions%2FPropertyTester.html):

<propertyTester
   namespace="org.eclipse.jdt.core"
   id="org.eclipse.jdt.core.IPackageFragmentTester"
   properties="isDefaultPackage"
   type="org.eclipse.jdt.core.IPackageFragment"
   class="org.eclipse.demo.MyPackageFragmentTester">
 </propertyTester>

with the following property tester implementation:

public class MyPackageFragmentTester extends PropertyTester {
    public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
        IPackageFragment fragment= (IPackageFragment)receiver;
              if ("isDefaultPackage".equals(property)) {
            return expectedValue == null
             ? fragment.isDefaultPackage()
             : fragment.isDefaultPackage() == ((Boolean)expectedValue).booleanValue();
        }
        Assert.isTrue(false);
        return false;
    }
}

I'm a bit wondering about the ((Boolean)expectedValue) part - because the expected value is give in the <test property="..."/> tag as string:

<test property="org.eclipse.jdt.core.isDefaultPackage" value="true" />

And whenever I implemented a property tester the value was given as a String.

So my question is: Is it possible to have an expected value that is not a String? According to the Eclipse RCP documentation it should be... but how!?

1

1 Answers

1
votes

It is not made very clear but the expected value can be a String or a Boolean, Float (!) or Integer.

The code that works out which is in org.eclipse.core.internal.expressions.Expressions:

public static Object convertArgument(String arg) throws CoreException {
    if (arg == null) {
        return null;
    } else if (arg.length() == 0) {
        return arg;
    } else if (arg.charAt(0) == '\'' && arg.charAt(arg.length() - 1) == '\'') {
        return unEscapeString(arg.substring(1, arg.length() - 1));
    } else if ("true".equals(arg)) { //$NON-NLS-1$
        return Boolean.TRUE;
    } else if ("false".equals(arg)) { //$NON-NLS-1$
        return Boolean.FALSE;
    } else if (arg.indexOf('.') != -1) {
        try {
            return Float.valueOf(arg);
        } catch (NumberFormatException e) {
            return arg;
        }
    } else {
        try {
            return Integer.valueOf(arg);
        } catch (NumberFormatException e) {
            return arg;
        }
    }
}

So it is a String unless it is true, false or a number.