本文整理汇总了Java中org.walkmod.javalang.ast.expr.AnnotationExpr类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationExpr类的具体用法?Java AnnotationExpr怎么用?Java AnnotationExpr使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationExpr类属于org.walkmod.javalang.ast.expr包,在下文中一共展示了AnnotationExpr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
public Node visit(AnnotationMemberDeclaration n, A arg) {
if (n.getJavaDoc() != null) {
n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg));
}
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.setType((Type) n.getType().accept(this, arg));
if (n.getDefaultValue() != null) {
n.setDefaultValue((Expression) n.getDefaultValue().accept(this, arg));
}
return n;
}
示例2: visit
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
public void visit(EnumDeclaration n, A arg) {
if (n.getJavaDoc() != null) {
n.getJavaDoc().accept(this, arg);
}
if (n.getAnnotations() != null) {
for (AnnotationExpr a : n.getAnnotations()) {
a.accept(this, arg);
}
}
if (n.getImplements() != null) {
for (ClassOrInterfaceType c : n.getImplements()) {
c.accept(this, arg);
}
}
if (n.getEntries() != null) {
for (EnumConstantDeclaration e : n.getEntries()) {
e.accept(this, arg);
}
}
if (n.getMembers() != null) {
for (BodyDeclaration member : n.getMembers()) {
member.accept(this, arg);
}
}
}
示例3: testAddAnnotation2
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Test
public void testAddAnnotation2() throws ParseException {
String code = "public class B {\n\t public void foo(){\t\teo();\t\tbar();\n} }";
DefaultJavaParser parser = new DefaultJavaParser();
CompilationUnit cu = parser.parse(code, false);
CompilationUnit cu2 = parser.parse(code, false);
MethodDeclaration md = (MethodDeclaration) cu.getTypes().get(0).getMembers().get(0);
List<AnnotationExpr> annotations = new LinkedList<AnnotationExpr>();
annotations.add(new MarkerAnnotationExpr(new NameExpr("Override")));
md.setAnnotations(annotations);
List<Action> actions = getActions(cu2, cu);
Assert.assertEquals(1, actions.size());
assertCode(actions, code, "public class B {\n\t @Override\n\t public void foo(){\t\teo();\t\tbar();\n} }");
}
示例4: removeChild
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override
public boolean removeChild(Node child) {
boolean result = false;
if (child != null) {
if (child instanceof AnnotationExpr) {
if (annotations != null) {
List<AnnotationExpr> annotationAux = new LinkedList<AnnotationExpr>(annotations);
result = annotationAux.remove(child);
this.annotations = annotationAux;
}
}
if (child == id && id != null) {
id = null;
result = true;
}
}
if (result) {
updateReferences(child);
}
return result;
}
示例5: replaceChildNode
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override
public boolean replaceChildNode(Node oldChild, Node newChild) {
boolean update = false;
if (annotations != null) {
List<AnnotationExpr> auxAnnotations = new LinkedList<AnnotationExpr>(annotations);
update = replaceChildNodeInList(oldChild, newChild, auxAnnotations);
if (update) {
annotations = auxAnnotations;
}
}
if (!update) {
if (id == oldChild) {
setId((VariableDeclaratorId) newChild);
update = true;
}
}
return update;
}
示例6: visit
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override
public void visit(IntersectionType n, Object arg) {
prepareComments(n);
printPreviousComments(n, arg);
if (n.getAnnotations() != null) {
for (AnnotationExpr ae : n.getAnnotations()) {
printer.print(" ");
ae.accept(this, arg);
}
}
List<ReferenceType> types = n.getBounds();
if (types != null) {
for (int i = 0; i < types.size(); i++) {
types.get(i).accept(this, arg);
if (i + 1 < types.size()) {
printer.print(" & ");
}
}
}
}
示例7: visit
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override
public Node visit(ReferenceType _n, Object _arg) {
List<AnnotationExpr> ann = visit(_n.getAnnotations(), _arg);
Type type_ = cloneNodes(_n.getType(), _arg);
List<List<AnnotationExpr>> arraysAnnotations = _n.getArraysAnnotations();
List<List<AnnotationExpr>> _arraysAnnotations = null;
if (arraysAnnotations != null) {
_arraysAnnotations = new LinkedList<List<AnnotationExpr>>();
for (List<AnnotationExpr> aux : arraysAnnotations) {
_arraysAnnotations.add(visit(aux, _arg));
}
}
ReferenceType r = new ReferenceType(_n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(),
type_, _n.getArrayCount(), ann, _arraysAnnotations);
return r;
}
示例8: removeChild
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override
public boolean removeChild(Node child) {
boolean result = false;
if (child != null) {
if (child instanceof AnnotationExpr) {
if (annotations != null) {
List<AnnotationExpr> aux = new LinkedList<AnnotationExpr>(annotations);
result = aux.remove(child);
this.annotations = aux;
}
} else if (child instanceof JavadocComment) {
if (javaDoc != null && javaDoc.equals(child)) {
javaDoc = null;
result = true;
}
}
}
if (result) {
updateReferences(child);
}
return result;
}
示例9: removeChild
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override
public boolean removeChild(Node child) {
boolean result = false;
if (child != null) {
if (child instanceof ClassOrInterfaceType) {
if (typeBound != null) {
List<ClassOrInterfaceType> auxTypeBound = new LinkedList<ClassOrInterfaceType>(typeBound);
result = auxTypeBound.remove(child);
this.typeBound = auxTypeBound;
}
} else if (child instanceof AnnotationExpr) {
if (annotations != null) {
List<AnnotationExpr> annotationsAux = new LinkedList<AnnotationExpr>(annotations);
result = annotationsAux.remove(child);
annotations = annotationsAux;
}
}
}
if (result) {
updateReferences(child);
}
return result;
}
示例10: Annotation
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
final public AnnotationExpr Annotation() throws ParseException {
AnnotationExpr ret;
if (jj_2_44(2147483647)) {
ret = NormalAnnotation();
} else if (jj_2_45(2147483647)) {
ret = SingleMemberAnnotation();
} else {
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case AT:
ret = MarkerAnnotation();
break;
default:
jj_la1[165] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
{
if (true)
return ret;
}
throw new Error("Missing return statement in function");
}
示例11: printMemberAnnotations
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
private void printMemberAnnotations(List<AnnotationExpr> annotations, Object arg) {
if (annotations != null) {
Node previous = null;
Iterator<AnnotationExpr> it = annotations.iterator();
while (it.hasNext()) {
AnnotationExpr current = it.next();
if (previous != null) {
if (!previous.isNewNode() && !current.isNewNode()) {
addEntersBetween(previous, current);
} else {
printer.printLn();
}
}
current.accept(this, arg);
previous = current;
}
if (!annotations.isEmpty()) {
printer.printLn();
}
}
}
示例12: visit
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
public R visit(AnnotationDeclaration n, A arg) {
if (n.getJavaDoc() != null) {
n.getJavaDoc().accept(this, arg);
}
if (n.getAnnotations() != null) {
for (AnnotationExpr a : n.getAnnotations()) {
a.accept(this, arg);
}
}
if (n.getMembers() != null) {
for (BodyDeclaration member : n.getMembers()) {
member.accept(this, arg);
}
}
return null;
}
示例13: testAddAnnotationInInnerClass
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Test
public void testAddAnnotationInInnerClass() throws ParseException {
String code = "public class Foo {\n\tpublic void aux(){\n\t\t new X(){\n\t\t\tvoid hello(){\n\t\t\t\ty();\n\t\t\t}\n\t\t};\n\t}\n}";
DefaultJavaParser parser = new DefaultJavaParser();
CompilationUnit cu = parser.parse(code, false);
CompilationUnit cu2 = parser.parse(code, false);
MethodDeclaration md = (MethodDeclaration) cu.getTypes().get(0).getMembers().get(0);
List<Statement> stmts = md.getBody().getStmts();
ExpressionStmt stmt = (ExpressionStmt) stmts.get(0);
ObjectCreationExpr oce = (ObjectCreationExpr) stmt.getExpression();
List<BodyDeclaration> body = oce.getAnonymousClassBody();
MethodDeclaration md2 = (MethodDeclaration) body.get(0);
List<AnnotationExpr> annotations = new LinkedList<AnnotationExpr>();
annotations.add(new MarkerAnnotationExpr(new NameExpr("Override")));
md2.setAnnotations(annotations);
List<Action> actions = getActions(cu2, cu);
Assert.assertEquals(1, actions.size());
assertCode(actions, code,
"public class Foo {\n\tpublic void aux(){\n\t\t new X(){\n\t\t\[email protected]\n\t\t\tvoid hello(){\n\t\t\t\ty();\n\t\t\t}\n\t\t};\n\t}\n}");
}
示例14: compare
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
@Override
public int compare(AnnotationExpr an1, AnnotationExpr an2) {
if (an1.getName().toString().equals(an2.getName().toString())) {
return 0;
}
return -1;
}
示例15: CatchClause
import org.walkmod.javalang.ast.expr.AnnotationExpr; //导入依赖的package包/类
public CatchClause(final int beginLine, final int beginColumn, final int endLine, final int endColumn,
final int exceptModifier, final List<AnnotationExpr> exceptAnnotations, final List<Type> exceptTypes,
final VariableDeclaratorId exceptId, final BlockStmt catchBlock) {
super(beginLine, beginColumn, endLine, endColumn);
setExcept(new MultiTypeParameter(beginLine, beginColumn, endLine, endColumn, exceptModifier, exceptAnnotations,
exceptTypes, exceptId));
setCatchBlock(catchBlock);
}