本文整理汇总了Java中japa.parser.ast.body.FieldDeclaration.getVariables方法的典型用法代码示例。如果您正苦于以下问题:Java FieldDeclaration.getVariables方法的具体用法?Java FieldDeclaration.getVariables怎么用?Java FieldDeclaration.getVariables使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类japa.parser.ast.body.FieldDeclaration
的用法示例。
在下文中一共展示了FieldDeclaration.getVariables方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTypeOrFieldNameForMsg
import japa.parser.ast.body.FieldDeclaration; //导入方法依赖的package包/类
private String getTypeOrFieldNameForMsg(final BodyDeclaration n) {
if (n instanceof TypeDeclaration) {
return ((TypeDeclaration) n).getName();
} else if (n instanceof FieldDeclaration) {
final FieldDeclaration fd = (FieldDeclaration) n;
//this wont work for nested classes but we should be in nexted classes at this point
final CompilationUnit unit = getCompilationUnit(n);
final TypeDeclaration parent = unit.getTypes().get(0);
Collection<String> variableNames = new ArrayList<String>();
if (fd.getVariables() != null) {
for (VariableDeclarator vd : fd.getVariables()) {
variableNames.add(vd.getId().getName());
}
}
return variableNames.size() == 1 ?
parent.getName() + "." + variableNames.iterator().next() :
parent.getName() + "." + variableNames.toString();
}
return null;
}
示例2: deconstructMultiDeclarations
import japa.parser.ast.body.FieldDeclaration; //导入方法依赖的package包/类
/**
* In Java variables can be defined like the following:
* int i, j, k;
*
* When mapping fields in xml this is not a problem. However when using annotation on a field,
* Each field should be defined separately. This helper will deconstruct these fields such
* that later AST analysis will not need to account for field defined on a separate line.
*/
public static void deconstructMultiDeclarations(Collection<FieldDeclaration> fields) {
for (FieldDeclaration field : fields) {
ClassOrInterfaceDeclaration parent = (ClassOrInterfaceDeclaration) field.getParentNode();
//these are chained together
if (field.getVariables().size() > 1) {
int index = parent.getMembers().indexOf(field);
parent.getMembers().remove(index);
List<FieldDeclaration> deconstructed = new ArrayList<FieldDeclaration>();
for (VariableDeclarator v : field.getVariables()) {
FieldDeclaration f = new FieldDeclaration(field.getModifiers(), field.getAnnotations(), field.getType(), Collections.singletonList(v));
f.setJavaDoc(field.getJavaDoc());
f.setComment(field.getComment());
f.setParentNode(field.getParentNode());
deconstructed.add(f);
}
parent.getMembers().addAll(index, deconstructed);
}
}
}
示例3: getDeclaration
import japa.parser.ast.body.FieldDeclaration; //导入方法依赖的package包/类
public static FieldDeclaration getDeclaration(CompilationUnit unit, Field field) {
TypeDeclaration typeDecl = getDeclaration(unit, field.getDeclaringClass());
if (typeDecl == null) {
return null;
}
for (BodyDeclaration decl : typeDecl.getMembers()) {
if (decl instanceof FieldDeclaration) {
FieldDeclaration fieldDecl = (FieldDeclaration) decl;
List<VariableDeclarator> variables = fieldDecl.getVariables();
if (variables.size() != 1) {
continue;
}
if (field.getName().equals(variables.get(0).getId().getName())) {
return fieldDecl;
}
}
}
return null;
}
示例4: deconstructMultiDeclarations
import japa.parser.ast.body.FieldDeclaration; //导入方法依赖的package包/类
/**
* In Java variables can be defined like the following:
* int i, j, k;
*
* When mapping fields in xml this is not a problem. However when using annotation on a field,
* Each field should be defined separately. This helper will deconstruct these fields such
* that later AST analysis will not need to account for field defined on a separate line.
*/
public static void deconstructMultiDeclarations(Collection<FieldDeclaration> fields) {
for (FieldDeclaration field : fields) {
ClassOrInterfaceDeclaration parent = (ClassOrInterfaceDeclaration) field.getParentNode();
//these are chained together
if (field.getVariables().size() > 1) {
int index = parent.getMembers().indexOf(field);
parent.getMembers().remove(index);
List<FieldDeclaration> deconstructed = new ArrayList<FieldDeclaration>();
for (VariableDeclarator v : field.getVariables()) {
FieldDeclaration f = new FieldDeclaration(field.getJavaDoc(), field.getModifiers(), field.getAnnotations(), field.getType(), Collections.singletonList(v));
f.setComment(field.getComment());
f.setParentNode(field.getParentNode());
deconstructed.add(f);
}
parent.getMembers().addAll(index, deconstructed);
}
}
}
示例5: getAttributesNames
import japa.parser.ast.body.FieldDeclaration; //导入方法依赖的package包/类
private LinkedList<String> getAttributesNames()
{
List<TypeDeclaration> types = compUnit.getTypes();
LinkedList<String> attNames = new LinkedList<String>();
if (types != null)
{
for (TypeDeclaration type : types)
{
List<BodyDeclaration> members = type.getMembers();
if (members != null)
for (BodyDeclaration member : members)
if (member instanceof FieldDeclaration)
{
FieldDeclaration t = (FieldDeclaration) member;
List<VariableDeclarator> variables = t.getVariables();
for (VariableDeclarator v : variables)
attNames.add(v.getId().getName());
}
}
}
return attNames;
}
示例6: visit
import japa.parser.ast.body.FieldDeclaration; //导入方法依赖的package包/类
public Node visit(FieldDeclaration 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));
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;
}
示例7: findFieldDeclaration
import japa.parser.ast.body.FieldDeclaration; //导入方法依赖的package包/类
public static FieldDeclaration findFieldDeclaration(String aFieldName, ClassOrInterfaceDeclaration aType) {
if (aType.getMembers() != null) {
for (BodyDeclaration theBody : aType.getMembers()) {
if (theBody instanceof FieldDeclaration) {
FieldDeclaration theField = (FieldDeclaration) theBody;
for (VariableDeclarator theDeclaration : theField.getVariables()) {
if (aFieldName.equals(theDeclaration.getId().getName())) {
return theField;
}
}
}
}
}
return null;
}
示例8: removeField
import japa.parser.ast.body.FieldDeclaration; //导入方法依赖的package包/类
public static void removeField(
final CompilationUnitServices compilationUnitServices,
final List<BodyDeclaration> members, final JavaSymbolName fieldName) {
Validate.notNull(compilationUnitServices,
"Flushable compilation unit services required");
Validate.notNull(members, "Members required");
Validate.notNull(fieldName, "Field name to remove is required");
// Locate the field
int i = -1;
int toDelete = -1;
for (final BodyDeclaration bd : members) {
i++;
if (bd instanceof FieldDeclaration) {
final FieldDeclaration fieldDeclaration = (FieldDeclaration) bd;
for (final VariableDeclarator var : fieldDeclaration
.getVariables()) {
if (var.getId().getName().equals(fieldName.getSymbolName())) {
toDelete = i;
break;
}
}
}
}
Validate.isTrue(toDelete > -1, "Could not locate field '%s' to delete",
fieldName);
// Do removal outside iteration of body declaration members, to avoid
// concurrent modification exceptions
members.remove(toDelete);
}
示例9: visit
import japa.parser.ast.body.FieldDeclaration; //导入方法依赖的package包/类
@Override
public void visit(FieldDeclaration n, Scope arg) {
// Introduce a field in the scope we're visiting.
super.visit(n, arg);
for (VariableDeclarator declarator : n.getVariables()) {
arg.vars.put(declarator.getId().toString(), new Scope.TypedVariableDeclarator(n.getType().toString(), declarator.getId()));
}
n.setData(arg);
}
示例10: visit
import japa.parser.ast.body.FieldDeclaration; //导入方法依赖的package包/类
public R visit(FieldDeclaration 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);
}
}
n.getType().accept(this, arg);
for (VariableDeclarator var : n.getVariables()) {
var.accept(this, arg);
}
return null;
}
示例11: visit
import japa.parser.ast.body.FieldDeclaration; //导入方法依赖的package包/类
public void visit(FieldDeclaration 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);
}
}
n.getType().accept(this, arg);
for (VariableDeclarator var : n.getVariables()) {
var.accept(this, arg);
}
}