public Factory getFactory() { return element.getFactory(); }
private static CtType<?> getType(String qualifiedName, CtElement anElement) { Class aClass; try { aClass = anElement.getClass().getClassLoader().loadClass(qualifiedName); } catch (ClassNotFoundException e) { //OK, that interface has no implementation class return null; } return anElement.getFactory().Type().get(aClass); }
protected Factory getFactory() { if (templateTypeRef != null) { return templateTypeRef.getFactory(); } if (!patternModel.isEmpty()) { return patternModel.get(0).getFactory(); } throw new SpoonException("PatternBuilder has no CtElement to provide a Factory"); }
/** * Creates a {@link TemplateBuilder}, which builds {@link Pattern} from {@link Template} * @param templateRoot the root element of {@link Template} model * @param template a instance of the {@link Template}. It is needed here, * because parameter value types influences which AST nodes will be the target of substitution * @return {@link TemplateBuilder} */ public static TemplateBuilder createPattern(CtElement templateRoot, Template<?> template) { CtClass<? extends Template<?>> templateType = Substitution.getTemplateCtClass(templateRoot.getFactory(), template); return createPattern(templateRoot, templateType, template); } //needed to provide access to protected members
/** * Verifies that the actual value is equal to the given one. * * @param expected * The expected render of the element. * @return {@code this} assertion object. */ public T isEqualTo(String expected) { assertNotNull(expected); process(actual.getFactory(), processors); if (!actual.toString().equals(expected)) { throw new AssertionError(String.format("%1$s and %2$s aren't equals.", actual.getShortRepresentation(), expected)); } return this.myself; } }
private FineModelChangeListener getModelChangeListener() { return getOwner().getFactory().getEnvironment().getModelChangeListener(); }
private FineModelChangeListener getModelChangeListener() { return getOwner().getFactory().getEnvironment().getModelChangeListener(); } }
private void addParameterCommentTo(CtElement ele, ParamOnElement... paramsOnElement) { for (ParamOnElement paramOnElement : paramsOnElement) { if (isNodeContained(paramOnElement.node) == false) { params.add(paramOnElement); } } if (isPrintParametersAsComments() && isCommentVisible(ele) && !params.isEmpty()) { ele.addComment(ele.getFactory().Code().createComment(getSubstitutionRequestsDescription(ele, params), CommentType.BLOCK)); params.clear(); } }
public SpoonModelTree(CtElement rootElement) { SpoonTreeBuilder cst = new SpoonTreeBuilder(); cst.scan(rootElement); this.factory = rootElement.getFactory(); root = cst.getRoot(); initialize(); }
/** * Verifies that the actual value is equal to the given one. * * @param expected * The expected element. * @return {@code this} assertion object. */ public T isEqualTo(CtElement expected) { assertNotNull(expected); assertIsSame(actual, expected); process(actual.getFactory(), processors); // using the new method to have a nice error message assertCtElementEquals(expected, actual); return this.myself; }
private CtComment getJavaDoc(CtElement ele) { for (CtComment comment : ele.getComments()) { if (comment.getCommentType() == CtComment.CommentType.JAVADOC) { return comment; } } CtComment c = ele.getFactory().Code().createComment("", CtComment.CommentType.JAVADOC); ele.addComment(c); return c; }
static void linkToParent(CtElement owner, CtElement element) { if (owner.getFactory().getEnvironment().checksAreSkipped() == false && element.isParentInitialized() && element.getParent() != owner) { //the `e` already has an different parent. Check if it is still linked to that parent if (element.getRoleInParent() != null) { throw new SpoonException("The default behavior has changed, a new check has been added! Don't worry, you can disable this check\n" + "with one of the following options:\n" + " - by configuring Spoon with getEnvironment().setSelfChecks(true)\n" + " - by removing the node from its previous parent (element.delete())\n" + " - by cloning the node before adding it here (element.clone())\n" ); } } element.setParent(owner); }
@Override public void apply(CtElement input, CtConsumer<Object> outputConsumer) { if (input == null) { return; } if (includingSelf) { outputConsumer.accept(input); } CtElement parent = input; CtModule topLevel = input.getFactory().getModel().getUnnamedModule(); while (parent != null && parent != topLevel && query.isTerminated() == false && parent.isParentInitialized()) { parent = parent.getParent(); outputConsumer.accept(parent); } }
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; }
Factory f = templateRoot.getFactory();
@Override public void apply(CtTypeInformation input, final CtConsumer<Object> outputConsumer) { final SubInheritanceHierarchyResolver fnc = new SubInheritanceHierarchyResolver(((CtElement) input).getFactory().getModel().getRootPackage()) .failOnClassNotFound(failOnClassNotFound) .includingInterfaces(includingInterfaces); if (includingSelf) { if (input instanceof CtTypeReference) { outputConsumer.accept(((CtTypeReference<?>) input).getTypeDeclaration()); } else { outputConsumer.accept(((CtType<?>) input)); } } fnc.addSuperType(input); fnc.forEachSubTypeInPackage(new CtConsumer<CtType>() { @Override public void accept(CtType typeInfo) { outputConsumer.accept(typeInfo); if (query.isTerminated()) { //Cannot terminate, because its support was removed. //I think there are cases where it might be useful. // fnc.terminate(); } } }); }
public static void addComment(CtElement element, String content, CtComment.CommentType type) { CtComment comment = element.getFactory().createComment(content, type); if (!element.getComments().contains(comment)) { element.addComment(comment); } }
private String partialElementPrint(CtElement element) { DefaultJavaPrettyPrinter print = new DefaultJavaPrettyPrinter(element.getFactory().getEnvironment()) { @Override public DefaultJavaPrettyPrinter scan(CtElement e) { if (e != null && e.getMetadata("isMoved") == null) { return super.scan(e); } return this; } }; print.scan(element); return print.getResult(); }
isInStaticScope = false; CtQuery siblingsQuery = input.getFactory().createQuery() .map(new SiblingsFunction().mode(SiblingsFunction.Mode.PREVIOUS))
/** * Remove template-specific {@link Local} annotations. */ @Override public void scanCtElement(CtElement e) { CtAnnotation<?> a = e.getAnnotation(e.getFactory().Type().createReference(Local.class)); if (a != null) { e.removeAnnotation(a); } super.scanCtElement(e); }