Пример #1
0
  @Override
  public boolean visit(NormalAnnotation node) {
    //
    // Test method?
    //
    if (isTestAnnotation(node.getTypeName().toString())) {
      ASTNode parent = node.getParent();
      if (parent instanceof MethodDeclaration) {
        addTestMethod((MethodDeclaration) parent, JDK15_ANNOTATION);
      } else if (parent instanceof TypeDeclaration) {
        m_typeIsTest = true;
        m_annotationType = JDK15_ANNOTATION;
      }

      List pairs = node.values();
      for (Iterator it = pairs.iterator(); it.hasNext(); ) {
        MemberValuePair mvp = (MemberValuePair) it.next();
        Name attribute = mvp.getName();
        String name = attribute.getFullyQualifiedName();
        if ("groups".equals(name)) {
          Expression value = mvp.getValue();
          // Array?
          if (value instanceof ArrayInitializer) {
            ArrayInitializer ai = (ArrayInitializer) value;
            List expressions = ai.expressions();
            for (Iterator it2 = expressions.iterator(); it2.hasNext(); ) {
              Expression e = (Expression) it2.next();
              addGroup(e.toString());
            }
          } else if (value instanceof SimpleName) {
            Object boundValue = value.resolveConstantExpressionValue();
            addGroup(boundValue.toString());
          } else if (value instanceof StringLiteral) {
            addGroup(value.toString());
          }
        }
      }
    } else if (isFactoryAnnotation(node.getTypeName().toString())) {
      if (node.getParent() instanceof MethodDeclaration) {
        m_annotationType = JDK15_ANNOTATION;
        addFactoryMethod((MethodDeclaration) node.getParent(), JDK15_ANNOTATION);
      }
    }

    return false;
  }
Пример #2
0
 /* (non-Javadoc)
  * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.PackageDeclaration)
  */
 public boolean visit(PackageDeclaration node) {
   Name name = node.getName();
   fPackage = Factory.packageDescriptor(name.getFullyQualifiedName());
   return false;
 }
Пример #3
0
  public static void addFinalAndValAnnotationToModifierList(
      Object converter, List<IExtendedModifier> modifiers, AST ast, LocalDeclaration in) {
    // First check that 'in' has the final flag on, and a @val / @lombok.val annotation.
    if ((in.modifiers & ClassFileConstants.AccFinal) == 0) return;
    if (in.annotations == null) return;
    boolean found = false;
    Annotation valAnnotation = null;

    for (Annotation ann : in.annotations) {
      if (PatchVal.couldBeVal(ann.type)) {
        found = true;
        valAnnotation = ann;
        break;
      }
    }

    if (!found) return;

    // Now check that 'out' is missing either of these.

    if (modifiers == null)
      return; // This is null only if the project is 1.4 or less. Lombok doesn't work in that.
    boolean finalIsPresent = false;
    boolean valIsPresent = false;

    for (Object present : modifiers) {
      if (present instanceof Modifier) {
        ModifierKeyword keyword = ((Modifier) present).getKeyword();
        if (keyword == null) continue;
        if (keyword.toFlagValue() == Modifier.FINAL) finalIsPresent = true;
      }

      if (present instanceof org.eclipse.jdt.core.dom.Annotation) {
        Name typeName = ((org.eclipse.jdt.core.dom.Annotation) present).getTypeName();
        if (typeName != null) {
          String fullyQualifiedName = typeName.getFullyQualifiedName();
          if ("val".equals(fullyQualifiedName) || "lombok.val".equals(fullyQualifiedName)) {
            valIsPresent = true;
          }
        }
      }
    }

    if (!finalIsPresent) {
      modifiers.add(
          createModifier(
              ast,
              ModifierKeyword.FINAL_KEYWORD,
              valAnnotation.sourceStart,
              valAnnotation.sourceEnd));
    }

    if (!valIsPresent) {
      MarkerAnnotation newAnnotation =
          createValAnnotation(
              ast, valAnnotation, valAnnotation.sourceStart, valAnnotation.sourceEnd);
      try {
        Reflection.astConverterRecordNodes.invoke(converter, newAnnotation, valAnnotation);
        Reflection.astConverterRecordNodes.invoke(
            converter, newAnnotation.getTypeName(), valAnnotation.type);
      } catch (IllegalAccessException e) {
        throw Lombok.sneakyThrow(e);
      } catch (InvocationTargetException e) {
        throw Lombok.sneakyThrow(e.getCause());
      }
      modifiers.add(newAnnotation);
    }
  }