本文整理汇总了Java中org.walkmod.javalang.ast.body.FieldDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java FieldDeclaration类的具体用法?Java FieldDeclaration怎么用?Java FieldDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FieldDeclaration类属于org.walkmod.javalang.ast.body包,在下文中一共展示了FieldDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
@Override
public void visit(FieldDeclaration n, A arg) {
List<VariableDeclarator> vds = n.getVariables();
List<FieldSymbolData> result = new LinkedList<FieldSymbolData>();
SymbolType thisType = symbolTable.getType("this", ReferenceType.VARIABLE);
for (VariableDeclarator vd : vds) {
String name = vd.getId().getName();
SymbolType st = symbolTable.getType(name, ReferenceType.VARIABLE).clone();
try {
st.setField(thisType.getClazz().getDeclaredField(name));
} catch (Exception e) {
throw new NoSuchExpressionTypeException(
"Ops! We can't find the field " + name + " in " + thisType.getClazz().getName(), e);
}
result.add(st);
}
n.setFieldsSymbolData(result);
}
示例2: removeField
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
public void removeField(Symbol<?> symbol, SymbolTable table, FieldDeclaration fd) {
int modifiers = fd.getModifiers();
if (ModifierSet.isPrivate(modifiers)) {
List<VariableDeclarator> vds = fd.getVariables();
if (vds != null) {
Iterator<VariableDeclarator> it = vds.iterator();
while (it.hasNext()) {
VariableDeclarator vd = it.next();
if (vd.getId().getName().equals(symbol.getName())) {
Expression init = vd.getInit();
if (isReadOnlyExpression(init)) {
if (vds.size() == 1) {
remove(fd);
} else {
it.remove();
}
}
}
}
}
}
}
示例3: apply
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
@Override
public void apply(FieldDeclaration remoteObject, List<FieldDeclaration> localList,
List<FieldDeclaration> resultList) {
List<FieldDeclaration> localFields = new LinkedList<FieldDeclaration>();
if (localList != null) {
for (FieldDeclaration localField : localList) {
localFields.addAll(split(localField));
}
}
if (remoteObject.getVariables() != null && remoteObject.getVariables().size() > 1) {
List<FieldDeclaration> remoteFields = split(remoteObject);
for (FieldDeclaration remoteField : remoteFields) {
super.apply(remoteField, localFields, resultList);
}
} else {
super.apply(remoteObject, localFields, resultList);
}
}
示例4: split
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
private List<FieldDeclaration> split(FieldDeclaration fieldDeclaration) {
List<FieldDeclaration> res = new LinkedList<FieldDeclaration>();
if (fieldDeclaration.getVariables().size() > 1) {
for (VariableDeclarator vd : fieldDeclaration.getVariables()) {
FieldDeclaration fd = new FieldDeclaration();
fd.setAnnotations(fieldDeclaration.getAnnotations());
fd.setJavaDoc(fieldDeclaration.getJavaDoc());
fd.setModifiers(fieldDeclaration.getModifiers());
fd.setType(fieldDeclaration.getType());
fd.setBeginLine(fieldDeclaration.getBeginLine());
fd.setBeginColumn(fieldDeclaration.getBeginColumn());
fd.setEndColumn(vd.getEndColumn());
fd.setEndLine(vd.getEndLine());
List<VariableDeclarator> vdList = new LinkedList<VariableDeclarator>();
vdList.add(vd);
fd.setVariables(vdList);
res.add(fd);
}
} else {
res.add(fieldDeclaration);
}
return res;
}
示例5: visit
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
public Boolean visit(FieldDeclaration n1, Node arg) {
FieldDeclaration n2 = (FieldDeclaration) arg;
if (n1.getModifiers() != n2.getModifiers()) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) {
return Boolean.FALSE;
}
if (!nodeEquals(n1.getType(), n2.getType())) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getVariables(), n2.getVariables())) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
示例6: visit
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
public void visit(FieldDeclaration n, Object arg) {
prepareComments(n);
printPreviousComments(n, arg);
JavadocComment comment = n.getJavaDoc();
printJavadoc(comment, arg);
printPreviousComments(n, arg);
printMemberAnnotations(n.getAnnotations(), arg);
Type type = n.getType();
printPreviousComments(type, arg);
printModifiers(n.getModifiers());
type.accept(this, arg);
printer.print(" ");
for (Iterator<VariableDeclarator> i = n.getVariables().iterator(); i.hasNext();) {
VariableDeclarator var = i.next();
var.accept(this, arg);
if (i.hasNext()) {
printer.print(", ");
}
}
printer.print(";");
}
示例7: visit
import org.walkmod.javalang.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;
}
示例8: compare
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
@Override
public int compare(FieldDeclaration fd1, FieldDeclaration fd2) {
if (fd1.getType().equals(fd2.getType())) {
List<VariableDeclarator> vds = fd1.getVariables();
List<VariableDeclarator> vds2 = fd2.getVariables();
if (vds == null || vds.size() == 0 || vds2 == null || vds2.size() == 0) {
return -1;
}
if (vds.size() == vds2.size()) {
if (vds.containsAll(vds2)) {
return 0;
}
}
}
return -1;
}
示例9: testRefactorTypeReference
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
@Test
public void testRefactorTypeReference() throws Exception {
String code = "public class A { Foo b;}";
CompilationUnit modifiedCu = parser.parse(code, false);
CompilationUnit originalCu = parser.parse(code, false);
FieldDeclaration fd = (FieldDeclaration) modifiedCu.getTypes().get(0).getMembers().get(0);
ClassOrInterfaceType type = (ClassOrInterfaceType) ((ReferenceType) fd.getType()).getType();
type.setName("B");
List<Action> actions = getActions(originalCu, modifiedCu);
Assert.assertEquals(1, actions.size());
Assert.assertEquals(ActionType.REPLACE, actions.get(0).getType());
assertCode(actions, code, "public class A { B b;}");
}
示例10: testAppendField
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
@Test
public void testAppendField() throws Exception {
String code = "public class A {\n private String name;\n}";
CompilationUnit modifiedCu = parser.parse(code, false);
String code2 = "public class A {\n private String name;\n}";
FieldDeclaration fd = (FieldDeclaration) ASTManager.parse(FieldDeclaration.class, "private int age;", true);
CompilationUnit originalCu = parser.parse(code2, false);
modifiedCu.getTypes().get(0).getMembers().add(fd);
List<Action> actions = getActions(originalCu, modifiedCu);
// 37
Assert.assertEquals(1, actions.size());
Assert.assertEquals(1, actions.get(0).getBeginColumn());
Assert.assertEquals(ActionType.APPEND, actions.get(0).getType());
assertCode(actions, code2, "public class A {\n private String name;\n private int age;\n}");
}
示例11: testInnerComments
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
@Test
public void testInnerComments() throws ParseException {
String code = "public class B { private /*final*/ int name;}";
DefaultJavaParser parser = new DefaultJavaParser();
CompilationUnit cu = parser.parse(code, false);
CompilationUnit cu2 = parser.parse(code, false);
FieldDeclaration fd = (FieldDeclaration) cu.getTypes().get(0).getMembers().get(0);
List<VariableDeclarator> vds = fd.getVariables();
vds.add(new VariableDeclarator(new VariableDeclaratorId("surname")));
Comment c = cu.getComments().get(0);
c.setContent("static");
List<Action> actions = getActions(cu2, cu);
Assert.assertEquals(1, actions.size());
assertCode(actions, code, "public class B { /*static*/private int name, surname;}");
}
示例12: doPop
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
@Override
public void doPop(Symbol<?> symbol, SymbolTable table) {
Node n = symbol.getLocation();
if (n != null) {
Map<String, Object> attrs = symbol.getAttributes();
Object reads = attrs.get(ReferencesCounterAction.READS);
Object writes = attrs.get(ReferencesCounterAction.WRITES);
if (reads == null && writes == null) {
if (n instanceof MethodDeclaration) {
removeMethod(symbol, table);
} else if (n instanceof VariableDeclarator) {
Node parentNode = n.getParentNode();
if (parentNode != null) {
if (parentNode instanceof FieldDeclaration) {
removeField(symbol, table, (FieldDeclaration) parentNode);
} else {
removeVariable(symbol, table, (VariableDeclarationExpr) parentNode);
}
}
} else if (n instanceof TypeDeclaration) {
Symbol<?> thisSymbol = table.findSymbol("this", ReferenceType.VARIABLE);
if (symbol.getReferenceType().equals(ReferenceType.TYPE) && thisSymbol != null
&& !thisSymbol.getType().equals(symbol.getType())) {
removeType(symbol, table);
}
} else if (n instanceof ImportDeclaration) {
removeImport(symbol, table);
}
}
}
}
示例13: testAnnonymousClass
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
@Test
public void testAnnonymousClass() throws Exception {
String code =
"public class Foo{ public void bar() { Foo o = new Foo() { private String name; public void bar() { System.out.println(\"hello\"); }};}}";
CompilationUnit cu = run(code);
MethodDeclaration md = (MethodDeclaration) cu.getTypes().get(0).getMembers().get(0);
ExpressionStmt stmt = (ExpressionStmt) md.getBody().getStmts().get(0);
VariableDeclarationExpr expr = (VariableDeclarationExpr) stmt.getExpression();
ObjectCreationExpr oce = (ObjectCreationExpr) expr.getVars().get(0).getInit();
// The name attribute should be removed
FieldDeclaration fd = (FieldDeclaration) oce.getAnonymousClassBody().get(0);
Assert.assertNull(fd.getUsages());
}
示例14: testMethodsOverwritingInAnnonymousClasses
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
@Test
public void testMethodsOverwritingInAnnonymousClasses() throws Exception {
String code =
"public class A{ public Object get() { return null; } public A foo = new A() { public String get(){ return name();} private String name(){ return \"hello\"; }};}";
CompilationUnit cu = run(code);
BodyDeclaration bd = cu.getTypes().get(0).getMembers().get(1);
FieldDeclaration aux = (FieldDeclaration) bd;
ObjectCreationExpr expr = (ObjectCreationExpr) aux.getVariables().get(0).getInit();
MethodDeclaration md = (MethodDeclaration) expr.getAnonymousClassBody().get(1);
Assert.assertNotNull(md.getUsages());
}
示例15: testAnonymousArrayExpressions
import org.walkmod.javalang.ast.body.FieldDeclaration; //导入依赖的package包/类
@Test
public void testAnonymousArrayExpressions() throws Exception {
CompilationUnit cu = run("public class A{ Integer v[][] = { new Integer[] {3} }; Integer a[] = v[0]; }");
FieldDeclaration fd = (FieldDeclaration) cu.getTypes().get(0).getMembers().get(0);
SymbolData sd = fd.getType().getSymbolData();
Assert.assertNotNull(sd);
Assert.assertEquals(Integer.class.getName(), sd.getName());
SymbolData sd2 = fd.getVariables().get(0).getInit().getSymbolData();
Assert.assertNotNull(sd2);
Assert.assertEquals(Integer.class.getName(), sd2.getName());
Assert.assertEquals(2, sd2.getArrayCount());
}