- Common ways to obtain JDefinedClass
private void myMethod () {JDefinedClass j =
JCodeModel codeModel;String fullyqualifiedName;codeModel._class(fullyqualifiedName)
JClassAlreadyExistsException e;e.getExistingClass()
JCodeModel cm;String fullyqualifiedName;ClassType t;cm._class(fullyqualifiedName, t)
- Smart code suggestions by Codota
}
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) throws SAXException { File javaFile = null; try { for(ClassOutline co : model.getClasses()) { javaFile = new File(opt.targetDir, co.target.fullName().replaceAll("\\.", "/") + ".java"); //System.out.println("simple_regenerator: [" //+ javaFile.getAbsolutePath() + "] " + (javaFile.canRead() ? "exists" : "non-existing")); if(!javaFile.canWrite()) continue; String preservedCode = getPreservedCode(javaFile); if(preservedCode != null) { System.out.println("simple_regenerator: preserved code in: [" + javaFile.getAbsolutePath() + "]"); co.implClass.direct(preservedCode); } } return true; } catch(Exception e) { errorHandler.error(new SAXParseException("Failed to write to "+ javaFile, null, e)); return false; } }
private void inject( final Context ctx, final File templateFile ) throws SAXException { info( "Injecting " + templateFile + " to " + ctx.definedClass.fullName() ); try { final StringBuilder text = FileUtils.read( templateFile ); // Remove everthing outside the outer {...} inclusive text.delete( 0, text.indexOf( "{" ) + 1 ); text.delete( text.lastIndexOf( "}" ), text.length() ); // Add comments either side of the injected source text.insert( 0, "\n\t// ========== Start of injected source ==========\n\n" ); text.append( "\n\t// ========== End of injected source ==========\n\n" ); ctx.definedClass.direct( text.toString() ); } catch( FileNotFoundException fnfe ) { // Just log the fact, no stacktrace fail( "Failed to locate template " + templateFile ); } catch( Exception ex ) { // catch everything else with a stacktrace fail( "failed to read template " + templateFile, ex ); } }
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) { for( ClassOutline co : model.getClasses() ) { CPluginCustomization c = co.target.getCustomizations().find(Const.NS,"code"); if(c==null) continue; // no customization --- nothing to inject here c.markAsAcknowledged(); // TODO: ideally you should validate this DOM element to make sure // that there's no typo/etc. JAXP 1.3 can do this very easily. String codeFragment = DOMUtils.getElementText(c.element); // inject the specified code fragment into the implementation class. co.implClass.direct(codeFragment); } return true; } }
public boolean run(Outline model, Options opt, ErrorHandler errorHandler) { for( ClassOutline co : model.getClasses() ) { CPluginCustomization c = co.target.getCustomizations().find(Const.NS,"code"); if(c==null) continue; // no customization --- nothing to inject here c.markAsAcknowledged(); // TODO: ideally you should validate this DOM element to make sure // that there's no typo/etc. JAXP 1.3 can do this very easily. String codeFragment = DOMUtils.getElementText(c.element); // inject the specified code fragment into the implementation class. co.implClass.direct(codeFragment); } return true; } }
private static void checkAndInject(Collection<? extends CustomizableOutline> outlines) { for (CustomizableOutline co : outlines) { CPluginCustomization c = co.getTarget().getCustomizations().find(Const.NS, "code"); if(c==null) continue; // no customization --- nothing to inject here c.markAsAcknowledged(); // TODO: ideally you should validate this DOM element to make sure // that there's no typo/etc. JAXP 1.3 can do this very easily. String codeFragment = DOMUtils.getElementText(c.element); // inject the specified code fragment into the implementation class. co.getImplClass().direct(codeFragment); } } }
private static void checkAndInject(Collection<? extends CustomizableOutline> outlines) { for (CustomizableOutline co : outlines) { CPluginCustomization c = co.getTarget().getCustomizations().find(Const.NS, "code"); if(c==null) continue; // no customization --- nothing to inject here c.markAsAcknowledged(); // TODO: ideally you should validate this DOM element to make sure // that there's no typo/etc. JAXP 1.3 can do this very easily. String codeFragment = DOMUtils.getElementText(c.element); // inject the specified code fragment into the implementation class. co.getImplClass().direct(codeFragment); } } }
private static void checkAndInject(Collection<? extends CustomizableOutline> outlines) { for (CustomizableOutline co : outlines) { CPluginCustomization c = co.getTarget().getCustomizations().find(Const.NS, "code"); if(c==null) continue; // no customization --- nothing to inject here c.markAsAcknowledged(); // TODO: ideally you should validate this DOM element to make sure // that there's no typo/etc. JAXP 1.3 can do this very easily. String codeFragment = DOMUtils.getElementText(c.element); // inject the specified code fragment into the implementation class. co.getImplClass().direct(codeFragment); } } }