org.mozilla.javascript.annotations.JSGetter Java Examples

The following examples show how to use org.mozilla.javascript.annotations.JSGetter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScriptableObject.java    From JsDroidCmd with Mozilla Public License 2.0 5 votes vote down vote up
private static String getPropertyName(String methodName,
                                      String prefix,
                                      Annotation annotation) {
    if (prefix != null) {
        return methodName.substring(prefix.length());
    }
    String propName = null;
    if (annotation instanceof JSGetter) {
        propName = ((JSGetter) annotation).value();
        if (propName == null || propName.length() == 0) {
            if (methodName.length() > 3 && methodName.startsWith("get")) {
                propName = methodName.substring(3);
                if (Character.isUpperCase(propName.charAt(0))) {
                    if (propName.length() == 1) {
                        propName = propName.toLowerCase();
                    } else if (!Character.isUpperCase(propName.charAt(1))){
                        propName = Character.toLowerCase(propName.charAt(0))
                                + propName.substring(1);
                    }
                }
            }
        }
    } else if (annotation instanceof JSFunction) {
        propName = ((JSFunction) annotation).value();
    } else if (annotation instanceof JSStaticFunction) {
        propName = ((JSStaticFunction) annotation).value();
    }
    if (propName == null || propName.length() == 0) {
        propName = methodName;
    }
    return propName;
}
 
Example #2
Source File: ScriptableObject.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private static String getPropertyName(String methodName,
                                      String prefix,
                                      Annotation annotation) {
    if (prefix != null) {
        return methodName.substring(prefix.length());
    }
    String propName = null;
    if (annotation instanceof JSGetter) {
        propName = ((JSGetter) annotation).value();
        if (propName == null || propName.length() == 0) {
            if (methodName.length() > 3 && methodName.startsWith("get")) {
                propName = methodName.substring(3);
                if (Character.isUpperCase(propName.charAt(0))) {
                    if (propName.length() == 1) {
                        propName = propName.toLowerCase();
                    } else if (!Character.isUpperCase(propName.charAt(1))){
                        propName = Character.toLowerCase(propName.charAt(0))
                                + propName.substring(1);
                    }
                }
            }
        }
    } else if (annotation instanceof JSFunction) {
        propName = ((JSFunction) annotation).value();
    } else if (annotation instanceof JSStaticFunction) {
        propName = ((JSStaticFunction) annotation).value();
    }
    if (propName == null || propName.length() == 0) {
        propName = methodName;
    }
    return propName;
}
 
Example #3
Source File: DefineClassTest.java    From rhino-android with Apache License 2.0 4 votes vote down vote up
@JSGetter
public String getFoo() {
    return foo;
}
 
Example #4
Source File: DefineClassTest.java    From rhino-android with Apache License 2.0 4 votes vote down vote up
@JSGetter("bar")
public String getMyBar() {
    return bar;
}
 
Example #5
Source File: Counter.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@JSGetter
public int getCount() { return count++; }
 
Example #6
Source File: File.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@JSGetter
public int getLineNumber()
    throws FileNotFoundException
{
    return getReader().getLineNumber();
}
 
Example #7
Source File: Foo.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * The Java method implementing the getter for the counter property.
 * <p>
 * If "setCounter" had been defined in this class, the runtime would
 * call the setter when the property is assigned to.
 */
@JSGetter
public int getCounter() {
    return counter++;
}
 
Example #8
Source File: File.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Get the name of the file.
 *
 * Used to define the "name" property.
 */
@JSGetter
public String getName() {
    return name;
}