Package lombok.ast

Examples of lombok.ast.VariableDefinition


            }
        }

        if (node instanceof VariableDeclaration) {
            VariableDeclaration declaration = (VariableDeclaration) node;
            VariableDefinition definition = declaration.astDefinition();
            if (definition != null) {
                lombok.ast.TypeReference typeReference = definition.astTypeReference();
                if (typeReference != null) {
                    return typeReference.getNativeNode();
                }
            }
        }
View Full Code Here


 
  private Node toVariableDefinition(java.util.List<JCVariableDecl> decls, Map<FlagKey, Object> keys) {
    boolean createDeclaration = !keys.containsKey(FlagKey.VARDEF_IS_DEFINITION);
   
    if (decls == null || decls.isEmpty()) {
      VariableDefinition def = new VariableDefinition();
      return createDeclaration ? new VariableDeclaration().astDefinition(def) : def;
    }
   
    JCVariableDecl first = decls.get(0);
    int startPosFirst = first.pos;
   
    JCExpression baseType = first.vartype;
    while (baseType instanceof JCArrayTypeTree) {
      // if written as int[] a[], b; then the base Type is *NOT* a's type, but a's type with any number of JCATT's dewrapped.
      // The only way to tell the difference is by checking positions, unfortunately: If end pos of type is after start pos of decl, it's a split.
      int endPosType = baseType.getEndPosition(endPosTable);
      if (endPosType != -1 && startPosFirst != -1 && endPosType > startPosFirst) {
        baseType = ((JCArrayTypeTree) baseType).elemtype;
      } else {
        break;
      }
    }
   
    VariableDefinition def = new VariableDefinition();
    def.astModifiers((Modifiers) toTree(first.mods));
    setPos(decls.get(decls.size()-1), def);
    if (decls.size() > 1) def.setPosition(new Position(startPosFirst, def.getPosition().getEnd()));
    int baseDims = countDims(baseType);
    if ((first.mods.flags & Flags.VARARGS) != 0) {
      def.astVarargs(true);
      setConversionPositionInfo(def, "...", getPosition(baseType));
      if (baseType instanceof JCArrayTypeTree) baseType = ((JCArrayTypeTree) baseType).elemtype;
    }
    def.rawTypeReference(toTree(baseType, FlagKey.TYPE_REFERENCE));
    def.astVarargs((first.mods.flags & Flags.VARARGS) != 0);
   
    for (JCVariableDecl varDecl : decls) {
      int extraDims = countDims(varDecl.vartype) - baseDims;
      VariableDefinitionEntry entry = new VariableDefinitionEntry();
      entry.astArrayDimensions(extraDims);
      entry.astName(setPos(varDecl, new Identifier().astValue(varDecl.name.toString())));
      entry.rawInitializer(toTree(varDecl.init));
      setPos(varDecl, entry);
      if (extraDims > 0) {
        JCArrayTypeTree arrayType = (JCArrayTypeTree) varDecl.vartype;
        for (int i = 0; i < extraDims; i++) {
          if (arrayType != null) setConversionPositionInfo(entry, "[]" + (extraDims - i - 1), getPosition(arrayType));
          arrayType = arrayType.elemtype instanceof JCArrayTypeTree ? (JCArrayTypeTree) arrayType.elemtype : null;
        }
        }
      def.astVariables().addToEnd(entry);
    }
   
    if (createDeclaration) {
      VariableDeclaration decl = new VariableDeclaration().astDefinition(def);
      decl.setPosition(def.getPosition());
      addJavadoc(decl, first.mods);
      return decl;
    }
   
    return def;
View Full Code Here

            }
        }

        if (node instanceof VariableDeclaration) {
            VariableDeclaration declaration = (VariableDeclaration) node;
            VariableDefinition definition = declaration.astDefinition();
            if (definition != null) {
                lombok.ast.TypeReference typeReference = definition.astTypeReference();
                if (typeReference != null) {
                    return typeReference.getNativeNode();
                }
            }
        }
View Full Code Here

            Class<? extends Node> type = scope.getClass();
            // The Lombok AST uses a flat hierarchy of node type implementation classes
            // so no need to do instanceof stuff here.
            if (type == VariableDefinition.class) {
                // Variable
                VariableDefinition declaration = (VariableDefinition) scope;
                if (isSuppressed(issue, declaration.astModifiers())) {
                    return true;
                }
            } else if (type == MethodDeclaration.class) {
                // Method
                // Look for annotations on the method
                MethodDeclaration declaration = (MethodDeclaration) scope;
                if (isSuppressed(issue, declaration.astModifiers())) {
                    return true;
                }
            } else if (type == ConstructorDeclaration.class) {
                // Constructor
                // Look for annotations on the method
                ConstructorDeclaration declaration = (ConstructorDeclaration) scope;
                if (isSuppressed(issue, declaration.astModifiers())) {
                    return true;
                }
            } else if (type == ClassDeclaration.class) {
                // Class
                ClassDeclaration declaration = (ClassDeclaration) scope;
                if (isSuppressed(issue, declaration.astModifiers())) {
                    return true;
                }
            }

            if (checkComments && context.isSuppressed(scope, issue)) {
View Full Code Here

            }
        }

        if (node instanceof VariableDeclaration) {
            VariableDeclaration declaration = (VariableDeclaration) node;
            VariableDefinition definition = declaration.astDefinition();
            if (definition != null) {
                lombok.ast.TypeReference typeReference = definition.astTypeReference();
                if (typeReference != null) {
                    return typeReference.getNativeNode();
                }
            }
        }
View Full Code Here

        }
        return true;
      }
     
      private void splitVariableDeclaration(VariableDeclaration varDecl) {
        VariableDefinition varDef = varDecl.astDefinition();
        Node upFromDecl = varDecl.getParent();
        if (!(upFromDecl instanceof Block || upFromDecl instanceof TypeBody)) {
          return;
        }
       
        for (VariableDefinitionEntry varDefEntry : varDef.astVariables()) {
          if (upFromDecl instanceof Block) {
            VariableDeclaration splitDecl = new VariableDeclaration().astDefinition(splitAndUnparentVariableDeclaration(varDef, varDefEntry));
            ((Block)upFromDecl).astContents().addBefore(varDecl, splitDecl);
          }
          else if (upFromDecl instanceof TypeBody) {
            VariableDeclaration splitDecl = new VariableDeclaration().astDefinition(splitAndUnparentVariableDeclaration(varDef, varDefEntry));
            ((TypeBody)upFromDecl).astMembers().addBefore(varDecl, splitDecl);
          }
        }
        varDecl.unparent();
      }
     
      private void splitFor(For forStat, VariableDefinition varDef) {
        for (VariableDefinitionEntry varDefEntry : varDef.astVariables()) {
          VariableDefinition splitVarDef = splitAndUnparentVariableDeclaration(varDef, varDefEntry);
         
          /*
           * TODO: The way the converter adds multiple varDefs in a
           * for is mimicked, though it does not seem to be a correct
           * AST. Verify this and rewrite both the converter and
           * the normalizer
           */
          forStat.rawExpressionInits().addToEnd(splitVarDef);
        }
        forStat.astVariableDeclaration().unparent();
      }
     
      private VariableDefinition splitAndUnparentVariableDeclaration(VariableDefinition def, VariableDefinitionEntry varDefEntry) {
        varDefEntry.unparent();
        VariableDefinition copy = def.copy();
        copy.astVariables().clear();
        copy.astVariables().addToEnd(varDefEntry);
        return copy;
      }
    });
  }
View Full Code Here

TOP

Related Classes of lombok.ast.VariableDefinition

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.