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

The following examples show how to use javax.lang.model.element.Modifier#FINAL . 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: Initializer.java    From vavr-jackson with Apache License 2.0 6 votes vote down vote up
public static void initMapper(TypeSpec.Builder builder, String name, VavrModule.Settings settings) {
    Modifier[] mods = new Modifier[] { Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL };
    if (settings != null) {
        builder.addField(FieldSpec.builder(ClassName.get(VavrModule.Settings.class), name + "_SETTINGS", mods)
                .initializer("new $T()\n        .useOptionInPlainFormat($L).deserializeNullAsEmptyCollection($L)",
                        ClassName.get(VavrModule.Settings.class),
                        settings.useOptionInPlainFormat(), settings.deserializeNullAsEmptyCollection())
                .build());
        builder.addField(FieldSpec.builder(ClassName.get(VavrModule.class), name + "_MODULE", mods)
                .initializer("new $T($L)", ClassName.get(VavrModule.class), name + "_SETTINGS")
                .build());
    } else {
        builder.addField(FieldSpec.builder(ClassName.get(VavrModule.class), name + "_MODULE", mods)
                .initializer("new $T()", ClassName.get(VavrModule.class))
                .build());
    }
    builder.addField(FieldSpec.builder(ClassName.get(ObjectMapper.class), name, mods)
            .initializer("new $T().registerModule($L)", ClassName.get(ObjectMapper.class), name + "_MODULE")
            .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: 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 6
Source File: NodeFactoryGenerator.java    From caffeine with Apache License 2.0 5 votes vote down vote up
private void addConstants() {
  Modifier[] modifiers = {Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL};
  nodeFactory.addField(FieldSpec.builder(Object.class, RETIRED_STRONG_KEY, modifiers)
      .initializer("new Object()")
      .build());
  nodeFactory.addField(FieldSpec.builder(Object.class, DEAD_STRONG_KEY, modifiers)
      .initializer("new Object()")
      .build());
  nodeFactory.addField(FieldSpec.builder(rawReferenceKeyType, RETIRED_WEAK_KEY, modifiers)
      .initializer("new $T(null, null)", rawReferenceKeyType)
      .build());
  nodeFactory.addField(FieldSpec.builder(rawReferenceKeyType, DEAD_WEAK_KEY, modifiers)
      .initializer("new $T(null, null)", rawReferenceKeyType)
      .build());
}
 
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: LocalCacheContext.java    From caffeine with Apache License 2.0 4 votes vote down vote up
public Modifier[] publicFinalModifiers() {
  return isFinal
      ? new Modifier[] { Modifier.PUBLIC }
      : new Modifier[] { Modifier.PUBLIC, Modifier.FINAL };
}
 
Example 9
Source File: LocalCacheContext.java    From caffeine with Apache License 2.0 4 votes vote down vote up
public Modifier[] protectedFinalModifiers() {
  return isFinal
      ? new Modifier[] { Modifier.PROTECTED }
      : new Modifier[] { Modifier.PROTECTED, Modifier.FINAL };
}
 
Example 10
Source File: NodeContext.java    From caffeine with Apache License 2.0 4 votes vote down vote up
public Modifier[] publicFinalModifiers() {
  return isFinal
      ? new Modifier[] { Modifier.PUBLIC }
      : new Modifier[] { Modifier.PUBLIC, Modifier.FINAL };
}
 
Example 11
Source File: NowFinal.java    From revapi with Apache License 2.0 4 votes vote down vote up
public NowFinal() {
    super(true, Code.METHOD_NOW_FINAL, Modifier.FINAL);
}
 
Example 12
Source File: NoLongerFinal.java    From revapi with Apache License 2.0 4 votes vote down vote up
public NoLongerFinal() {
    super(false, Code.METHOD_NO_LONGER_FINAL, Modifier.FINAL);
}
 
Example 13
Source File: NowFinal.java    From revapi with Apache License 2.0 4 votes vote down vote up
public NowFinal() {
    super(true, Code.CLASS_NOW_FINAL, Modifier.FINAL);
}
 
Example 14
Source File: NoLongerFinal.java    From revapi with Apache License 2.0 4 votes vote down vote up
public NoLongerFinal() {
    super(false, Code.CLASS_NO_LONGER_FINAL, Modifier.FINAL);
}
 
Example 15
Source File: NowFinal.java    From revapi with Apache License 2.0 4 votes vote down vote up
public NowFinal() {
    super(true, Code.FIELD_NOW_FINAL, Modifier.FINAL);
}
 
Example 16
Source File: NoLongerFinal.java    From revapi with Apache License 2.0 4 votes vote down vote up
public NoLongerFinal() {
    super(false, Code.FIELD_NO_LONGER_FINAL, Modifier.FINAL);
}