Example usage for org.eclipse.jdt.core.dom Expression setProperty

List of usage examples for org.eclipse.jdt.core.dom Expression setProperty

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom Expression setProperty.

Prototype

public final void setProperty(String propertyName, Object data) 

Source Link

Document

Sets the named property of this node to the given value, or to null to clear it.

Usage

From source file:com.google.gdt.eclipse.designer.nls.GwtSource.java

License:Open Source License

/**
 * Parse given expression and if it is valid GWT NLS expression, extract required information.
 *//*from w ww .j a v a 2s.c  o m*/
private static ExpressionInfo getExpressionInfo(JavaInfo component, Expression expression) {
    if (expression instanceof MethodInvocation) {
        MethodInvocation invocation = (MethodInvocation) expression;
        // check invocation
        if (invocation.arguments().size() != 0) {
            return null;
        }
        if (!(invocation.getExpression() instanceof SimpleName)) {
            return null;
        }
        //
        SimpleName field = (SimpleName) invocation.getExpression();
        String bundleName = AstNodeUtils.getFullyQualifiedName(field, true);
        String fieldName = field.getIdentifier();
        //
        SimpleName keyExpression = invocation.getName();
        String key = keyExpression.getIdentifier();
        //
        ExpressionInfo expressionInfo = new ExpressionInfo(expression, bundleName, fieldName, keyExpression,
                key);
        expression.setProperty(NLS_EXPRESSION_INFO, expressionInfo);
        return expressionInfo;
    }
    return null;
}

From source file:org.eclipse.wb.core.eval.ExecutionFlowUtils.java

License:Open Source License

/**
 * Tracks assignments on execution flow starting from given {@link ExecutionFlowDescription} and
 * remember results in {@link ASTNode} properties.
 *//*from   w w  w  .  ja v a2s.  com*/
private static void prepareAssignmentInformation(ExecutionFlowDescription flowDescription) {
    final Long assignmentStamp = flowDescription.getAST().modificationCount();
    // visit execution flow, find declarations/assignments for all variables
    visit(new VisitingContext(true), flowDescription, new AbstractVariablesExecutionFlowVisitor(true) {
        @Override
        public void endVisit(Assignment node) {
            Expression leftSide = node.getLeftHandSide();
            if (isVariable(leftSide)) {
                Expression variable = leftSide;
                executionFlowContext.addAssignment(variable, node);
                executionFlowContext.storeAssignments(variable);
            }
        }

        ////////////////////////////////////////////////////////////////////////////
        //
        // Generic ASTNode pre/post visiting
        //
        ////////////////////////////////////////////////////////////////////////////
        @Override
        public void postVisit(ASTNode node) {
            // store assignment for variable usage
            if (node instanceof Expression && isVariable(node)) {
                Expression variable = (Expression) node;
                variable.setProperty(KEY_LAST_VARIABLE_STAMP, assignmentStamp);
                executionFlowContext.storeAssignments(variable);
            }
        }
    });
    // visit CompilationUnit, find references for all variables
    flowDescription.getCompilationUnit().accept(new AbstractVariablesExecutionFlowVisitor(false) {
        @Override
        public boolean visit(AnonymousClassDeclaration node) {
            return true;
        }

        @Override
        public void preVisit(ASTNode node) {
            super.preVisit(node);
            if (isFrameNode(node)) {
                enterFrame(node);
                // visit all fields on enter TypeDeclaration
                if (node instanceof TypeDeclaration) {
                    TypeDeclaration typeDeclaration = (TypeDeclaration) node;
                    visitFields(this, typeDeclaration, true);
                    visitFields(this, typeDeclaration, false);
                }
            }
        }

        @Override
        public void postVisit(ASTNode node) {
            super.postVisit(node);
            if (isFrameNode(node)) {
                leaveFrame(node);
            }
            if (node instanceof Expression) {
                if (isVariable(node)) {
                    executionFlowContext.storeReferences((Expression) node);
                }
                // special support for "instanceOfTopType.field"
                if (node instanceof QualifiedName) {
                    QualifiedName qualifiedName = (QualifiedName) node;
                    CompilationUnit unit = (CompilationUnit) qualifiedName.getRoot();
                    TypeDeclaration topType = (TypeDeclaration) unit.types().get(0);
                    if (qualifiedName.getQualifier().resolveTypeBinding() == topType.resolveBinding()) {
                        executionFlowContext.storeReferences(qualifiedName.getName());
                    }
                }
            }
        }

        private boolean isFrameNode(ASTNode node) {
            return node instanceof TypeDeclaration || node instanceof MethodDeclaration
                    || node instanceof Block;
        }
    });
}

From source file:org.eclipse.wb.core.eval.ExecutionFlowUtils2.java

License:Open Source License

/**
 * Sets the {@link ExpressionValue}.//from w w  w . j  a va2  s. co  m
 */
public static void setValue0(Expression expression, ExpressionValue value) {
    expression.setProperty(KEY_VALUE, value);
}

From source file:org.eclipse.wb.core.eval.ExecutionFlowUtils2.java

License:Open Source License

/**
 * Sets the permanent {@link ExpressionValue}.
 *///  w w  w.  j ava 2  s .  com
public static void setPermanentValue0(Expression expression, ExpressionValue value) {
    expression.setProperty(KEY_VALUE_PERMANENT, value);
}

From source file:org.eclipse.wb.core.eval.ExecutionFlowUtils2.java

License:Open Source License

/**
 * @return ensures that {@link Expression} has permanent {@link ExpressionValue}, uses existing
 *         value or creates new one./* w ww .j ava2s.co  m*/
 */
public static ExpressionValue ensurePermanentValue(Expression expression) {
    ExpressionValue value;
    {
        // usually there is already some ExpressionValue
        value = (ExpressionValue) expression.getProperty(KEY_VALUE);
        // if no, create new one
        if (value == null) {
            value = new ExpressionValue(expression);
        }
    }
    // use this value as permanent
    expression.setProperty(KEY_VALUE_PERMANENT, value);
    // done
    return value;
}

From source file:org.eclipse.wb.core.eval.ExecutionFlowUtils2.java

License:Open Source License

/**
 * Clears permanent {@link ExpressionValue} associated with given {@link Expression}. Permanent
 * value is used to associate model, so practically we remove reference on model.
 *///from w  w  w  . j  a va 2  s . c  om
public static void clearPermanentValue(Expression expression) {
    ExpressionValue value = (ExpressionValue) expression.getProperty(KEY_VALUE_PERMANENT);
    if (value != null) {
        value.setModel(null);
        expression.setProperty(KEY_VALUE_PERMANENT, null);
    }
}

From source file:org.eclipse.wb.internal.core.databinding.parser.AstModelSupport.java

License:Open Source License

protected final boolean isRepresentedOverReference(Expression expression) throws Exception {
    if (m_nameReference != null) {
        // prepare cached value
        String nameReference = (String) expression.getProperty(REFERENCE_VALUE_KEY);
        if (nameReference != null) {
            return m_nameReference.equals(nameReference);
        }/* w  ww  . j ava  2s  .  c om*/
        // check variable references
        if (AstNodeUtils.isVariable(expression)) {
            nameReference = CoreUtils.getNodeReference(expression);
            expression.setProperty(REFERENCE_VALUE_KEY, nameReference);
            //
            return m_nameReference.equals(nameReference);
        }
    }
    return false;
}

From source file:org.eclipse.wb.internal.core.model.JavaInfoEvaluationHelper.java

License:Open Source License

/**
 * Sets the value associated with {@link Expression} during AST evaluation.
 *///from   www.j a v a  2s  .c o  m
public static void setValue(Expression expression, Object value) {
    if (value == null) {
        value = NULL_VALUE;
    }
    if (expression != null) {
        expression.setProperty(KEY_EXPRESSION_VALUE, value);
    }
}

From source file:org.eclipse.wb.internal.core.nls.bundle.eclipse.modern.ModernEclipseSource.java

License:Open Source License

/**
 * Parse given expression and if it is valid Eclipse style accessor class access, extract resource
 * bundle name and key./* w w w. j  a v  a  2s .  c  o  m*/
 */
private static ExpressionInfo getExpressionInfo(Expression expression) {
    if (expression instanceof QualifiedName) {
        QualifiedName qualifiedName = (QualifiedName) expression;
        Name qualifier = qualifiedName.getQualifier();
        // check that qualifier is successor of NLS
        if (!AstNodeUtils.isSuccessorOf(AstNodeUtils.getTypeBinding(qualifier), "org.eclipse.osgi.util.NLS")) {
            return null;
        }
        // prepare parameters
        String accessorClassName = AstNodeUtils.getFullyQualifiedName(qualifier, true);
        SimpleName keyExpression = qualifiedName.getName();
        String key = keyExpression.getIdentifier();
        //
        ExpressionInfo expressionInfo = new ExpressionInfo(expression, accessorClassName, keyExpression, key);
        expression.setProperty(NLS_EXPRESSION_INFO, expressionInfo);
        return expressionInfo;
    }
    return null;
}

From source file:org.eclipse.wb.internal.core.nls.bundle.eclipse.old.EclipseSource.java

License:Open Source License

/**
 * Parse given expression and if it is valid Eclipse style accessor class access, extract resource
 * bundle name, key and optional default value.
 *///  w  w  w.j av a  2 s . com
private static ExpressionInfo getExpressionInfo(JavaInfo component, Expression expression) throws Exception {
    if (expression instanceof MethodInvocation) {
        // check for getString(key)
        MethodInvocation getString_invocation = (MethodInvocation) expression;
        int argumentCount = getString_invocation.arguments().size();
        {
            boolean is_getString = getString_invocation.getName().getIdentifier().equals("getString")
                    && (argumentCount == 1 || argumentCount == 2)
                    && getString_invocation.arguments().get(0) instanceof StringLiteral;
            if (!is_getString) {
                return null;
            }
        }
        // check for Messages.getString(key)
        String accessorClassName;
        {
            Expression invocationExpression = getString_invocation.getExpression();
            if (invocationExpression == null) {
                return null;
            }
            accessorClassName = AstNodeUtils.getFullyQualifiedName(invocationExpression, false);
        }
        // check that accessor has BUNDLE_NAME field
        {
            String bundleName = accessor_getBundleName(component, accessorClassName);
            if (bundleName == null) {
                return null;
            }
        }
        // all was checked, we can create expression information
        {
            // prepare key
            StringLiteral keyLiteral = (StringLiteral) getString_invocation.arguments().get(0);
            String key = keyLiteral.getLiteralValue();
            // prepare default value
            Expression def_argument = argumentCount == 2 ? (Expression) getString_invocation.arguments().get(1)
                    : null;
            StringLiteral defaultLiteral = def_argument instanceof StringLiteral ? (StringLiteral) def_argument
                    : null;
            String defaultValue = defaultLiteral != null ? defaultLiteral.getLiteralValue() : null;
            // return information about expression
            ExpressionInfo expressionInfo = new ExpressionInfo(expression, accessorClassName, keyLiteral, key,
                    defaultLiteral, defaultValue);
            expression.setProperty(NLS_EXPRESSION_INFO, expressionInfo);
            return expressionInfo;
        }
    }
    return null;
}