本文整理汇总了Java中com.github.javaparser.ast.expr.AnnotationExpr类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationExpr类的具体用法?Java AnnotationExpr怎么用?Java AnnotationExpr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationExpr类属于com.github.javaparser.ast.expr包,在下文中一共展示了AnnotationExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override
public Node visit(ClassOrInterfaceDeclaration _n, Object _arg) {
List<AnnotationExpr> annotations = visit(_n.getAnnotations(), _arg);
List<TypeParameter> typeParameters = visit(_n.getTypeParameters(), _arg);
List<ClassOrInterfaceType> extendsList = visit(_n.getExtends(), _arg);
List<ClassOrInterfaceType> implementsList = visit(_n.getImplements(), _arg);
List<BodyDeclaration<?>> members = visit(_n.getMembers(), _arg);
Comment comment = cloneNodes(_n.getComment(), _arg);
ClassOrInterfaceDeclaration r = new ClassOrInterfaceDeclaration(
_n.getRange(),
_n.getModifiers(), annotations, _n.isInterface(), _n.getName(), typeParameters, extendsList, implementsList, members
);
r.setComment(comment);
return r;
}
示例2: calculate
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
public void calculate(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, CompilationUnit compilationUnit) {
List<AnnotationExpr> annotations = classOrInterfaceDeclaration.getAnnotations();
for (AnnotationExpr annotation : annotations) {
String annotationName = annotation.getNameAsString();
String annotationPackageName = annotation
.findCompilationUnit()
.flatMap(CompilationUnit::getPackageDeclaration)
.flatMap(pkg -> Optional.of(pkg.getNameAsString())).orElse("???");
if (typeDao.exist(annotationName, annotationPackageName)) { // JDK annotations are not indexed
int annotationId = typeDao.getId(annotationName, annotationPackageName);
int typeId = typeDao.getId(classOrInterfaceDeclaration.getNameAsString(), compilationUnit.getPackageDeclaration().get().getNameAsString());
annotatedWithDao.save(new AnnotatedWith(typeId, annotationId));
}
}
}
示例3: createOrFindAnnotation
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
protected NormalAnnotationExpr createOrFindAnnotation(BodyDeclaration<?> getter, String fullAnnotationName) {
String name = AbstractGenerator.finalName(fullAnnotationName);
//importIf(fullAnnotationName);
for(AnnotationExpr annotationExpr : getter.getAnnotations()) {
String annName = annotationExpr.getName().asString();
if(annName.equals(fullAnnotationName) || name.equals(annName)) {
return (NormalAnnotationExpr) annotationExpr;
}
}
importIf(fullAnnotationName);
String pkg = AbstractGenerator.packageName(fullAnnotationName);
NodeList<MemberValuePair> nodes = NodeList.nodeList();
//Name nm = new Name(new Name(pkg), name);
NormalAnnotationExpr ax = new NormalAnnotationExpr(new Name(name), nodes);
getter.addAnnotation(ax);
return ax;
}
示例4: createOrFindMarkerAnnotation
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
protected MarkerAnnotationExpr createOrFindMarkerAnnotation(BodyDeclaration<?> getter, String fullAnnotationName) {
String name = AbstractGenerator.finalName(fullAnnotationName);
importIf(fullAnnotationName);
//getUnit().addImport(fullAnnotationName);
for(AnnotationExpr annotationExpr : getter.getAnnotations()) {
String annName = annotationExpr.getName().asString();
if(annName.equals(fullAnnotationName) || name.equals(annName)) {
return (MarkerAnnotationExpr) annotationExpr;
}
}
String pkg = AbstractGenerator.packageName(fullAnnotationName);
NodeList<MemberValuePair> nodes = NodeList.nodeList();
//Name nm = new Name(new Name(pkg), name);
MarkerAnnotationExpr ax = new MarkerAnnotationExpr(new Name(name));
getter.addAnnotation(ax);
return ax;
}
示例5: visit
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override
public final void visit(final EnumConstantDeclaration ctx, Object arg) {
final Component enumConstCmp = createComponent(ctx, OOPSourceModelConstants.ComponentType.ENUM_CONSTANT);
enumConstCmp.setName(ctx.getNameAsString());
enumConstCmp.setComponentName(generateComponentName(ctx.getNameAsString()));
pointParentsToGivenChild(enumConstCmp);
for (final AnnotationExpr annot : ctx.getAnnotations()) {
populateAnnotation(enumConstCmp, annot);
}
if (ctx.getComment().isPresent()) {
enumConstCmp.setComment(ctx.getComment().get().toString());
}
componentStack.push(enumConstCmp);
super.visit(ctx, arg);
completeComponent();
}
示例6: visit
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override
public void visit(final ClassOrInterfaceType n, final Object arg) {
printer.printLn("ClassOrInterfaceType");
printJavaComment(n.getComment(), arg);
if (n.getAnnotations() != null) {
for (AnnotationExpr ae : n.getAnnotations()) {
ae.accept(this, arg);
printer.print(" ");
}
}
if (n.getScope() != null) {
n.getScope().accept(this, arg);
printer.print(".");
}
printer.print(n.getName());
printTypeArgs(n.getTypeArgs(), arg);
}
示例7: diffNode
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
private void diffNode(final Node a, final Node aParent,
final Node b, final Node bParent,
final Consumer<Quintet<Node, Node, Node, Node, DiffStatus>> diffCallback) {
if (b == null) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISSING));
} else if (a instanceof NameExpr && !Objects.equals(((NameExpr) a).getName(), ((NameExpr) b).getName())) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISMATCH));
} else if (a instanceof FieldAccessExpr && !Objects.equals(((FieldAccessExpr) a).getFieldExpr(), ((FieldAccessExpr) b).getFieldExpr())) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISMATCH));
} else if (a instanceof LiteralExpr && !Objects.equals(a, b)) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISMATCH));
} else if (a instanceof AnnotationExpr && !Objects.equals(((AnnotationExpr) a).getName().getName(), ((AnnotationExpr) b).getName().getName())) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISMATCH));
} else if (a instanceof Parameter && !Objects.equals(((Parameter) a).getType(), ((Parameter) b).getType())) {
diffCallback.accept(Quintet.with(a, aParent, b, bParent, DiffStatus.MISMATCH));
} else if (a instanceof MethodDeclaration) {
final Iterator<Parameter> iSourceParameters = ((MethodDeclaration) b).getParameters().iterator();
for (Parameter parameter : ((MethodDeclaration) a).getParameters()) {
diffNode(parameter, a, iSourceParameters.hasNext() ? iSourceParameters.next() : null, b, diffCallback);
}
introspect(a, b, diffCallback);
} else {
introspect(a, b, diffCallback);
}
}
示例8: MethodDeclaration
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
public MethodDeclaration(final EnumSet<Modifier> modifiers,
final List<AnnotationExpr> annotations,
final List<TypeParameter> typeParameters,
final Type elementType,
final List<ArrayBracketPair> arrayBracketPairsAfterElementType,
final String name,
final List<Parameter> parameters,
final List<ArrayBracketPair> arrayBracketPairsAfterParameterList,
final List<ReferenceType> throws_,
final BlockStmt body) {
super(annotations);
setModifiers(modifiers);
setTypeParameters(typeParameters);
setElementType(elementType);
setName(name);
setParameters(parameters);
setArrayBracketPairsAfterElementType(arrayBracketPairsAfterElementType);
setArrayBracketPairsAfterParameterList(arrayBracketPairsAfterParameterList);
setThrows(throws_);
setBody(body);
}
示例9: visit
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override public Node visit(final FieldDeclaration n, final A arg) {
visitComment(n, arg);
final List<AnnotationExpr> annotations = n.getAnnotations();
if (annotations != null) {
for (int i = 0; i < annotations.size(); i++) {
annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg));
}
removeNulls(annotations);
}
n.setElementType((Type) n.getElementType().accept(this, arg));
final List<VariableDeclarator> variables = n.getVariables();
for (int i = 0; i < variables.size(); i++) {
variables.set(i, (VariableDeclarator) variables.get(i).accept(this, arg));
}
removeNulls(variables);
return n;
}
示例10: visit
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override public Node visit(final AnnotationDeclaration n, final A arg) {
if (n.getJavaDoc() != null) {
n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg));
}
final List<AnnotationExpr> annotations = n.getAnnotations();
if (annotations != null) {
for (int i = 0; i < annotations.size(); i++) {
annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg));
}
removeNulls(annotations);
}
final List<BodyDeclaration> members = n.getMembers();
if (members != null) {
for (int i = 0; i < members.size(); i++) {
members.set(i, (BodyDeclaration) members.get(i).accept(this, arg));
}
removeNulls(members);
}
return n;
}
示例11: printMemberAnnotations
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
private void printMemberAnnotations(final NodeList<AnnotationExpr> annotations, final Void arg) {
if (annotations.isEmpty()) {
return;
}
for (final AnnotationExpr a : annotations) {
a.accept(this, arg);
printer.println();
}
}
示例12: printAnnotations
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
private void printAnnotations(final NodeList<AnnotationExpr> annotations, boolean prefixWithASpace,
final Void arg) {
if (annotations.isEmpty()) {
return;
}
if (prefixWithASpace) {
printer.print(" ");
}
for (AnnotationExpr annotation : annotations) {
annotation.accept(this, arg);
printer.print(" ");
}
}
示例13: visit
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override
public void visit(MethodDeclaration n, Optional<PackageDeclaration> clazzPackage) {
/* CHECK METHOD-LEVEL ANNOTATIONS FOR URL AND HTTP METHOD */
// We found a new method to look at
logger.debug("Method Name: " + n.getName());
String methodClazzName = getClassNameFromMethod(n);
// Get all annotations on method
NodeList<AnnotationExpr> nodeList = n.getAnnotations();
for (AnnotationExpr annotation : nodeList) {
// Found an annotation on the method
logger.debug("Found annotation: " + annotation.getNameAsString());
if (annotation.getNameAsString().equals("RequestMapping")) {
String packageName = "";
if (clazzPackage.isPresent()) {
packageName = clazzPackage.get().getNameAsString();
}
Endpoint newEndpoint = handleRequestMappingFound(annotation, packageName, methodClazzName);
// Check method parameters since we have a RequestMapping
newEndpoint.setParams(handleMethodParameters(n.getParameters()));
SpringAPIIdentifier.addEndpoint(newEndpoint);
}
}
super.visit(n, clazzPackage);
}
示例14: visit
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
/**
* Increment method and parameter count
*
* @param declaration
* @param collector
*/
@Override
public void visit(MethodDeclaration declaration, Collector collector) {
for (AnnotationExpr annotation: declaration.getAnnotations()) {
if (annotation.getName().equals("Override"))
collector.incrementMetric("Overridden Methods");
}
if (declaration.toString().startsWith("public")) {
collector.incrementMetric("Public Methods");
}
if (declaration.toString().startsWith("private")) {
collector.incrementMetric("Private Methods");
}
if (declaration.toString().startsWith("protected")) {
collector.incrementMetric("Protected Methods");
}
if (!declaration.hasComment()) {
collector.incrementMetric("Methods without Javadoc");
}
collector.incrementMetric("Methods");
collector.incrementMetric("Parameters", declaration.getParameters().size());
super.visit(declaration, collector);
}
示例15: removeResponseBodyAnnotationFromRequestMappingMethods
import com.github.javaparser.ast.expr.AnnotationExpr; //导入依赖的package包/类
private void removeResponseBodyAnnotationFromRequestMappingMethods() {
for (MethodDeclaration methodDeclaration : methodsToRemoveAnnotationFrom) {
ListIterator<AnnotationExpr> annotationsIterator = methodDeclaration.getAnnotations().listIterator();
while (annotationsIterator.hasNext()) {
AnnotationExpr annotation = annotationsIterator.next();
if (annotation.getName().getName().equals("ResponseBody")) {
annotationsIterator.remove();
break;
}
}
}
}