use of org.eclipse.wst.css.core.internal.metamodel.CSSMetaModel in project webtools.sourceediting by eclipse.
the class CSSProfileTest method main.
/**
* Test use only
*/
public static void main(String[] args) {
if (args.length == 0)
return;
CSSMetaModel metamodel = null;
try {
// $NON-NLS-1$
CSSProfile profile = new CSSProfileImpl("test", new URL(args[0]));
metamodel = profile.getMetaModel();
} catch (MalformedURLException e) {
Logger.logException(e);
}
if (metamodel == null) {
return;
}
/*
* CSSMMTypeCollector collector = new CSSMMTypeCollector();
* collector.apply(metamodel, CSSMMNode.TYPE_PROPERTY); Iterator
* iProperty = collector.getNodes(); while (iProperty.hasNext()) {
* CSSMMNode node = (CSSMMNode)iProperty.next();
* System.out.println("Property " + node.getName() + " can contain:");
* //$NON-NLS-2$ //$NON-NLS-1$ Iterator iValue =
* node.getDescendants(); while (iValue.hasNext()) {
* debugOut((CSSMMNode)iValue.next(), 0, false); } }
*/
debugOut(metamodel, 0, true);
}
use of org.eclipse.wst.css.core.internal.metamodel.CSSMetaModel 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.CSSMetaModel in project webtools.sourceediting by eclipse.
the class CSSMetaModelTest method testDisplayPropertyValues2r1.
public void testDisplayPropertyValues2r1() {
CSSMetaModel model = CSSProfileRegistry.getInstance().getDefaultProfile().getMetaModel();
if (model != null) {
CSSMetaModelUtil util = new CSSMetaModelUtil(model);
CSSMMProperty property = util.getProperty(PropCMProperty.P_DISPLAY);
Iterator it = property.getValues();
Set set = new HashSet(1);
set.add(IValID.V_INLINE_BLOCK);
while (it.hasNext()) {
CSSMMNode node = (CSSMMNode) it.next();
if (set.contains(node.getName())) {
assertEquals("Property should be a keyword", CSSMMNode.TYPE_KEYWORD, node.getType());
set.remove(node.getName());
}
}
assertTrue("The content property is missing values added for CSS 2 revision 1.", set.isEmpty());
}
}
use of org.eclipse.wst.css.core.internal.metamodel.CSSMetaModel in project webtools.sourceediting by eclipse.
the class CSSMetaModelTest method testWhitespacePropertyValues2r1.
public void testWhitespacePropertyValues2r1() {
CSSMetaModel model = CSSProfileRegistry.getInstance().getDefaultProfile().getMetaModel();
if (model != null) {
CSSMetaModelUtil util = new CSSMetaModelUtil(model);
CSSMMProperty property = util.getProperty(PropCMProperty.P_WHITE_SPACE);
Iterator it = property.getValues();
Set set = new HashSet(1);
set.add(IValID.V_PRE_LINE);
set.add(IValID.V_PRE_WRAP);
while (it.hasNext()) {
CSSMMNode node = (CSSMMNode) it.next();
if (set.contains(node.getName())) {
assertEquals("Property should be a keyword", CSSMMNode.TYPE_KEYWORD, node.getType());
set.remove(node.getName());
}
}
assertTrue("The content property is missing values added for CSS 2 revision 1.", set.isEmpty());
}
}
use of org.eclipse.wst.css.core.internal.metamodel.CSSMetaModel in project webtools.sourceediting by eclipse.
the class CSSMetaModelTest method testCursorPropertyValues2r1.
public void testCursorPropertyValues2r1() {
CSSMetaModel model = CSSProfileRegistry.getInstance().getDefaultProfile().getMetaModel();
if (model != null) {
CSSMetaModelUtil util = new CSSMetaModelUtil(model);
CSSMMProperty property = util.getProperty(PropCMProperty.P_CURSOR);
Iterator it = property.getValues();
Set set = new HashSet(1);
set.add(IValID.V_PROGRESS);
while (it.hasNext()) {
CSSMMNode node = (CSSMMNode) it.next();
if (set.contains(node.getName())) {
assertEquals("Property should be a keyword", CSSMMNode.TYPE_KEYWORD, node.getType());
set.remove(node.getName());
}
}
assertTrue("The content property is missing values added for CSS 2 revision 1.", set.isEmpty());
}
}
Aggregations