Package org.eclipse.jdt.core.dom

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


        if (parameters.size() != 1)
          continue;
        setMethods.add(method);
        MethodDeclaration newMethod = copyMethodDeclaration(newType.getAST(), method);
        SingleVariableDeclaration oldParameter = parameters.get(0);
        SimpleName paramName = oldParameter.getName();
        /*
         * the statement
         */
        org.eclipse.jdt.core.dom.Block block = ast.newBlock();
        MethodInvocation methodInvocation = ast.newMethodInvocation();
        methodInvocation.setName(ast.newSimpleName("set"));
       
        /*
         * the parameters
         */
        String thePropertyKey = method.getName().toString().substring(3);
        StringLiteral literal = ast.newStringLiteral();
        literal.setLiteralValue(thePropertyKey);
        methodInvocation.arguments().add(literal);
        methodInvocation.arguments().add(paramName.copySubtree(newMethod.getAST(), paramName));
       
        ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation);
        block.statements().add(expressionStatement);
         
        newMethod.setBody(block); // add the block to the method
View Full Code Here


     */
    org.eclipse.jdt.core.dom.Block block = ast.newBlock();
    /*
     * define the return value
     */
    SimpleName returnValueName = ast.newSimpleName("newGXTBean");
    VariableDeclarationFragment fragment = ast.newVariableDeclarationFragment();
    fragment.setName(returnValueName);
    ClassInstanceCreation newClassInstance = ast.newClassInstanceCreation();
    newClassInstance.setType((Type)returnType.copySubtree(ast, returnType));
    fragment.setInitializer(newClassInstance);
    VariableDeclarationStatement returnValue = ast.newVariableDeclarationStatement(fragment);
    returnValue.setType((Type)returnType.copySubtree(ast, returnType));
    block.statements().add(returnValue);
    /*
     * call each get method in the original and pass the result to the new set method
     *
     */
    for (MethodDeclaration method : getMethods){
      /*
       * the set expression
       */
      String propertyName = method.getName().toString().substring(3);
      MethodInvocation methodInvocation = ast.newMethodInvocation();
      methodInvocation.setExpression((Name)returnValueName.copySubtree(ast, returnValueName));
      methodInvocation.setName(ast.newSimpleName("set"));
      /*
       * the get expression
       */
      MethodInvocation paramInvocation = ast.newMethodInvocation();
      String getterName = "get" + propertyName;
      paramInvocation.setName(ast.newSimpleName(getterName));
     
      methodInvocation.arguments().add(paramInvocation);
     
      ExpressionStatement expressionStatement = ast.newExpressionStatement(methodInvocation);
      block.statements().add(expressionStatement);

     
    }
    /*
     * return the newly created object
     */
    ReturnStatement returnStatement = ast.newReturnStatement();
    returnStatement.setExpression((SimpleName)returnValueName.copySubtree(ast, returnValueName));
    block.statements().add(returnStatement);
    toGXTmethod.setBody(block); // add the block to the method
    return toGXTmethod;
  }
View Full Code Here

    parser.setSource(ClassContent.toCharArray());
    parser.setKind(ASTParser.K_COMPILATION_UNIT);
    final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
    cu.accept(new ASTVisitor() {
      public boolean visit(VariableDeclarationFragment node) {
        SimpleName name = node.getName();
        addIfNotExist(name.toString(),propList);
        return false;
      }

      public boolean visit(MethodDeclaration node){
        SimpleName name = node.getName();
        String methodName = name.toString();
        if(node.getModifiers() == Modifier.PUBLIC && methodName.startsWith("get") && methodName.length()>3){
          String propName = methodName.substring(3).toLowerCase();
          addIfNotExist(propName,propList);
          methodList.add(methodName+"()");
        }
View Full Code Here

                name = ast.newQualifiedName(ast.newSimpleName(part), ast
                        .newSimpleName(((SimpleName) name).getIdentifier()));
                newName = name;
            } else {
                QualifiedName qualifiedName = (QualifiedName) name;
                SimpleName leftPart = (SimpleName) qualifiedName.getQualifier();
                qualifiedName.setQualifier(ast.newQualifiedName(ast
                        .newSimpleName(part), ast.newSimpleName(leftPart
                        .getIdentifier())));
                name = qualifiedName.getQualifier();
            }
        }
View Full Code Here

        }

        String fieldTypeName = fieldType.getName();

        // Set the name and return type.
        SimpleName name = ast.newSimpleName(methodName);
        org.eclipse.jdt.core.dom.Type type;
        method.setName(name);

        String typeName = getClassName(fieldTypeName, state, root);
View Full Code Here

                            .getExpression();
                }
            }

            Expression newObject = null;
            SimpleName name;

            if (nodeIterator instanceof FieldAccess) {
                Expression object = ((FieldAccess) nodeIterator)
                        .getExpression();
                name = ((FieldAccess) nodeIterator).getName();
                newObject = (Expression) ASTNode.copySubtree(ast, object);
            } else if (nodeIterator instanceof QualifiedName) {
                Name object = ((QualifiedName) nodeIterator).getQualifier();
                name = ((QualifiedName) nodeIterator).getName();
                newObject = (Expression) ASTNode.copySubtree(ast, object);
            } else if (nodeIterator instanceof SimpleName) {
                name = (SimpleName) nodeIterator;
            } else {
                return null;
            }

            // Get the class of the owner and test the modifiers of the field.
            Class ownerClass;
            boolean isStatic;

            try {
                ownerClass = owner.toClass(state.getClassLoader());

                Field field = ownerClass.getDeclaredField(name.getIdentifier());
                int modifiers = field.getModifiers();

                if (!java.lang.reflect.Modifier.isPrivate(modifiers)) {
                    return null; // Not handling non-private fields.
                }

                isStatic = java.lang.reflect.Modifier.isStatic(modifiers);
            } catch (ClassNotFoundException e) {
                throw new ASTClassNotFoundException(owner.getName());
            } catch (NoSuchFieldException e) {
                // The field is not defined in this class.
                return null;
            }

            if (isStatic && !HANDLE_STATIC_FIELDS) {
                return null;
            }

            MethodInvocation backup = ast.newMethodInvocation();

            if (newObject != null) {
                backup.setExpression(newObject);
            }

            SimpleName newName = ast.newSimpleName(_getBackupMethodName(name
                    .getIdentifier()));
            backup.setName(newName);

            // If the field is static, add the checkpoint object as the first
            // argument.
View Full Code Here

        }

        // For expression.name on the left-hand side, set newObject to be the
        // expression and name to be the name. newObject may be null.
        Expression newObject = null;
        SimpleName name;

        if (leftHand instanceof FieldAccess) {
            Expression object = ((FieldAccess) leftHand).getExpression();
            name = ((FieldAccess) leftHand).getName();

            Type type = Type.getType(object);

            if (!type.getName().equals(state.getCurrentClass().getName())) {
                return;
            }

            newObject = (Expression) ASTNode.copySubtree(ast, object);
        } else if (leftHand instanceof QualifiedName) {
            Name object = ((QualifiedName) leftHand).getQualifier();
            name = ((QualifiedName) leftHand).getName();

            Type type = Type.getType(object);

            if (!type.getName().equals(state.getCurrentClass().getName())) {
                return;
            }

            newObject = (Expression) ASTNode.copySubtree(ast, object);
        } else if (leftHand instanceof SimpleName) {
            name = (SimpleName) leftHand;
        } else {
            return; // Some unknown situation.
        }

        // Get the owner of the left-hand side, if it is a field.
        Type owner = Type.getOwner(leftHand);

        if (owner == null) { // Not a field.
            return;
        }

        // Get the class of the owner and test the modifiers of the field.
        Class ownerClass;
        boolean isStatic;

        try {
            ownerClass = owner.toClass(state.getClassLoader());

            Field field = ownerClass.getDeclaredField(name.getIdentifier());
            int modifiers = field.getModifiers();

            if (!java.lang.reflect.Modifier.isPrivate(modifiers)) {
                return; // Not handling non-private fields or final fields.
            }

            if (java.lang.reflect.Modifier.isFinal(modifiers)) {
                if (!field.getType().isArray()) {
                    return;
                }
            }

            isStatic = java.lang.reflect.Modifier.isStatic(modifiers);
        } catch (ClassNotFoundException e) {
            throw new ASTClassNotFoundException(owner.getName());
        } catch (NoSuchFieldException e) {
            // The field is not defined in this class.
            return;
        }

        if (isStatic && !HANDLE_STATIC_FIELDS) {
            return;
        }

        // The new method invocation to replace the assignment.
        MethodInvocation invocation = ast.newMethodInvocation();

        // Set the expression and name of the method invocation.
        if (newObject != null) {
            invocation.setExpression(newObject);
        }

        SimpleName newName = ast.newSimpleName(_getAssignMethodName(name
                .getIdentifier(), isSpecial));
        invocation.setName(newName);

        // If the field is static, add the checkpoint object as the first
        // argument.
View Full Code Here

     *
     *  @param node The node to be visited.
     */
    public void endVisit(FieldAccess node) {
        Expression expression = node.getExpression();
        SimpleName name = node.getName();
        Type owner = Type.getType(expression);
        TypeAndOwner typeAndOwner = _resolveName(name.getIdentifier(), owner);

        Type.setOwner(node, typeAndOwner._getOwner());
        Type.setType(node, typeAndOwner._getType());
    }
View Full Code Here

     @param node The node to be visited.
     */
    public void endVisit(QualifiedName node) {
        if (_state.getCurrentClass() != null) {
            Name qualifier = node.getQualifier();
            SimpleName name = node.getName();
            Type owner;

            if (qualifier instanceof SimpleName) {
                TypeAndOwner ownerTypeAndOwner = _resolveName(
                        ((SimpleName) qualifier).getIdentifier(), null);

                if (ownerTypeAndOwner == null) {
                    owner = null;
                } else {
                    Type.setOwner(qualifier, ownerTypeAndOwner._getOwner());
                    owner = ownerTypeAndOwner._getType();
                    Type.setType(qualifier, owner);
                }
            } else {
                owner = Type.getType(qualifier);
            }

            String resolveName;

            if (owner == null) {
                resolveName = qualifier.toString() + "." + name.getIdentifier();
            } else {
                resolveName = name.getIdentifier();
            }

            TypeAndOwner nodeTypeAndOwner = _resolveName(resolveName, owner);

            if (nodeTypeAndOwner == null) {
View Full Code Here

  public MethodFinder(IFile resource){
    this.resource = resource;
  }
  public IMethod convertMethodDecl2IMethod(MethodDeclaration methodDecl){
    SimpleName methodName = methodDecl.getName();
    //cu.accept(visitor);
   
    try {
      ICompilationUnit iCompilationUnit = JavaCore.createCompilationUnitFrom((IFile) resource);
     
View Full Code Here

TOP

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

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.