Package lombok.ast

Examples of lombok.ast.TypeDeclaration


        "annotation method declarations");
    checkStaticChain(md.astModifiers());
  }
 
  public void fieldModifiersCheck(VariableDeclaration vd) {
    TypeDeclaration td = vd.upUpToTypeDeclaration();
    if (td == null) return//not a field.
    VariableDefinition def = vd.astDefinition();
    if (def != null) {
      Modifiers m = def.astModifiers();
      modifiersCheck(m, FIELD_MODIFIERS_EXCLUSIVITY, FIELD_MODIFIERS_LEGAL, "field declarations");
View Full Code Here


   
    return flags;
  }
 
  public void checkStaticInitializerInNonStaticType(StaticInitializer node) {
    TypeDeclaration parent = node.upUpToTypeDeclaration();
    if (parent != null) {
      if (!parent.astModifiers().isStatic()) {
        node.addMessage(error(INITIALIZER_STATIC_IN_NON_STATIC_TYPE,
            "static initializers are only allowed in top-level or static types declarations."));
      }
    }
  }
View Full Code Here

public class StructuralChecks {
  public void checkAbstractMembersOnlyInAbstractTypes(MethodDeclaration md) {
    Modifiers modifiers = md.astModifiers();
    if (modifiers == null) return;
    if (!modifiers.isAbstract()) return;
    TypeDeclaration parent = md.upUpToTypeDeclaration();
    if (parent != null) {
      Modifiers modifiersOfParent = parent.astModifiers();
      if (modifiersOfParent != null && modifiersOfParent.isAbstract()) return;
      md.addMessage(error(MODIFIERS_ABSTRACT_NOT_ALLOWED, "Abstract methods are only allowed in interfaces and abstract classes"));
    }
  }
View Full Code Here

    private static final long ENUM_CONSTANT_FLAGS = Flags.PUBLIC | Flags.STATIC | Flags.FINAL | Flags.ENUM;
   
    @Override public void visitClassDef(JCClassDecl node) {
      long flags = node.mods.flags;
      String name = node.getSimpleName().toString();
      TypeDeclaration typeDecl;
      Map<FlagKey, Object> flagKeyMap = Maps.newHashMap();
      flagKeyMap.put(FlagKey.CONTAINING_TYPE_NAME, name);
      flagKeyMap.put(FlagKey.BLOCKS_ARE_INITIALIZERS, FlagKey.BLOCKS_ARE_INITIALIZERS);
      flagKeyMap.put(FlagKey.SKIP_IS_DECL, FlagKey.SKIP_IS_DECL);
     
      if ((flags & (Flags.ENUM | Flags.INTERFACE)) == 0) {
        ClassDeclaration classDecl = new ClassDeclaration();
        typeDecl = classDecl;
        fillList(node.implementing, classDecl.rawImplementing(), FlagKey.TYPE_REFERENCE);
        classDecl.rawExtending(toTree(node.extending, FlagKey.TYPE_REFERENCE));
        fillList(node.typarams, classDecl.rawTypeVariables());
        NormalTypeBody body = new NormalTypeBody();
        fillList(node.defs, body.rawMembers(), flagKeyMap);
        classDecl.astBody(body);
      } else if ((flags & Flags.ANNOTATION) != 0) {
        AnnotationDeclaration annDecl = new AnnotationDeclaration();
        typeDecl = annDecl;
        NormalTypeBody body = new NormalTypeBody();
        flagKeyMap.put(FlagKey.METHODS_ARE_ANNMETHODS, FlagKey.METHODS_ARE_ANNMETHODS);
        fillList(node.defs, body.rawMembers(), flagKeyMap);
        annDecl.astBody(body);
      } else if ((flags & Flags.INTERFACE) != 0) {
        InterfaceDeclaration itfDecl = new InterfaceDeclaration();
        typeDecl = itfDecl;
        fillList(node.typarams, itfDecl.rawTypeVariables());
        fillList(node.implementing, itfDecl.rawExtending(), FlagKey.TYPE_REFERENCE);
        NormalTypeBody body = new NormalTypeBody();
        fillList(node.defs, body.rawMembers(), flagKeyMap);
        itfDecl.astBody(body);
      } else if ((flags & Flags.ENUM) != 0) {
        EnumDeclaration enumDecl = new EnumDeclaration();
        typeDecl = enumDecl;
        EnumTypeBody body = new EnumTypeBody();
        fillList(node.implementing, enumDecl.rawImplementing(), FlagKey.TYPE_REFERENCE);
        java.util.List<JCTree> defs = new ArrayList<JCTree>();
       
        for (JCTree def : node.defs) {
          if (def instanceof JCVariableDecl) {
            JCVariableDecl vd = (JCVariableDecl) def;
            if (vd.mods != null && (vd.mods.flags & ENUM_CONSTANT_FLAGS) == ENUM_CONSTANT_FLAGS) {
              // This is an enum constant, not a field of the enum class.
              EnumConstant ec = new EnumConstant();
              setPos(def, ec);
              ec.astName(new Identifier().astValue(vd.getName().toString()));
              fillList(vd.mods.annotations, ec.rawAnnotations());
              if (vd.init instanceof JCNewClass) {
                JCNewClass init = (JCNewClass) vd.init;
                fillList(init.getArguments(), ec.rawArguments());
                if (init.getClassBody() != null) {
                  NormalTypeBody constantBody = setPos(init, new NormalTypeBody());
                  fillList(init.getClassBody().getMembers(), constantBody.rawMembers());
                  ec.astBody(constantBody);
                }
                setConversionPositionInfo(ec, "newClass", getPosition(init));
              }
              body.astConstants().addToEnd(ec);
              continue;
            }
          }
         
          defs.add(def);
        }
        fillList(defs, body.rawMembers(), flagKeyMap);
        enumDecl.astBody(body);
      } else {
        throw new IllegalStateException("Unknown type declaration: " + node);
      }
     
      typeDecl.astName(new Identifier().astValue(name));
      typeDecl.astModifiers((Modifiers) toTree(node.mods));
      addJavadoc(typeDecl, node.mods);
      set(node, typeDecl);
    }
View Full Code Here

TOP

Related Classes of lombok.ast.TypeDeclaration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.