Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.NormalAnnotation


      return;
    }

    AST ast = declaration.getAST();
   
    NormalAnnotation normalAnnotation = AstUtils.createNormalAnnotation(
            ast, getAnnotationFullyQualifiedName(), memberValues);
    normalAnnotation.setSourceRange(
        AstUtils.calculateOffset(declaration).offset,
        normalAnnotation.getLength());

    ImportDeclaration importDeclaration =
      AstUtils.createImportStatement(ast, getAnnotationFullyQualifiedName());

   
View Full Code Here


  private void updateNormalAnnotation(
      ICompilationUnit compilationUnit, BodyDeclaration declaration,
      Map<String, Object> memberValues) throws JavaModelException, MalformedTreeException, BadLocationException {

    NormalAnnotation normalAnnotation =
      annotation(declaration, NormalAnnotation.class);
    if (normalAnnotation == null) {
      return;
    }

    String source = compilationUnit.getBuffer().getContents();
    Document document= new Document(source);
   
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(compilationUnit);

    AST ast = normalAnnotation.getAST();

    ASTRewrite rewrite = ASTRewrite.create(ast);

    maintainValuesProperty(normalAnnotation, memberValues, ast, rewrite);
   
View Full Code Here

  }
  private void updateNormalAnnotation(
      ICompilationUnit compilationUnit, SingleVariableDeclaration declaration,
      Map<String, Object> memberValues) throws JavaModelException, MalformedTreeException, BadLocationException {

    NormalAnnotation normalAnnotation =
      annotation(declaration, NormalAnnotation.class);
    if (normalAnnotation == null) {
      return;
    }

    String source = compilationUnit.getBuffer().getContents();
    Document document= new Document(source);
   
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(compilationUnit);

    AST ast = normalAnnotation.getAST();

    ASTRewrite rewrite = ASTRewrite.create(ast);

    maintainValuesProperty(normalAnnotation, memberValues, ast, rewrite);
   
View Full Code Here

    if (annotation != null && !annotation.isNormalAnnotation()) {
      return;
    }
       
        // get existing members as map (if any), and update
        NormalAnnotation normalAnnotation = (NormalAnnotation)annotation;
        LinkedHashMap<String, Object> memberValues = ASTTools.memberValues(normalAnnotation);
        if (value != null) {
            memberValues.put(memberName, Generics.asT(value));
        } else {
            memberValues.remove(memberName);
View Full Code Here

   * Convenience method on AST to create a new NormalAnnotation with the given annotation name.
   * If annotationName is "Table", this will result in  "@Table()" in the java source when it is added
   * to a BodyDeclaration. See addAnnotation(BodyDeclaration, Annotation)
   */
  public static NormalAnnotation newNormalAnnotation(AST ast, String annotationName) {
    NormalAnnotation annotation = ast.newNormalAnnotation();
    annotation.setTypeName(ast.newSimpleName(annotationName));
    return annotation;
  }
View Full Code Here

    return createNormalAnnotation(ast, annotationName, memberValues, false);
  }

  public static NormalAnnotation createNormalAnnotation(
      AST ast, String annotationName, Map<String, Object> memberValues, boolean forceFullyQualified) {
    NormalAnnotation newNormalAnnotation = ast.newNormalAnnotation();
    String name = forceFullyQualified?annotationName:unqualified(annotationName);
    newNormalAnnotation.setTypeName(ast.newName(name));
    //newNormalAnnotation.
    //TODO
    //newNormalAnnotation.setValue(AstUtils.createExpression(ast, memberValues));
    return newNormalAnnotation;
  }
View Full Code Here

    }

    @SuppressWarnings( "unchecked" )
    protected AnnotationMetadata createAnnotationMetadataFor( Annotation annotation ) {
        if (annotation instanceof NormalAnnotation) {
            NormalAnnotation normalAnnotation = (NormalAnnotation)annotation;

            Map<String, String> memberValues = new LinkedHashMap<String, String>();
            List<MemberValuePair> values = normalAnnotation.values();
            for (MemberValuePair pair : values) {
                memberValues.put(pair.getName().getIdentifier(), JavaMetadataUtil.expressionString(pair.getValue()));
            }

            return AnnotationMetadata.normalAnnotation(JavaMetadataUtil.getName(normalAnnotation.getTypeName()), memberValues);
        }

        if (annotation instanceof MarkerAnnotation) {
            MarkerAnnotation markerAnnotation = (MarkerAnnotation)annotation;
            return AnnotationMetadata.markerAnnotation(JavaMetadataUtil.getName(markerAnnotation.getTypeName()));
View Full Code Here

   @SuppressWarnings("unchecked")
   public AnnotationSource<O> removeValue(final String name)
   {
      if (annotation.isNormalAnnotation())
      {
         NormalAnnotation na = (NormalAnnotation) annotation;

         List<MemberValuePair> toBeRemoved = new ArrayList<MemberValuePair>();
         for (Object v : na.values())
         {
            if (v instanceof MemberValuePair)
            {
               MemberValuePair pair = (MemberValuePair) v;
               if (pair.getName().toString().equals(name))
               {
                  toBeRemoved.add(pair);
               }
            }
         }
         na.values().removeAll(toBeRemoved);

         if ((getLiteralValue() != null) && (getValues().size() == 1))
         {
            convertTo(AnnotationType.SINGLE);
         }
View Full Code Here

      if (isSingleValue() && DEFAULT_VALUE.equals(name))
      {
         return setLiteralValue(value);
      }

      NormalAnnotation na = (NormalAnnotation) annotation;

      String stub = "@" + getName() + "(" + name + "=" + value + " ) public class Stub { }";
      JavaClass<?> temp = Roaster.parse(JavaClass.class, stub);

      NormalAnnotation anno = (NormalAnnotation) temp.getAnnotations().get(0).getInternal();
      MemberValuePair mvp = (MemberValuePair) anno.values().get(0);

      List<MemberValuePair> values = na.values();
      ListIterator<MemberValuePair> iter = values.listIterator();
      while (iter.hasNext())
      {
View Full Code Here

      AnnotationSource<O> result = new Nested(this);

      String stub = "@" + getName() + "(" + name + "= 0 ) public class Stub { }";
      JavaClass<?> temp = Roaster.parse(JavaClass.class, stub);

      NormalAnnotation anno = (NormalAnnotation) temp.getAnnotations().get(0).getInternal();
      MemberValuePair mvp = (MemberValuePair) anno.values().get(0);

      @SuppressWarnings("unchecked")
      List<MemberValuePair> values = ((NormalAnnotation) annotation).values();
      ListIterator<MemberValuePair> iter = values.listIterator();
      while (iter.hasNext())
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.NormalAnnotation

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.