Search in sources :

Example 1 with CSSMMNode

use of org.eclipse.wst.css.core.internal.metamodel.CSSMMNode in project webtools.sourceediting by eclipse.

the class CSSMMNodeImpl method getDescendants.

public Iterator getDescendants() {
    List descendants = new ArrayList();
    Iterator iChild = getChildNodes();
    while (iChild.hasNext()) {
        CSSMMNode child = (CSSMMNode) iChild.next();
        Iterator iDescendant = child.getDescendants();
        if (iDescendant.hasNext()) {
            while (iDescendant.hasNext()) {
                CSSMMNode descendant = (CSSMMNode) iDescendant.next();
                if (!descendants.contains(descendant)) {
                    descendants.add(descendant);
                }
            }
        } else {
            if (!descendants.contains(child)) {
                descendants.add(child);
            }
        }
    }
    return Collections.unmodifiableCollection(descendants).iterator();
}
Also used : CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with CSSMMNode

use of org.eclipse.wst.css.core.internal.metamodel.CSSMMNode in project webtools.sourceediting by eclipse.

the class CSSMetaModelUtil method getMetaModelNodeFor.

public CSSMMNode getMetaModelNodeFor(ICSSNode node) {
    if (node instanceof ICSSStyleDeclaration) {
        node = node.getParentNode();
    }
    if (node instanceof ICSSStyleDeclItem) {
        ICSSNode parent = node.getParentNode();
        if (parent != null) {
            parent = parent.getParentNode();
        }
        if (parent instanceof ICSSStyleRule) {
            return getProperty(((ICSSStyleDeclItem) node).getPropertyName());
        } else if (parent instanceof CSSFontFaceRule) {
            return getDescriptor(((ICSSStyleDeclItem) node).getPropertyName());
        }
    }
    if (node == null) {
        return null;
    }
    if (fTypeMap == null) {
        fTypeMap = new HashMap();
        fTypeMap.put(new Short(ICSSNode.STYLERULE_NODE), CSSMMNode.TYPE_STYLE_RULE);
        fTypeMap.put(new Short(ICSSNode.FONTFACERULE_NODE), CSSMMNode.TYPE_FONT_FACE_RULE);
        fTypeMap.put(new Short(ICSSNode.PAGERULE_NODE), CSSMMNode.TYPE_PAGE_RULE);
    }
    String nodeType = (String) fTypeMap.get(new Short(node.getNodeType()));
    if (nodeType == null) {
        return null;
    }
    Iterator iNodes = collectNodesByType(nodeType);
    if (iNodes.hasNext()) {
        CSSMMNode targetNode = (CSSMMNode) iNodes.next();
        if (!iNodes.hasNext()) {
            // it's only one
            return targetNode;
        }
    }
    return null;
}
Also used : CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) ICSSStyleDeclaration(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) HashMap(java.util.HashMap) Iterator(java.util.Iterator) CSSFontFaceRule(org.w3c.dom.css.CSSFontFaceRule) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSStyleRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)

Example 3 with CSSMMNode

use of org.eclipse.wst.css.core.internal.metamodel.CSSMMNode in project webtools.sourceediting by eclipse.

the class CSSMetaModelTraverser method traverse.

private final short traverse(CSSMMNode node) {
    if (node == null) {
        return TRAV_CONT;
    }
    fTravStack.push(node);
    short rc;
    rc = preNode(node);
    if (rc == TRAV_CONT) {
        Iterator i = node.getChildNodes();
        while (i.hasNext()) {
            CSSMMNode child = (CSSMMNode) i.next();
            short rcChild = traverse(child);
            if (rcChild == TRAV_STOP) {
                fTravStack.pop();
                return TRAV_STOP;
            }
        }
    } else if (rc == TRAV_STOP) {
        fTravStack.pop();
        return TRAV_STOP;
    }
    rc = postNode(node);
    fTravStack.pop();
    return (rc == TRAV_PRUNE) ? TRAV_CONT : rc;
}
Also used : CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) Iterator(java.util.Iterator)

Example 4 with CSSMMNode

use of org.eclipse.wst.css.core.internal.metamodel.CSSMMNode in project webtools.sourceediting by eclipse.

the class CSSPropertySource method getPropertyDescriptors.

/**
 * Returns the current collection of property descriptors.
 *
 * @return a vector containing all descriptors.
 */
public IPropertyDescriptor[] getPropertyDescriptors() {
    time0 = System.currentTimeMillis();
    CSSMetaModel metamodel = CSSMetaModelFinder.getInstance().findMetaModelFor(fNode);
    Iterator iProperties = Collections.EMPTY_LIST.iterator();
    switch(fNode.getNodeType()) {
        case ICSSNode.STYLERULE_NODE:
        case ICSSNode.FONTFACERULE_NODE:
        case ICSSNode.PAGERULE_NODE:
        case ICSSNode.STYLEDECLARATION_NODE:
            CSSMMNode mmParent = new CSSMetaModelUtil(metamodel).getMetaModelNodeFor(fNode);
            if (mmParent != null) {
                iProperties = mmParent.getChildNodes();
            }
            break;
        case ICSSNode.STYLEDECLITEM_NODE:
            CSSMMNode mmNode = new CSSMetaModelUtil(metamodel).getMetaModelNodeFor(fNode);
            if (mmNode != null) {
                iProperties = Collections.singletonList(mmNode).iterator();
            }
            break;
        default:
            break;
    }
    // setup categories
    Map categories = new HashMap();
    Iterator iCategories = metamodel.getCategories();
    while (iCategories.hasNext()) {
        CSSMMCategory category = (CSSMMCategory) iCategories.next();
        categories.put(category.getName(), category.getCaption());
    }
    // collect property names
    Set declaredProperties = new HashSet();
    if (iProperties.hasNext()) {
        CSSStyleDeclaration declaration = getDeclarationNode();
        if (declaration != null) {
            ICSSNodeList nodeList = ((ICSSNode) declaration).getChildNodes();
            int nProps = (nodeList != null) ? nodeList.getLength() : 0;
            for (int i = 0; i < nProps; i++) {
                ICSSNode node = nodeList.item(i);
                if (node instanceof ICSSStyleDeclItem) {
                    String name = ((ICSSStyleDeclItem) node).getPropertyName();
                    if (name != null && 0 < name.length()) {
                        declaredProperties.add(name.toLowerCase());
                    }
                }
            }
        }
    }
    List descriptors = new ArrayList();
    // first: properties from content model
    while (iProperties.hasNext()) {
        CSSMMNode node = (CSSMMNode) iProperties.next();
        if (node.getType() == CSSMMNode.TYPE_PROPERTY || node.getType() == CSSMMNode.TYPE_DESCRIPTOR) {
            // $NON-NLS-1$
            String category = (String) categories.get(node.getAttribute("category"));
            String name = node.getName().toLowerCase();
            if (declaredProperties.contains(name)) {
                declaredProperties.remove(name);
            }
            IPropertyDescriptor descriptor = createPropertyDescriptor(name, category);
            if (descriptor != null) {
                descriptors.add(descriptor);
            }
        }
    }
    // second: existing properties but not in content model
    Iterator iRemains = declaredProperties.iterator();
    while (iRemains.hasNext()) {
        IPropertyDescriptor descriptor = createPropertyDescriptor((String) iRemains.next(), null);
        if (descriptor != null) {
            descriptors.add(descriptor);
        }
    }
    IPropertyDescriptor[] resultArray = new IPropertyDescriptor[descriptors.size()];
    if (PERF_GETDESCRIPTORS) {
        // $NON-NLS-1$ //$NON-NLS-2$
        System.out.println(getClass().getName() + ".getPropertyDescriptors: " + (System.currentTimeMillis() - time0) + "ms");
    }
    return (IPropertyDescriptor[]) descriptors.toArray(resultArray);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) CSSMetaModelUtil(org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil) HashMap(java.util.HashMap) CSSMetaModel(org.eclipse.wst.css.core.internal.metamodel.CSSMetaModel) ArrayList(java.util.ArrayList) CSSStyleDeclaration(org.w3c.dom.css.CSSStyleDeclaration) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode) ICSSNodeList(org.eclipse.wst.css.core.internal.provisional.document.ICSSNodeList) CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) CSSMMCategory(org.eclipse.wst.css.core.internal.metamodel.CSSMMCategory) ICSSStyleDeclItem(org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem) Iterator(java.util.Iterator) ICSSNodeList(org.eclipse.wst.css.core.internal.provisional.document.ICSSNodeList) ArrayList(java.util.ArrayList) List(java.util.List) IPropertyDescriptor(org.eclipse.ui.views.properties.IPropertyDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 5 with CSSMMNode

use of org.eclipse.wst.css.core.internal.metamodel.CSSMMNode in project webtools.sourceediting by eclipse.

the class CSSProposalGeneratorForPseudoSelector method getSelectorTags.

/**
 */
List getSelectorTags() {
    List tagList = new ArrayList();
    ICSSNode targetNode = fContext.getTargetNode();
    String rootType = (targetNode instanceof ICSSPageRule) ? CSSMMNode.TYPE_PAGE_RULE : CSSMMNode.TYPE_STYLE_RULE;
    CSSMMTypeCollector collector = new CSSMMTypeCollector();
    collector.collectNestedType(false);
    collector.apply(fContext.getMetaModel(), rootType);
    Iterator i;
    i = collector.getNodes();
    if (!i.hasNext()) {
        return tagList;
    }
    CSSMMNode node = (CSSMMNode) i.next();
    i = node.getChildNodes();
    while (i.hasNext()) {
        CSSMMNode child = (CSSMMNode) i.next();
        if (child.getType() == CSSMMNode.TYPE_SELECTOR) {
            String selType = ((CSSMMSelector) child).getSelectorType();
            if (selType == CSSMMSelector.TYPE_PSEUDO_CLASS || selType == CSSMMSelector.TYPE_PSEUDO_ELEMENT) {
                tagList.add(child);
            }
        }
    }
    return tagList;
}
Also used : CSSMMNode(org.eclipse.wst.css.core.internal.metamodel.CSSMMNode) ICSSPageRule(org.eclipse.wst.css.core.internal.provisional.document.ICSSPageRule) CSSMMTypeCollector(org.eclipse.wst.css.core.internal.metamodel.util.CSSMMTypeCollector) CSSMMSelector(org.eclipse.wst.css.core.internal.metamodel.CSSMMSelector) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ICSSNode(org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)

Aggregations

Iterator (java.util.Iterator)14 CSSMMNode (org.eclipse.wst.css.core.internal.metamodel.CSSMMNode)14 CSSMetaModelUtil (org.eclipse.wst.css.core.internal.metamodel.util.CSSMetaModelUtil)8 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 List (java.util.List)6 Set (java.util.Set)6 CSSMMProperty (org.eclipse.wst.css.core.internal.metamodel.CSSMMProperty)6 CSSMetaModel (org.eclipse.wst.css.core.internal.metamodel.CSSMetaModel)6 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)4 ICSSStyleDeclItem (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem)3 HashMap (java.util.HashMap)2 ICSSStyleDeclaration (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclaration)2 ICSSStyleRule (org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleRule)2 Map (java.util.Map)1 Preferences (org.eclipse.core.runtime.Preferences)1 IPropertyDescriptor (org.eclipse.ui.views.properties.IPropertyDescriptor)1 CSSMMCategory (org.eclipse.wst.css.core.internal.metamodel.CSSMMCategory)1 CSSMMDescriptor (org.eclipse.wst.css.core.internal.metamodel.CSSMMDescriptor)1 CSSMMNumber (org.eclipse.wst.css.core.internal.metamodel.CSSMMNumber)1