com.github.javaparser.ast.type.PrimitiveType Java Examples

The following examples show how to use com.github.javaparser.ast.type.PrimitiveType. 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: Sources.java    From sundrio with Apache License 2.0 6 votes vote down vote up
public TypeRef apply(Type type) {
    if (type instanceof VoidType) {
        return new VoidRef();
    } else if (type instanceof WildcardType) {
        return new WildcardRef();
    } else if (type instanceof ReferenceType) {
        ReferenceType referenceType = (ReferenceType) type;
        int dimensions = referenceType.getArrayCount();
        TypeRef typeRef = TYPEREF.apply(referenceType.getType());
        if (dimensions == 0) {
            return typeRef;
        } else if (typeRef instanceof ClassRef) {
            return new ClassRefBuilder((ClassRef)typeRef).withDimensions(dimensions).build();
        } else if (typeRef instanceof PrimitiveRef) {
            return new PrimitiveRefBuilder((PrimitiveRef)typeRef).withDimensions(dimensions).build();
        } else if (typeRef instanceof TypeParamRef) {
            return new TypeParamRefBuilder((TypeParamRef)typeRef).withDimensions(dimensions).build();
        }
    } else if (type instanceof PrimitiveType) {
        PrimitiveType primitiveType = (PrimitiveType) type;
        return new PrimitiveRefBuilder().withName(primitiveType.getType().name()).build();
    } else if (type instanceof ClassOrInterfaceType) {
        return CLASS_OR_TYPEPARAM_REF.apply((ClassOrInterfaceType) type);
    }
    throw new IllegalArgumentException("Can't handle type:[" + type + "].");
}
 
Example #2
Source File: ClassCodeAnalyser.java    From CodeDefenders with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void extractResultsFromFieldDeclaration(FieldDeclaration f, CodeAnalysisResult result) {
    final boolean compileTimeConstant = f.isFinal() && ((f.getCommonType() instanceof PrimitiveType) || (String.class.getSimpleName().equals(f.getElementType().asString())));
    for (VariableDeclarator v : f.getVariables()) {
        for (int line = v.getBegin().get().line; line <= v.getEnd().get().line; line++) {
            if (compileTimeConstant) {
                logger.debug("Found compile-time constant " + v);
                // compile time targets are non coverable, too
                result.compileTimeConstant(line);
                result.nonCoverableCode(line);
            }
            if (!v.getInitializer().isPresent()) {
                // non initialized fields are non coverable
                result.nonInitializedField(line);
                result.nonCoverableCode(line);
            }
        }
    }
}
 
Example #3
Source File: JavaParsingAtomicArrayQueueGenerator.java    From JCTools with Apache License 2.0 6 votes vote down vote up
/**
 * Given a variable declaration of some sort, check it's name and type and
 * if it looks like any of the key type changes between unsafe and atomic
 * queues, perform the conversion to change it's type.
 */
void processSpecialNodeTypes(NodeWithType<?, Type> node, String name) {
    Type type = node.getType();
    if ("buffer".equals(name) && isRefArray(type, "E")) {
        node.setType(atomicRefArrayType((ArrayType) type));
    } else if ("sBuffer".equals(name) && isLongArray(type)) {
        node.setType(atomicLongArrayType());
    } else if (PrimitiveType.longType().equals(type)) {
        switch(name) {
        case "mask":
        case "offset":
        case "seqOffset":
        case "lookAheadSeqOffset":
        case "lookAheadElementOffset":
            node.setType(PrimitiveType.intType());
        }
    }
}
 
Example #4
Source File: JavaParsingAtomicLinkedQueueGenerator.java    From JCTools with Apache License 2.0 6 votes vote down vote up
/**
 * Given a variable declaration of some sort, check it's name and type and
 * if it looks like any of the key type changes between unsafe and atomic
 * queues, perform the conversion to change it's type.
 */
void processSpecialNodeTypes(NodeWithType<?, Type> node, String name) {
    Type type = node.getType();
    if (node instanceof MethodDeclaration && ("newBufferAndOffset".equals(name) || "nextArrayOffset".equals(name))) {
        node.setType(PrimitiveType.intType());
    } else if (PrimitiveType.longType().equals(type)) {
        switch(name) {
        case "offset":
        case "offsetInNew":
        case "offsetInOld":
        case "lookAheadElementOffset":
            node.setType(PrimitiveType.intType());
        }
    } else if (isRefType(type, "LinkedQueueNode")) {
        node.setType(simpleParametricType("LinkedQueueAtomicNode", "E"));
    } else if (isRefArray(type, "E")) {
        node.setType(atomicRefArrayType((ArrayType) type));
    }
}
 
Example #5
Source File: PrimitiveTypeMerger.java    From dolphin with Apache License 2.0 5 votes vote down vote up
@Override
public PrimitiveType doMerge(PrimitiveType first, PrimitiveType second) {
  PrimitiveType pt = new PrimitiveType();
  pt.setAnnotations(mergeCollections(first.getAnnotations(),second.getAnnotations()));
  pt.setType(first.getType());
  return first;
}
 
Example #6
Source File: JavaParsingAtomicArrayQueueGenerator.java    From JCTools with Apache License 2.0 5 votes vote down vote up
@Override
public void visit(ClassOrInterfaceDeclaration node, Void arg) {
    super.visit(node, arg);

    replaceParentClassesForAtomics(node);

    node.setName(translateQueueName(node.getNameAsString()));

    if (isCommentPresent(node, GEN_DIRECTIVE_CLASS_CONTAINS_ORDERED_FIELD_ACCESSORS)) {
        node.setComment(null);
        removeStaticFieldsAndInitialisers(node);
        patchAtomicFieldUpdaterAccessorMethods(node);
    }

    for (MethodDeclaration method : node.getMethods()) {
        if (isCommentPresent(method, GEN_DIRECTIVE_METHOD_IGNORE)) {
            method.remove();
        }
    }

    if (!node.getMethodsByName("failFastOffer").isEmpty()) {
        MethodDeclaration deprecatedMethodRedirect = node.addMethod("weakOffer", Keyword.PUBLIC);
        patchMethodAsDeprecatedRedirector(deprecatedMethodRedirect, "failFastOffer", PrimitiveType.intType(),
                new Parameter(classType("E"), "e"));
    }

    node.setJavadocComment(formatMultilineJavadoc(0,
            "NOTE: This class was automatically generated by "
                    + JavaParsingAtomicArrayQueueGenerator.class.getName(),
            "which can found in the jctools-build module. The original source file is " + sourceFileName + ".")
            + node.getJavadocComment().orElse(new JavadocComment("")).getContent());
}
 
Example #7
Source File: JavaParsingAtomicArrayQueueGenerator.java    From JCTools with Apache License 2.0 5 votes vote down vote up
private boolean isLongArray(Type in) {
    if (in instanceof ArrayType) {
        ArrayType aType = (ArrayType) in;
        return PrimitiveType.longType().equals(aType.getComponentType());
    }
    return false;
}
 
Example #8
Source File: MigrateJCas.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
private String getTypeName(Type t) {
//    if (t instanceof ReferenceType) {
//      t = ((ReferenceType<?>)t).getType();
//    }
    
    if (t instanceof PrimitiveType) {
      return ((PrimitiveType)t).toString(); 
    }
    if (t instanceof ClassOrInterfaceType) {
      return ((ClassOrInterfaceType)t).getNameAsString();
    }
    Misc.internalError(); return null;
  }
 
Example #9
Source File: PrettyPrintVisitor.java    From stategen with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void visit(final PrimitiveType n, final Void arg) {
    printJavaComment(n.getComment(), arg);
    printAnnotations(n.getAnnotations(), true, arg);
    printer.print(n.getType().asString());
}
 
Example #10
Source File: FinalRClassBuilder.java    From Briefness with Apache License 2.0 4 votes vote down vote up
private static boolean isInt(FieldDeclaration field) {
  Type type = field.getCommonType();
  return type instanceof PrimitiveType
      && ((PrimitiveType) type).getType() == PrimitiveType.Primitive.INT;
}
 
Example #11
Source File: TraceVisitor.java    From JCTools with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(PrimitiveType n, Void arg) {
    out.println("PrimitiveType: " + (extended ? n : n.getType()));
    super.visit(n, arg);
}
 
Example #12
Source File: PrimitiveTypeMerger.java    From dolphin with Apache License 2.0 3 votes vote down vote up
@Override
public boolean doIsEquals(PrimitiveType first, PrimitiveType second) {

  if (!first.getType().equals(second.getType())) return false;

  return true;
}