Java Code Examples for javax.lang.model.element.Modifier#ABSTRACT

The following examples show how to use javax.lang.model.element.Modifier#ABSTRACT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ClazzAs.java    From sundrio with Apache License 2.0 6 votes vote down vote up
public TypeDef apply(final TypeDef item) {
    final Modifier[] modifiers = item.isAbstract()
            ? new Modifier[]{Modifier.PUBLIC, Modifier.ABSTRACT}
            : new Modifier[]{Modifier.PUBLIC};

    final TypeDef editable = EDITABLE.apply(item);
    return new TypeDefBuilder(BUILDER.apply(item))
            .withAnnotations()
            .accept(new TypedVisitor<MethodBuilder>() {
        public void visit(MethodBuilder builder) {
            if (builder.getName() != null && builder.getName().equals("build")) {
                builder.withModifiers(TypeUtils.modifiersToInt(modifiers));
                builder.withReturnType(editable.toInternalReference());
                builder.withBlock(new Block(new Provider<List<Statement>>() {
                    @Override
                    public List<Statement> get() {
                        return toBuild(editable, editable);
                    }
                }));
            }
        }
    }).build();
}
 
Example 2
Source File: ModifierOrderer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
     * Returns the {@link Modifier} for the given token kind, or {@code
     * null}.
     */
    private static Modifier getModifier(TokenKind kind) {
        if (kind == null) {
            return null;
        }
        switch (kind) {
            case PUBLIC:
                return Modifier.PUBLIC;
            case PROTECTED:
                return Modifier.PROTECTED;
            case PRIVATE:
                return Modifier.PRIVATE;
            case ABSTRACT:
                return Modifier.ABSTRACT;
            case STATIC:
                return Modifier.STATIC;
            // TODO: 22-Jul-17 unsupported lambdas expr
//            case DEFAULT:
//                return Modifier.DEFAULT;
            case FINAL:
                return Modifier.FINAL;
            case TRANSIENT:
                return Modifier.TRANSIENT;
            case VOLATILE:
                return Modifier.VOLATILE;
            case SYNCHRONIZED:
                return Modifier.SYNCHRONIZED;
            case NATIVE:
                return Modifier.NATIVE;
            case STRICTFP:
                return Modifier.STRICTFP;
            default:
                return null;
        }
    }
 
Example 3
Source File: PsiModifierExtractor.java    From litho with Apache License 2.0 5 votes vote down vote up
private static Modifier psiModifierToModifier(PsiElement psiModifier) {
  switch (psiModifier.getText()) {
    case PsiModifier.ABSTRACT:
      return Modifier.ABSTRACT;
    case PsiModifier.FINAL:
      return Modifier.FINAL;
    case PsiModifier.NATIVE:
      return Modifier.NATIVE;
    case PsiModifier.PRIVATE:
      return Modifier.PRIVATE;
    case PsiModifier.PROTECTED:
      return Modifier.PROTECTED;
    case PsiModifier.PUBLIC:
      return Modifier.PUBLIC;
    case PsiModifier.STATIC:
      return Modifier.STATIC;
    case PsiModifier.STRICTFP:
      return Modifier.STRICTFP;
    case PsiModifier.SYNCHRONIZED:
      return Modifier.SYNCHRONIZED;
    case PsiModifier.TRANSIENT:
      return Modifier.TRANSIENT;
    case PsiModifier.VOLATILE:
      return Modifier.VOLATILE;
    default:
      // TODO better error message, ideally w/ line number
      throw new ComponentsProcessingException(
          "Unexpected Modifier, modifier is: " + psiModifier.getText());
  }
}
 
Example 4
Source File: ModifierOrderer.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
     * Returns the {@link Modifier} for the given token kind, or {@code
     * null}.
     */
    private static Modifier getModifier(TokenKind kind) {
        if (kind == null) {
            return null;
        }
        switch (kind) {
            case PUBLIC:
                return Modifier.PUBLIC;
            case PROTECTED:
                return Modifier.PROTECTED;
            case PRIVATE:
                return Modifier.PRIVATE;
            case ABSTRACT:
                return Modifier.ABSTRACT;
            case STATIC:
                return Modifier.STATIC;
            // TODO: 22-Jul-17 unsupported lambdas expr
//            case DEFAULT:
//                return Modifier.DEFAULT;
            case FINAL:
                return Modifier.FINAL;
            case TRANSIENT:
                return Modifier.TRANSIENT;
            case VOLATILE:
                return Modifier.VOLATILE;
            case SYNCHRONIZED:
                return Modifier.SYNCHRONIZED;
            case NATIVE:
                return Modifier.NATIVE;
            case STRICTFP:
                return Modifier.STRICTFP;
            default:
                return null;
        }
    }
 
Example 5
Source File: PropertyUtility.java    From kripton with Apache License 2.0 5 votes vote down vote up
/**
 * Modifier is acceptable.
 *
 * @param item
 *            the item
 * @return true, if successful
 */
static boolean modifierIsAcceptable(Element item) {
	// kotlin define properties as final
	Object[] values = { Modifier.NATIVE, Modifier.STATIC,
			/* Modifier.FINAL, */ Modifier.ABSTRACT };

	for (Object i : values) {
		if (item.getModifiers().contains(i))
			return false;
	}

	return true;
}
 
Example 6
Source File: ModifierOrderer.java    From google-java-format with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link javax.lang.model.element.Modifier} for the given token kind, or {@code
 * null}.
 */
private static Modifier getModifier(TokenKind kind) {
  if (kind == null) {
    return null;
  }
  switch (kind) {
    case PUBLIC:
      return Modifier.PUBLIC;
    case PROTECTED:
      return Modifier.PROTECTED;
    case PRIVATE:
      return Modifier.PRIVATE;
    case ABSTRACT:
      return Modifier.ABSTRACT;
    case STATIC:
      return Modifier.STATIC;
    case DEFAULT:
      return Modifier.DEFAULT;
    case FINAL:
      return Modifier.FINAL;
    case TRANSIENT:
      return Modifier.TRANSIENT;
    case VOLATILE:
      return Modifier.VOLATILE;
    case SYNCHRONIZED:
      return Modifier.SYNCHRONIZED;
    case NATIVE:
      return Modifier.NATIVE;
    case STRICTFP:
      return Modifier.STRICTFP;
    default:
      return null;
  }
}
 
Example 7
Source File: ElementJavadoc.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private StringBuilder getClassHeader(TypeElement cdoc) {
    StringBuilder sb = new StringBuilder();
    sb.append("<pre>"); //NOI18N
    cdoc.getAnnotationMirrors().forEach((annotationDesc) -> {
        appendAnnotation(sb, annotationDesc, true);
    });
    for (Modifier modifier : cdoc.getModifiers()) {
        switch(cdoc.getKind()) {
            case ENUM:
                if (modifier == Modifier.FINAL)
                    continue;
                break;
            case INTERFACE:
            case ANNOTATION_TYPE:
                if (modifier == Modifier.ABSTRACT)
                    continue;
                break;                     
        }
        sb.append(modifier).append(' '); //NOI18N
    }
    switch (cdoc.getKind()) {
        case ANNOTATION_TYPE:
            sb.append("@interface "); //NOI18N
            break;
        case ENUM:
            sb.append("enum "); //NOI18N
            break;
        case INTERFACE:
            sb.append("interface "); //NOI18N
            break;
        default:
            sb.append("class "); //NOI18N            
    }
    sb.append("<b>").append(cdoc.getSimpleName()); //NOI18N
    List<? extends TypeParameterElement> typeParams = cdoc.getTypeParameters();
    if (!typeParams.isEmpty()) {
        sb.append("&lt;"); //NOI18N
        for (Iterator<? extends TypeParameterElement> it = typeParams.iterator(); it.hasNext();) {
            TypeParameterElement typeParam = it.next();
            appendType(sb, typeParam.asType(), false, true, false);
            if (it.hasNext())
                sb.append(","); //NOI18N
        }
        sb.append("&gt;"); //NOI18N
    }
    sb.append("</b>"); //NOi18N
    if (cdoc.getKind() != ElementKind.ANNOTATION_TYPE) {
        TypeMirror supercls = cdoc.getSuperclass();
        if (supercls != null && supercls.getKind() != TypeKind.NONE) {
            sb.append("<br>extends "); //NOI18N
            appendType(sb, supercls, false, false, false);            
        }
        List<? extends TypeMirror> ifaces = cdoc.getInterfaces();
        if (!ifaces.isEmpty()) {
            sb.append(cdoc.getKind().isInterface() ? "<br>extends " : "<br>implements "); //NOI18N
            for (Iterator<? extends TypeMirror> it = ifaces.iterator(); it.hasNext();) {
                TypeMirror iface = it.next();
                appendType(sb, iface, false, false, false);
                if (it.hasNext())
                    sb.append(", "); //NOI18N
            }            
        }
    }
    sb.append("</pre>"); //NOI18N
    return sb;
}
 
Example 8
Source File: ClazzAs.java    From sundrio with Apache License 2.0 4 votes vote down vote up
public TypeDef apply(TypeDef item) {
    Modifier[] modifiers = item.isAbstract()
            ? new Modifier[]{Modifier.PUBLIC, Modifier.ABSTRACT}
            : new Modifier[]{Modifier.PUBLIC};

    TypeDef editableType = TypeAs.EDITABLE.apply(item);
    final TypeDef builderType = TypeAs.BUILDER.apply(item);

    List<Method> constructors = new ArrayList<Method>();
    List<Method> methods = new ArrayList<Method>();

    for (Method constructor : item.getConstructors()) {
        constructors.add(superConstructorOf(constructor, editableType));
    }

    Method edit = new MethodBuilder()
            .withModifiers(TypeUtils.modifiersToInt(modifiers))
            .withReturnType(builderType.toInternalReference())
            .withName("edit")
            .withNewBlock()
                .addToStatements(new StringStatement(new Provider<String>() {
                    @Override
                    public String get() {
                        return "return new " + builderType.getName() + "(this);";
                    }
                }))
            .endBlock()
            .build();

    methods.add(edit);

    //We need to treat the editable classes as buildables themselves.
    return CodegenContext.getContext().getDefinitionRepository().register(
            BuilderContextManager.getContext().getBuildableRepository().register(new TypeDefBuilder(editableType)
                    .withAnnotations()
                    .withModifiers(TypeUtils.modifiersToInt(modifiers))
                    .withConstructors(constructors)
                    .withMethods(methods)
                    .addToAttributes(BUILDABLE_ENABLED, true)
                    .addToAttributes(GENERATED, true) // We want to know that its a generated type...
                    .build())
    );
}
 
Example 9
Source File: NoLongerAbstract.java    From revapi with Apache License 2.0 4 votes vote down vote up
public NoLongerAbstract() {
    super(false, Code.METHOD_NO_LONGER_ABSTRACT, Modifier.ABSTRACT);
}
 
Example 10
Source File: NowAbstract.java    From revapi with Apache License 2.0 4 votes vote down vote up
public NowAbstract() {
    super(true, Code.METHOD_NOW_ABSTRACT, Modifier.ABSTRACT);
}
 
Example 11
Source File: NoLongerAbstract.java    From revapi with Apache License 2.0 4 votes vote down vote up
public NoLongerAbstract() {
    super(false, Code.CLASS_NO_LONGER_ABSTRACT, Modifier.ABSTRACT);
}
 
Example 12
Source File: NowAbstract.java    From revapi with Apache License 2.0 4 votes vote down vote up
public NowAbstract() {
    super(true, Code.CLASS_NOW_ABSTRACT, Modifier.ABSTRACT);
}