Package ptolemy.backtrack.eclipse.ast

Examples of ptolemy.backtrack.eclipse.ast.Type


            Iterator namesIter = fieldNames.iterator();
            Iterator typesIter = fieldTypes.iterator();

            while (namesIter.hasNext()) {
                String fieldName = (String) namesIter.next();
                Type fieldType = (Type) typesIter.next();

                MethodInvocation restoreMethodCall = ast.newMethodInvocation();
                restoreMethodCall.setExpression(ast
                        .newSimpleName(_getRecordName(fieldName)));

                // Set the restore method name.
                restoreMethodCall.arguments().add(ast.newSimpleName(fieldName));
                restoreMethodCall.setName(ast.newSimpleName("restore"));

                // Add two arguments to the restore method call.
                restoreMethodCall.arguments().add(
                        ast.newSimpleName("timestamp"));
                restoreMethodCall.arguments().add(ast.newSimpleName("trim"));

                boolean isFinal = false;

                try {
                    Field field = currentClass.getDeclaredField(fieldName);

                    if (java.lang.reflect.Modifier
                            .isFinal(field.getModifiers())) {
                        isFinal = true;
                    }
                } catch (NoSuchFieldException e) {
                }

                if (isFinal) {
                    if ((_getAccessedField(currentClass.getName(), fieldName) != null)
                            || !Type.isPrimitive(Type.getElementType(fieldType
                                    .getName()))) {
                        body.statements().add(
                                ast.newExpressionStatement(restoreMethodCall));
                    }
                } else {
                    Expression rightHandSide;

                    if (fieldType.isPrimitive()) {
                        rightHandSide = restoreMethodCall;
                    } else {
                        CastExpression castExpression = ast.newCastExpression();
                        String typeName = getClassName(fieldType.getName(),
                                state, root);
                        castExpression.setType(createType(ast, typeName));
                        castExpression.setExpression(restoreMethodCall);
                        rightHandSide = castExpression;
                    }
View Full Code Here


     @param state The current state of the type analyzer.
     *  @return The new node if the given node is an alias, or <tt>null</tt>
     *   otherwise.
     */
    private Expression _handleAlias(Expression node, TypeAnalyzerState state) {
        Type owner = Type.getOwner(node);

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

        String ownerName = owner.getName();
        Type type = Type.getType(node);
        String typeName = type.getName();

        Expression array = node;
        Type arrayType = type;

        // Check if we need to refactor the argument.
        boolean needRefactor = type.isArray();

        if (node instanceof ArrayAccess) {
            ArrayAccess arrayAccess = (ArrayAccess) node;

            while (arrayAccess.getArray() instanceof ArrayAccess) {
                arrayAccess = (ArrayAccess) arrayAccess.getArray();
                arrayType = arrayType.addOneDimension();
            }

            array = arrayAccess.getArray();
            arrayType = arrayType.addOneDimension();

            if (array instanceof MethodInvocation) {
                needRefactor = false;
            }
        }
View Full Code Here

        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.
        if (isStatic) {
            invocation.arguments().add(ast.newSimpleName(CHECKPOINT_NAME));
        }

        // Add an operator, if necessary.
        Type type = Type.getType(node);

        if (isSpecial && _assignOperators.containsKey(type.getName())) {
            int i = 0;
            String[] operators = _assignOperators.get(type.getName());

            String operator;

            if (node instanceof Assignment) {
                operator = ((Assignment) node).getOperator().toString();
            } else if (node instanceof PrefixExpression) {
                operator = ((PrefixExpression) node).getOperator().toString();
            } else {
                operator = ((PostfixExpression) node).getOperator().toString();
            }

            for (; i < operators.length; i++) {
                if (operators[i].equals(operator)) {
                    break;
                }
            }

            if (node instanceof PrefixExpression) {
                i += 2;
            }

            invocation.arguments().add(
                    ast.newNumberLiteral(Integer.toString(i)));
        }

        // Add all the indices into the argument list.
        invocation.arguments().addAll(indices);

        // Add the right-hand side expression to the argument list.
        Type rightHandType = Type.getType(rightHand);

        if (!isSpecial && type.isPrimitive() && !type.equals(rightHandType)) {
            // Require an explicit conversion.
            CastExpression castExpression = ast.newCastExpression();
            castExpression.setType(createType(ast, type.getName()));
View Full Code Here

                    continue;
                }

                // Handle only private fields or the $CHECKPOINT special field.
                if (Modifier.isPrivate(fieldDecl.getModifiers())) {
                    Type type = Type.getType(fieldDecl);

                    // Iterate over all the fragments in the field declaration.
                    Iterator fragmentIter = fieldDecl.fragments().iterator();

                    while (fragmentIter.hasNext()) {
                        VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragmentIter
                                .next();
                        String fieldName = fragment.getName().getIdentifier();

                        // Get the list of numbers of indices.
                        Hashtable[] tables = new Hashtable[] { _accessedFields,
                                _specialAccessedFields, _backupFields };

                        for (int i = 0; i < tables.length; i++) {
                            List indicesList = _getAccessedField(tables[i],
                                    currentClass.getName(), fieldName);

                            if (indicesList == null) {
                                continue;
                            }

                            // Iterate over all the numbers of indices.
                            Iterator indicesIter = indicesList.iterator();

                            while (indicesIter.hasNext()) {
                                int indices = ((Integer) indicesIter.next())
                                        .intValue();

                                // Create an extra method for every different
                                // number of indices.
                                if (tables[i] == _backupFields) {
                                    newMethods.add(_createBackupMethod(ast,
                                            root, state, fieldName, type,
                                            indices, isStatic));
                                } else {
                                    newMethods
                                            .add(_createAssignMethod(
                                                    ast,
                                                    root,
                                                    state,
                                                    fieldName,
                                                    type,
                                                    indices,
                                                    tables[i] == _specialAccessedFields,
                                                    isStatic));
                                }
                            }
                        }

                        fieldNames.add(fieldName);
                        fieldTypes.add(type);

                        // Create a record field.
                        FieldDeclaration field = _createFieldRecord(ast, root,
                                state, fieldName, type.dimensions(), isStatic);

                        if (field != null) {
                            newFields.add(field);
                        }
                    }
View Full Code Here

            if (_isStaticField.peek().booleanValue()) {
                return;
            }

            // Do not refactor class instance creations within methods.
            Type type = Type.getType(node);
            String typeName = type.getName();

            if (state.getCrossAnalyzedTypes().contains(typeName)
                    || (HANDLE_SPECIAL_TYPE_MAPPINGS && SPECIAL_TYPE_MAPPING
                            .containsKey(typeName))) {
                if (!state.getCrossAnalyzedTypes().contains(typeName)) {
View Full Code Here

     @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

         */
        private void _handleName(Name node) {
            if (node.getParent() != null) {
                String id = node.toString();

                Type type = Type.getType(node);
                Type owner = Type.getOwner(node);
                String fullName;

                boolean convert = false;
                boolean addImport = false;

View Full Code Here

        }

        name = _getNonarrayClassName(name, state, root);

        if (dimensions > 0) {
            Type type = Type.createType(name);

            for (int i = 0; i < dimensions; i++) {
                type = type.addOneDimension();
            }

            name = type.getName();
        }

        return name;
    }
View Full Code Here

TOP

Related Classes of ptolemy.backtrack.eclipse.ast.Type

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.