Java Code Examples for jdk.nashorn.internal.runtime.Context#findClass()

The following examples show how to use jdk.nashorn.internal.runtime.Context#findClass() . 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: NativeJava.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(final ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(final ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}
 
Example 2
Source File: NativeJava.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(final ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(final ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}
 
Example 3
Source File: NativeJava.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(final ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(final ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}
 
Example 4
Source File: NativeJava.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(final ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(final ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}
 
Example 5
Source File: NativeJava.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(final ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(final ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}
 
Example 6
Source File: NativeJava.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(final ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(final ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}
 
Example 7
Source File: NativeJava.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}
 
Example 8
Source File: NativeJava.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}
 
Example 9
Source File: NativeJava.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(final ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(final ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}
 
Example 10
Source File: NativeJava.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static Class<?> simpleType(final String typeName) throws ClassNotFoundException {
    final Class<?> primClass = TypeUtilities.getPrimitiveTypeByName(typeName);
    if(primClass != null) {
        return primClass;
    }
    final Context ctx = Global.getThisContext();
    try {
        return ctx.findClass(typeName);
    } catch(ClassNotFoundException e) {
        // The logic below compensates for a frequent user error - when people use dot notation to separate inner
        // class names, i.e. "java.lang.Character.UnicodeBlock" vs."java.lang.Character$UnicodeBlock". The logic
        // below will try alternative class names, replacing dots at the end of the name with dollar signs.
        final StringBuilder nextName = new StringBuilder(typeName);
        int lastDot = nextName.length();
        for(;;) {
            lastDot = nextName.lastIndexOf(".", lastDot - 1);
            if(lastDot == -1) {
                // Exhausted the search space, class not found - rethrow the original exception.
                throw e;
            }
            nextName.setCharAt(lastDot, '$');
            try {
                return ctx.findClass(nextName.toString());
            } catch(ClassNotFoundException cnfe) {
                // Intentionally ignored, so the loop retries with the next name
            }
        }
    }

}