use of com.github.javaparser.ast.expr.AnnotationExpr in project checker-framework by typetools.
the class StubParser method annotateAsArray.
/**
* Add the annotations from {@code type} to {@code atype}. Type annotations that parsed as
* declaration annotations (ie those in {@code declAnnos} are applied to the innermost component
* type.
*
* @param atype annotated type to which to add annotations
* @param type parsed type
* @param declAnnos annotations stored on the declaration of the variable with this type or null
*/
private void annotateAsArray(AnnotatedArrayType atype, ReferenceType type, NodeList<AnnotationExpr> declAnnos) {
annotateInnermostComponentType(atype, declAnnos);
Type typeDef = type;
AnnotatedTypeMirror currentAtype = atype;
while (typeDef.isArrayType() && currentAtype.getKind() == TypeKind.ARRAY) {
// handle generic type
clearAnnotations(currentAtype, typeDef);
List<AnnotationExpr> annotations = typeDef.getAnnotations();
if (annotations != null) {
annotate(currentAtype, annotations);
}
typeDef = ((com.github.javaparser.ast.type.ArrayType) typeDef).getComponentType();
currentAtype = ((AnnotatedArrayType) currentAtype).getComponentType();
if (typeDef.isArrayType() ^ currentAtype.getKind() == TypeKind.ARRAY) {
stubWarn("Mismatched array lengths; atype: " + atype + "%n type: " + type);
}
}
}
use of com.github.javaparser.ast.expr.AnnotationExpr in project checker-framework by typetools.
the class ToIndexFileConverter method visit.
@Override
public Void visit(VariableDeclarationExpr expr, AElement elem) {
List<AnnotationExpr> annos = expr.getAnnotations();
AMethod method = (AMethod) elem;
List<VariableDeclarator> varDecls = expr.getVariables();
for (int i = 0; i < varDecls.size(); i++) {
VariableDeclarator decl = varDecls.get(i);
LocalLocation loc = new LocalLocation(decl.getNameAsString(), i);
AField field = method.body.locals.vivify(loc);
visitType(expr.getCommonType(), field.type);
if (annos != null) {
for (AnnotationExpr annoExpr : annos) {
Annotation anno = extractAnnotation(annoExpr);
field.tlAnnotationsHere.add(anno);
}
}
}
return null;
}
use of com.github.javaparser.ast.expr.AnnotationExpr 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.vivify(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.vivify(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.vivify(loc));
}
}
}
}
return body == null ? null : body.accept(this, method);
}
use of com.github.javaparser.ast.expr.AnnotationExpr in project activityinfo by bedatadriven.
the class DefaultUpdatingVisitor method removeUnnecessaryKeyAnnotations.
/**
* Remove {@code Key} annotations with the same name as the method.
*/
private void removeUnnecessaryKeyAnnotations(MethodDeclaration decl) {
ListIterator<AnnotationExpr> it = decl.getAnnotations().listIterator();
while (it.hasNext()) {
AnnotationExpr annotation = it.next();
if (annotation.getName().getName().equals("Key")) {
String keyName = tryGetAnnotationValue(annotation);
if (Objects.equals(keyName, decl.getName())) {
it.remove();
dirty = true;
}
}
}
}
use of com.github.javaparser.ast.expr.AnnotationExpr in project javaparser by javaparser.
the class CloneVisitor method visit.
@Override
public Node visit(ArrayType _n, Object _arg) {
List<AnnotationExpr> ann = visit(_n.getAnnotations(), _arg);
Type<?> type_ = cloneNodes(_n.getComponentType(), _arg);
ArrayType r = new ArrayType(_n.getRange(), type_, ann);
Comment comment = cloneNodes(_n.getComment(), _arg);
r.setComment(comment);
return r;
}
Aggregations