本文整理汇总了Java中com.github.javaparser.ast.visitor.VoidVisitorAdapter类的典型用法代码示例。如果您正苦于以下问题:Java VoidVisitorAdapter类的具体用法?Java VoidVisitorAdapter怎么用?Java VoidVisitorAdapter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
VoidVisitorAdapter类属于com.github.javaparser.ast.visitor包,在下文中一共展示了VoidVisitorAdapter类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: analyze
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; //导入依赖的package包/类
public List<EntityField> analyze(File source) throws IOException, ParseException {
List<EntityField> entityFields = new ArrayList<>();
CompilationUnit cu = JavaParser.parse(source);
cu.accept(new VoidVisitorAdapter<List<EntityField>>() {
@Override
public void visit(FieldDeclaration fd, List<EntityField> f) {
if (fd.getAnnotations().stream().anyMatch(anno -> anno.getName().getName().equals("Column"))) {
Class<?> type = null;
switch (fd.getType().toString()) {
case "String": type = String.class; break;
case "Long": type = Long.class; break;
case "Integer": type = Integer.class; break;
case "boolean": type = boolean.class; break;
}
if (type == null) return;
f.add(new EntityField(
fd.getVariables().get(0).getId().getName(),
type,
fd.getAnnotations().stream().anyMatch(anno -> anno.getName().getName().equals("Id"))));
}
}
}, entityFields);
return entityFields;
}
示例2: renameFieldName
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; //导入依赖的package包/类
public void renameFieldName() {
String fieldPrefix = g().getFieldPrefix();
String propertyName = getPropertyName();
String fieldName = propertyName;
if(null != fieldPrefix) {
fieldName = fieldPrefix + propertyName;
}
VariableDeclarator vd = getVariableDeclaration();
if(null == vd)
return;
//if(m_classWrapper.getTable().getName().equals("definition")) {
// System.out.println("GOTCHA");
//}
String oldName = vd.getName().asString();
if(! oldName.equals(fieldName)) {
vd.setName(fieldName);
//-- We need to rename inside the getter and setter too
MethodDeclaration getter = getGetter();
GetterFieldRenamingVisitor fieldVisitor = new GetterFieldRenamingVisitor(oldName, fieldName);
if(null != getter) {
getter.accept(fieldVisitor, null);
}
MethodDeclaration setter = getSetter();
if(null != setter) {
setter.accept(fieldVisitor, null);
}
m_classWrapper.getRootType().accept(new VoidVisitorAdapter<Void>() {
@Override public void visit(ConstructorDeclaration n, Void arg) {
n.accept(fieldVisitor, null);
}
}, null);
}
}
示例3: destroyConstructors
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; //导入依赖的package包/类
/**
* Delete all constructors.
*/
public void destroyConstructors() {
List<ConstructorDeclaration> list = new ArrayList<>();
getRootType().accept(new VoidVisitorAdapter<Void>() {
@Override public void visit(ConstructorDeclaration n, Void arg) {
list.add(n);
}
}, null);
list.forEach(n -> n.remove());
}
示例4: givenAVoidVisitorAdapterWithAVisitMethodThatChangesVariableNamesToUppercase
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; //导入依赖的package包/类
@Given("a VoidVisitorAdapter with a visit method that changes variable names to uppercase")
public void givenAVoidVisitorAdapterWithAVisitMethodThatChangesVariableNamesToUppercase() {
toUpperCaseVariableNameVisitor = new VoidVisitorAdapter<AtomicReference<String>>() {
@Override
public void visit(VariableDeclaratorId n, AtomicReference<String> arg) {
n.setName(n.getName().toUpperCase());
}
};
}
示例5: givenAVoidVisitorAdapterWithAVisitMethodThatCollectsTheVariableName
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; //导入依赖的package包/类
@Given("a VoidVisitorAdapter with a visit method and collects the variable names")
public void givenAVoidVisitorAdapterWithAVisitMethodThatCollectsTheVariableName() {
collectVariableNameVisitor = new VoidVisitorAdapter<AtomicReference<String>>() {
@Override
public void visit(VariableDeclaratorId n, AtomicReference<String> arg) {
arg.set(arg.get() + n.getName() + ";");
}
};
}
示例6: calculatesTypeNames
import com.github.javaparser.ast.visitor.VoidVisitorAdapter; //导入依赖的package包/类
@Test
public void calculatesTypeNames() throws IOException, ParseException {
CompilationUnit compilationUnit = JavaParser.parse(
FileLoader.getFile("de/is24/javaparser/TypeNameTestClass.java"));
compilationUnit.accept(new VoidVisitorAdapter<Void>() {
@Override
public void visit(StringLiteralExpr n, Void arg) {
assertThat("Name of anonymous class is invalid!", Nodes.getTypeName(n), is(n.getValue()));
}
}, null);
}