com.sun.source.tree.PrimitiveTypeTree Java Examples
The following examples show how to use
com.sun.source.tree.PrimitiveTypeTree.
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: GenerationUtilsTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testPrimitiveTypes() throws Exception { TestUtilities.copyStringToFileObject(testFO, "package foo;" + "public class TestClass {" + "}"); runModificationTask(testFO, new Task<WorkingCopy>() { public void run(WorkingCopy copy) throws Exception { GenerationUtils genUtils = GenerationUtils.newInstance(copy); TypeElement scope = SourceUtils.getPublicTopLevelElement(copy); assertEquals(TypeKind.BOOLEAN, ((PrimitiveTypeTree)genUtils.createType("boolean", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.BYTE, ((PrimitiveTypeTree)genUtils.createType("byte", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.SHORT, ((PrimitiveTypeTree)genUtils.createType("short", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.INT, ((PrimitiveTypeTree)genUtils.createType("int", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.LONG, ((PrimitiveTypeTree)genUtils.createType("long", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.CHAR, ((PrimitiveTypeTree)genUtils.createType("char", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.FLOAT, ((PrimitiveTypeTree)genUtils.createType("float", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.DOUBLE, ((PrimitiveTypeTree)genUtils.createType("double", scope)).getPrimitiveTypeKind()); } }); }
Example #2
Source File: AddWsOperationHelper.java From netbeans with Apache License 2.0 | 6 votes |
private String getMethodBody(Tree returnType) { String body = null; if (Kind.PRIMITIVE_TYPE == returnType.getKind()) { TypeKind type = ((PrimitiveTypeTree)returnType).getPrimitiveTypeKind(); if (TypeKind.VOID == type) body = ""; //NOI18N else if (TypeKind.BOOLEAN == type) body = "return false;"; // NOI18N else if (TypeKind.INT == type) body = "return 0;"; // NOI18N else if (TypeKind.LONG == type) body = "return 0;"; // NOI18N else if (TypeKind.FLOAT == type) body = "return 0.0;"; // NOI18N else if (TypeKind.DOUBLE == type) body = "return 0.0;"; // NOI18N else if (TypeKind.BYTE == type) body = "return 0;"; // NOI18N else if (TypeKind.SHORT == type) body = "return 0;"; // NOI18N else if (TypeKind.CHAR == type) body = "return ' ';"; // NOI18N else body = "return null"; //NOI18N } else body = "return null"; //NOI18N return "{\n\t\t"+NbBundle.getMessage(AddWsOperationHelper.class, "TXT_TodoComment")+"\n"+body+"\n}"; }
Example #3
Source File: GeneratorUtilities.java From netbeans with Apache License 2.0 | 6 votes |
private static String[] correspondingGSNames(Tree member) { if (isSetter(member)) { String name = name(member); VariableTree param = ((MethodTree)member).getParameters().get(0); if (param.getType().getKind() == Tree.Kind.PRIMITIVE_TYPE && ((PrimitiveTypeTree)param.getType()).getPrimitiveTypeKind() == TypeKind.BOOLEAN) { return new String[] {'g' + name.substring(1), "is" + name.substring(3)}; } return new String[] {'g' + name.substring(1)}; } if (isGetter(member)) { return new String[] {'s' + name(member).substring(1)}; } if (isBooleanGetter(member)) { return new String[] {"set" + name(member).substring(2)}; //NOI18N } return null; }
Example #4
Source File: GenerationUtilsTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testPrimitiveTypes() throws Exception { TestUtilities.copyStringToFileObject(testFO, "package foo;" + "public class TestClass {" + "}"); runModificationTask(testFO, new Task<WorkingCopy>() { public void run(WorkingCopy copy) throws Exception { GenerationUtils genUtils = GenerationUtils.newInstance(copy); TypeElement scope = SourceUtils.getPublicTopLevelElement(copy); assertEquals(TypeKind.BOOLEAN, ((PrimitiveTypeTree)genUtils.createType("boolean", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.BYTE, ((PrimitiveTypeTree)genUtils.createType("byte", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.SHORT, ((PrimitiveTypeTree)genUtils.createType("short", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.INT, ((PrimitiveTypeTree)genUtils.createType("int", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.LONG, ((PrimitiveTypeTree)genUtils.createType("long", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.CHAR, ((PrimitiveTypeTree)genUtils.createType("char", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.FLOAT, ((PrimitiveTypeTree)genUtils.createType("float", scope)).getPrimitiveTypeKind()); assertEquals(TypeKind.DOUBLE, ((PrimitiveTypeTree)genUtils.createType("double", scope)).getPrimitiveTypeKind()); } }); }
Example #5
Source File: MethodModelSupportTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testCreateMethodTree() throws Exception { final MethodModel methodModel = MethodModel.create( "method", "void", "{ String name; }", // for now, Retouche requires those parenthesis (they won't appear in file) Collections.<MethodModel.Variable>emptyList(), Collections.<String>emptyList(), Collections.<Modifier>emptySet() ); TestUtilities.copyStringToFileObject(testFO, "package foo;" + "public class TestClass {" + "}"); runModificationTask(testFO, new Task<WorkingCopy>() { public void run(WorkingCopy workingCopy) throws IOException { workingCopy.toPhase(JavaSource.Phase.ELEMENTS_RESOLVED); MethodTree methodTree = MethodModelSupport.createMethodTree(workingCopy, methodModel); assertEquals(0, methodTree.getModifiers().getFlags().size()); PrimitiveTypeTree returnTypeTree = (PrimitiveTypeTree) methodTree.getReturnType(); assertTrue(TypeKind.VOID == returnTypeTree.getPrimitiveTypeKind()); assertTrue(methodTree.getName().contentEquals("method")); assertEquals(0, methodTree.getParameters().size()); assertEquals(0, methodTree.getThrows().size()); List<? extends StatementTree> statements = methodTree.getBody().getStatements(); assertEquals(1, statements.size()); } }); }
Example #6
Source File: TreeDiffer.java From compile-testing with Apache License 2.0 | 5 votes |
@Override public Void visitPrimitiveType(PrimitiveTypeTree expected, Tree actual) { Optional<PrimitiveTypeTree> other = checkTypeAndCast(expected, actual); if (!other.isPresent()) { addTypeMismatch(expected, actual); return null; } checkForDiff(expected.getPrimitiveTypeKind() == other.get().getPrimitiveTypeKind(), "Expected primitive type kind to be <%s> but was <%s>.", expected.getPrimitiveTypeKind(), other.get().getPrimitiveTypeKind()); return null; }
Example #7
Source File: JavaInputAstVisitor.java From google-java-format with Apache License 2.0 | 5 votes |
@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 #8
Source File: JavacParserTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Test void testVoidLambdaParameter() throws IOException { String code = "package t; class Test { " + "Runnable r = (void v) -> { };" + "}"; DiagnosticCollector<JavaFileObject> coll = new DiagnosticCollector<>(); JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, coll, null, null, Arrays.asList(new MyFileObject(code))); CompilationUnitTree cut = ct.parse().iterator().next(); ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0); VariableTree field = (VariableTree) clazz.getMembers().get(0); assertEquals("actual kind: " + field.getInitializer().getKind(), field.getInitializer().getKind(), Kind.LAMBDA_EXPRESSION); LambdaExpressionTree lambda = (LambdaExpressionTree) field.getInitializer(); assertEquals("actual parameters: " + lambda.getParameters().size(), lambda.getParameters().size(), 1); Tree paramType = lambda.getParameters().get(0).getType(); assertEquals("actual parameter type: " + paramType.getKind(), paramType.getKind(), Kind.PRIMITIVE_TYPE); TypeKind primitiveTypeKind = ((PrimitiveTypeTree) paramType).getPrimitiveTypeKind(); assertEquals("actual parameter type: " + primitiveTypeKind, primitiveTypeKind, TypeKind.VOID); }
Example #9
Source File: JavaInputAstVisitor.java From javaide with GNU General Public License v3.0 | 5 votes |
@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 #10
Source File: AddWsOperationHelper.java From netbeans with Apache License 2.0 | 5 votes |
private String getMethodBody(Tree returnType) { String body = null; if (Kind.PRIMITIVE_TYPE == returnType.getKind()) { TypeKind type = ((PrimitiveTypeTree)returnType).getPrimitiveTypeKind(); if (TypeKind.VOID == type) { body = ""; //NOI18N } else if (TypeKind.BOOLEAN == type) { body = "return false;"; // NOI18N } else if (TypeKind.INT == type) { body = "return 0;"; // NOI18N } else if (TypeKind.LONG == type) { body = "return 0;"; // NOI18N } else if (TypeKind.FLOAT == type) { body = "return 0.0;"; // NOI18N } else if (TypeKind.DOUBLE == type) { body = "return 0.0;"; // NOI18N } else if (TypeKind.BYTE == type) { body = "return 0;"; // NOI18N } else if (TypeKind.SHORT == type) { body = "return 0;"; // NOI18N } else if (TypeKind.CHAR == type) { body = "return ' ';"; // NOI18N } else { body = "return null"; //NOI18N } } else body = "return null"; //NOI18N return "{\n\t\t"+NbBundle.getMessage(AddWsOperationHelper.class, "TXT_TodoComment")+"\n"+body+"\n}"; }
Example #11
Source File: TreeNode.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Void visitPrimitiveType(PrimitiveTypeTree tree, List<Node> d) { List<Node> below = new ArrayList<Node>(); addCorrespondingType(below); addCorrespondingComments(below); super.visitPrimitiveType(tree, below); d.add(new TreeNode(info, getCurrentPath(), below)); return null; }
Example #12
Source File: RenameTestClassRefactoringPlugin.java From netbeans with Apache License 2.0 | 5 votes |
private void addIfMatchMethod(final LocationResult location, final TestLocator testLocator, final List<RenameRefactoring> renameRefactoringsList) { if(location.getFileObject() != null && testLocator.getFileType(location.getFileObject()).equals(TestLocator.FileType.TEST)) { try { JavaSource.forFileObject(location.getFileObject()).runUserActionTask(new Task<CompilationController>() { @Override public void run(CompilationController javac) throws Exception { javac.toPhase(JavaSource.Phase.RESOLVED); final Element methodElement = treePathHandle.resolveElement(javac); String methodName = methodElement.getSimpleName().toString(); String testMethodName = RefactoringUtils.getTestMethodName(methodName); CompilationUnitTree cut = javac.getCompilationUnit(); Tree classTree = cut.getTypeDecls().get(0); List<? extends Tree> members = ((ClassTree) classTree).getMembers(); for (int i = 0; i < members.size(); i++) { Tree member = members.get(i); if(member.getKind() != Tree.Kind.METHOD) { continue; } MethodTree methodTree = (MethodTree) member; if (methodTree.getName().contentEquals(testMethodName) && methodTree.getReturnType().getKind() == Tree.Kind.PRIMITIVE_TYPE && ((PrimitiveTypeTree) methodTree.getReturnType()).getPrimitiveTypeKind() == TypeKind.VOID) { // test method should at least be void classTree = ((ClassTree) classTree).getMembers().get(i); TreePath tp = TreePath.getPath(cut, classTree); RenameRefactoring renameRefactoring = new RenameRefactoring(Lookups.singleton(TreePathHandle.create(tp, javac))); renameRefactoring.setNewName(RefactoringUtils.getTestMethodName(refactoring.getNewName())); renameRefactoring.setSearchInComments(true); renameRefactoringsList.add(renameRefactoring); break; } } } }, true); } catch (IOException ex) { Exceptions.printStackTrace(ex); } } }
Example #13
Source File: FieldTest1.java From netbeans with Apache License 2.0 | 5 votes |
/** * Changes long type of the field to short type. */ public void testFieldType() throws IOException { System.err.println("testFieldType"); process( new Transformer<Void, Object>() { public Void visitVariable(VariableTree node, Object p) { super.visitVariable(node, p); if ("typeField".contentEquals(node.getName())) { PrimitiveTypeTree pt = make.PrimitiveType(TypeKind.SHORT); VariableTree vt = make.Variable( node.getModifiers(), node.getName(), pt, node.getInitializer() ); model.setElement(vt, model.getElement(node)); model.setType(vt, model.getType(node)); model.setPos(vt, model.getPos(node)); //copy.rewrite(node.getType(), tree); copy.rewrite(node, vt); } return null; } } ); assertFiles("testFieldType.pass"); }
Example #14
Source File: JavaInputAstVisitor.java From java-n-IDE-for-Android with Apache License 2.0 | 5 votes |
@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 #15
Source File: EntityMethodGenerator.java From netbeans with Apache License 2.0 | 5 votes |
private String createHashCodeLineForField(VariableTree field) { Name fieldName = field.getName(); Tree fieldType = field.getType(); if (fieldType.getKind() == Tree.Kind.PRIMITIVE_TYPE) { if (((PrimitiveTypeTree) fieldType).getPrimitiveTypeKind() == TypeKind.BOOLEAN) { return "hash += (" + fieldName + " ? 1 : 0"; // NOI18N } return "hash += (int)" + fieldName + ";"; // NOI18N } return "hash += (" + fieldName + " != null ? " + fieldName + ".hashCode() : 0);"; // NOI18N }
Example #16
Source File: TreeDuplicator.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Tree visitPrimitiveType(PrimitiveTypeTree tree, Void p) { PrimitiveTypeTree n = make.PrimitiveType(tree.getPrimitiveTypeKind()); model.setType(n, model.getType(tree)); comments.copyComments(tree, n); model.setPos(n, model.getPos(tree)); return n; }
Example #17
Source File: CopyFinder.java From netbeans with Apache License 2.0 | 5 votes |
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 #18
Source File: GeneratorUtilities.java From netbeans with Apache License 2.0 | 5 votes |
private static boolean isSetter(Tree member) { return member.getKind() == Tree.Kind.METHOD && name(member).startsWith("set") //NOI18N && ((MethodTree)member).getParameters().size() == 1 && ((MethodTree)member).getReturnType().getKind() == Tree.Kind.PRIMITIVE_TYPE && ((PrimitiveTypeTree)((MethodTree)member).getReturnType()).getPrimitiveTypeKind() == TypeKind.VOID; }
Example #19
Source File: GeneratorUtilities.java From netbeans with Apache License 2.0 | 5 votes |
private static boolean isBooleanGetter(Tree member) { return member.getKind() == Tree.Kind.METHOD && name(member).startsWith("is") //NOI18N && ((MethodTree)member).getParameters().isEmpty() && ((MethodTree)member).getReturnType().getKind() == Tree.Kind.PRIMITIVE_TYPE && ((PrimitiveTypeTree)((MethodTree)member).getReturnType()).getPrimitiveTypeKind() == TypeKind.BOOLEAN; }
Example #20
Source File: Field6Test.java From netbeans with Apache License 2.0 | 5 votes |
public void testAddFieldToIndex0() throws Exception { testFile = new File(getWorkDir(), "Test.java"); TestUtilities.copyStringToFile(testFile, "package hierbas.del.litoral;\n\n" + "import java.io.*;\n\n" + "public class Test {\n" + " public void taragui() {\n" + " }\n" + "}\n" ); String golden = "package hierbas.del.litoral;\n\n" + "import java.io.*;\n\n" + "public class Test {\n" + "\n" + " int field1;\n" + " public void taragui() {\n" + " }\n" + "}\n"; process( new Transformer<Void, Object>() { public Void visitClass(ClassTree node, Object p) { super.visitClass(node, p); ModifiersTree mods = make.Modifiers(Collections.<Modifier>emptySet()); PrimitiveTypeTree type = make.PrimitiveType(TypeKind.INT); VariableTree var = make.Variable(mods, "field1", type, null); ClassTree copy = make.insertClassMember(node, 0, var); this.copy.rewrite(node, copy); return null; } } ); String res = TestUtilities.copyFileToString(testFile); assertEquals(golden, res); }
Example #21
Source File: GeneratorUtilities.java From netbeans with Apache License 2.0 | 5 votes |
private static boolean isGetter(Tree member) { return member.getKind() == Tree.Kind.METHOD && name(member).startsWith("get") //NOI18N && ((MethodTree)member).getParameters().isEmpty() && (((MethodTree)member).getReturnType().getKind() != Tree.Kind.PRIMITIVE_TYPE || ((PrimitiveTypeTree)((MethodTree)member).getReturnType()).getPrimitiveTypeKind() != TypeKind.VOID); }
Example #22
Source File: T6345974.java From hottub with GNU General Public License v2.0 | 4 votes |
public Void visitPrimitiveType(PrimitiveTypeTree node, Void ignore) { // The following call of getPrimitiveTypeKind should not throw an AssertionError System.out.println(node + " " + node.getPrimitiveTypeKind()); return null; }
Example #23
Source File: T6345974.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public Void visitPrimitiveType(PrimitiveTypeTree node, Void ignore) { // The following call of getPrimitiveTypeKind should not throw an AssertionError System.out.println(node + " " + node.getPrimitiveTypeKind()); return null; }
Example #24
Source File: Breadcrumbs.java From compile-testing with Apache License 2.0 | 4 votes |
@Override public String visitPrimitiveType(PrimitiveTypeTree reference, Void v) { return (reference != null) ? detailedKindString(reference, reference.getPrimitiveTypeKind()) : ""; }
Example #25
Source File: UTemplater.java From Refaster with Apache License 2.0 | 4 votes |
@Override public UPrimitiveTypeTree visitPrimitiveType(PrimitiveTypeTree tree, Void v) { return UPrimitiveTypeTree.create(tree.getPrimitiveTypeKind()); }
Example #26
Source File: UPrimitiveTypeTree.java From Refaster with Apache License 2.0 | 4 votes |
@Override @Nullable public Unifier visitPrimitiveType(PrimitiveTypeTree tree, @Nullable Unifier unifier) { return getPrimitiveTypeKind().equals(tree.getPrimitiveTypeKind()) ? unifier : null; }
Example #27
Source File: Translator.java From groovy-cps with Apache License 2.0 | 4 votes |
@Override public JType visitPrimitiveType(PrimitiveTypeTree pt, Void aVoid) { return primitive(pt, pt.getPrimitiveTypeKind()); }
Example #28
Source File: TreeConverter.java From j2objc with Apache License 2.0 | 4 votes |
private TreeNode convertPrimitiveType(PrimitiveTypeTree node, TreePath parent) { return new PrimitiveType(getTypeMirror(getTreePath(parent, node))); }
Example #29
Source File: TreeFinder.java From annotation-tools with MIT License | 4 votes |
@Override public Pair<ASTRecord, Integer> visitPrimitiveType(PrimitiveTypeTree node, Insertion ins) { dbug.debug("TypePositionFinder.visitPrimitiveType(%s)%n", node); return pathAndPos((JCTree) node); }
Example #30
Source File: T6345974.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public Void visitPrimitiveType(PrimitiveTypeTree node, Void ignore) { // The following call of getPrimitiveTypeKind should not throw an AssertionError System.out.println(node + " " + node.getPrimitiveTypeKind()); return null; }