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();
}
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;
}
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;
}
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);
}
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;
}
Aggregations