@Override public boolean process(@Nullable Set<? extends TypeElement> annotations, @NonNull RoundEnvironment roundEnv) { try { final ArrayList<? extends Element> annotatedElements = new ArrayList<>(roundEnv.getElementsAnnotatedWith(Configuration.class)); if (!annotatedElements.isEmpty()) { for (final Element e : annotatedElements) { if (e.getKind() == ElementKind.ANNOTATION_TYPE) { new ClassCreator(MoreElements.asType(e), e.getAnnotation(Configuration.class), processingEnv).createClasses(); } else { processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, String.format("%s is only supported on %s", Configuration.class.getName(), ElementKind.ANNOTATION_TYPE.name()), e); } } } } catch (Exception e) { e.printStackTrace(); processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to generate acra classes"); } return true; }
"Inner type %s is %s - not supported as Builder extend/super type", t.getSimpleName(), kind.name().toLowerCase());
protected String descriptionOf(javax.lang.model.element.Element element) { StringBuilder description = new StringBuilder(); ElementKind kind = element.getKind(); if (kind != null) { description.append(kind.name()).append(' '); } Name name = element.getSimpleName(); if (element instanceof TypeElement) { name = ((TypeElement) element).getQualifiedName(); } description.append(name.toString()); return description.toString(); } }
protected String descriptionOf(javax.lang.model.element.Element element) { StringBuilder description = new StringBuilder(); ElementKind kind = element.getKind(); if (kind != null) { description.append(kind.name()).append(' '); } Name name = element.getSimpleName(); if (element instanceof TypeElement) { name = ((TypeElement) element).getQualifiedName(); } description.append(name.toString()); return description.toString(); } }
private static void assertKind(Element element) throws ProcessorException { ElementKind kind = element.getKind(); if (kind != ElementKind.CLASS) { String errMsg = "%s(%s) must not be annotated as @%s."; throw new ProcessorException(errMsg, element.getSimpleName(), kind.name(), moduleClass.getSimpleName()); } }
private void processColdClasses(RoundEnvironment roundEnv) { for (Element annotation : roundEnv.getElementsAnnotatedWith(Cold.class)) { if (!(annotation instanceof TypeElement)) { error("annotating element " + annotation + " of type " + annotation.getKind().name() + " with @Cold is not supported", annotation); continue; } TypeElement typeElem = (TypeElement) annotation; coldClassesDeclaration.declareColdClass(typeElem.getQualifiedName().toString()); } }
private void processColdClasses(RoundEnvironment roundEnv) { for (Element annotation : roundEnv.getElementsAnnotatedWith(Cold.class)) { if (!(annotation instanceof TypeElement)) { error("annotating element " + annotation + " of type " + annotation.getKind().name() + " with @Cold is not supported", annotation); continue; } TypeElement typeElem = (TypeElement) annotation; coldClassesDeclaration.declareColdClass(typeElem.getQualifiedName().toString()); } }
@Override public BeanInfo visitUnknown(Element e, Void aVoid) { logger.log(Diagnostic.Kind.NOTE, "unknown Element type:" + e.getKind().name()); return new BeanInfo(); }
private void processMachines(RoundEnvironment roundEnv) throws IOException { for (Element annotation : roundEnv.getElementsAnnotatedWith(Machine.class)) { try { if (!(annotation instanceof TypeElement)) { error("annotating element " + annotation + " of type " + annotation.getKind().name() + " with @Machine is not supported", annotation); continue; } TypeElement typeElem = (TypeElement) annotation; machinesDeclaration.declareService(typeElem.getQualifiedName().toString()); } catch (Exception e) { fatalError("error when processing " + annotation, e, annotation); } } }
for (Element element : elements){ if(element.getKind() != kind){ throw new AnnotationTargetUseException(element.getSimpleName() + "'s annotation Denpendency must be on a " + kind.name());
@Pure @Override public @Nonnull Contract generateContract(@Nonnull Element element, @Nonnull AnnotationMirror annotationMirror, @NonCaptured @Modified @Nonnull TypeImporter typeImporter) { return Contract.with("# == null || " + getCondition(element, getKind(), typeImporter), "The # has to be null or of the kind '" + getKind().name().toLowerCase().replace("_", " ") + "' but was $.", element); }
ERROR, processingErrorMessage( "this " + Ascii.toLowerCase(missingElement.get().getKind().name())), missingElement.get()); } else {
/** * Returns the condition for the given element depending on the type of the element. */ @Pure public static @Nonnull String getCondition(@Nonnull Element element, @Nonnull ElementKind kind, @NonCaptured @Modified @Nonnull TypeImporter typeImporter) { if (ProcessingUtility.isRawSubtype(element, Class.class)) { switch (kind) { case CLASS: return "!#.isInterface() && !#.isEnum()"; case INTERFACE: return "#.isInterface() && !#.isAnnotation()"; case ENUM: return "#.isEnum()"; case ANNOTATION_TYPE: return "#.isAnnotation()"; default: return "false"; } } else { return "#.getKind() == " + typeImporter.importIfPossible(ElementKind.class) + "." + kind.name(); } }
for (Element element : elements){ if(element.getKind() != kind){ throw new AnnotationTargetUseException(element.getSimpleName() + "'s annotation must be on a " + kind.name());
String eltKind = elt.getKind().name(); String ret = "[[" + rawType.getRaw().translateName("scala"); if (eltKind.equals("METHOD")) {
try { if (!(elem instanceof TypeElement)) { error("annotating element " + elem + " of type " + elem.getKind().name() + " with @Component is not supported", elem); continue;
private String renderLinkToHtml(Tag.Link link) { ClassTypeInfo rawType = link.getTargetType().getRaw(); if (rawType.getModule() != null) { String label = link.getLabel().trim(); if (rawType.getKind() == DATA_OBJECT) { return "{@link " + rawType.getName() + "}"; } else { if (rawType.getKind() == ClassKind.API) { Element elt = link.getTargetElement(); String eltKind = elt.getKind().name(); String ret = "{@link " + rawType.translateName(id); if ("METHOD".equals(eltKind)) { /* todo find a way for translating the complete signature */ ret += "#" + elt.getSimpleName().toString(); } if (label.length() > 0) { ret += " " + label; } ret += "}"; return ret; } } } return "{@link " + rawType.getName() + "}"; } }
private String renderLinkToHtml(Tag.Link link) { ClassTypeInfo rawType = link.getTargetType().getRaw(); if (rawType.getModule() != null) { String label = link.getLabel().trim(); if (rawType.getKind() == DATA_OBJECT) { return "{@link " + rawType.getName() + "}"; } else { if (rawType.getKind() == ClassKind.API) { Element elt = link.getTargetElement(); String eltKind = elt.getKind().name(); String ret = "{@link " + rawType.translateName(id); if ("METHOD".equals(eltKind)) { /* todo find a way for translating the complete signature */ ret += "#" + elt.getSimpleName().toString(); } if (label.length() > 0) { ret += " " + label; } ret += "}"; return ret; } } } return "{@link " + rawType.getName() + "}"; } }
error("annotating element " + elem + " of type " + elem.getKind().name() + " with @Alternative is not supported", elem); continue;
/** * {@link Element}が開始されたことを出力します. * * @param e {@link Element} */ protected void printEnterMessage(final Element e) { final String comment = processingEnv.getElementUtils().getDocComment(e); if (comment != null) { indent(depth * 2); out.println("/**"); final BufferedReader reader = new BufferedReader(new StringReader(comment)); try { String line; while ((line = reader.readLine()) != null) { indent(depth * 2); out.print(" * "); out.println(line); } } catch (final IOException ignore) { } indent(depth * 2); out.println(" */"); } indent(depth * 2); out.print(e.getKind().name()); out.print(' '); out.print(e); out.println(" {"); }