• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java PrimitiveTypeTree类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: visitPrimitiveType

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


示例17: testVoidLambdaParameter

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


示例18: visitPrimitiveType

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
@Override
public Void visitPrimitiveType(PrimitiveTypeTree tree, VisitorState visitorState) {
  VisitorState state = visitorState.withPath(getCurrentPath());
  for (PrimitiveTypeTreeMatcher matcher : primitiveTypeMatchers) {
    if (!isSuppressed(matcher, state)) {
      try {
        reportMatch(matcher.matchPrimitiveType(tree, state), tree, state);
      } catch (Throwable t) {
        handleError(matcher, t);
      }
    }
  }
  return super.visitPrimitiveType(tree, state);
}
 
开发者ID:google,项目名称:error-prone,代码行数:15,代码来源:ErrorProneScanner.java


示例19: visitTypeCast

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
@Override
public Number visitTypeCast(TypeCastTree node, Void p) {
  Number value = node.getExpression().accept(this, null);
  if (value == null) {
    return null;
  }
  if (!(node.getType() instanceof PrimitiveTypeTree)) {
    return null;
  }
  TypeKind kind = ((PrimitiveTypeTree) node.getType()).getPrimitiveTypeKind();
  return cast(kind, value);
}
 
开发者ID:google,项目名称:error-prone,代码行数:13,代码来源:ConstantOverflow.java


示例20: returnsVoid

import com.sun.source.tree.PrimitiveTypeTree; //导入依赖的package包/类
private boolean returnsVoid(MethodTree methodNode) {
    if (methodNode.getReturnType().getKind().equals(Tree.Kind.PRIMITIVE_TYPE)) {
        PrimitiveTypeTree retType = (PrimitiveTypeTree) methodNode.getReturnType();
        return retType.getPrimitiveTypeKind().equals(TypeKind.VOID);
    }
    return false;
}
 
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:8,代码来源:OnDepartureVisitorCTree.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NotFoundException类代码示例发布时间:2022-05-21
下一篇:
Java EditorModificationUtil类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap