Package org.eclipse.jdt.core.dom

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


        assert bug != null;

        TypeDeclaration type = getTypeDeclaration(workingUnit, bug.getPrimaryClass());
        MethodDeclaration method = getMethodDeclaration(type, bug.getPrimaryMethod());

        AST ast = rewrite.getAST();

        SuperMethodInvocation superCall = createSuperMethodInvocation(rewrite, method);
        ExpressionStatement statement = ast.newExpressionStatement(superCall);
        Block methodBody = method.getBody();
        ListRewrite listRewrite = rewrite.getListRewrite(methodBody, Block.STATEMENTS_PROPERTY);
        if (isInsertFirst()) {
            listRewrite.insertFirst(statement, null);
        } else {
View Full Code Here


    protected SuperMethodInvocation createSuperMethodInvocation(ASTRewrite rewrite, MethodDeclaration method) {
        assert rewrite != null;
        assert method != null;

        AST ast = rewrite.getAST();
        SuperMethodInvocation invocation = ast.newSuperMethodInvocation();

        invocation.setName((SimpleName) rewrite.createCopyTarget(method.getName()));

        return invocation;
    }
View Full Code Here

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

        final AST ast = rewrite.getAST();
        InfixExpression andOddnessCheck = ast.newInfixExpression();
        ParenthesizedExpression parenthesizedExpression = ast.newParenthesizedExpression();
        InfixExpression andExpression = ast.newInfixExpression();

        andExpression.setLeftOperand((Expression) rewrite.createMoveTarget(numberExpression));
        andExpression.setOperator(AND);
        andExpression.setRightOperand(ast.newNumberLiteral("1"));
        parenthesizedExpression.setExpression(andExpression);
        andOddnessCheck.setLeftOperand(parenthesizedExpression);
        andOddnessCheck.setOperator(EQUALS);
        andOddnessCheck.setRightOperand(ast.newNumberLiteral("1"));

        return andOddnessCheck;

    }
View Full Code Here

        Document document = new Document(source);

        ASTParser parser = ASTParser.newParser(AST.JLS3);
        parser.setSource(asyncContents);
        CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
        AST ast = astRoot.getAST();

        astRoot.recordModifications();

        // Modify imports (+AsyncCallback, -RemoteService, -*Exception)
        List imports = astRoot.imports();
        List importsToBeRemoved = new ArrayList();

        for (Iterator j = imports.iterator(); j.hasNext();) {

          ImportDeclaration anImportDecl = (ImportDeclaration) j.next();
          String importName = anImportDecl.getName().getFullyQualifiedName();
          if (importName.endsWith("Exception") || //$NON-NLS-1$
              importName.equals("com.google.gwt.core.client.GWT") || //$NON-NLS-1$
              importName.equals("com.google.gwt.user.client.rpc.ServiceDefTarget") || //$NON-NLS-1$
              importName.equals("com.google.gwt.user.client.rpc.RemoteService")//$NON-NLS-1$
          )
            importsToBeRemoved.add(anImportDecl);
        }

        imports.removeAll(importsToBeRemoved);

        ImportDeclaration importDecl = ast.newImportDeclaration();
        importDecl.setName(ast.newName("com.google.gwt.user.client.rpc.AsyncCallback")); //$NON-NLS-1$
        astRoot.imports().add(importDecl);

        // Add Async to the name
        TypeDeclaration aRemoteService = (TypeDeclaration) astRoot.types().get(0);
        String remoteServiceAsyncName = aRemoteService.getName().getFullyQualifiedName() + "Async"; //$NON-NLS-1$
        aRemoteService.setName(astRoot.getAST().newSimpleName(remoteServiceAsyncName));

        // Remote all interfaces
        aRemoteService.superInterfaceTypes().clear();

        // Change methods, fields and inner classes
        List bodyDeclarations = aRemoteService.bodyDeclarations();
        List declarationsToDelete = new ArrayList();
        for (Iterator k = bodyDeclarations.iterator(); k.hasNext();) {

          Object currDeclaration = k.next();

          if (currDeclaration instanceof MethodDeclaration) {
            // Make return type void
            MethodDeclaration aMethod = (MethodDeclaration) currDeclaration;
            aMethod.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));

            // Add AsyncCallback parameter
            SingleVariableDeclaration asyncCallbackParam = ast.newSingleVariableDeclaration();
            asyncCallbackParam.setName(ast.newSimpleName("callback")); //$NON-NLS-1$
            asyncCallbackParam.setType(ast.newSimpleType(ast.newName("AsyncCallback"))); //$NON-NLS-1$
            aMethod.parameters().add(asyncCallbackParam);

            // Remove throws
            aMethod.thrownExceptions().clear();

View Full Code Here

        Document document = new Document(source);

        ASTParser parser = ASTParser.newParser(AST.JLS3);
        parser.setSource(asyncContents);
        CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
        AST ast = astRoot.getAST();

        astRoot.recordModifications();

        // Modify imports (+AsyncCallback, -RemoteService, -*Exception)
        List imports = astRoot.imports();
        List importsToBeRemoved = new ArrayList();
       
        for (Iterator j = imports.iterator(); j.hasNext();) {

          ImportDeclaration anImportDecl = (ImportDeclaration) j.next();
          String importName = anImportDecl.getName().getFullyQualifiedName();
          if(importName.equals("com.google.gwt.user.client.rpc.RemoteService") || importName.endsWith("Exception")) //$NON-NLS-1$ //$NON-NLS-2$
            importsToBeRemoved.add(anImportDecl);
         
        }
       
        imports.removeAll(importsToBeRemoved);

        ImportDeclaration importDecl = ast.newImportDeclaration();
        importDecl.setName(ast.newName("com.google.gwt.user.client.rpc.AsyncCallback")); //$NON-NLS-1$
        astRoot.imports().add(importDecl);

        // Add Async to the name
        TypeDeclaration aRemoteService = (TypeDeclaration) astRoot.types().get(0);
        String remoteServiceAsyncName = aRemoteService.getName().getFullyQualifiedName()+"Async"; //$NON-NLS-1$
        aRemoteService.setName(astRoot.getAST().newSimpleName(remoteServiceAsyncName));
       
        // Remote all interfaces
        aRemoteService.superInterfaceTypes().clear();
       
        // Change methods, fields and inner classes
        List bodyDeclarations = aRemoteService.bodyDeclarations();
        List declarationsToDelete = new ArrayList();
        for (Iterator k = bodyDeclarations.iterator(); k.hasNext();) {
         
          Object currDeclaration = k.next();
         
          if(currDeclaration instanceof MethodDeclaration) {
            // Make return type void
            MethodDeclaration aMethod = (MethodDeclaration) currDeclaration;
            aMethod.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));

            // Add AsyncCallback parameter
            SingleVariableDeclaration asyncCallbackParam = ast.newSingleVariableDeclaration();
            asyncCallbackParam.setName(ast.newSimpleName("callback")); //$NON-NLS-1$
            asyncCallbackParam.setType(ast.newSimpleType(ast.newName("AsyncCallback"))); //$NON-NLS-1$
            aMethod.parameters().add(asyncCallbackParam);
           
            // Remove throws
            aMethod.thrownExceptions().clear();
           
View Full Code Here

        Document document = new Document(source);

        ASTParser parser = ASTParser.newParser(AST.JLS3);
        parser.setSource(asyncContents);
        CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
        AST ast = astRoot.getAST();

        astRoot.recordModifications();

        // Modify imports (+AsyncCallback, -RemoteService, -*Exception)
        List imports = astRoot.imports();
        List importsToBeRemoved = new ArrayList();
       
        for (Iterator j = imports.iterator(); j.hasNext();) {

          ImportDeclaration anImportDecl = (ImportDeclaration) j.next();
          String importName = anImportDecl.getName().getFullyQualifiedName();
          if(importName.endsWith("Exception") || //$NON-NLS-1$
              importName.equals("com.google.gwt.core.client.GWT") ||//$NON-NLS-1$
              importName.equals("com.google.gwt.user.client.rpc.ServiceDefTarget") || //$NON-NLS-1$
              importName.equals("com.google.gwt.user.client.rpc.RemoteService")//$NON-NLS-1$
             
            importsToBeRemoved.add(anImportDecl);
        }
       
        imports.removeAll(importsToBeRemoved);

        ImportDeclaration importDecl = ast.newImportDeclaration();
        importDecl.setName(ast.newName("com.google.gwt.user.client.rpc.AsyncCallback")); //$NON-NLS-1$
        astRoot.imports().add(importDecl);

        // Add Async to the name
        TypeDeclaration aRemoteService = (TypeDeclaration) astRoot.types().get(0);
        String remoteServiceAsyncName = aRemoteService.getName().getFullyQualifiedName()+"Async"; //$NON-NLS-1$
        aRemoteService.setName(astRoot.getAST().newSimpleName(remoteServiceAsyncName));
       
        // Remote all interfaces
        aRemoteService.superInterfaceTypes().clear();
       
        // Change methods, fields and inner classes
        List bodyDeclarations = aRemoteService.bodyDeclarations();
        List declarationsToDelete = new ArrayList();
        for (Iterator k = bodyDeclarations.iterator(); k.hasNext();) {
         
          Object currDeclaration = k.next();
         
          if(currDeclaration instanceof MethodDeclaration) {
            // Make return type void
            MethodDeclaration aMethod = (MethodDeclaration) currDeclaration;
            aMethod.setReturnType2(ast.newPrimitiveType(PrimitiveType.VOID));

            // Add AsyncCallback parameter
            SingleVariableDeclaration asyncCallbackParam = ast.newSingleVariableDeclaration();
            asyncCallbackParam.setName(ast.newSimpleName("callback")); //$NON-NLS-1$
            asyncCallbackParam.setType(ast.newSimpleType(ast.newName("AsyncCallback"))); //$NON-NLS-1$
            aMethod.parameters().add(asyncCallbackParam);
           
            // Remove throws
            aMethod.thrownExceptions().clear();
           
View Full Code Here

    Document document = new Document(source);

    ASTParser parser = ASTParser.newParser(AST.JLS3);
    parser.setSource(asyncContents);
    CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
    AST ast = astRoot.getAST();

    astRoot.recordModifications();

    // Modify imports (+AsyncCallback, -RemoteService, -*Exception)
    updateImports(astRoot, ast);
View Full Code Here

     *
     *  @param node The AST node of the class instance creation.
     *  @param state The current state of the type analyzer.
     */
    private void _refactor(ClassInstanceCreation node, TypeAnalyzerState state) {
        AST ast = node.getAST();
        CompilationUnit root = (CompilationUnit) node.getRoot();
        Type type = Type.getType(node);
        ClassInstanceCreation newNode = (ClassInstanceCreation) ASTNode
                .copySubtree(ast, node);

        if (SPECIAL_TYPE_MAPPING.containsKey(type.getName())) {
            type = Type.createType(SPECIAL_TYPE_MAPPING.get(type.getName()));
            Name newName = createName(ast, getClassName(type.getName(), state,
                    root));
            newNode.setType(ast.newSimpleType(newName));
            Type.setType(node, type);
        }

        String setCheckpointName = SET_CHECKPOINT_NAME;
        MethodInvocation extraSetCheckpoint = ast.newMethodInvocation();
        extraSetCheckpoint.setExpression(newNode);
        extraSetCheckpoint.setName(ast.newSimpleName(setCheckpointName));
        extraSetCheckpoint.arguments().add(ast.newSimpleName(CHECKPOINT_NAME));

        CastExpression typeCast = ast.newCastExpression();
        typeCast.setExpression(extraSetCheckpoint);
        typeCast.setType(createType(ast, getClassName(type.getName(), state,
                root)));
        replaceNode(node, typeCast);
    }
View Full Code Here

        if ((_prefix != null) && (_prefix.length() > 0)) {
            // Add a prefix to each name node, if necessary.
            root.accept(new Renamer(analyzer.getState()));

            PackageDeclaration packageDeclaration = root.getPackage();
            AST ast = root.getAST();

            if (packageDeclaration == null) {
                packageDeclaration = ast.newPackageDeclaration();
                packageDeclaration.setName(AbstractTransformer.createName(ast,
                        _prefix));
                root.setPackage(packageDeclaration);
            }
        }
View Full Code Here

     @param oldPackageName The name of the old package.
     */
    private void _addImport(LocalClassLoader loader, Name name,
            String oldPackageName) {
        CompilationUnit root = (CompilationUnit) name.getRoot();
        AST ast = name.getAST();
        String className = name.toString();
        String fullName = oldPackageName + "." + className;

        boolean transform = true;

        // Try to load the class within the package.
        try {
            loader.loadClass(fullName);
        } catch (ClassNotFoundException e) {
            transform = false;
        } catch (NoClassDefFoundError e) {
            transform = false;
        }

        // Check conflict.
        if (transform) {
            Iterator classesIter = loader.getImportedClasses().iterator();

            while (classesIter.hasNext()) {
                LocalClassLoader.ClassImport classImport = (LocalClassLoader.ClassImport) classesIter
                        .next();

                if (classImport.getClassName().equals(className)) {
                    transform = false;
                    break;
                }
            }

            if (transform) {
                ImportDeclaration importDeclaration = ast
                        .newImportDeclaration();
                importDeclaration.setName(AbstractTransformer.createName(ast,
                        fullName));
                root.imports().add(importDeclaration);
                loader.importClass(fullName);
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.