@Override public <T> void visitCtClass(CtClass<T> ctClass) { context.pushCurrentThis(ctClass); if (ctClass.getSimpleName() != null && !CtType.NAME_UNKNOWN.equals(ctClass.getSimpleName()) && !ctClass.isAnonymous()) { visitCtType(ctClass); if (ctClass.isLocalType()) { printer.writeKeyword("class").writeSpace().writeIdentifier(ctClass.getSimpleName().replaceAll("^[0-9]*", "")); } else { printer.writeKeyword("class").writeSpace().writeIdentifier(ctClass.getSimpleName()); } elementPrinterHelper.writeFormalTypeParameters(ctClass); elementPrinterHelper.writeExtendsClause(ctClass); elementPrinterHelper.writeImplementsClause(ctClass); } printer.writeSpace().writeSeparator("{").incTab(); elementPrinterHelper.writeElementList(ctClass.getTypeMembers()); getPrinterHelper().adjustEndPosition(ctClass); printer.decTab().writeSeparator("}"); context.popCurrentThis(); }
private static CtStatement internalCompileStatement(CtElement st, CtTypeReference returnType) { Factory f = st.getFactory(); String contents = createWrapperContent(st, f, returnType); build(f, contents); CtType<?> c = f.Type().get(WRAPPER_CLASS_NAME); // Get the part we want CtMethod<?> wrapper = c.getMethod(WRAPPER_METHOD_NAME); List<CtStatement> statements = wrapper.getBody().getStatements(); CtStatement ret = statements.get(statements.size() - 1); // Clean up c.getPackage().removeType(c); //disconnect element from the parent, so it can be added to another model ret.delete(); ret.setParent(null); if (ret instanceof CtClass) { CtClass klass = (CtClass) ret; ret.getFactory().Package().getRootPackage().addType(klass); klass.setSimpleName(klass.getSimpleName().replaceAll("^[0-9]*", "")); } return ret; }
static String classPrefixedName(CtClass<?> ctClass, CtMethod<?> method) { return "_" + ctClass.getSimpleName() + "_" + method.getSimpleName(); } }
@Override public boolean matches(CtNewClass<?> element) { return getSimpleName().equals(element.getAnonymousClass().getSimpleName()); } }).get(0);
System.out.println("Error " + expression + " class " + ctofClass.getSimpleName()); e.printStackTrace();
public MethodNode(CompilationContext cxt, CtMethod<?> method, CtClass<?> declaringType) { super(cxt, capitalize(declaringType.getSimpleName()) + capitalize(method.getSimpleName()), declaringType); Stream.concat(stagedClassExtensionChain(declaringType).stream(), declaringType.getSuperInterfaces().stream() .flatMap(i -> Stream.concat(Stream.of(i), i.getSuperInterfaces().stream())) .flatMap(i -> { CtType<?> declaration = i.getDeclaration(); return declaration != null && declaration.getAnnotation(Staged.class) != null ? Stream.of(declaration) : Stream.empty(); })) .forEach(baseType -> baseType.getMethods().stream().filter(m -> overrides(method, m)).findAny() .ifPresent(m -> { methods.add(m); cxt.bind(m, this); })); CompilationNode declaringNode = cxt.getCompilationNode(declaringType); declaringType.getSuperInterfaces().stream() .flatMap(i -> Stream.concat(Stream.of(i), i.getSuperInterfaces().stream())) .forEach(superInterface -> { CtType<?> superInterfaceDeclaration = superInterface.getDeclaration(); if (superInterfaceDeclaration != null) { superInterfaceDeclaration.getMethods().stream() .filter(m -> overrides(method, m)) .forEach(m -> declaringNode.bind(m, this)); } }); }
public void computeAccessPaths() { cxt.allClasses().forEach(ctC -> stagedClassExtensionChain(ctC).forEach(baseClass -> baseClass.getFields().forEach((CtField<?> field) -> { if (field.getAnnotation(StageRef.class) != null) { CtTypeReference<?> fieldClass = field.getType(); List<CtClass<?>> candidates = cxt.allClasses() .filter(c -> fieldClass.isAssignableFrom(c.getReference())) .collect(toList()); if (candidates.size() != 1) { throw sgce("Can assign " + candidates.stream().map(CtClass::getSimpleName).collect(toList()) + " to field " + field + " in " + baseClass.getSimpleName()); } cxt.bindReferenced(field, candidates.get(0)); CompilationNode referencingNode = cxt.getCompilationNode(ctC); CompilationNode referencedNode = cxt.getCompilationNode(candidates.get(0)); if (referencedNode.parent == referencingNode && referencedNode.parentAccessField == null) { referencedNode.parentAccessField = field; } } }))); root.computeRootAccessPath(); }
public <T> void visitCtClass(CtClass<T> ctClass) { SortedList<CtElement> lst = new SortedList<CtElement>(new CtLineElementComparator()); if (ctClass.getSimpleName() != null && !ctClass.isAnonymous()) { visitCtType(ctClass); write("class " + ctClass.getSimpleName()); lst.addAll(ctClass.getMethods()); if ((ctClass.getSimpleName() == null || ctClass.getSimpleName().isEmpty()) && ctClass.getParent() != null && ctClass.getParent() instanceof CtNewClass) { context.currentThis.push(((CtNewClass<?>) ctClass.getParent()).getType()); } else {
void mergeChildNodes() { CtClass<?> mergedClass = getMergedClass(); for (CompilationNode child : innerNodes) { CtClass<?> childMergedClass = child.getMergedClass(); add(mergedClass, childMergedClass, mergedClass::addNestedType); CtCodeSnippetExpression constructor = f.Core().createCodeSnippetExpression(); constructor.setValue("new " + childMergedClass.getSimpleName() + "()"); child.parentAccessField.setDefaultExpression(constructor); child.parentAccessField.setType((CtTypeReference) childMergedClass.getReference()); child.parentAccessField.addModifier(FINAL); child.mergeChildNodes(); } } }
@Override public <T> void visitCtTypeReference(CtTypeReference<T> ref) { CtType<?> ctType = ref.getDeclaration(); if (ctType instanceof CtClass) { CompilationNode node = cxt.getNodeByAnyStagedClass((CtClass) ctType); if (node != null) { CtClass<?> mergedClass = node.getMergedClass(); CtPackage mergedPackage = mergedClass.getPackage(); if (mergedPackage != null) ref.setPackage(mergedPackage.getReference()); CtType<?> declaringType = mergedClass.getDeclaringType(); if (declaringType != null) { CtTypeReference<?> declaringTypeRef = declaringType.getReference(); declaringTypeRef.setActualTypeArguments( (List) declaringType.getFormalTypeParameters()); ref.setDeclaringType(declaringTypeRef); } ref.setSimpleName(mergedClass.getSimpleName()); if (node.eraseTypeParameters) { ref.setActualTypeArguments(emptyList()); } else if (!ref.getActualTypeArguments().isEmpty()){ ref.setActualTypeArguments((List) mergedClass.getFormalTypeParameters()); } return; } } super.visitCtTypeReference(ref); } });
invocation += "\"" + parent.getSimpleName() + "\""; } else { return;