public String apply(String from) { if (from.startsWith("org.eclipse.emf.ecore")) return null; String customClassName = from + "Custom"; String fromPath = from.replace('.', '/'); for (String srcPath : srcPaths) { URI createURI = URI.createURI(srcPath + "/" + fromPath + "Custom.java"); if (URIConverter.INSTANCE.exists(createURI, null)) { return customClassName; } if (from.endsWith("Impl") && generateCustomClasses) { generate(from, customClassName, createURI); return customClassName; } } if (getClass().getClassLoader().getResourceAsStream(fromPath + "Custom.class") != null) { return customClassName; } return null; }
public void generate(String from, String customClassName, URI path) { StringBuilder sb = new StringBuilder(); sb.append(copyright()).append("\n"); int lastIndexOfDot = customClassName.lastIndexOf('.'); sb.append("package ").append(customClassName.substring(0, lastIndexOfDot)).append(";\n\n\n"); sb.append("public class ") .append(customClassName.substring(lastIndexOfDot + 1)) .append(" extends ") .append(from) .append(" {\n\n"); sb.append("}\n"); try { OutputStream stream = URIConverter.INSTANCE.createOutputStream(path); stream.write(sb.toString().getBytes()); stream.close(); } catch (IOException e) { throw new WrappedException(e); } }