当前位置: 首页>>代码示例>>Java>>正文


Java PrimitiveTypeTree类代码示例

本文整理汇总了Java中com.sun.source.tree.PrimitiveTypeTree的典型用法代码示例。如果您正苦于以下问题:Java PrimitiveTypeTree类的具体用法?Java PrimitiveTypeTree怎么用?Java PrimitiveTypeTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PrimitiveTypeTree类属于com.sun.source.tree包,在下文中一共展示了PrimitiveTypeTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: correspondingGSNames

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:GeneratorUtilities.java

示例2: testPrimitiveTypes

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
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());
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:GenerationUtilsTest.java

示例3: visitMemberSelect

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
@Override
public AnnotatedTypeMirror visitMemberSelect(MemberSelectTree node,
        AnnotatedTypeFactory f) {

    Element elt = TreeUtils.elementFromUse(node);
    if (elt.getKind().isClass() || elt.getKind().isInterface())
        return f.fromElement(elt);

    // The expression might be a primitive type (as in "int.class").
    if (!(node.getExpression() instanceof PrimitiveTypeTree)) {
        // TODO: why don't we use getSelfType here?
        if (node.getIdentifier().contentEquals("this")) {
            return f.getEnclosingType((TypeElement)InternalUtils.symbol(node.getExpression()), node);
        }
        // We need the original t with the implicit annotations
        AnnotatedTypeMirror t = f.getAnnotatedType(node.getExpression());
        if (t instanceof AnnotatedDeclaredType)
            return AnnotatedTypes.asMemberOf(f.types, f, t, elt);
    }

    return f.fromElement(elt);
}
 
开发者ID:reprogrammer,项目名称:checker-framework,代码行数:23,代码来源:TypeFromTree.java

示例4: createHashCodeLineForField

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
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
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:EntityMethodGenerator.java

示例5: visitPrimitiveType

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
@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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:TreeDuplicator.java

示例6: visitPrimitiveType

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:CopyFinder.java

示例7: isSetter

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:GeneratorUtilities.java

示例8: isGetter

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:GeneratorUtilities.java

示例9: isBooleanGetter

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:GeneratorUtilities.java

示例10: testFieldType

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
/**
 * 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");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:FieldTest1.java

示例11: testAddFieldToIndex0

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:Field6Test.java

示例12: addIfMatchMethod

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
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 {
		final Element methodElement = treePathHandle.resolveElement(javac);
		String methodName = methodElement.getSimpleName().toString();
		String testMethodName = RefactoringUtils.getTestMethodName(methodName);
		javac.toPhase(JavaSource.Phase.RESOLVED);
		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);
    }
}
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:40,代码来源:RenameTestClassRefactoringPlugin.java

示例13: visitPrimitiveType

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
@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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:TreeNode.java

示例14: testCreateMethodTree

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
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());
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:MethodModelSupportTest.java

示例15: visitPrimitiveType

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
@Override
public Mirror visitPrimitiveType(PrimitiveTypeTree arg0, EvaluationContext evaluationContext) {
    TypeKind type = arg0.getPrimitiveTypeKind();
    VirtualMachine vm = evaluationContext.getDebugger().getVirtualMachine();
    if (vm == null) {
        return null;
    }
    switch(type) {
        case BOOLEAN:
            return vm.mirrorOf(true).type();
        case BYTE:
            return vm.mirrorOf((byte) 0).type();
        case CHAR:
            return vm.mirrorOf('a').type();
        case DOUBLE:
            return vm.mirrorOf(0.).type();
        case FLOAT:
            return vm.mirrorOf(0f).type();
        case INT:
            return vm.mirrorOf(0).type();
        case LONG:
            return vm.mirrorOf(0l).type();
        case SHORT:
            return vm.mirrorOf((short) 0).type();
        case VOID:
            return vm.mirrorOfVoid().type();
        default:
            throw new IllegalStateException("Tree = "+arg0);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:EvaluatorVisitor.java


注:本文中的com.sun.source.tree.PrimitiveTypeTree类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。