@Override public Void visitIdentifier(IdentifierTree node, Void p) { translate.put(node, QualIdent(node.toString())); return null; } }.scan(typeTree, null);
@Override public Void visitMemberSelect(MemberSelectTree node, Void p) { translate.put(node, QualIdent(node.toString())); return null; } @Override
public Void visitMemberSelect(MemberSelectTree node, Void p) { TypeElement e = info.getElements().getTypeElement(node.toString()); if (e != null) { translateMap.put(node, make.QualIdent(e)); return null; } else { return super.visitMemberSelect(node, p); } }
private ExpressionTree tryCreateQualIdent(String typeName) { TypeElement typeElement = copy.getElements().getTypeElement(typeName); if (typeElement != null) { return getTreeMaker().QualIdent(typeElement); } return null; }
private ModifiersTree addAnnotation( String annotationFqn , TreeMaker maker,ModifiersTree modifiers ) { AnnotationTree newAnnotation = maker.Annotation( maker.QualIdent(annotationFqn) , Collections.<ExpressionTree>emptyList()); if (modifiers != null) { modifiers = maker.addModifiersAnnotation(modifiers, newAnnotation); } return modifiers; }
private ClassTree createMethods(Collection<String> classNames, MethodTree getClasses, TreeMaker maker, ClassTree modified, CompilationController controller) throws IOException { WildcardTree wildCard = maker.Wildcard(Tree.Kind.UNBOUNDED_WILDCARD, null); ParameterizedTypeTree wildClass = maker.ParameterizedType( maker.QualIdent(Class.class.getCanonicalName()), Collections.singletonList(wildCard)); ParameterizedTypeTree wildSet = maker.ParameterizedType( maker.QualIdent(Set.class.getCanonicalName()), Collections.singletonList(wildClass)); String methodBody = MiscPrivateUtilities.collectRestResources(classNames, restSupport, false); return MiscUtilities.createAddResourceClasses(maker, modified, controller, methodBody, false); }
throw new IllegalArgumentException("Type " + typeName + " cannot be found"); // NOI18N return make.QualIdent(typeElement);
private ClassTree createMethodsOlderVersion(Collection<String> classNames, TreeMaker maker,ClassTree modified, CompilationController controller) throws IOException { WildcardTree wildCard = maker.Wildcard(Tree.Kind.UNBOUNDED_WILDCARD, null); ParameterizedTypeTree wildClass = maker.ParameterizedType( maker.QualIdent(Class.class.getCanonicalName()), Collections.singletonList(wildCard)); ParameterizedTypeTree wildSet = maker.ParameterizedType( maker.QualIdent(Set.class.getCanonicalName()), Collections.singletonList(wildClass)); //StringBuilder builder = new StringBuilder(); String methodBody = MiscPrivateUtilities.collectRestResources(classNames, restSupport, true); ModifiersTree modifiersTree = maker.Modifiers(EnumSet .of(Modifier.PRIVATE)); MethodTree methodTree = maker.Method(modifiersTree, GET_REST_RESOURCE_CLASSES, wildSet, Collections.<TypeParameterTree> emptyList(), Collections.<VariableTree> emptyList(), Collections.<ExpressionTree> emptyList(), methodBody, null); modified = maker.addClassMember(modified, methodTree); return modified; }
private static AnnotationTree createAnnotation(ProxyAction action, TreeMaker make, WorkingCopy workingCopy) { List<AssignmentTree> annAttrs = new LinkedList<AssignmentTree>(); for (String attrName : ProxyAction.getAnnotationAttributeNames()) { if (action.isAnnotationAttributeSet(attrName)) { Object value = action.getAnnotationAttributeValue(attrName); ExpressionTree expTree; if (value instanceof String) { expTree = make.Literal(value); } else if (value instanceof ProxyAction.BlockingType) { expTree = make.MemberSelect( make.MemberSelect(make.QualIdent(workingCopy.getElements().getTypeElement("org.jdesktop.application.Task")), // NOI18N "BlockingScope"), // NOI18N value.toString()); } else { continue; } ExpressionTree identTree = make.Identifier(attrName); AssignmentTree attrTree = make.Assignment(identTree, expTree); annAttrs.add(attrTree); } } return make.Annotation(make.QualIdent(workingCopy.getElements().getTypeElement("org.jdesktop.application.Action")), annAttrs); // NOI18N }
null); ParameterizedTypeTree wildClass = maker.ParameterizedType( maker.QualIdent(Class.class.getCanonicalName()), Collections.singletonList(wildCard)); ParameterizedTypeTree wildSet = maker.ParameterizedType( maker.QualIdent(Set.class.getCanonicalName()), Collections.singletonList(wildClass)); ModifiersTree modifiersTree = maker.Modifiers(EnumSet
public Void visitIdentifier(IdentifierTree node, Void p) { TreePath path = getCurrentPath(); Element element = info.getTrees().getElement(path); if (element != null && element.asType().getKind() != TypeKind.ERROR) { // solve the imports only when declared type!!! if (element.getKind().isClass() || element.getKind().isInterface() || (element.getKind().isField() && ((Symbol) element).isStatic())) { Tree parent = path.getParentPath() != null ? path.getParentPath().getLeaf() : null; if ( (parent != null && parent.getKind() == Kind.CASE && ((CaseTree) parent).getExpression() == node && element.getKind() == ElementKind.ENUM_CONSTANT) || (path.getCompilationUnit() != null && ((Symbol) element).enclClass() != null && path.getCompilationUnit().getSourceFile() == ((Symbol) element).enclClass().sourcefile)) { translateMap.put(node, make.Identifier(element.getSimpleName())); } else { translateMap.put(node, make.QualIdent(element)); } } } return null; }
methodModifiers, action.getMethodName(), make.QualIdent(workingCopy.getElements().getTypeElement("org.jdesktop.application.Task")), // NOI18N Collections.<TypeParameterTree>emptyList(), Collections.<VariableTree>emptyList(),
TypeMirror changeSupportMirror = changeSupportElement.asType(); Tree changeSupportType = make.Type(changeSupportMirror); NewClassTree changeSupportConstructor = make.NewClass(null, Collections.EMPTY_LIST, make.QualIdent(changeSupportElement), Collections.singletonList(make.Identifier("this")), null); VariableTree changeSupport = make.Variable(modifiers, "changeSupport", changeSupportType, changeSupportConstructor); // NOI18N modifiedClass = make.insertClassMember(clazz, 0, changeSupport);
AssignmentTree cascadeParameter = make.Assignment(make.Identifier("cascade"), make.MemberSelect(make.QualIdent(cascadeTypeElement),"ALL")); // NOI18N AssignmentTree mappedByParameter = make.Assignment(make.Identifier("mappedBy"), make.Literal(df[0])); // NOI18N List<ExpressionTree> parameters = new ArrayList<ExpressionTree>(); parameters.add(mappedByParameter); TypeElement oneToManyElement = wc.getElements().getTypeElement("javax.persistence.OneToMany"); // NOI18N AnnotationTree oneToManyTree = make.Annotation(make.QualIdent(oneToManyElement), parameters); ModifiersTree modifiers = make.Modifiers(Collections.singleton(Modifier.PRIVATE), Collections.singletonList(oneToManyTree)); TypeElement collectionElement = wc.getElements().getTypeElement("java.util.Collection"); // NOI18N TypeElement detailElement = wc.getElements().getTypeElement(detailInfo[1]); ParameterizedTypeTree collectionTree = make.ParameterizedType(make.QualIdent(collectionElement), Collections.singletonList(make.QualIdent(detailElement))); VariableTree field = make.Variable(modifiers, masterFieldName, collectionTree, null); ClassTree modifiedClass = make.insertClassMember(clazz, fieldIndex, field);
ImportTree newImportTree = make.Import(make.QualIdent(replacingClass), false); for (ImportTree importTree : imports) { if (deprecatedClass.equals(importTree.getQualifiedIdentifier().toString())) {
VariableTree par = make.Variable(parMods, "listener", make.QualIdent(changeListenerElement), null); // NOI18N TypeElement changeSupportElement = wc.getElements().getTypeElement("java.beans.PropertyChangeSupport"); // NOI18N VariableTree changeSupport = make.Variable(parMods, "changeSupport", make.QualIdent(changeSupportElement), null); // NOI18N MemberSelectTree removeCall = make.MemberSelect(make.Identifier(changeSupport.getName()), "removePropertyChangeListener"); // NOI18N MethodInvocationTree removeInvocation = make.MethodInvocation(Collections.EMPTY_LIST, removeCall, Collections.singletonList(make.Identifier(par.getName())));
VariableTree par = make.Variable(parMods, "listener", make.QualIdent(changeListenerElement), null); // NOI18N TypeElement changeSupportElement = wc.getElements().getTypeElement("java.beans.PropertyChangeSupport"); // NOI18N VariableTree changeSupport = make.Variable(parMods, "changeSupport", make.QualIdent(changeSupportElement), null); // NOI18N MemberSelectTree addCall = make.MemberSelect(make.Identifier(changeSupport.getName()), "addPropertyChangeListener"); // NOI18N MethodInvocationTree addInvocation = make.MethodInvocation(Collections.EMPTY_LIST, addCall, Collections.singletonList(make.Identifier(par.getName())));
AnnotationTree newAnnotation = make.Annotation(make.QualIdent(annotation), Collections.singletonList(attributeAssignmentTree));
method.getModifiers(), method.getName(), make.QualIdent(workingCopy.getElements().getTypeElement("org.jdesktop.application.Task")), // NOI18N method.getTypeParameters(), method.getParameters(),
public void run (WorkingCopy workingCopy) throws Exception { workingCopy.toPhase (JavaSource.Phase.ELEMENTS_RESOLVED); CompilationUnitTree compilationUnit = workingCopy.getCompilationUnit (); TreeMaker treeMaker = workingCopy.getTreeMaker (); Trees trees = workingCopy.getTrees (); ContainsMethodTreeVisitor visitor = new ContainsMethodTreeVisitor (trees, methodName, parameters); visitor.scan (compilationUnit, null); TreePath classTreePath = visitor.getClassTreePath (); if (classTreePath != null) { ExpressionTree expressionTree = findImplementIdentifier (trees, classTreePath, className); if (visitor.isMethodExists ()) { if (expressionTree == null) { TypeElement typeElement = workingCopy.getElements ().getTypeElement (className); ExpressionTree implementsClause = typeElement != null ? treeMaker.QualIdent (typeElement) : treeMaker.Identifier (className); ClassTree oldClassTree = (ClassTree) classTreePath.getLeaf (); ClassTree newClassTree = treeMaker.addClassImplementsClause (oldClassTree, implementsClause); workingCopy.rewrite (oldClassTree, newClassTree); } } else { if (expressionTree != null) { ClassTree oldClassTree = (ClassTree) classTreePath.getLeaf (); ClassTree newClassTree = treeMaker.removeClassImplementsClause (oldClassTree, expressionTree); workingCopy.rewrite (oldClassTree, newClassTree); } } } } });