MCPcopy Create free account
hub / github.com/GateNLP/gate-core / createCompilerInstance

Method createCompilerInstance

src/main/java/gate/util/Javac.java:108–142  ·  view source on GitHub ↗
(String compilerType)

Source from the content-addressed store, hash-verified

106 }
107
108 private static Javac createCompilerInstance(String compilerType)
109 throws GateException {
110 Class<?> compilerClass = null;
111 try {
112 // first treat the compiler type as a fully qualified class name
113 compilerClass = Gate.getClassLoader().loadClass(compilerType, true);
114 } catch(ClassNotFoundException cnfe) {
115 // ignore exception but leave compilerClass == null
116 }
117
118 if(compilerClass == null || !Javac.class.isAssignableFrom(compilerClass)) { throw new GateException(
119 "Unable to load Java compiler class " + compilerType); }
120
121 // At this point we have successfully loaded a compiler class.
122 // Now try and create an instance using a no-argument constructor.
123 try {
124 Constructor<?> noArgConstructor = compilerClass.getConstructor();
125 return (Javac)noArgConstructor.newInstance();
126 } catch(IllegalAccessException iae) {
127 throw new GateException("Cannot access Java compiler class "
128 + compilerType, iae);
129 } catch(InstantiationException ie) {
130 throw new GateException("Cannot instantiate Java compiler class "
131 + compilerType, ie);
132 } catch(NoSuchMethodException nsme) {
133 throw new GateException("Java compiler class " + compilerType
134 + " does not have a no-argument constructor", nsme);
135 } catch(InvocationTargetException ite) {
136 throw new GateException("Exception when constructing Java compiler "
137 + "of type " + compilerType, ite.getCause());
138 } catch(ExceptionInInitializerError eiie) {
139 throw new GateException("Exception when initializing Java compiler "
140 + "class " + compilerType, eiie.getCause());
141 }
142 }
143
144 /**
145 * Compile a set of Java sources, and load the resulting classes into the GATE

Callers 1

Calls 2

getClassLoaderMethod · 0.95
loadClassMethod · 0.80

Tested by

no test coverage detected