Package org.eclipse.jdt.core.dom

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


  @SuppressWarnings("rawtypes")
  private Annotation findAnnotation(List modifiers) {
    for (int i = 0; i < modifiers.size(); i++) {
      Object curr = modifiers.get(i);
      if (curr instanceof Annotation) {
        Annotation annot = (Annotation) curr;
        ITypeBinding binding = annot.getTypeName().resolveTypeBinding();
        if (binding != null && "java.lang.Deprecated".equals(binding.getQualifiedName())) {
          return annot;
        }
      }
    }
View Full Code Here


  }

  // similar to
  // org.eclipse.jdt.internal.ui.text.correction.ModifierCorrectionSubProcessor.removeOverrideAnnotationProposal(..)
  public void removeDeprecatedAnnotation(IDocument document, ICompilationUnit cu, BodyDeclaration decl) {
    Annotation annot = findAnnotation(decl.modifiers());
    if (annot != null) {
      ASTRewrite rewrite = ASTRewrite.create(annot.getAST());
      rewrite.remove(annot, null);

      callASTRewriteCorrectionProposal(getDisplayString(), cu, rewrite, 6, getImage(), document);

      ITextViewer viewer = getViewer(JavaPlugin.getActivePage().getActiveEditor());
View Full Code Here

      }

      if (!(a instanceof Annotation)) {
        return Collections.emptyList();
      }
      Annotation annotation = (Annotation) a;

      LocationInformation locationInfo = null;
      if (node instanceof NormalAnnotation) {
        NormalAnnotation normalAnnotation = (NormalAnnotation) node;
        @SuppressWarnings("unchecked")
View Full Code Here

      }

      if (!(a instanceof Annotation)) {
        return Collections.emptyList();
      }
      Annotation annotation = (Annotation) a;

      LocationInformation locationInfo = null;
      if (node instanceof NormalAnnotation) {
        NormalAnnotation normalAnnotation = (NormalAnnotation) node;
        @SuppressWarnings("unchecked")
        List<MemberValuePair> pairs = normalAnnotation.values();

        for (MemberValuePair pair : pairs) {
          Expression expression = pair.getValue();
          if (expression instanceof StringLiteral) {
            locationInfo = getLocationInformation((StringLiteral) expression, javaContext);
          }
        }
      }
      else if (node instanceof SingleMemberAnnotation) {
        SingleMemberAnnotation singleMemberAnnotation = (SingleMemberAnnotation) node;
        Expression expression = singleMemberAnnotation.getValue();
        locationInfo = getLocationInformation((StringLiteral) expression, javaContext);
      }

      if (locationInfo == null) {
        return Collections.emptyList();
      }

      Name typeName = annotation.getTypeName();
      return getBeanProposals(javaContext, type.getCompilationUnit(), javaContext.getInvocationOffset(),
          typeName.getFullyQualifiedName(), typeName.getStartPosition(), typeName.getLength());
    }

    // }
View Full Code Here

    if (!ProposalCalculatorUtil.containsImport(getCompilationUnit(), importName)) {
      ImportRewrite importRewrite = createImportRewrite(astRoot);
      importRewrite.addImport(importName);
    }

    Annotation annotation;
    if (annotationClass.equals(PathVariable.class)) {
      SingleMemberAnnotation sAnnotation = ast.newSingleMemberAnnotation();
      StringLiteral paramName = ast.newStringLiteral();
      paramName.setLiteralValue(param.getName().getFullyQualifiedName());
      sAnnotation.setValue(paramName);

      addLinkedPosition(new StringLiteralTrackedPosition(astRewrite.track(paramName)), true, "paramValue");
      annotation = sAnnotation;
    }
    else {
      annotation = ast.newMarkerAnnotation();
    }

    annotation.setTypeName(ast.newSimpleName(annotationClass.getSimpleName()));

    astRewrite.getListRewrite(param, SingleVariableDeclaration.MODIFIERS2_PROPERTY).insertFirst(annotation, null);

    return astRewrite;
  }
View Full Code Here

      createImportRewrite(astRoot).addImport(importName);
    }

    AST ast = astRewrite.getAST();

    Annotation annotation;
    if (exceptionNames.isEmpty()) {
      MarkerAnnotation mAnnotation = ast.newMarkerAnnotation();
      annotation = mAnnotation;
    }
    else {
      SingleMemberAnnotation sAnnotation = ast.newSingleMemberAnnotation();
      annotation = sAnnotation;
      Expression value;
      if (exceptionNames.size() == 1) {
        TypeLiteral typeLiteral = getTypeLiteral(exceptionNames.get(0), ast);
        value = typeLiteral;
        addLinkedPosition(astRewrite.track(typeLiteral.getType()), true, "ExceptionHandler");
      }
      else {
        ArrayInitializer arrayInitializer = ast.newArrayInitializer();
        List<Expression> expressions = arrayInitializer.expressions();
        for (int i = 0; i < exceptionNames.size(); i++) {
          String exceptionName = exceptionNames.get(i);
          TypeLiteral typeLiteral = getTypeLiteral(exceptionName, ast);
          addLinkedPosition(astRewrite.track(typeLiteral.getType()), i == 0, "ExceptionHandler" + i);
          expressions.add(typeLiteral);
        }

        value = arrayInitializer;
      }
      sAnnotation.setValue(value);
    }

    SimpleName name = ast.newSimpleName("ExceptionHandler");
    annotation.setTypeName(name);

    astRewrite.getListRewrite(methodDecl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(annotation, null);

    return astRewrite;
  }
View Full Code Here

  }

  // based on StubUtility2.addOverrideAnnotation
  public void addAutowiredAnnotation(IJavaProject project, ASTRewrite rewrite, MethodDeclaration decl,
      IMethodBinding binding) {
    final Annotation marker = rewrite.getAST().newMarkerAnnotation();
    marker.setTypeName(rewrite.getAST().newSimpleName("Autowired")); //$NON-NLS-1$
    rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, null);
  }
View Full Code Here

          //Now get the 'real' ast.
          assistContext = new AssistContext(javaContext.getCompilationUnit(), sourceViewer,
              sourceRange.getOffset(), sourceRange.getLength(), SharedASTProvider.WAIT_YES);

          node = assistContext.getCoveringNode();
          Annotation annotation = (Annotation) ((SourceRefElement) a).findNode(assistContext.getASTRoot());

          if (content.endsWith("}")) {
            content = content.substring(0, content.length() - 1);
          }
View Full Code Here

      ASTRewrite astRewrite, ImportRewrite importRewrite, boolean memberValuePair, ASTNode precedingNode) {
    if (!ProposalCalculatorUtil.containsImport(getCompilationUnit(), qualifiedName)) {
      importRewrite.addImport(qualifiedName);
    }

    Annotation annotation;

    if (memberValuePair) {
      annotation = ast.newNormalAnnotation();
    }
    else {
      annotation = ast.newMarkerAnnotation();
    }
    annotation.setTypeName(ast.newSimpleName(simpleName));

    ChildListPropertyDescriptor property;

    if (decl instanceof FieldDeclaration) {
      property = FieldDeclaration.MODIFIERS2_PROPERTY;
View Full Code Here

TOP

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

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.