javax.lang.model.element.Element#accept ( )源码实例Demo

下面列出了javax.lang.model.element.Element#accept ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: helidon-build-tools   文件: Visitor.java
@Override
public CommandFragmentMetaModel visitType(TypeElement type, Void p) {
    List<MetaModel<?>> params = null;
    for (Element elt : type.getEnclosedElements()) {
        if (elt.getKind() == ElementKind.CONSTRUCTOR && elt.getAnnotation(Creator.class) != null) {
            params = elt.accept(new ConstructorVisitor(), null);
            break;
        }
    }
    if (params != null) {
        String pkg = env.getElementUtils().getPackageOf(type).getQualifiedName().toString();
        CommandFragmentMetaModel model = new CommandFragmentMetaModel(type, pkg, params);
        fragmentsByQualifiedName.put(type.getQualifiedName().toString(), model);
        return model;
    }
    env.getMessager().printMessage(Diagnostic.Kind.ERROR,
                String.format("No constructor annotated with @%s found", Creator.class.getSimpleName()),
                type);
    return null;
}
 
源代码2 项目: netbeans   文件: JavaUtils.java
@Override
public TypeElement visitType(TypeElement typeElement, String binaryName) {
    String bName = ElementUtilities.getBinaryName(typeElement);
    if(binaryName.equals(bName)) {
        return typeElement;
    } else if(binaryName.startsWith(bName)) {
        for(Element child : typeElement.getEnclosedElements()) {
            if(!child.getKind().isClass()) {
                continue;
            }
            
            TypeElement retVal = child.accept(this, binaryName);
            if(retVal != null) {
                return retVal;
            }
        }
    }
    
    return null;
}
 
源代码3 项目: Akatsuki   文件: RetainerLUTModel.java
private Map<String, RetainedStateModel> findAllTypes(final Element element,
		final Map<String, RetainedStateModel> referenceMap) {
	Map<String, RetainedStateModel> modelMap = new HashMap<>();
	element.accept(new SimpleElementVisitor8<Void, Map<String, RetainedStateModel>>() {

		@Override
		public Void visitType(TypeElement e, Map<String, RetainedStateModel> map) {
			if (e.getKind() == ElementKind.CLASS) {
				// only process class that isn't in the map
				if (!referenceMap.containsKey(e.getQualifiedName().toString())) {
					findInheritedModel(e, referenceMap.values())
							.ifPresent(m -> map.put(e.getQualifiedName().toString(), m));
				}
				e.getEnclosedElements().forEach(ee -> ee.accept(this, map));
			}
			return null;
		}
	}, modelMap);
	return modelMap;
}
 
源代码4 项目: buck   文件: SignatureFactory.java
/**
 * Returns the type signature of the given element. If none is required by the VM spec, returns
 * null.
 */
@Nullable
public String getSignature(Element element) {
  SignatureWriter writer = new SignatureWriter();
  element.accept(elementVisitorAdapter, writer);
  String result = writer.toString();
  return result.isEmpty() ? null : result;
}
 
源代码5 项目: netbeans   文件: JPAEditorUtil.java
@Override
public TypeElement visitPackage(PackageElement packElem, String binaryName) {
    for (Element e : packElem.getEnclosedElements()) {
        if (e.getKind().isClass()) {
            TypeElement ret = e.accept(this, binaryName);
            if (ret != null) {
                return ret;
            }
        }
    }

    return null;
}
 
源代码6 项目: netbeans   文件: JavaUtils.java
@Override
public TypeElement visitPackage(PackageElement packElem, String binaryName) {
    for(Element e : packElem.getEnclosedElements()) {
        if(e.getKind().isClass()) {
            TypeElement ret = e.accept(this, binaryName);
            if(ret != null) {
                return ret;
            }
        }
    }
    
    return null;
}
 
源代码7 项目: buck   文件: BuckModuleAnnotationProcessor.java
private List<BuckModuleDescriptor> collectBuckModuleDescriptors(
    Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
  BuckModuleVisitor visitor = new BuckModuleVisitor(processingEnv);
  for (TypeElement annotation : annotations) {
    for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
      element.accept(visitor, annotation);
    }
  }

  if (visitor.hasData()) {
    return visitor.getBuckModuleDescriptors();
  }
  return Collections.emptyList();
}
 
源代码8 项目: doma   文件: MoreElements.java
public TypeElement toTypeElement(Element element) {
  assertNotNull(element);
  return element.accept(
      new SimpleElementVisitor8<TypeElement, Void>() {

        // delegate to elementUtils
        public TypeElement visitType(TypeElement e, Void p) {
          return e;
        }
      },
      null);
}
 
源代码9 项目: doma   文件: MoreElements.java
public TypeParameterElement toTypeParameterElement(Element element) {
  assertNotNull(element);
  return element.accept(
      new SimpleElementVisitor8<TypeParameterElement, Void>() {

        @Override
        public TypeParameterElement visitTypeParameter(TypeParameterElement e, Void aVoid) {
          return e;
        }
      },
      null);
}
 
源代码10 项目: netbeans   文件: ExportNonAccessibleElement.java
public List<ErrorDescription> run(CompilationInfo compilationInfo,
                                      TreePath treePath) {
        stop = false;
        Element e = compilationInfo.getTrees().getElement(treePath);
        if (e == null) {
            return null;
        }
        Boolean b = e.accept(this, null);

        if (b) {
            Element parent = e;
            for (;;) {
                if (stop) {
                    return null;
                }

                if (parent == null || parent.getKind() == ElementKind.PACKAGE) {
                    break;
                }
                if (!parent.getModifiers().contains(Modifier.PUBLIC) && !parent.getModifiers().contains(Modifier.PROTECTED)) {
                    return null;
                }
                parent = parent.getEnclosingElement();
            }

            //#124456: disabling the fix:
//            List<Fix> fixes = Collections.<Fix>singletonList(new FixImpl(
//                "MSG_ExportNonAccessibleElementMakeNonVisible", // NOI18N
//                TreePathHandle.create(e, compilationInfo), 
//                compilationInfo.getFileObject()
//            ));

            int[] span = null;

            switch (treePath.getLeaf().getKind()) {
                case METHOD: span = compilationInfo.getTreeUtilities().findNameSpan((MethodTree) treePath.getLeaf()); break;
                case ANNOTATION_TYPE:
                case CLASS:
                case ENUM:
                case INTERFACE:
                    span = compilationInfo.getTreeUtilities().findNameSpan((ClassTree) treePath.getLeaf()); break;
                case VARIABLE: span = compilationInfo.getTreeUtilities().findNameSpan((VariableTree) treePath.getLeaf()); break;
            }

            if (span != null) {
                ErrorDescription ed = ErrorDescriptionFactory.createErrorDescription(
                        getSeverity().toEditorSeverity(),
                        NbBundle.getMessage(ExportNonAccessibleElement.class, "MSG_ExportNonAccessibleElement"),
//                        fixes,
                        compilationInfo.getFileObject(),
                        span[0],
                        span[1]
                        );

                return Collections.singletonList(ed);
            }
        }
        
        return null;
    }
 
源代码11 项目: auto   文件: SuperficialValidation.java
public static boolean validateElement(Element element) {
  return element.accept(ELEMENT_VALIDATING_VISITOR, null);
}
 
源代码12 项目: buck   文件: ClassVisitorDriverFromElement.java
public void driveVisitor(Element fullElement, ClassVisitor visitor) {
  fullElement.accept(new ElementVisitorAdapter(), visitor);
  visitor.visitEnd();
}
 
源代码13 项目: helidon-build-tools   文件: Visitor.java
/**
 * Visitor a command fragment class.
 *
 * @param elt element to visit
 * @return meta-model
 */
CommandFragmentMetaModel visitCommandFragment(Element elt) {
    return elt.accept(new CommandFragmentVisitor(), null);
}
 
源代码14 项目: immutables   文件: MoreElements.java
/**
 * Returns the given {@link Element} instance as {@link TypeElement}.
 *
 * <p>This method is functionally equivalent to an {@code instanceof} check and a cast, but should
 * always be used over that idiom as instructed in the documentation for {@link Element}.
 *
 * @throws IllegalArgumentException if {@code element} isn't a {@link TypeElement}.
 */
public static TypeElement asType(Element element) {
  return element.accept(TypeElementVisitor.INSTANCE, null);
}
 
源代码15 项目: auto   文件: MoreElements.java
/**
 * Returns the given {@link Element} instance as {@link ExecutableElement}.
 *
 * <p>This method is functionally equivalent to an {@code instanceof} check and a cast, but should
 * always be used over that idiom as instructed in the documentation for {@link Element}.
 *
 * @throws NullPointerException if {@code element} is {@code null}
 * @throws IllegalArgumentException if {@code element} isn't a {@link ExecutableElement}.
 */
public static ExecutableElement asExecutable(Element element) {
  return element.accept(ExecutableElementVisitor.INSTANCE, null);
}
 
源代码16 项目: auto   文件: MoreElements.java
/**
 * Returns the given {@link Element} instance as {@link TypeParameterElement}.
 *
 * <p>This method is functionally equivalent to an {@code instanceof} check and a cast, but should
 * always be used over that idiom as instructed in the documentation for {@link Element}.
 *
 * @throws NullPointerException if {@code element} is {@code null}
 * @throws IllegalArgumentException if {@code element} isn't a {@link TypeParameterElement}.
 */
public static TypeParameterElement asTypeParameter(Element element) {
  return element.accept(TypeParameterElementVisitor.INSTANCE, null);
}
 
源代码17 项目: auto-parcel   文件: MoreElements.java
/**
 * Returns the given {@link Element} instance as {@link TypeElement}.
 * <p/>
 * <p>This method is functionally equivalent to an {@code instanceof} check and a cast, but should
 * always be used over that idiom as instructed in the documentation for {@link Element}.
 *
 * @throws NullPointerException     if {@code element} is {@code null}
 * @throws IllegalArgumentException if {@code element} isn't a {@link TypeElement}.
 */
public static TypeElement asType(Element element) {
    return element.accept(TYPE_ELEMENT_VISITOR, null);
}
 
源代码18 项目: auto-parcel   文件: MoreElements.java
/**
 * Returns the given {@link Element} instance as {@link VariableElement}.
 * <p/>
 * <p>This method is functionally equivalent to an {@code instanceof} check and a cast, but should
 * always be used over that idiom as instructed in the documentation for {@link Element}.
 *
 * @throws NullPointerException     if {@code element} is {@code null}
 * @throws IllegalArgumentException if {@code element} isn't a {@link VariableElement}.
 */
public static VariableElement asVariable(Element element) {
    return element.accept(VARIABLE_ELEMENT_VISITOR, null);
}
 
源代码19 项目: immutables   文件: MoreElements.java
/**
 * Returns the given {@link Element} instance as {@link PackageElement}.
 *
 * <p>This method is functionally equivalent to an {@code instanceof} check and a cast, but should
 * always be used over that idiom as instructed in the documentation for {@link Element}.
 *
 * @throws IllegalArgumentException if {@code element} isn't a {@link TypeElement}.
 */
public static PackageElement asPackage(Element element) {
  return element.accept(PackageElementVisitor.INSTANCE, null);
}
 
源代码20 项目: auto   文件: MoreElements.java
/**
 * Returns the given {@link Element} instance as {@link VariableElement}.
 *
 * <p>This method is functionally equivalent to an {@code instanceof} check and a cast, but should
 * always be used over that idiom as instructed in the documentation for {@link Element}.
 *
 * @throws NullPointerException if {@code element} is {@code null}
 * @throws IllegalArgumentException if {@code element} isn't a {@link VariableElement}.
 */
public static VariableElement asVariable(Element element) {
  return element.accept(VariableElementVisitor.INSTANCE, null);
}