当前位置: 首页>>代码示例>>Java>>正文


Java BodyDeclaration类代码示例

本文整理汇总了Java中com.github.javaparser.ast.body.BodyDeclaration的典型用法代码示例。如果您正苦于以下问题:Java BodyDeclaration类的具体用法?Java BodyDeclaration怎么用?Java BodyDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BodyDeclaration类属于com.github.javaparser.ast.body包,在下文中一共展示了BodyDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visit

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的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;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:17,代码来源:CloneVisitor.java

示例2: addResourceType

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的package包/类
private static void addResourceType(List<String> supportedTypes, TypeSpec.Builder result,
    TypeDeclaration node) {
  if (!supportedTypes.contains(node.getName())) {
    return;
  }

  String type = node.getName();
  TypeSpec.Builder resourceType = TypeSpec.classBuilder(type).addModifiers(PUBLIC, STATIC, FINAL);

  for (BodyDeclaration field : node.getMembers()) {
    if (field instanceof FieldDeclaration) {
      addResourceField(resourceType, ((FieldDeclaration) field).getVariables().get(0),
          getSupportAnnotationClass(type));
    }
  }

  result.addType(resourceType.build());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:FinalRClassBuilder.java

示例3: printMembers

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的package包/类
private void printMembers(final NodeList<BodyDeclaration<?>> members, final Void arg) {
	BodyDeclaration<?> prev = null;

	members.sort((a, b) -> {
		if (a instanceof FieldDeclaration && b instanceof CallableDeclaration) {
			return 1;
		} else if (b instanceof FieldDeclaration && a instanceof CallableDeclaration) {
			return -1;
		} else if (a instanceof MethodDeclaration && !((MethodDeclaration) a).getModifiers().contains(Modifier.STATIC) && b instanceof ConstructorDeclaration) {
			return 1;
		} else if (b instanceof MethodDeclaration && !((MethodDeclaration) b).getModifiers().contains(Modifier.STATIC) && a instanceof ConstructorDeclaration) {
			return -1;
		} else {
			return 0;
		}
	});

	for (final BodyDeclaration<?> member : members) {
		if (prev != null && (!prev.isFieldDeclaration() || !member.isFieldDeclaration())) printer.println();
		member.accept(this, arg);
		printer.println();

		prev = member;
	}
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:26,代码来源:SrcRemapper.java

示例4: createOrFindAnnotation

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的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;
}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:20,代码来源:ClassWrapper.java

示例5: createOrFindMarkerAnnotation

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的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;
}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:20,代码来源:ClassWrapper.java

示例6: visit

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的package包/类
@Override
public void visit(ClassOrInterfaceDeclaration clazz, Object arg) {
    for (BodyDeclaration member : clazz.getMembers()) {
        if (member instanceof ClassOrInterfaceDeclaration)
            visit((ClassOrInterfaceDeclaration)member, arg);
        else if (member instanceof FieldDeclaration) {
            FieldDeclaration field = (FieldDeclaration)member;
            String type = null != field.getType() ? field.getType().toString() : "";
            if (type.equals("int")) {
                VariableDeclarator variable = field.getVariables().stream().findFirst().get();
                String name = variable.getId().toString();
                Integer value = null != variable.getInit() ? Integer.parseInt(variable.getInit().toString()) : 0;
                // decimal value of 0x7f000000, which is what AAPT starts numbering at - http://stackoverflow.com/a/6646113/311304
                if (value >= 2130706432) {
                    name = "R." + ((ClassOrInterfaceDeclaration)field.getParentNode()).getName() + "." + name;
                    transform.put(value, name);
                }
            }
        }
    }
}
 
开发者ID:justingarrick,项目名称:android-reverse-r,代码行数:22,代码来源:Reverser.java

示例7: parseIfStatement

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的package包/类
/**
 *
 * @param is
 *      a github javaparser IfStatement
 * @param attributes
 *      the list of attributes of the class,
 *      to potentially get a type from the name
 * @param bd
 *      a body declaration
 * @return
 *      an IfStatement structure
 */
private IfStatement parseIfStatement(IfStmt is, List<Attribute> attributes, BodyDeclaration bd) {
    IfStatement ifSt = new IfStatement();
    List<Stmt> body = new ArrayList<>();
    ifSt.setCondition(parseExpression(is.getCondition(), attributes, bd.getBeginLine()));
    body.addAll(parseStatement(is.getThenStmt(), attributes, bd));
    if (is.getElseStmt() != null) {
        List<Stmt> elsStmts = new ArrayList<>();
        elsStmts.addAll(parseStatement(is.getElseStmt(), attributes, bd));
        ifSt.setElseStmt(elsStmts);
    }
    ifSt.setBody(body);
    ifSt.setLine(is.getBeginLine() - bd.getBeginLine());

    return ifSt;
}
 
开发者ID:DevMine,项目名称:parsers,代码行数:28,代码来源:Parser.java

示例8: extractInformation

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的package包/类
private void extractInformation(String filename) throws ClassParserException {
	List<TypeDeclaration> types = cu.getTypes();
	for (TypeDeclaration type : types) {
		if (type instanceof ClassOrInterfaceDeclaration) {
			clazz = (ClassOrInterfaceDeclaration) type;
		}
		List<BodyDeclaration> members = type.getMembers();
		for (BodyDeclaration member : members) {
			if (member instanceof FieldDeclaration) {
				fields.add((FieldDeclaration) member);
			}
			else if (member instanceof ConstructorDeclaration) {
				constructors.add((ConstructorDeclaration) member);
			}
			else if (member instanceof MethodDeclaration) {
				methods.add((MethodDeclaration) member);
			}
		}
	}
	if (clazz == null) {
		throw new ClassParserException("No toplevel type declaration found in " + filename + ".");
	}
}
 
开发者ID:umlet,项目名称:umlet,代码行数:24,代码来源:JpJavaClass.java

示例9: visit

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的package包/类
@Override
public Node visit(ClassOrInterfaceDeclaration _n, Object _arg) {
	JavadocComment javaDoc = cloneNodes(_n.getJavaDoc(), _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.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(),
			_n.getModifiers(), annotations, _n.isInterface(), _n.getName(), typeParameters, extendsList, implementsList, members
	);
	r.setComment(comment);
	return r;
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:18,代码来源:CloneVisitor.java

示例10: visit

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的package包/类
@Override public void visit(final AnnotationDeclaration n, final A arg) {
	visitComment(n.getComment(), arg);
	if (n.getJavaDoc() != null) {
		n.getJavaDoc().accept(this, arg);
	}
	if (n.getAnnotations() != null) {
		for (final AnnotationExpr a : n.getAnnotations()) {
			a.accept(this, arg);
		}
	}
	if (n.getMembers() != null) {
		for (final BodyDeclaration member : n.getMembers()) {
			member.accept(this, arg);
		}
	}
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:17,代码来源:VoidVisitorAdapter.java

示例11: visit

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的package包/类
@Override public void visit(final AnnotationDeclaration n, final A arg) {
    jw.write(n); 
    visitComment(n.getComment(), arg);
    if (n.getJavaDoc() != null) {
        n.getJavaDoc().accept(this, arg);
    }
    if (n.getAnnotations() != null) {
        for (final AnnotationExpr a : n.getAnnotations()) {
            a.accept(this, arg);
        }
    }
    if (n.getMembers() != null) {
        for (final BodyDeclaration member : n.getMembers()) {
            member.accept(this, arg);
        }
    }
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:18,代码来源:JsonVisitorAdapter.java

示例12: visit

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的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;
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:21,代码来源:ModifierVisitorAdapter.java

示例13: getMethodByPositionAndClassPosition

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的package包/类
public static MethodDeclaration getMethodByPositionAndClassPosition(CompilationUnit compilationUnit,
                                                                     int methodPosition, int classPosition) {
    TypeDeclaration type = compilationUnit.getTypes().get(classPosition -1);

    int memberCount = 0;
    int methodCount = 0;
    for(BodyDeclaration bodyDeclaration : type.getMembers()) {
        if(bodyDeclaration instanceof MethodDeclaration){
            if(methodCount == methodPosition -1) {
                return (MethodDeclaration) type.getMembers().get(memberCount);
            }
            methodCount++;
        }
        memberCount++;
    }
    throw new IllegalArgumentException("Method not found at position " +methodPosition+ "in class " + classPosition);
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:18,代码来源:SharedSteps.java

示例14: visit

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的package包/类
@Override public void visit(final EnumDeclaration n, final A arg) {
	visitComment(n.getComment(), arg);
	visitAnnotations(n, arg);
	n.getNameExpr().accept(this, arg);
	if (n.getImplements() != null) {
		for (final ClassOrInterfaceType c : n.getImplements()) {
			c.accept(this, arg);
		}
	}
	if (n.getEntries() != null) {
		for (final EnumConstantDeclaration e : n.getEntries()) {
			e.accept(this, arg);
		}
	}
	if (n.getMembers() != null) {
           for (final BodyDeclaration<?> member : n.getMembers()) {
			member.accept(this, arg);
		}
	}
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:21,代码来源:VoidVisitorAdapter.java

示例15: visit

import com.github.javaparser.ast.body.BodyDeclaration; //导入依赖的package包/类
@Override public Node visit(final EnumConstantDeclaration 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);
	}
	final List<Expression> args = n.getArgs();
	if (args != null) {
		for (int i = 0; i < args.size(); i++) {
			args.set(i, (Expression) args.get(i).accept(this, arg));
		}
		removeNulls(args);
	}
       final List<BodyDeclaration<?>> classBody = n.getClassBody();
	if (classBody != null) {
		for (int i = 0; i < classBody.size(); i++) {
               classBody.set(i, (BodyDeclaration<?>) classBody.get(i).accept(this, arg));
		}
		removeNulls(classBody);
	}
	return n;
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:26,代码来源:ModifierVisitorAdapter.java


注:本文中的com.github.javaparser.ast.body.BodyDeclaration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。