private CodeAnnotationMirror createUnusedAnnotationMirror() { CodeAnnotationMirror mirror = new CodeAnnotationMirror(unusedAnnotation); mirror.setElementValue(mirror.findExecutableElement("value"), new CodeAnnotationValue("unused")); return mirror; }
private CodeAnnotationMirror createUnusedAnnotationMirror() { CodeAnnotationMirror mirror = new CodeAnnotationMirror(unusedAnnotation); mirror.setElementValue(mirror.findExecutableElement("value"), new CodeAnnotationValue("unused")); return mirror; }
private static void setFieldCompilationFinal(CodeVariableElement field, int dimensions) { if (field.getModifiers().contains(Modifier.FINAL) && dimensions <= 0) { // no need for the compilation final annotation. return; } CodeAnnotationMirror annotation = new CodeAnnotationMirror(ProcessorContext.getInstance().getDeclaredType(CompilationFinal.class)); if (dimensions > 0 || field.getType().getKind() == TypeKind.ARRAY) { annotation.setElementValue(annotation.findExecutableElement("dimensions"), new CodeAnnotationValue(dimensions < 0 ? 0 : dimensions)); } field.getAnnotationMirrors().add(annotation); }
private static void addGeneratedBy(ProcessorContext context, CodeTypeElement generatedType, TypeElement generatedByType) { DeclaredType generatedBy = (DeclaredType) context.getType(GeneratedBy.class); // only do this if generatedBy is on the classpath. if (generatedBy != null) { CodeAnnotationMirror generatedByAnnotation = new CodeAnnotationMirror(generatedBy); generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("value"), new CodeAnnotationValue(generatedByType.asType())); generatedType.addAnnotationMirror(generatedByAnnotation); } }
private static CodeVariableElement createNodeChild(ProcessorContext context, TypeMirror type, String name) { CodeVariableElement var = new CodeVariableElement(ElementUtils.modifiers(Modifier.PRIVATE), type, name); var.addAnnotationMirror(new CodeAnnotationMirror((DeclaredType) context.getType(Child.class))); return var; }
private CodeVariableElement createNodeField(Modifier visibility, TypeMirror type, String name, Class<?> annotationType) { CodeVariableElement childField = new CodeVariableElement(modifiers(), type, name); childField.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(annotationType))); setVisibility(childField.getModifiers(), visibility); return childField; }
private Element createFastPathExecuteMethod(SpecializationData specialization, ExecutableTypeData executedType, List<ExecutableTypeData> allTypes) { LocalContext currentLocals = LocalContext.load(this, executedType, Integer.MAX_VALUE); CodeExecutableElement executable = createExecuteMethod(specialization, executedType, currentLocals, false, Integer.MAX_VALUE); CodeTreeBuilder builder = executable.createBuilder(); if (specialization == null) { if (executedType.getDelegatedTo() == null) { executable.getModifiers().add(ABSTRACT); } } else { executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); } builder.tree(createFastPath(builder, specialization, executedType, allTypes, currentLocals)); return executable; }
@Override public Void visitExecutable(CodeExecutableElement e, Void p) { if (!e.getModifiers().contains(Modifier.STATIC) && !e.getModifiers().contains(Modifier.PRIVATE)) { String name = e.getSimpleName().toString(); TypeMirror[] params = e.getParameterTypes(); for (AnnotationMirror mirror : e.getAnnotationMirrors()) { if (ElementUtils.typeEquals(overrideType, mirror.getAnnotationType())) { // already declared (may happen if method copied from super class) return super.visitExecutable(e, p); } } if (isDeclaredMethodInSuperType(e.getEnclosingClass(), name, params)) { e.addAnnotationMirror(new CodeAnnotationMirror(overrideType)); } } return super.visitExecutable(e, p); }
private CodeAnnotationMirror createExplodeLoop() { DeclaredType explodeLoopType = context.getDeclaredType(ExplodeLoop.class); CodeAnnotationMirror explodeLoop = new CodeAnnotationMirror(explodeLoopType); DeclaredType loopExplosionKind = context.getDeclaredType(ExplodeLoop.LoopExplosionKind.class); if (loopExplosionKind != null) { VariableElement kindValue = ElementUtils.findVariableElement(loopExplosionKind, "FULL_EXPLODE_UNTIL_RETURN"); if (kindValue != null) { explodeLoop.setElementValue(ElementUtils.findExecutableElement(explodeLoopType, "kind"), new CodeAnnotationValue(kindValue)); } } return explodeLoop; }
private static CodeVariableElement createNodeField(Modifier visibility, TypeMirror type, String name, Class<?> annotationClass, Modifier... modifiers) { CodeVariableElement childField = new CodeVariableElement(modifiers(modifiers), type, name); if (annotationClass != null) { if (annotationClass == CompilationFinal.class) { setFieldCompilationFinal(childField, 0); } else { childField.getAnnotationMirrors().add(new CodeAnnotationMirror(ProcessorContext.getInstance().getDeclaredType(annotationClass))); } } setVisibility(childField.getModifiers(), visibility); return childField; }
private Element createCreatePolymorphic(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) { SpecializationData polymorphic = node.getPolymorphicSpecialization(); CodeTypeElement generatedPolymorphic = generatedSpecializationClasses.get(polymorphic); if (generatedPolymorphic == null) { return null; } TypeMirror returnType = getType(SpecializationNode.class); CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), returnType, "createPolymorphic"); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); method.createBuilder().startReturn().tree(createCallCreateMethod(polymorphic, null, null)).end(); return method; }
private Element createGetSuppliedChildrenMethod() { ArrayType nodeArray = context.getEnvironment().getTypeUtils().getArrayType(getType(Node.class)); CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), nodeArray, "getSuppliedChildren"); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = method.createBuilder(); builder.startReturn().tree(createGetSuppliedChildren()).end(); return method; }
private CodeVariableElement createSingleton(CodeTypeElement clazz) { CodeVariableElement field = new CodeVariableElement(modifiers(PUBLIC, STATIC, FINAL), clazz.asType(), singletonName(typeSystem)); field.createInitBuilder().startNew(clazz.asType()).end(); CodeAnnotationMirror annotationMirror = new CodeAnnotationMirror((DeclaredType) context.getType(Deprecated.class)); field.getAnnotationMirrors().add(annotationMirror); return field; }
private Element createCreateFallback(Map<SpecializationData, CodeTypeElement> generatedSpecializationClasses) { SpecializationData fallback = node.getGenericSpecialization(); if (fallback == null) { return null; } CodeTypeElement generatedType = generatedSpecializationClasses.get(fallback); if (generatedType == null) { return null; } TypeMirror returnType = getType(SpecializationNode.class); CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), returnType, "createFallback"); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); method.createBuilder().startReturn().tree(createCallCreateMethod(fallback, null, null)).end(); return method; }
private CodeVariableElement createSingleton(CodeTypeElement clazz) { CodeVariableElement field = new CodeVariableElement(modifiers(PUBLIC, STATIC, FINAL), clazz.asType(), singletonName(typeSystem)); field.createInitBuilder().startNew(clazz.asType()).end(); CodeAnnotationMirror annotationMirror = new CodeAnnotationMirror((DeclaredType) context.getType(Deprecated.class)); field.getAnnotationMirrors().add(annotationMirror); return field; }
private Element createDeepCopyMethod() { if (singleSpecializable) { return null; } CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), getType(Node.class), "deepCopy"); executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = executable.createBuilder(); builder.startReturn().startStaticCall(getType(SpecializationNode.class), "updateRoot").string("super.deepCopy()").end().end(); return executable; }
static CodeTypeElement createClass(Template sourceModel, TemplateMethod sourceMethod, Set<Modifier> modifiers, String simpleName, TypeMirror superType) { TypeElement templateType = sourceModel.getTemplateType(); ProcessorContext context = ProcessorContext.getInstance(); PackageElement pack = context.getEnvironment().getElementUtils().getPackageOf(templateType); CodeTypeElement clazz = new CodeTypeElement(modifiers, ElementKind.CLASS, pack, simpleName); TypeMirror resolvedSuperType = superType; if (resolvedSuperType == null) { resolvedSuperType = context.getType(Object.class); } clazz.setSuperClass(resolvedSuperType); CodeAnnotationMirror generatedByAnnotation = new CodeAnnotationMirror((DeclaredType) context.getType(GeneratedBy.class)); generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("value"), new CodeAnnotationValue(templateType.asType())); if (sourceMethod != null && sourceMethod.getMethod() != null) { generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("methodName"), new CodeAnnotationValue(sourceMethod.createReferenceName())); } clazz.addAnnotationMirror(generatedByAnnotation); return clazz; }
public static CodeTypeElement createClass(Template sourceModel, TemplateMethod sourceMethod, Set<Modifier> modifiers, String simpleName, TypeMirror superType) { TypeElement templateType = sourceModel.getTemplateType(); ProcessorContext context = ProcessorContext.getInstance(); PackageElement pack = context.getEnvironment().getElementUtils().getPackageOf(templateType); CodeTypeElement clazz = new CodeTypeElement(modifiers, ElementKind.CLASS, pack, simpleName); TypeMirror resolvedSuperType = superType; if (resolvedSuperType == null) { resolvedSuperType = context.getType(Object.class); } clazz.setSuperClass(resolvedSuperType); CodeAnnotationMirror generatedByAnnotation = new CodeAnnotationMirror((DeclaredType) context.getType(GeneratedBy.class)); generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("value"), new CodeAnnotationValue(templateType.asType())); if (sourceMethod != null && sourceMethod.getMethod() != null) { generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("methodName"), new CodeAnnotationValue(sourceMethod.createReferenceName())); } clazz.addAnnotationMirror(generatedByAnnotation); return clazz; }
private Element createUnsupported() { SpecializationData fallback = node.getGenericSpecialization(); if (fallback == null || optimizeFallback(fallback) || fallback.getMethod() == null) { return null; } LocalContext locals = LocalContext.load(this); CodeExecutableElement method = locals.createMethod(modifiers(PROTECTED, FINAL), genericType, "unsupported", varArgsThreshold, FRAME_VALUE); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = method.createBuilder(); builder.startReturn(); builder.tree(callTemplateMethod(accessParent(null), fallback, locals)); builder.end(); return method; }
private Element createGetCostMethod() { TypeMirror returnType = getType(NodeCost.class); CodeExecutableElement executable = new CodeExecutableElement(modifiers(PUBLIC), returnType, "getCost"); executable.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = executable.createBuilder(); if (singleSpecializable) { builder.startReturn().staticReference(getType(NodeCost.class), "MONOMORPHIC").end().end(); } else { builder.startReturn().startCall(specializationStartFieldName(), "getNodeCost").end().end(); } return executable; }