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

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

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom VariableDeclarationFragment 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.databinding.utils.CoreUtils.java

License:Open Source License

/**
 * XXX/*from w  ww . j a  va 2s.  c o m*/
 * 
 * @param rootNode
 * @param methodName
 * @return
 * @throws Exception
 */
public static List<VariableDeclarationFragment> getLocalFragments(TypeDeclaration rootNode, String methodName)
        throws Exception {
    final List<VariableDeclarationFragment> fragments = Lists.newArrayList();
    MethodDeclaration initDataBindings = AstNodeUtils.getMethodBySignature(rootNode, methodName + "()");
    if (initDataBindings != null) {
        initDataBindings.accept(new ASTVisitor() {
            @Override
            public void endVisit(VariableDeclarationFragment fragment) {
                IVariableBinding variableBinding = AstNodeUtils.getVariableBinding(fragment);
                ITypeBinding binding = variableBinding == null ? null : variableBinding.getType();
                if (isIncludeTypeBinding(binding)) {
                    fragment.setProperty(TYPE_PROPERTY, binding);
                    fragments.add(fragment);
                }
            }
        });
    }
    return fragments;
}

From source file:org.eclipse.wb.internal.core.databinding.utils.CoreUtils.java

License:Open Source License

/**
 * @return all {@link VariableDeclarationFragment} for compilation unit fields.
 *///from w  w w . j  a  v  a 2s. com
public static List<VariableDeclarationFragment> getFieldFragments(TypeDeclaration rootNode) throws Exception {
    List<VariableDeclarationFragment> fragments = Lists.newArrayList();
    //
    for (FieldDeclaration fieldDeclaration : rootNode.getFields()) {
        Type type = fieldDeclaration.getType();
        if (type == null || AstNodeUtils.getTypeBinding(type) == null) {
            continue;
        }
        //
        for (VariableDeclarationFragment fragment : DomGenerics.fragments(fieldDeclaration)) {
            // ignore primitives and arrays
            if (isIncludeType(type)) {
                fragment.setProperty(TYPE_PROPERTY, type);
                fragments.add(fragment);
            }
        }
    }
    // sort fragments by position
    Collections.sort(fragments, new Comparator<VariableDeclarationFragment>() {
        public int compare(VariableDeclarationFragment fragment1, VariableDeclarationFragment fragment2) {
            return fragment1.getStartPosition() - fragment2.getStartPosition();
        }
    });
    return fragments;
}

From source file:org.eclipse.wb.internal.core.databinding.utils.CoreUtils.java

License:Open Source License

/**
 * XXX//from  w  ww.  ja v  a  2s .c o  m
 * 
 * @param <T>
 * @param fragment
 * @param clearProperty
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> T getType(VariableDeclarationFragment fragment, boolean clearProperty) {
    T type = (T) fragment.getProperty(TYPE_PROPERTY);
    Assert.isNotNull(type);
    if (clearProperty) {
        fragment.setProperty(TYPE_PROPERTY, null);
    }
    return type;
}