protected void generate(AbstractJavaStructure structure, CodeMerger merger) { if (structure.getParent() == null) { addToDestPackage(structure); } // annotate the generated class as: @Generated("...") structure.getMetadata().add(Annotations.generated(GENERATED_BY)); // finally, generate the source code // if inDebugMode was set to true, the JAnnocessor UI will be displayed context.generateCode(structure, merger, inDebugMode); }
@SuppressWarnings("unchecked") protected <S extends AbstractJavaStructure> PowerList<S> findTypeParts( JavaType type, PowerList<S> typeParts) { PowerList<S> ss = Power.list(); for (AbstractJavaStructure typePart : typeParts) { String typeName = typePart.getType().getCanonicalName(); Pattern p = Pattern.compile("^.*\\b(" + typeName + ")\\b.*$"); Matcher m = p.matcher(type.getCanonicalName()); while (m.find()) { ss.add((S) typePart); } } return ss; }
private void addToDestPackage(AbstractJavaStructure structure) { switch (structure.getKind()) { case INTERFACE: getDestinationPackage().getInterfaces().add((JavaInterface) structure); break; case CLASS: getDestinationPackage().getClasses().add((JavaClass) structure); break; case ENUM: getDestinationPackage().getEnums().add((JavaEnum) structure); break; case ANNOTATION: getDestinationPackage().getAnnotations().add((JavaAnnotation) structure); break; default: throw new IllegalStateException( "Cannot put element of kind +" + structure.getKind() + " into a package!"); } }
protected JavaType replaceTypeParts( JavaType type, List<? extends AbstractJavaStructure> typeParts, Transformation<String, String> replacement) { String fullType = type.getCanonicalName(); for (AbstractJavaStructure typePart : typeParts) { String typeName = typePart.getType().getCanonicalName(); Pattern p = Pattern.compile("^.*\\b(" + typeName + ")\\b.*$"); Matcher m = p.matcher(fullType); while (m.find()) { String simpleTypeName = New.type(m.group(1)).getSimpleName().toString(); fullType = fullType.substring(0, m.start(1)) + replacement.transform(simpleTypeName) + fullType.substring(m.end(1)); m = p.matcher(fullType); } } return New.type(fullType); }