public void createFactoryMethods(CodeTypeElement clazz) { List<ExecutableElement> constructors = GeneratorUtils.findUserConstructors(createdFactoryElement.asType()); for (ExecutableElement constructor : constructors) { clazz.add(createCreateMethod(constructor)); if (constructor instanceof CodeExecutableElement) { ElementUtils.setVisibility(constructor.getModifiers(), Modifier.PRIVATE); } } }
public void createFactoryMethods(CodeTypeElement clazz) { List<ExecutableElement> constructors = GeneratorUtils.findUserConstructors(createdFactoryElement.asType()); for (ExecutableElement constructor : constructors) { clazz.add(createCreateMethod(constructor)); if (constructor instanceof CodeExecutableElement) { ElementUtils.setVisibility(constructor.getModifiers(), Modifier.PRIVATE); } } }
private Element createGetNext(CodeTypeElement type) { if (!nextUsed) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), type.asType(), "getNext"); CodeTreeBuilder builder = method.createBuilder(); builder.startReturn().cast(type.asType(), CodeTreeBuilder.singleString("this.next")).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 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 SpecializationData createSpecializations(CodeTypeElement clazz) { CodeTypeElement baseSpecialization = clazz.add(createBaseSpecialization()); TypeMirror baseSpecializationType = baseSpecialization.asType(); Map<SpecializationData, CodeTypeElement> generated = new LinkedHashMap<>(); List<SpecializationData> generateSpecializations = new ArrayList<>(); generateSpecializations.add(node.getUninitializedSpecialization()); if (needsPolymorphic()) { generateSpecializations.add(node.getPolymorphicSpecialization()); } generateSpecializations.addAll(reachableSpecializations); for (SpecializationData specialization : generateSpecializations) { generated.put(specialization, clazz.add(createSpecialization(specialization, baseSpecializationType))); } baseSpecialization.addOptional(createCreateNext(generated)); baseSpecialization.addOptional(createCreateFallback(generated)); baseSpecialization.addOptional(createCreatePolymorphic(generated)); baseSpecialization.addOptional(createGetNext(baseSpecialization)); for (NodeExecutionData execution : node.getChildExecutions()) { Collection<TypeMirror> specializedTypes = node.findSpecializedTypes(execution); specializedTypes.add(genericType); for (TypeMirror specializedType : specializedTypes) { if (isExecuteChildShared(execution, specializedType)) { baseSpecialization.addOptional(createExecuteChildMethod(execution, specializedType)); } } } return node.getUninitializedSpecialization(); }
private Element createCreate(CodeTypeElement clazz) { String methodName = "create"; CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), clazz.asType(), methodName); method.addParameter(new CodeVariableElement(context.getType(Object.class), "value")); CodeTreeBuilder builder = method.createBuilder(); builder.declaration(clazz.asType(), "newCast", builder.create().startNew(clazz.asType()).end()); for (TypeMirror sourceType : sourceTypes) { String seenField = seenFieldName(sourceType); builder.startStatement(); builder.string("newCast.").string(seenField).string(" = ").tree(TypeSystemCodeGenerator.check(typeSystem, sourceType, "value")); builder.end(); } builder.startReturn().string("newCast").end(); return method; }
builder.startReturn().startNew(wrapper.asType()); if (firstParameterReference != null) { builder.string(firstParameterReference);
List<ExecutableElement> signatures = GeneratorUtils.findUserConstructors(createdFactoryElement.asType()); boolean ifStarted = false;
List<ExecutableElement> signatures = GeneratorUtils.findUserConstructors(createdFactoryElement.asType()); boolean ifStarted = false;
private CodeExecutableElement createCreateGetNodeSignatures() { TypeMirror returnValue = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(context.getType(List.class))); CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), returnValue, "getNodeSignatures"); CodeTreeBuilder builder = method.createBuilder(); builder.startReturn(); builder.startGroup(); builder.startStaticCall(context.getType(Arrays.class), "asList"); List<ExecutableElement> constructors = GeneratorUtils.findUserConstructors(createdFactoryElement.asType()); for (ExecutableElement constructor : constructors) { builder.startGroup(); builder.startStaticCall(context.getType(Arrays.class), "asList"); for (VariableElement var : constructor.getParameters()) { builder.typeLiteral(var.asType()); } builder.end(); builder.end(); } builder.end(); builder.end(); builder.end(); return method; }
public CodeTypeElement create() { Modifier visibility = ElementUtils.getVisibility(node.getTemplateType().getModifiers()); TypeMirror nodeFactory = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(context.getTruffleTypes().getNodeFactoryBase()), node.getNodeType()); CodeTypeElement clazz = GeneratorUtils.createClass(node, null, modifiers(), factoryClassName(node), null); if (visibility != null) { clazz.getModifiers().add(visibility); } clazz.getModifiers().add(Modifier.FINAL); if (createdFactoryElement != null) { clazz.setSuperClass(nodeFactory); clazz.add(createNodeFactoryConstructor()); clazz.add(createCreateNodeMethod()); clazz.add(createGetInstanceMethod(visibility)); clazz.add(createInstanceConstant(clazz.asType())); createFactoryMethods(clazz); } return clazz; }
private Element createMerge(CodeTypeElement clazz) { String methodName = "merge"; CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC), context.getType(void.class), methodName); method.addParameter(new CodeVariableElement(clazz.asType(), "otherCast")); CodeTreeBuilder builder = method.createBuilder(); for (TypeMirror sourceType : sourceTypes) { String seenField = seenFieldName(sourceType); builder.startStatement(); builder.string("this.").string(seenField).string(" |= ").string("otherCast.").string(seenField); builder.end(); } return method; }
public CodeTypeElement create() { Modifier visibility = ElementUtils.getVisibility(node.getTemplateType().getModifiers()); TypeMirror nodeFactory = ElementUtils.getDeclaredType(ElementUtils.fromTypeMirror(context.getType(NodeFactory.class)), node.getNodeType()); CodeTypeElement clazz = GeneratorUtils.createClass(node, null, modifiers(), factoryClassName(node), null); if (visibility != null) { clazz.getModifiers().add(visibility); } clazz.getModifiers().add(Modifier.FINAL); if (createdFactoryElement != null) { clazz.getImplements().add(nodeFactory); CodeAnnotationMirror supressWarnings = new CodeAnnotationMirror(context.getDeclaredType(SuppressWarnings.class)); supressWarnings.setElementValue(supressWarnings.findExecutableElement("value"), new CodeAnnotationValue(Arrays.asList(new CodeAnnotationValue("unchecked"), new CodeAnnotationValue("rawtypes")))); clazz.getAnnotationMirrors().add(supressWarnings); clazz.add(createNodeFactoryConstructor()); clazz.add(createCreateGetNodeClass()); clazz.add(createCreateGetExecutionSignature()); clazz.add(createCreateGetNodeSignatures()); clazz.add(createCreateNodeMethod()); clazz.add(createGetInstanceMethod(visibility)); clazz.add(createInstanceConstant(clazz.asType())); createFactoryMethods(clazz); } return clazz; }
annotationType = Child.class; if (specialization.getMaximumNumberOfInstances() > 1) { cacheType.add(createNodeField(null, cacheType.asType(), "next_", Child.class)); annotationType = CompilationFinal.class; if (specialization.getMaximumNumberOfInstances() > 1) { cacheType.add(createNodeField(null, cacheType.asType(), "next_", annotationType)); cacheType.getEnclosedElements().addAll(fields); clazz.add(createNodeField(PRIVATE, cacheType.asType(), createSpecializationFieldName(specialization), annotationType));
List<ExecutableElement> constructors = GeneratorUtils.findUserConstructors(createdFactoryElement.asType()); for (ExecutableElement constructor : constructors) { builder.startGroup();