Java Code Examples for com.sun.source.tree.PrimitiveTypeTree#getPrimitiveTypeKind()

The following examples show how to use com.sun.source.tree.PrimitiveTypeTree#getPrimitiveTypeKind() . 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 5 votes vote down vote up
@Override
public Void visitPrimitiveType(PrimitiveTypeTree node, Void unused) {
    sync(node);
    switch (node.getPrimitiveTypeKind()) {
        case BOOLEAN:
            token("boolean");
            break;
        case BYTE:
            token("byte");
            break;
        case SHORT:
            token("short");
            break;
        case INT:
            token("int");
            break;
        case LONG:
            token("long");
            break;
        case CHAR:
            token("char");
            break;
        case FLOAT:
            token("float");
            break;
        case DOUBLE:
            token("double");
            break;
        case VOID:
            token("void");
            break;
        default:
            throw new AssertionError(node.getPrimitiveTypeKind());
    }
    return null;
}
 
Example 2
Source File: CopyFinder.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Boolean visitPrimitiveType(PrimitiveTypeTree node, TreePath p) {
    if (p == null)
        return super.visitPrimitiveType(node, p);

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

    return node.getPrimitiveTypeKind() == t.getPrimitiveTypeKind();
}
 
Example 3
Source File: JavaInputAstVisitor.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Void visitPrimitiveType(PrimitiveTypeTree node, Void unused) {
    sync(node);
    switch (node.getPrimitiveTypeKind()) {
        case BOOLEAN:
            token("boolean");
            break;
        case BYTE:
            token("byte");
            break;
        case SHORT:
            token("short");
            break;
        case INT:
            token("int");
            break;
        case LONG:
            token("long");
            break;
        case CHAR:
            token("char");
            break;
        case FLOAT:
            token("float");
            break;
        case DOUBLE:
            token("double");
            break;
        case VOID:
            token("void");
            break;
        default:
            throw new AssertionError(node.getPrimitiveTypeKind());
    }
    return null;
}
 
Example 4
Source File: JavaInputAstVisitor.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
@Override
public Void visitPrimitiveType(PrimitiveTypeTree node, Void unused) {
  sync(node);
  switch (node.getPrimitiveTypeKind()) {
    case BOOLEAN:
      token("boolean");
      break;
    case BYTE:
      token("byte");
      break;
    case SHORT:
      token("short");
      break;
    case INT:
      token("int");
      break;
    case LONG:
      token("long");
      break;
    case CHAR:
      token("char");
      break;
    case FLOAT:
      token("float");
      break;
    case DOUBLE:
      token("double");
      break;
    case VOID:
      token("void");
      break;
    default:
      throw new AssertionError(node.getPrimitiveTypeKind());
  }
  return null;
}
 
Example 5
Source File: JaxWsClassesCookieImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@org.netbeans.api.annotations.common.SuppressWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE")
@Override
public void addOperation(final MethodTree method) {
    JavaSource targetSource = JavaSource.forFileObject(implClassFO);
    CancellableTask<WorkingCopy> modificationTask = 
        new CancellableTask<WorkingCopy>() 
        {
        @Override
        public void run(WorkingCopy workingCopy) throws IOException {
            workingCopy.toPhase(Phase.RESOLVED);            
            TreeMaker make = workingCopy.getTreeMaker();
            ClassTree javaClass = SourceUtils.
                getPublicTopLevelTree(workingCopy);
            if (javaClass!=null) {
                GenerationUtils genUtils = GenerationUtils.newInstance(
                            workingCopy);
                
                AnnotationTree webMethodAnnotation = make.Annotation(
                    make.QualIdent("javax.jws.WebMethod"),      //NOI18N
                    Collections.<ExpressionTree>emptyList()
                );
                // add @WebMethod annotation
                ModifiersTree modifiersTree = make.addModifiersAnnotation(
                        method.getModifiers(), webMethodAnnotation);
                
                // add @Oneway annotation
                if (Kind.PRIMITIVE_TYPE == method.getReturnType().getKind()) {
                    PrimitiveTypeTree primitiveType = 
                        (PrimitiveTypeTree)method.getReturnType();
                    if (TypeKind.VOID == primitiveType.getPrimitiveTypeKind()) {
                        AnnotationTree oneWayAnnotation = make.Annotation(
                            make.QualIdent("javax.jws.Oneway"),         // NOI18N
                            Collections.<ExpressionTree>emptyList()
                        );
                        modifiersTree = make.addModifiersAnnotation(
                                modifiersTree, oneWayAnnotation);
                    }
                }
                
                // add @WebParam annotations 
                List<? extends VariableTree> parameters = method.getParameters();
                List<VariableTree> newParameters = new ArrayList<VariableTree>();
                for (VariableTree param:parameters) {
                    AnnotationTree paramAnnotation = make.Annotation(
                        make.QualIdent("javax.jws.WebParam"),           //NOI18N
                        Collections.<ExpressionTree>singletonList(
                            make.Assignment(make.Identifier("name"),    //NOI18N
                                    make.Literal(param.getName().toString()))) 
                    );
                    newParameters.add(genUtils.addAnnotation(param, paramAnnotation));
                }
                // create new (annotated) method
                MethodTree  annotatedMethod = make.Method(
                            modifiersTree,
                            method.getName(),
                            method.getReturnType(),
                            method.getTypeParameters(),
                            newParameters,
                            method.getThrows(),
                            method.getBody(),
                            (ExpressionTree)method.getDefaultValue());
                Comment comment = Comment.create(NbBundle.getMessage(
                        JaxWsClassesCookieImpl.class, "TXT_WSOperation"));      //NOI18N                 
                make.addComment(annotatedMethod, comment, true);
                
                ClassTree modifiedClass = make.addClassMember(javaClass,
                        annotatedMethod);
                workingCopy.rewrite(javaClass, modifiedClass);
            }
        }
        @Override
        public void cancel() {
            
        }
    };
    try {
        targetSource.runModificationTask(modificationTask).commit();
    } catch (IOException ex) {
        ErrorManager.getDefault().notify(ex);
    }
}