use of com.github.javaparser.ast.type.ClassOrInterfaceType in project checker-framework by typetools.
the class ToIndexFileConverter method visit.
@Override
public Void visit(MethodDeclaration decl, AElement elem) {
Type type = decl.getType();
List<Parameter> params = decl.getParameters();
List<TypeParameter> typeParams = decl.getTypeParameters();
Optional<ReceiverParameter> rcvrParam = decl.getReceiverParameter();
BlockStmt body = decl.getBody().orElse(null);
StringBuilder sb = new StringBuilder(decl.getNameAsString()).append('(');
AClass clazz = (AClass) elem;
AMethod method;
if (params != null) {
for (Parameter param : params) {
Type ptype = param.getType();
sb.append(getJVML(ptype));
}
}
sb.append(')').append(getJVML(type));
method = clazz.methods.getVivify(sb.toString());
visitDecl(decl, method);
visitType(type, method.returnType);
if (params != null) {
for (int i = 0; i < params.size(); i++) {
Parameter param = params.get(i);
AField field = method.parameters.getVivify(i);
visitType(param.getType(), field.type);
}
}
if (rcvrParam.isPresent()) {
for (AnnotationExpr expr : rcvrParam.get().getAnnotations()) {
Annotation anno = extractAnnotation(expr);
method.receiver.type.tlAnnotationsHere.add(anno);
}
}
if (typeParams != null) {
for (int i = 0; i < typeParams.size(); i++) {
TypeParameter typeParam = typeParams.get(i);
List<ClassOrInterfaceType> bounds = typeParam.getTypeBound();
if (bounds != null) {
for (int j = 0; j < bounds.size(); j++) {
ClassOrInterfaceType bound = bounds.get(j);
BoundLocation loc = new BoundLocation(i, j);
bound.accept(this, method.bounds.getVivify(loc));
}
}
}
}
return body == null ? null : body.accept(this, method);
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project checker-framework by typetools.
the class ToIndexFileConverter method visit.
@Override
public Void visit(ObjectCreationExpr expr, AElement elem) {
ClassOrInterfaceType type = expr.getType();
AClass clazz = scene.classes.getVivify(type.getNameAsString());
Expression scope = expr.getScope().orElse(null);
List<Type> typeArgs = expr.getTypeArguments().orElse(null);
List<Expression> args = expr.getArguments();
NodeList<BodyDeclaration<?>> bodyDecls = expr.getAnonymousClassBody().orElse(null);
if (scope != null) {
scope.accept(this, elem);
}
if (args != null) {
for (Expression arg : args) {
arg.accept(this, elem);
}
}
if (typeArgs != null) {
for (Type typeArg : typeArgs) {
typeArg.accept(this, elem);
}
}
type.accept(this, clazz);
if (bodyDecls != null) {
for (BodyDeclaration<?> decl : bodyDecls) {
decl.accept(this, clazz);
}
}
return null;
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project checker-framework by typetools.
the class WholeProgramInferenceJavaParserStorage method addExplicitReceiver.
/**
* Adds an explicit receiver type to a JavaParser method declaration.
*
* @param methodDeclaration declaration to add a receiver to
*/
private static void addExplicitReceiver(MethodDeclaration methodDeclaration) {
if (methodDeclaration.getReceiverParameter().isPresent()) {
return;
}
com.github.javaparser.ast.Node parent = methodDeclaration.getParentNode().get();
if (!(parent instanceof TypeDeclaration)) {
return;
}
TypeDeclaration<?> parentDecl = (TypeDeclaration<?>) parent;
ClassOrInterfaceType receiver = new ClassOrInterfaceType();
receiver.setName(parentDecl.getName());
if (parentDecl.isClassOrInterfaceDeclaration()) {
ClassOrInterfaceDeclaration parentClassDecl = parentDecl.asClassOrInterfaceDeclaration();
if (!parentClassDecl.getTypeParameters().isEmpty()) {
NodeList<Type> typeArgs = new NodeList<>();
for (TypeParameter typeParam : parentClassDecl.getTypeParameters()) {
ClassOrInterfaceType typeArg = new ClassOrInterfaceType();
typeArg.setName(typeParam.getNameAsString());
typeArgs.add(typeArg);
}
receiver.setTypeArguments(typeArgs);
}
}
methodDeclaration.setReceiverParameter(new ReceiverParameter(receiver, "this"));
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project checker-framework by typetools.
the class JointJavacJavaParserVisitor method visitParameterizedType.
@Override
public Void visitParameterizedType(ParameterizedTypeTree javacTree, Node javaParserNode) {
ClassOrInterfaceType node = castNode(ClassOrInterfaceType.class, javaParserNode, javacTree);
processParameterizedType(javacTree, node);
javacTree.getType().accept(this, node);
// TODO: In a parameterized type, will the first branch ever run?
if (javacTree.getTypeArguments().isEmpty()) {
assert !node.getTypeArguments().isPresent() || node.getTypeArguments().get().isEmpty();
} else {
assert node.getTypeArguments().isPresent();
visitLists(javacTree.getTypeArguments(), node.getTypeArguments().get());
}
return null;
}
use of com.github.javaparser.ast.type.ClassOrInterfaceType in project checker-framework by typetools.
the class DoubleJavaParserVisitor method visit.
@Override
public void visit(final ClassOrInterfaceType node1, final Node other) {
ClassOrInterfaceType node2 = (ClassOrInterfaceType) other;
defaultAction(node1, node2);
node1.getName().accept(this, node2.getName());
node1.getScope().ifPresent(l -> l.accept(this, node2.getScope().get()));
node1.getTypeArguments().ifPresent(l -> visitLists(l, node2.getTypeArguments().get()));
}
Aggregations