Refine search
private static boolean isTypeElement(Element element) { ElementKind kind = element.getKind(); return kind.isClass() || kind.isInterface(); }
private void writeAsyncClass(Element elem) throws ClassNotFoundException, IOException, Exception { if (elem.getKind().isInterface()) { TypeElement interfaceClazz = (TypeElement) elem; String className = interfaceClazz.getSimpleName().toString(); TypeSpec.Builder classBuilder = TypeSpec.interfaceBuilder(className + ASYNC).addModifiers(Modifier.PUBLIC) .addSuperinterface(TypeName.get(elem.asType())); // add class generic type classBuilder.addTypeVariables(getTypeNames(interfaceClazz.getTypeParameters())); // add direct method addMethods(interfaceClazz, classBuilder); // add method form superinterface addSuperInterfaceMethods(interfaceClazz.getInterfaces(), classBuilder); // write class JavaFile javaFile = JavaFile.builder(processingEnv.getElementUtils().getPackageOf(interfaceClazz).getQualifiedName().toString(), classBuilder.build()).build(); javaFile.writeTo(new File(System.getProperty("basedir"), TARGET_DIR)); } else { processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "MotanAsyncProcessor not process, because " + elem.toString() + " not a interface."); } }
private boolean isMethodProcessable(ExecutableElement element) { // if an immutable type with an implementation provided skip it if (!isUnimplementable() && element().getKind().isClass() && isImmutable() && !element.getModifiers().contains(Modifier.ABSTRACT)) { if (!ImmutableAnnotationKind.of(element()).isPresent() || !ImmutableAnnotationKind.of(element()).get().hasAnyMemberAnnotation(element)) { return false; } } String name = element.getSimpleName().toString(); // skip kotlin data class methods with component1, component2.. names if (isUnimplementable() && name.startsWith("component") && name.length() > "component".length()) { return false; } TypeMirror type = element.getReturnType(); boolean isInterface = element().getKind().isInterface(); boolean isTransient = Mirrors.findAnnotationMirror(element, Transient.class).isPresent(); // must be a getter style method with no args, can't return void or itself or its builder return type.getKind() != TypeKind.VOID && element.getParameters().isEmpty() && (isImmutable() || isInterface || !element.getModifiers().contains(Modifier.FINAL)) && (!isImmutable() || !type.equals(element().asType())) && !type.equals(builderType().orElse(null)) && !element.getModifiers().contains(Modifier.STATIC) && !element.getModifiers().contains(Modifier.DEFAULT) && (!isTransient || isInterface) && !name.equals("toString") && !name.equals("hashCode"); }
private TypeElement enclosingTypeOf(Element element) { for (Element e = element; e != null;) { ElementKind kind = e.getKind(); if (kind.isClass() || kind.isInterface()) { return (TypeElement) e; } e = e.getEnclosingElement(); } throw new NoSuchElementException(); }
boolean generateMembers = typeElement.getKind().isInterface() || !entity.builderType().isPresent(); Set<String> existingFieldNames = entity.attributes().stream() .map(AttributeDescriptor::element) .filter(it -> it.getKind() == ElementKind.FIELD) .map(it -> it.getSimpleName().toString()) .collect(Collectors.toSet()); for (AttributeDescriptor attribute : entity.attributes()) { Element element = attribute.element(); if (element.getKind() == ElementKind.METHOD) { ExecutableElement methodElement = (ExecutableElement) element; TypeMirror typeMirror = methodElement.getReturnType();
private static boolean isSameKind (ElementKind k1, ElementKind k2) { if ((k1 == k2) || (k1 == ElementKind.OTHER && (k2.isClass() || k2.isInterface())) || (k2 == ElementKind.OTHER && (k1.isClass() || k1.isInterface()))) { return true; } return false; }
private String computePath(ExecutableElement element) { String path = element.getSimpleName().toString(); for (Element e = element.getEnclosingElement(); // e.getKind().isClass() || e.getKind().isInterface(); // e = e.getEnclosingElement()) { path = e.getSimpleName() + "." + path; } if (element.getModifiers().contains(Modifier.ABSTRACT)) { return path; } return path + "()"; }
/** * Test if the given {@link TypeMirror} represents an interface or not. */ public boolean isInterface(TypeMirror typeMirror) { return TypeKind.DECLARED.equals( typeMirror.getKind() ) && ( (DeclaredType) typeMirror ).asElement().getKind().isInterface(); }
public static void addParent(final TypeSpec.Builder builder, final TypeElement superElement) { final ElementKind kind = superElement.getKind(); final TypeName parentType = TypeUtils.getTypeName(superElement); if (kind.isInterface()) { builder.addSuperinterface(parentType); } else if (kind.isClass()) { builder.superclass(parentType); } else { throw new UnsupportedOperationException("Unknown type of parent"); } }
private String getName(Element e) { if (e.getKind().isClass() || e.getKind().isInterface()) { return processingEnv.getElementUtils().getBinaryName((TypeElement)e).toString(); } else if (e.getKind() == ElementKind.PACKAGE) { return e.getSimpleName().toString(); } else { return getName(e.getEnclosingElement()) + '.' + e.getSimpleName(); } }
public boolean isInterface() { return element.getKind().isInterface(); }
/** * Returns a binary name of the {@link TypeElement} represented by this * {@link ElementHandle}. When the {@link ElementHandle} doesn't represent * a {@link TypeElement} it throws a {@link IllegalStateException} * @return the qualified name * @throws an {@link IllegalStateException} when this {@link ElementHandle} * isn't created for the {@link TypeElement}. */ public @NonNull String getBinaryName () throws IllegalStateException { if ((this.kind.isClass() && !isArray(signatures[0])) || this.kind.isInterface() || this.kind == ElementKind.OTHER) { return this.signatures[0]; } else { throw new IllegalStateException (); } }
private static boolean shouldDisableFor(Reporter reporter, Element element) { while (element != null) { if (element.getKind() == ElementKind.PACKAGE) { for (String segment : DOT_SPLITTER.split(((PackageElement) element).getQualifiedName())) { if (!segment.isEmpty() && Ascii.isUpperCase(segment.charAt(0))) { reporter.warning(About.INCOMPAT, WARNING_START + " uppercase package names"); return true; } } } if (element.getKind().isClass() || element.getKind().isInterface()) { if (Ascii.isLowerCase(element.getSimpleName().charAt(0))) { reporter.warning(About.INCOMPAT, WARNING_START + " lowercase class names"); return true; } } element = element.getEnclosingElement(); } return false; } }
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { if (roundEnv.processingOver()) return false; roundEnv.getElementsAnnotatedWith(AutoRestGwt.class).stream() .filter(e -> e.getKind().isInterface() && e instanceof TypeElement).map(e -> (TypeElement) e) .forEach(restService -> { try { processRestService(restService); } catch (Exception e) { // We don't allow exceptions of any kind to propagate to the compiler error("uncaught exception processing rest service " + restService + ": " + e + "\n" + Throwables.getStackTraceAsString(e)); } }); return true; }
private TypeInfoKind kind() { ElementKind kind = element.getKind(); if (kind.isClass()) { return TypeInfoKind.CLASS; } if (kind.isInterface()) { return TypeInfoKind.INTERFACE; } if (ElementKind.ANNOTATION_TYPE.equals(kind)) { return TypeInfoKind.ANNOTATION_TYPE; } if (ElementKind.ENUM.equals(kind)) { return TypeInfoKind.ENUM; } throw new UnsupportedOperationException(kind.toString()); }
@Nullable private TypeElement findBuilderElement() { Protoclass protoclass = protoclass(); if (!protoclass.kind().isValue()) { return null; } for (Element t : protoclass.sourceElement().getEnclosedElements()) { ElementKind kind = t.getKind(); if (kind.isClass() || kind.isInterface()) { String simpleName = t.getSimpleName().toString(); Naming typeInnerBuilderNaming = names().namings.typeInnerBuilder; if (!typeInnerBuilderNaming.detect(simpleName).isEmpty()) { return (TypeElement) t; } } } return null; }
if (decl.getModifiers().contains(Modifier.ABSTRACT) && !decl.getKind().isInterface()) { c.add(ColoringAttributes.ABSTRACT);
private TypeInfoKind kind() { ElementKind kind = element.getKind(); if (kind.isClass()) { return TypeInfoKind.CLASS; } if (kind.isInterface()) { return TypeInfoKind.INTERFACE; } if (ElementKind.ANNOTATION_TYPE.equals(kind)) { return TypeInfoKind.ANNOTATION_TYPE; } if (ElementKind.ENUM.equals(kind)) { return TypeInfoKind.ENUM; } throw new UnsupportedOperationException(kind.toString()); }
static TypeElement getMostEnclosingElement(Element element) { if (element == null) { return null; } while (element.getEnclosingElement() != null && element.getEnclosingElement().getKind().isClass() || element.getEnclosingElement().getKind().isInterface()) { element = element.getEnclosingElement(); } return (TypeElement) element; } }
Descriptor(final Element element, final Elements elements, final Types types) throws AutoMatterProcessorException { if (!element.getKind().isInterface()) { throw new AutoMatterProcessorException("@AutoMatter target must be an interface", element); } this.valueType = (DeclaredType) element.asType(); this.valueTypeElement = (TypeElement) element; this.valueTypeArguments = valueType.getTypeArguments(); this.valueTypeName = nestedName(valueTypeElement, elements); this.isGeneric = !valueTypeArguments.isEmpty(); this.packageName = elements.getPackageOf(element).getQualifiedName().toString(); this.builderName = element.getSimpleName().toString() + "Builder"; final String typeParameterization = isGeneric ? "<" + valueTypeArguments.stream().map(TypeMirror::toString).collect(joining(",")) + ">" : ""; this.concreteBuilderName = builderName + typeParameterization; this.fullyQualifiedBuilderName = fullyQualifedName(packageName, concreteBuilderName); this.fields = new ArrayList<>(); this.fieldTypes = new LinkedHashMap<>(); this.isPublic = element.getModifiers().contains(PUBLIC); this.toString = findToStringMethod(valueTypeElement); enumerateFields(types); }