@Override public void scanCtNamedElement(CtNamedElement e) { if (e.getSimpleName() != null) { hashCode += e.getSimpleName().hashCode(); } }
/** * Gets a list of references from a list of elements. * * @param <R> * the expected reference type * @param <E> * the element type * @param elements * the element list * @return the corresponding list of references */ @SuppressWarnings("unchecked") public <R extends CtReference, E extends CtNamedElement> List<R> getReferences(List<E> elements) { List<R> refs = new ArrayList<>(elements.size()); for (E e : elements) { refs.add((R) e.getReference()); } return refs; }
/** * Scans an abstract named element. */ // auto-generated, see spoon.generating.CloneVisitorGenerator public void scanCtNamedElement(spoon.reflect.declaration.CtNamedElement e) { ((spoon.reflect.declaration.CtNamedElement) (other)).setSimpleName(e.getSimpleName()); super.scanCtNamedElement(e); }
@Override public boolean isToBeProcessed(CtNamedElement candidate) { return candidate instanceof CtType<?> || candidate instanceof CtModule || candidate instanceof CtPackage && (!candidate.getComments().isEmpty() || !candidate.getAnnotations().isEmpty()); }
/** * Replaces parameters in element names (even if detected as a * substring). */ @Override public void scanCtNamedElement(CtNamedElement element) { if (element.getDocComment() != null) { element.setDocComment(substituteInDocComment(element.getDocComment())); } // replace parameters in names String name = element.getSimpleName(); for (String pname : parameterNames) { if (name.contains(pname)) { Object value = Parameters.getValue(template, pname, null); if (value instanceof String) { // replace with the string value name = name.replace(pname, (String) value); element.setSimpleName(name); } else if ((value instanceof CtTypeReference) && (element instanceof CtType)) { // replace with the type reference's name name = name.replace(pname, ((CtTypeReference<?>) value).getSimpleName()); element.setSimpleName(name); } } } super.scanCtNamedElement(element); }
@Override public <T, U> void setValue(T element, U value) { castTarget(element).setSimpleName(castValue(value)); } }
public void visitCtNamedElement(CtNamedElement e) { // Write comments if (!env.isPreserveLineNumbers() && env.isGenerateJavadoc() && (e.getDocComment() != null)) { write("/** ").writeln().writeTabs(); String[] lines = e.getDocComment().split("\n"); for (int i = 0; i < lines.length; i++) { String com = lines[i].trim(); if ("".equals(com) && (i == 0 || i == lines.length - 1)) { continue; } if (com.startsWith("//")) { write(com).writeln().writeTabs(); } else { write(" * " + com).writeln().writeTabs(); } } write(" */").writeln(); } // Write element parameters (Annotations) writeAnnotations(e); if (env.isPreserveLineNumbers()) { adjustPosition(e); } }
@Override public NameScopeImpl addNamedElement(CtNamedElement element) { elementsByName.put(element.getSimpleName(), element); return this; }
this.imports.add(createImportWithPosition(methodOrField.getReference(), importRef));
@Override public boolean matches(T element) { try { return name.equals(element.getSimpleName()); } catch (UnsupportedOperationException e) { return false; } }
/** * Gets a list of references from a list of elements. * * @param <R> * the expected reference type * @param <E> * the element type * @param elements * the element list * @return the corresponding list of references */ @SuppressWarnings("unchecked") public <R extends CtReference, E extends CtNamedElement> List<R> getReferences(List<E> elements) { List<R> refs = new ArrayList<R>(elements.size()); for (E e : elements) { refs.add((R) e.getReference()); } return refs; }
private <T extends CtNamedElement> void putIfNotExists(Map<String, T> map, T element) { if (element == null) { //noclasspath mode. Ignore that. return; } String name = element.getSimpleName(); if (!map.containsKey(name)) { map.put(name, element); } } }
@Override public boolean matches(T element) { try { return acceptedClass.isAssignableFrom(element.getClass()) && name.equals(element.getSimpleName()); } catch (UnsupportedOperationException e) { return false; } }
@SuppressWarnings("unchecked") @Override public <T, U> U getValue(T element) { return ((U) ((Object) (castTarget(element).getSimpleName()))); }
@Override public void scanCtNamedElement(CtNamedElement e) { final CtNamedElement peek = (CtNamedElement) this.other; if (!e.getSimpleName().equals(peek.getSimpleName())) { setNotEqual(CtRole.NAME); } super.scanCtNamedElement(e); }
@Override public void scanCtElement(CtElement e) { if (WILDCARD.equals(pattern) || RECURSIVE_WILDCARD.equals(pattern)) { results.add(e); } else if (e instanceof CtExecutable && matchPattern(getSignature((CtExecutable) e))) { results.add(e); } else if (e instanceof CtNamedElement && matchPattern(((CtNamedElement) e).getSimpleName())) { results.add(e); } else if (e instanceof CtReference && matchPattern(((CtReference) e).getSimpleName())) { results.add(e); } }
private CtElement getFromSet(Collection<?> set, String name) throws CtPathException { for (Object o: set) { if (o instanceof CtNamedElement) { if (((CtNamedElement) o).getSimpleName().equals(name)) { return (CtElement) o; } } else if (o instanceof CtReference) { if (((CtReference) o).getSimpleName().equals(name)) { return (CtElement) o; } } else { throw new CtPathException(); } } //Element is not found in set. return null; }
private static void addParentPath(StringBuilder sb, CtElement ele) { if (ele == null || (ele instanceof CtPackage && ((CtPackage) ele).isUnnamedPackage())) { return; } if (ele.isParentInitialized()) { addParentPath(sb, ele.getParent()); } sb.append("\n\t").append(ele.getClass().getSimpleName()); if (ele instanceof CtNamedElement) { sb.append(":").append(((CtNamedElement) ele).getSimpleName()); } else if (ele instanceof CtReference) { sb.append(":").append(((CtReference) ele).getSimpleName()); } }
private String[] getArg(CtElement item) { String name = null; String attrName = "name"; if (item instanceof CtExecutable) { name = getSignature((CtExecutable) item); attrName = "signature"; } else if (item instanceof CtNamedElement) { name = ((CtNamedElement) item).getSimpleName(); } else if (item instanceof CtReference) { name = ((CtReference) item).getSimpleName(); } return new String[]{attrName, name}; }
@Override public CtElement getParent() throws ParentNotInitializedException { if (parent == null) { String exceptionMsg; if (this instanceof CtReference) { exceptionMsg = "parent not initialized for " + ((CtReference) this).getSimpleName() + "(" + this.getClass() + ")"; } else { SourcePosition pos = getPosition(); if (this instanceof CtNamedElement) { exceptionMsg = ("parent not initialized for " + ((CtNamedElement) this).getSimpleName() + "(" + this.getClass() + ")" + (pos != null ? " " + pos : " (?)")); } else { exceptionMsg = ("parent not initialized for " + this.getClass() + (pos != null ? " " + pos : " (?)")); } } throw new ParentNotInitializedException(exceptionMsg); } return parent; }