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

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

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom SimpleName 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:org.eclipse.wb.internal.core.utils.ast.AstEditor.java

License:Open Source License

/**
 * Given the {@link ASTNode} that can use fully qualified types, this method tries to import
 * qualified types and update node/source accordingly. It is expected that node already added to
 * the AST and source already modified.// www .  ja  v a 2s  .co  m
 */
public void resolveImports(final ASTNode node) {
    if (!m_resolveImports) {
        return;
    }
    node.accept(new AstVisitorEx() {
        @Override
        public boolean visitEx(QualifiedName qualifiedName) throws Exception {
            String qualifiedClassName = qualifiedName.getFullyQualifiedName();
            // if we can find IType with this name, consider it as type name
            if (getJavaProject().findType(qualifiedClassName) != null) {
                String shortClassName = ensureClassImport2(qualifiedClassName);
                if (!shortClassName.equals(qualifiedClassName)) {
                    int sourceBegin = AstNodeUtils.getSourceBegin(qualifiedName);
                    // replace source
                    replaceSubstring(qualifiedName, shortClassName);
                    // replace node
                    {
                        ITypeBinding typeBinding = AstNodeUtils.getTypeBinding(qualifiedName);
                        SimpleName simpleName = m_parser.parseSimpleName(sourceBegin, shortClassName);
                        simpleName.setProperty(AstParser.KEY_TYPE_BINDING, typeBinding);
                        replaceNode(qualifiedName, simpleName);
                    }
                    // done
                    return false;
                }
            }
            return true;
        }
    });
}

From source file:org.eclipse.wb.internal.core.utils.ast.AstParser.java

License:Open Source License

/**
 * @return the {@link SimpleName} for variable with given identifier, type and field/modifiers
 *         flags.//from ww  w.  j a  v  a2s .  com
 */
public SimpleName parseVariable(int position, String identifier, ITypeBinding declaringClass, ITypeBinding type,
        boolean field, int modifiers) {
    SimpleName simpleName = parseSimpleName(position, identifier);
    simpleName.setProperty(KEY_TYPE_BINDING, m_context.get(type));
    simpleName.setProperty(KEY_VARIABLE_BINDING,
            m_context.get(identifier, declaringClass, type, field, modifiers));
    return simpleName;
}