Exemplo n.º 1
0
 private com.github.javaparser.ast.type.Type toType(Type t) {
   String name = getContext().typeToString(t);
   if (t.isPrimitiveType()) {
     return new PrimitiveType(JVMUtil.searchEnum(PrimitiveType.Primitive.class, name));
   } else {
     return new ClassOrInterfaceType(name);
   }
 }
Exemplo n.º 2
0
  @Test
  public void testPrimitiveParameter() throws Exception {
    Type typeParameter = new Type("Z", null);
    assertFalse(typeParameter.isClassType());
    assertFalse(typeParameter.isTypeParameter());
    assertTrue(typeParameter.isPrimitiveType());

    assertEquals("boolean", typeParameter.getPrimitiveTypeName());
  }
Exemplo n.º 3
0
  @Test
  public void testClassParameter() throws Exception {
    Type typeParameter = new Type("Ljava/lang/Object;", null);
    assertTrue(typeParameter.isClassType());
    assertFalse(typeParameter.isTypeParameter());
    assertFalse(typeParameter.isPrimitiveType());

    assertEquals("java.lang.Object", typeParameter.getClassName());
  }
Exemplo n.º 4
0
 @Override
 public boolean visit(VariableDeclarationStatement node) {
   Type typ = node.getType();
   if (typ.isSimpleType()) {
     SimpleType simple = (SimpleType) typ;
     String typName = simple.getName().getFullyQualifiedName();
     List<VariableDeclarationFragment> vars = node.fragments();
     for (VariableDeclarationFragment var : vars) {
       map.put(var.getName().getIdentifier(), typName);
     }
   }
   if (typ.isQualifiedType()) {
     QualifiedType qual = (QualifiedType) typ;
     String typName = qual.getName().getFullyQualifiedName();
     List<VariableDeclarationFragment> vars = node.fragments();
     for (VariableDeclarationFragment var : vars) {
       map.put(var.getName().getIdentifier(), typName);
     }
   }
   if (typ.isPrimitiveType()) {
     PrimitiveType prim = (PrimitiveType) typ;
     String typName = prim.getPrimitiveTypeCode().toString();
     List<VariableDeclarationFragment> vars = node.fragments();
     for (VariableDeclarationFragment var : vars) {
       map.put(var.getName().getIdentifier(), typName);
     }
   }
   if (typ.isParameterizedType()) {
     ParameterizedType prim = (ParameterizedType) typ;
     String typName = prim.getType().toString();
     List<VariableDeclarationFragment> vars = node.fragments();
     for (VariableDeclarationFragment var : vars) {
       map.put(var.getName().getIdentifier(), typName);
     }
   }
   if (typ.isArrayType()) {
     ArrayType prim = (ArrayType) typ;
     String typName = "Array";
     List<VariableDeclarationFragment> vars = node.fragments();
     for (VariableDeclarationFragment var : vars) {
       map.put(var.getName().getIdentifier(), typName);
     }
   }
   return true;
 }