Package org.eclipse.jdt.core.dom

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


      unit.getBuffer().save(null, true);
    }
  }

  private static void addImport(CompilationUnit compilationUnit, String qualifiedName) {
    AST ast = compilationUnit.getAST();
    List<ImportDeclaration> imports = DomGenerics.imports(compilationUnit);
    // check for existing ImportDeclaration
    for (ImportDeclaration importDeclaration : imports) {
      if (importDeclaration.getName().toString().equals(qualifiedName)) {
        return;
      }
    }
    // add new ImportDeclaration
    ImportDeclaration importDeclaration = ast.newImportDeclaration();
    importDeclaration.setName(ast.newName(qualifiedName));
    imports.add(importDeclaration);
  }
View Full Code Here


   */
  private static void updateInterfacesOfAsync(IJavaProject javaProject,
      CompilationUnit serviceUnit,
      TypeDeclaration serviceType) throws Exception {
    String serviceName = AstNodeUtils.getFullyQualifiedName(serviceType, false);
    AST ast = serviceType.getAST();
    for (Iterator<?> I = serviceType.superInterfaceTypes().iterator(); I.hasNext();) {
      Type type = (Type) I.next();
      ITypeBinding typeBinding = AstNodeUtils.getTypeBinding(type);
      if (AstNodeUtils.isSuccessorOf(typeBinding, Constants.CLASS_REMOTE_SERVICE)) {
        String superServiceName = AstNodeUtils.getFullyQualifiedName(typeBinding, false);
        String superAsyncName = superServiceName + "Async";
        if (javaProject.findType(superAsyncName) != null) {
          if (type instanceof SimpleType) {
            {
              SimpleType simpleType = (SimpleType) type;
              String superAsyncNameSimple = CodeUtils.getShortClass(superAsyncName);
              simpleType.setName(ast.newSimpleName(superAsyncNameSimple));
            }
            if (!CodeUtils.isSamePackage(serviceName, superAsyncName)) {
              addImport(serviceUnit, superAsyncName);
            }
            continue;
View Full Code Here

   }

   private static org.eclipse.jdt.core.dom.Annotation createAnnotation(final AnnotationTargetSource<?, ?> parent,
            final AnnotationType type)
   {
      AST ast = ((ASTNode) parent.getInternal()).getAST();
      switch (type)
      {
      case MARKER:
         return ast.newMarkerAnnotation();
      case SINGLE:
         return ast.newSingleMemberAnnotation();
      case NORMAL:
         return ast.newNormalAnnotation();
      default:
         throw new IllegalArgumentException("Unknown annotation type: " + type);
      }
   }
View Full Code Here

          );
      }
    }
    else group = model;
    // 2°) Second step, we build a rewriter from the compilation unit
    AST ast = u.getAST();
    ImportDeclaration id = ast.newImportDeclaration();
    id.setName(ast.newName(new String[] {"java", "util", "Set"}));
    ASTRewrite rewriter = ASTRewrite.create(ast);
    // 3°) Third step, we can process the type declaration
    if(t.isInterface()) {
      result = new InterfaceService(t, group, rewriter, u);
    }
View Full Code Here

   *
   * @see net.sourceforge.earticleast.app.AbstractManipulator#addNewVariableDeclaration(net.sourceforge.earticleast.app.VariableBindingManager)
   */
  @Override
  protected void addNewVariableDeclaration(VariableBindingManager manager) {
    AST ast = manager.getFirstReference().getAST();
    VariableDeclarationStatement statement = createNewVariableDeclarationStatement(
        manager, ast);
    int firstReferenceIndex = getFirstReferenceListIndex(manager);
    Block block = Helper.getParentBlock(manager.getFirstReference());
    block.statements().add(firstReferenceIndex, statement);
View Full Code Here

   *
   * @see net.sourceforge.earticleast.app.AbstractManipulator#deleteOldVariableDeclaration(net.sourceforge.earticleast.app.VariableBindingManager)
   */
  @Override
  protected void deleteOldVariableDeclaration(VariableBindingManager manager) {
    AST ast = manager.getFirstReference().getAST();
    VariableDeclarationStatement statement = createNewVariableDeclarationStatement(
        manager, ast);
    int firstReferenceIndex = getFirstReferenceListIndex(manager);
    Block block = Helper.getParentBlock(manager.getFirstReference());
    // get the list rewriter for the statments list
View Full Code Here

    protected MethodInvocation createValueOfInvocation(ASTRewrite rewrite, CompilationUnit compilationUnit,
            ClassInstanceCreation primitiveTypeCreation) {
        assert rewrite != null;
        assert primitiveTypeCreation != null;

        final AST ast = rewrite.getAST();
        MethodInvocation valueOfInvocation = ast.newMethodInvocation();
        valueOfInvocation.setName(ast.newSimpleName(VALUE_OF_METHOD_NAME));

        ITypeBinding binding = primitiveTypeCreation.getType().resolveBinding();
        if (isStaticImport()) {
            addStaticImports(rewrite, compilationUnit, binding.getQualifiedName() + "." + VALUE_OF_METHOD_NAME);
        } else {
            valueOfInvocation.setExpression(ast.newSimpleName(binding.getName()));
        }

        List<?> arguments = primitiveTypeCreation.arguments();
        List<Expression> newArguments = valueOfInvocation.arguments();
        for (Object argument : arguments) {
View Full Code Here

    @Override
    protected InfixExpression createCorrectOddnessCheck(ASTRewrite rewrite, Expression numberExpression) {
        assert rewrite != null;
        assert numberExpression != null;

        final AST ast = rewrite.getAST();
        InfixExpression correctOddnessCheck = ast.newInfixExpression();
        InfixExpression remainderExp = ast.newInfixExpression();

        correctOddnessCheck.setLeftOperand(remainderExp);
        correctOddnessCheck.setOperator(NOT_EQUALS);
        correctOddnessCheck.setRightOperand(ast.newNumberLiteral("0"));

        remainderExp.setLeftOperand((Expression) rewrite.createMoveTarget(numberExpression));
        remainderExp.setOperator(REMAINDER);
        remainderExp.setRightOperand(ast.newNumberLiteral("2"));

        return correctOddnessCheck;
    }
View Full Code Here

    protected void updateLocalVariableDeclarations(final ASTRewrite rewrite, final Set<String> variables, Block block) {
        assert rewrite != null;
        assert block != null;
        assert variables != null;

        final AST ast = rewrite.getAST();
        block.accept(new ASTVisitor() {

            @Override
            public boolean visit(VariableDeclarationFragment fragment) {
                if (variables.contains(fragment.getName().getFullyQualifiedName())) {
                    ASTNode parent = fragment.getParent();
                    if (parent instanceof VariableDeclarationStatement) {
                        ListRewrite listRewrite = rewrite
                                .getListRewrite(parent, VariableDeclarationStatement.MODIFIERS2_PROPERTY);
                        listRewrite.insertLast(ast.newModifier(ModifierKeyword.FINAL_KEYWORD), null);
                    }
                }
                return true;
            }
View Full Code Here

    protected void updateImportDeclarations(ASTRewrite rewrite, CompilationUnit compilationUnit) {
        assert rewrite != null;
        assert compilationUnit != null;

        if (isUpdateImports()) {
            final AST ast = rewrite.getAST();
            SortedSet<ImportDeclaration> imports = new TreeSet<ImportDeclaration>(importComparator);
            imports.add(createImportDeclaration(ast, PrivilegedAction.class));
            if (!isStaticImport()) {
                imports.add(createImportDeclaration(ast, AccessController.class));
            } else {
View Full Code Here

TOP

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

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.