Package org.eclipse.jdt.core.dom

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


         convertTo(AnnotationType.SINGLE);
      }

      if (isSingleValue())
      {
         SingleMemberAnnotation sa = (SingleMemberAnnotation) annotation;

         String stub = "@" + getName() + "(" + value + ") public class Stub { }";
         JavaClass temp = (JavaClass) JavaParser.parse(stub);

         SingleMemberAnnotation anno = (SingleMemberAnnotation) temp.getAnnotations().get(0).getInternal();

         Expression expression = anno.getValue();
         sa.setValue((Expression) ASTNode.copySubtree(ast, expression));
      }
      else
      {
         setLiteralValue(DEFAULT_VALUE, value);
View Full Code Here


   public String getLiteralValue() throws IllegalStateException
   {
      String result = null;
      if (isSingleValue())
      {
         SingleMemberAnnotation sm = (SingleMemberAnnotation) annotation;
         result = sm.getValue().toString();
      }
      else if (isNormal())
      {
         List<ValuePair> values = getValues();
         for (ValuePair pair : values)
View Full Code Here

         convertTo(AnnotationType.SINGLE);
      }

      if (isSingleValue())
      {
         SingleMemberAnnotation sa = (SingleMemberAnnotation) annotation;

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

         SingleMemberAnnotation anno = (SingleMemberAnnotation) temp.getAnnotations().get(0).getInternal();

         Expression expression = anno.getValue();
         sa.setValue((Expression) ASTNode.copySubtree(ast, expression));
      }
      else
      {
         setLiteralValue(DEFAULT_VALUE, value);
View Full Code Here

   @Override
   public AnnotationSource<O> getAnnotationValue()
   {
      if (isSingleValue())
      {
         SingleMemberAnnotation single = (SingleMemberAnnotation) annotation;
         Expression value = single.getValue();
         if (value instanceof org.eclipse.jdt.core.dom.Annotation)
         {
            return new Nested(this, value);
         }
      }
View Full Code Here

   public String getLiteralValue() throws IllegalStateException
   {
      String result = null;
      if (isSingleValue())
      {
         SingleMemberAnnotation sm = (SingleMemberAnnotation) annotation;
         result = sm.getValue().toString();
      }
      else if (isNormal())
      {
         List<ValuePair> values = getValues();
         for (ValuePair pair : values)
View Full Code Here

         convertTo(AnnotationType.SINGLE);
      }

      if (isSingleValue())
      {
         SingleMemberAnnotation sa = (SingleMemberAnnotation) annotation;

         String stub = "@" + getName() + "(" + value + ") public class Stub { }";
         JavaClass temp = (JavaClass) JavaParser.parse(stub);

         SingleMemberAnnotation anno = (SingleMemberAnnotation) temp.getAnnotations().get(0).getInternal();

         Expression expression = anno.getValue();
         sa.setValue((Expression) ASTNode.copySubtree(ast, expression));
      }
      else
      {
         setLiteralValue(DEFAULT_VALUE, value);
View Full Code Here

  private void updateSingleMemberAnnotation(
      ICompilationUnit compilationUnit,
      BodyDeclaration declaration, Object value) throws JavaModelException, MalformedTreeException, BadLocationException {
   
    SingleMemberAnnotation singleMemberAnnotation =
      annotation(declaration, SingleMemberAnnotation.class);
    if (singleMemberAnnotation != null) {
            AST ast = singleMemberAnnotation.getAST();
            if (value != QualifiedNameValue.DEFAULT_VALUE) {
                Expression replacement = 
                    value != null? AstUtils.createExpression(
                            ast, value): null;
       
                AstUtils.rewriteReplace(
                    compilationUnit, singleMemberAnnotation.getValue(), replacement);
                return;
            } else {
                MarkerAnnotation replacementAnnotation = ast.newMarkerAnnotation();
                replacementAnnotation.setTypeName(ast.newName(singleMemberAnnotation.getTypeName().getFullyQualifiedName()));
                AstUtils.rewriteReplace(
                    compilationUnit, singleMemberAnnotation, replacementAnnotation);
                return;
            }
        }
        MarkerAnnotation markerAnnotation =
            annotation(declaration, MarkerAnnotation.class);
        if (markerAnnotation != null) {
            AST ast = markerAnnotation.getAST();
            if (value != QualifiedNameValue.DEFAULT_VALUE) {
                SingleMemberAnnotation replacementAnnotation = ast.newSingleMemberAnnotation();
                replacementAnnotation.setTypeName(ast.newName(markerAnnotation.getTypeName().getFullyQualifiedName()));
                Expression memberValueExpression = 
                    value != null? AstUtils.createExpression(
                            ast, value): null;
                replacementAnnotation.setValue(memberValueExpression);
                AstUtils.rewriteReplace(
                    compilationUnit, markerAnnotation, replacementAnnotation);
            } else {
                // nothing to do
            }
View Full Code Here

  }
  private void updateSingleMemberAnnotation(
      ICompilationUnit compilationUnit,
      SingleVariableDeclaration declaration, Object value) throws JavaModelException, MalformedTreeException, BadLocationException {
   
    SingleMemberAnnotation singleMemberAnnotation =
      annotation(declaration, SingleMemberAnnotation.class);
    if (singleMemberAnnotation == null) {
      return;
    }

    Expression replacement = 
      value != null? AstUtils.createExpression(
          singleMemberAnnotation.getAST(), value): null;

    AstUtils.rewriteReplace(
      compilationUnit, singleMemberAnnotation.getValue(), replacement);
  }
View Full Code Here

   * Convenience method on AST to create a new MarkerAnnotation 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 SingleMemberAnnotation newSingleMemberAnnotation(AST ast, String annotationName) {
    SingleMemberAnnotation annotation = ast.newSingleMemberAnnotation();
    annotation.setTypeName(ast.newSimpleName(annotationName));
    return annotation;
  }
View Full Code Here

  public static Annotation createSingleMemberAnnotation(
      AST ast, String annotationName, Object value, boolean forceFullyQualified) {
      String name = forceFullyQualified?annotationName:unqualified(annotationName);
        if (value != QualifiedNameValue.DEFAULT_VALUE) {
            SingleMemberAnnotation newSingleMemberAnnotation = ast.newSingleMemberAnnotation();
            newSingleMemberAnnotation.setTypeName(ast.newName(name));
            newSingleMemberAnnotation.setValue(AstUtils.createExpression(ast, value));
            return newSingleMemberAnnotation;
        } else {
            MarkerAnnotation newMarkerAnnotation = ast.newMarkerAnnotation();;
            newMarkerAnnotation.setTypeName(ast.newName(name));
            return newMarkerAnnotation;
View Full Code Here

TOP

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

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.