< prev index next >

buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/Main.java

Print this page




 123                 // instrument @ScriptClass
 124                 final ClassWriter writer = ClassGenerator.makeClassWriter();
 125                 final ClassReader reader = new ClassReader(buf);
 126                 final ScriptClassInstrumentor inst = new ScriptClassInstrumentor(writer, sci);
 127                 reader.accept(inst, 0);
 128                 //noinspection UnusedAssignment
 129 
 130                 // write instrumented class
 131                 try (FileOutputStream fos = new FileOutputStream(new File(outDir, inFile.getName()))) {
 132                     buf = writer.toByteArray();
 133                     if (DEBUG) {
 134                         verify(buf);
 135                     }
 136                     fos.write(buf);
 137                 }
 138 
 139                 // simple class name without package prefix
 140                 String simpleName = inFile.getName();
 141                 simpleName = simpleName.substring(0, simpleName.indexOf(".class"));
 142 
 143                 if (sci.getPrototypeMemberCount() > 0) {
 144                     // generate prototype class
 145                     final PrototypeGenerator protGen = new PrototypeGenerator(sci);
 146                     buf = protGen.getClassBytes();
 147                     if (DEBUG) {
 148                         verify(buf);
 149                     }
 150                     try (FileOutputStream fos = new FileOutputStream(new File(outDir, simpleName + StringConstants.PROTOTYPE_SUFFIX + ".class"))) {
 151                         fos.write(buf);
 152                     }
 153                 }
 154 
 155                 if (sci.getConstructorMemberCount() > 0 || sci.getConstructor() != null) {
 156                     // generate constructor class
 157                     final ConstructorGenerator consGen = new ConstructorGenerator(sci);
 158                     buf = consGen.getClassBytes();
 159                     if (DEBUG) {
 160                         verify(buf);
 161                     }
 162                     try (FileOutputStream fos = new FileOutputStream(new File(outDir, simpleName + StringConstants.CONSTRUCTOR_SUFFIX + ".class"))) {
 163                         fos.write(buf);
 164                     }
 165                 }
 166             }
 167             return true;
 168         } catch (final IOException | RuntimeException e) {
 169             if (DEBUG) {
 170                 e.printStackTrace(System.err);
 171             }
 172             reporter.error(e.getMessage());
 173 
 174             return false;
 175         }


 123                 // instrument @ScriptClass
 124                 final ClassWriter writer = ClassGenerator.makeClassWriter();
 125                 final ClassReader reader = new ClassReader(buf);
 126                 final ScriptClassInstrumentor inst = new ScriptClassInstrumentor(writer, sci);
 127                 reader.accept(inst, 0);
 128                 //noinspection UnusedAssignment
 129 
 130                 // write instrumented class
 131                 try (FileOutputStream fos = new FileOutputStream(new File(outDir, inFile.getName()))) {
 132                     buf = writer.toByteArray();
 133                     if (DEBUG) {
 134                         verify(buf);
 135                     }
 136                     fos.write(buf);
 137                 }
 138 
 139                 // simple class name without package prefix
 140                 String simpleName = inFile.getName();
 141                 simpleName = simpleName.substring(0, simpleName.indexOf(".class"));
 142 
 143                 if (sci.isPrototypeNeeded()) {
 144                     // generate prototype class
 145                     final PrototypeGenerator protGen = new PrototypeGenerator(sci);
 146                     buf = protGen.getClassBytes();
 147                     if (DEBUG) {
 148                         verify(buf);
 149                     }
 150                     try (FileOutputStream fos = new FileOutputStream(new File(outDir, simpleName + StringConstants.PROTOTYPE_SUFFIX + ".class"))) {
 151                         fos.write(buf);
 152                     }
 153                 }
 154 
 155                 if (sci.isConstructorNeeded()) {
 156                     // generate constructor class
 157                     final ConstructorGenerator consGen = new ConstructorGenerator(sci);
 158                     buf = consGen.getClassBytes();
 159                     if (DEBUG) {
 160                         verify(buf);
 161                     }
 162                     try (FileOutputStream fos = new FileOutputStream(new File(outDir, simpleName + StringConstants.CONSTRUCTOR_SUFFIX + ".class"))) {
 163                         fos.write(buf);
 164                     }
 165                 }
 166             }
 167             return true;
 168         } catch (final IOException | RuntimeException e) {
 169             if (DEBUG) {
 170                 e.printStackTrace(System.err);
 171             }
 172             reporter.error(e.getMessage());
 173 
 174             return false;
 175         }
< prev index next >