com.sun.source.tree.WildcardTree Java Examples

The following examples show how to use com.sun.source.tree.WildcardTree. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JavaInputAstVisitor.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitWildcard(WildcardTree node, Void unused) {
    sync(node);
    builder.open(ZERO);
    token("?");
    if (node.getBound() != null) {
        builder.open(plusFour);
        builder.space();
        token(node.getKind() == EXTENDS_WILDCARD ? "extends" : "super");
        builder.breakOp(" ");
        scan(node.getBound(), null);
        builder.close();
    }
    builder.close();
    return null;
}
 
Example #2
Source File: ApplicationSubclassGenerator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: ApplicationSubclassGenerator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Void visitWildcard(WildcardTree node, Void unused) {
    sync(node);
    builder.open(ZERO);
    token("?");
    if (node.getBound() != null) {
        builder.open(plusFour);
        builder.space();
        token(node.getKind() == EXTENDS_WILDCARD ? "extends" : "super");
        builder.breakOp(" ");
        scan(node.getBound(), null);
        builder.close();
    }
    builder.close();
    return null;
}
 
Example #5
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 6 votes vote down vote up
@Override
public Void visitWildcard(WildcardTree node, Void unused) {
  sync(node);
  builder.open(ZERO);
  token("?");
  if (node.getBound() != null) {
    builder.open(plusFour);
    builder.space();
    token(node.getKind() == EXTENDS_WILDCARD ? "extends" : "super");
    builder.breakOp(" ");
    scan(node.getBound(), null);
    builder.close();
  }
  builder.close();
  return null;
}
 
Example #6
Source File: TreeDuplicator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Tree visitWildcard(WildcardTree tree, Void p) {
    WildcardTree n = make.Wildcard(tree.getKind(), tree.getBound());
    model.setType(n, model.getType(tree));
    comments.copyComments(tree, n);
    model.setPos(n, model.getPos(tree));
    return n;
}
 
Example #7
Source File: CopyFinder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Boolean visitWildcard(WildcardTree node, TreePath p) {
    if (p == null)
        return super.visitWildcard(node, p);

    WildcardTree t = (WildcardTree) p.getLeaf();

    return scan(node.getBound(), t.getBound(), p);
}
 
Example #8
Source File: TreeNode.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitWildcard(WildcardTree tree, List<Node> d) {
    List<Node> below = new ArrayList<Node>();
    
    addCorrespondingType(below);
    addCorrespondingComments(below);
    super.visitWildcard(tree, below);
    
    d.add(new TreeNode(info, getCurrentPath(), below));
    return null;
}
 
Example #9
Source File: MiscUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** creates addResourceClasses method
 * 
 * @param maker tree maker
 * @param classTree class tree
 * @param controller compilation controller
 * @param methodBody method body
 * @param addComment add comment or not
 * @return modified class tree
 * @throws IOException 
 */
public static ClassTree createAddResourceClasses(TreeMaker maker,
        ClassTree classTree, CompilationController controller,
        String methodBody, boolean addComment) 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));
    ModifiersTree modifiersTree = maker.Modifiers(EnumSet
            .of(Modifier.PRIVATE));
    VariableTree newParam = maker.Variable(
            maker.Modifiers(Collections.<Modifier>emptySet()),
            "resources", wildSet, null);
    MethodTree methodTree = maker.Method(modifiersTree,
            RestConstants.GET_REST_RESOURCE_CLASSES2, maker.Type("void"),
            Collections.<TypeParameterTree> emptyList(),
            Arrays.asList(newParam),
            Collections.<ExpressionTree> emptyList(), methodBody,
            null);
    if (addComment) {
        Comment comment = Comment.create(Comment.Style.JAVADOC,// -2, -2, -2,
                "Do not modify "+RestConstants.GET_REST_RESOURCE_CLASSES2+"() method.\n"
                + "It is automatically populated with\n"
                + "all resources defined in the project.\n"
                + "If required, comment out calling this method in getClasses()."); // NOI18N
        maker.addComment(methodTree, comment, true);
    }
    return maker.addClassMember(classTree, methodTree);
}
 
Example #10
Source File: TreeDiffer.java    From compile-testing with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitWildcard(WildcardTree expected, Tree actual) {
  Optional<WildcardTree> other = checkTypeAndCast(expected, actual);
  if (!other.isPresent()) {
    addTypeMismatch(expected, actual);
    return null;
  }

  scan(expected.getBound(), other.get().getBound());
  return null;
}
 
Example #11
Source File: Flow.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public Boolean visitWildcard(WildcardTree node, ConstructorData p) {
    super.visitWildcard(node, p);
    return null;
}
 
Example #12
Source File: ExpectedTypeResolver.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public List<? extends TypeMirror> visitWildcard(WildcardTree node, Object p) {
    return null;
}
 
Example #13
Source File: RestUtils.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static FileObject createApplicationConfigClass(final RestSupport restSupport, FileObject packageFolder,
        String name ) throws IOException
{   
    FileObject appClass = GenerationUtils.createClass(packageFolder,name, null );
    JavaSource javaSource = JavaSource.forFileObject(appClass);
    if ( javaSource == null ){
        return null;
    }        
    javaSource.runModificationTask( new Task<WorkingCopy>(){

        @Override
        public void run(WorkingCopy workingCopy) throws Exception {
            workingCopy.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED);
            JavaSourceHelper.addClassAnnotation(workingCopy, 
                    new String[]{"javax.ws.rs.ApplicationPath"}, 
                    new String[]{"webresources"});         // NOI18N
            ClassTree tree = JavaSourceHelper.getTopLevelClassTree(workingCopy);
            TreeMaker maker = workingCopy.getTreeMaker();
            ClassTree newTree = maker.setExtends(tree, 
                    maker.QualIdent(JAX_RS_APPLICATION_CLASS)); // NOI18N
            
            ModifiersTree modifiersTree = maker.Modifiers(
                    EnumSet.of(Modifier.PUBLIC), Collections.singletonList(
                            maker.Annotation( maker.QualIdent(
                                    Override.class.getCanonicalName()),
                                    Collections.<ExpressionTree>emptyList())));
            
            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));
            
            MethodTree methodTree = maker.Method(modifiersTree,
                    RestConstants.GET_CLASSES, wildSet,
                    Collections.<TypeParameterTree>emptyList(),
                    Collections.<VariableTree>emptyList(),
                    Collections.<ExpressionTree>emptyList(),
                    MiscUtilities.createBodyForGetClassesMethod(restSupport), null);
            newTree = maker.addClassMember(newTree, methodTree);
            
            newTree = MiscUtilities.createAddResourceClasses(maker, newTree, workingCopy, "{}", true);
            
            workingCopy.rewrite( tree, newTree);
        }
        
    }).commit();
    return appClass;
}
 
Example #14
Source File: TreeFinder.java    From annotation-tools with MIT License 4 votes vote down vote up
@Override
public Pair<ASTRecord, Integer> visitWildcard(WildcardTree node, Insertion ins) {
  JCWildcard wc = (JCWildcard) node;
  return Pair.of(astRecord(node), wc.getStartPosition());
}
 
Example #15
Source File: Translator.java    From groovy-cps with Apache License 2.0 4 votes vote down vote up
@Override
public JType visitWildcard(WildcardTree wt, Void __) {
    Tree b = wt.getBound();
    if (b==null)    return codeModel.wildcard();
    else            return visit(b).boxify().wildcard();
}
 
Example #16
Source File: ASTPath.java    From annotation-tools with MIT License 2 votes vote down vote up
/**
 * Determines if the given kind is a wildcard.
 *
 * @param kind
 *            the kind to test
 * @return true if the given kind is a wildcard
 */
public static boolean isWildcard(Tree.Kind kind) {
  return kind.asInterface().equals(WildcardTree.class);
}