本文整理汇总了Java中japa.parser.ast.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于japa.parser.ast包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolve
import japa.parser.ast.Node; //导入依赖的package包/类
@Override
public NodeData resolve(Node node, String mappedClass) {
if (!(node instanceof ClassOrInterfaceDeclaration)) {
throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration");
}
final TypeDeclaration dclr = (TypeDeclaration) node;
if (!(dclr.getParentNode() instanceof CompilationUnit)) {
//handling nested classes
return null;
}
final String name = dclr.getName();
final Collection<FieldDescriptor> primaryKeyDescriptors = getPrimaryKeyDescriptors(mappedClass);
if (primaryKeyDescriptors != null && primaryKeyDescriptors.size() > 1 && nodeContainsPkFields(dclr,
primaryKeyDescriptors)) {
final NodeAndImports<ClassOrInterfaceDeclaration> primaryKeyClass = createPrimaryKeyClass(name, primaryKeyDescriptors);
final String pkClassName = primaryKeyClass.node.getName();
return new NodeData(new SingleMemberAnnotationExpr(new NameExpr(SIMPLE_NAME), new NameExpr(name + "." + pkClassName + ".class")),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), primaryKeyClass.imprts, primaryKeyClass.node);
}
return null;
}
示例2: resolve
import japa.parser.ast.Node; //导入依赖的package包/类
@Override
public NodeData resolve(Node node, String mappedClass) {
if (!(node instanceof ClassOrInterfaceDeclaration)) {
throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration");
}
final TypeDeclaration dclr = (TypeDeclaration) node;
if (!(dclr.getParentNode() instanceof CompilationUnit)) {
//handling nested classes
return null;
}
final String name = dclr.getName();
final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString();
final String enclosingClass = pckg + "." + name;
final ClassDescriptor cd = OjbUtil.findClassDescriptor(enclosingClass, descriptorRepositories);
if (cd != null) {
return new NodeData(new MarkerAnnotationExpr(new NameExpr(SIMPLE_NAME)),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
return null;
}
示例3: resolve
import japa.parser.ast.Node; //导入依赖的package包/类
@Override
public final NodeData resolve(Node node, String mappedClass) {
if (!(node instanceof FieldDeclaration)) {
throw new IllegalArgumentException("this annotation belongs only on FieldDeclaration");
}
final FieldDeclaration field = (FieldDeclaration) node;
if (ResolverUtil.canFieldBeAnnotated(field)) {
final TypeDeclaration dclr = (TypeDeclaration) node.getParentNode();
final String name = dclr.getName();
final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString();
final String fullyQualifiedClass = pckg + "." + name;
final boolean mappedColumn = OjbUtil.isMappedColumn(mappedClass, ParserUtil.getFieldName(field),
descriptorRepositories);
if (mappedColumn) {
return getAnnotationNodes(fullyQualifiedClass, ParserUtil.getFieldName(field), mappedClass);
}
}
return null;
}
示例4: resolve
import japa.parser.ast.Node; //导入依赖的package包/类
@Override
public NodeData resolve(Node node, String mappedClass) {
if (!(node instanceof ClassOrInterfaceDeclaration)) {
throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration");
}
final TypeDeclaration dclr = (TypeDeclaration) node;
if (!(dclr.getParentNode() instanceof CompilationUnit)) {
//handling nested classes
return null;
}
final String name = dclr.getName();
final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString();
final String enclosingClass = pckg + "." + name;
if (!enclosingClass.equals(mappedClass)) {
return new NodeData(new MarkerAnnotationExpr(new NameExpr(SIMPLE_NAME)),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
return null;
}
示例5: resolve
import japa.parser.ast.Node; //导入依赖的package包/类
@Override
public NodeData resolve(Node node, String mappedClass) {
if (!(node instanceof ClassOrInterfaceDeclaration)) {
throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration");
}
final TypeDeclaration dclr = (TypeDeclaration) node;
if (!(dclr.getParentNode() instanceof CompilationUnit)) {
//handling nested classes
return null;
}
final String name = dclr.getName();
final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString();
final String enclosingClass = pckg + "." + name;
final Collection<String> customizedFieldsOnNode = getFieldsOnNode(dclr, getCustomizedFields(mappedClass));
if (customizedFieldsOnNode == null || customizedFieldsOnNode.isEmpty()) {
LOG.info(ResolverUtil.logMsgForClass(enclosingClass, mappedClass) + " has no customized fields");
return null;
}
return new NodeData(new SingleMemberAnnotationExpr(new NameExpr(SIMPLE_NAME), new NameExpr("CreateCustomizerFor" + customizedFieldsOnNode.toString())),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
示例6: resolve
import japa.parser.ast.Node; //导入依赖的package包/类
@Override
public NodeData resolve(Node node, String mappedClass) {
if (!(node instanceof FieldDeclaration)) {
throw new IllegalArgumentException("this annotation belongs only on FieldDeclaration");
}
final FieldDeclaration field = (FieldDeclaration) node;
if (ResolverUtil.canFieldBeAnnotated(field)) {
final boolean mappedColumn = OjbUtil.isMappedColumn(mappedClass, ParserUtil.getFieldName(field),
descriptorRepositories);
if (!mappedColumn) {
return new NodeData(new MarkerAnnotationExpr(new NameExpr(SIMPLE_NAME)),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
}
return null;
}
示例7: appendNode
import japa.parser.ast.Node; //导入依赖的package包/类
private void appendNode(StringBuilder s, Node node) {
for (int lineNum = node.getBeginLine(); lineNum <= node.getEndLine(); lineNum++) {
String line = lines.get(lineNum);
int start;
if (lineNum == node.getBeginLine())
start = node.getBeginColumn();
else
start = 0;
int end;
if (lineNum == node.getEndLine())
end = node.getEndColumn();
else
end = line.length();
s.append(line.substring(start, end));
}
}
示例8: getNode
import japa.parser.ast.Node; //导入依赖的package包/类
public static Node getNode(CompilationUnit unit, String fqName) {
String pkg = getQualifiedName(unit.getPackage().getName());
if (!fqName.startsWith(pkg)) {
return null;
}
if (fqName.equals(pkg)) {
return unit.getPackage();
}
String name = fqName.substring(pkg.length() + 1);
for (TypeDeclaration typeDecl : unit.getTypes()) {
if (name.startsWith(typeDecl.getName())) {
if (name.length() == typeDecl.getName().length()) {
return typeDecl;
} else {
return getNode(typeDecl, name.substring(typeDecl.getName().length() + 1));
}
}
}
return null;
}
示例9: visit
import japa.parser.ast.Node; //导入依赖的package包/类
public Node visit(ExplicitConstructorInvocationStmt n, A arg) {
if (!n.isThis()) {
if (n.getExpr() != null) {
n.setExpr((Expression) n.getExpr().accept(this, arg));
}
}
List<Type> typeArgs = n.getTypeArgs();
if (typeArgs != null) {
for (int i = 0; i < typeArgs.size(); i++) {
typeArgs.set(i, (Type) typeArgs.get(i).accept(this, arg));
}
removeNulls(typeArgs);
}
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);
}
return n;
}
示例10: nodesEquals
import japa.parser.ast.Node; //导入依赖的package包/类
private <T extends Node> boolean nodesEquals(List<T> nodes1, List<T> nodes2) {
if (nodes1 == null) {
if (nodes2 == null) {
return true;
}
return false;
} else if (nodes2 == null) {
return false;
}
if (nodes1.size() != nodes2.size()) {
return false;
}
for (int i = 0; i < nodes1.size(); i++) {
if (!nodeEquals(nodes1.get(i), nodes2.get(i))) {
return false;
}
}
return true;
}
示例11: nodeEquals
import japa.parser.ast.Node; //导入依赖的package包/类
private <T extends Node> boolean nodeEquals(T n1, T n2) {
if (n1 == n2) {
return true;
}
if (n1 == null) {
if (n2 == null) {
return true;
}
return false;
} else if (n2 == null) {
return false;
}
if (n1.getClass() != n2.getClass()) {
return false;
}
return n1.accept(this, n2).booleanValue();
}
示例12: visit
import japa.parser.ast.Node; //导入依赖的package包/类
public Boolean visit(Parameter n1, Node arg) {
Parameter n2 = (Parameter) arg;
if (n1.getModifiers() != n2.getModifiers()) {
return Boolean.FALSE;
}
if (!nodeEquals(n1.getId(), n2.getId())) {
return Boolean.FALSE;
}
if (!nodeEquals(n1.getType(), n2.getType())) {
return Boolean.FALSE;
}
if (!nodesEquals(n1.getAnnotations(), n2.getAnnotations())) {
return Boolean.FALSE;
}
return Boolean.TRUE;
}
示例13: doTest
import japa.parser.ast.Node; //导入依赖的package包/类
void doTest(String source, Node node) {
String parsed = node.toString();
assertTrue(node.getClass().getName() + ": " + parsed, node.getBeginLine() >= 0);
assertTrue(node.getClass().getName() + ": " + parsed, node.getBeginColumn() >= 0);
assertTrue(node.getClass().getName() + ": " + parsed, node.getEndLine() >= 0);
assertTrue(node.getClass().getName() + ": " + parsed, node.getEndColumn() >= 0);
if (node.getBeginLine() == node.getEndLine()) {
assertTrue(node.getClass().getName() + ": " + parsed, node.getBeginColumn() <= node.getEndColumn());
} else {
assertTrue(node.getClass().getName() + ": " + parsed, node.getBeginLine() <= node.getEndLine());
}
String substr = substring(source, node.getBeginLine(), node.getBeginColumn(), node.getEndLine(), node.getEndColumn());
assertEquals(node.getClass().getName(), trimLines(parsed), trimLines(substr));
}
示例14: resolve
import japa.parser.ast.Node; //导入依赖的package包/类
@Override
public NodeData resolve(Node node, String mappedClass) {
if (!(node instanceof ClassOrInterfaceDeclaration)) {
throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration");
}
final TypeDeclaration dclr = (TypeDeclaration) node;
if (!(dclr.getParentNode() instanceof CompilationUnit)) {
//handling nested classes
return null;
}
final String name = dclr.getName();
final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString();
final String enclosingClass = pckg + "." + name;
final ClassDescriptor cd = OjbUtil.findClassDescriptor(enclosingClass, descriptorRepositories);
if (cd != null) {
final String tableName = getMappedTable(enclosingClass);
if (tableName == null) {
LOG.error(ResolverUtil.logMsgForClass(enclosingClass, mappedClass) + " table could not be found");
return null;
}
return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("name", new StringLiteralExpr(upperCaseTableName ? tableName.toUpperCase() : tableName)))),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
return null;
}
示例15: getCompilationUnit
import japa.parser.ast.Node; //导入依赖的package包/类
/** walks up the tree until reaching the CompilationUnit. */
private CompilationUnit getCompilationUnit(Node n) {
Node unit = n;
while (!(unit instanceof CompilationUnit) && unit != null) {
unit = unit.getParentNode();
}
return (CompilationUnit) unit;
}