use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertSemiColonForStyleDeclarationItem.
/**
*/
private CSSNodeImpl insertSemiColonForStyleDeclarationItem(IStructuredDocumentRegion region) {
// only target/net node is changed. nothing to do.
CSSNodeImpl targetNode = fCreationContext.getTargetNode();
if (targetNode instanceof ICSSStyleDeclItem) {
int offset = targetNode.getStartOffset();
// widen document region range
// ((CSSStyleDeclItemImpl)targetNode).setLastStructuredDocumentRegion(region);
CSSModelUtil.expandStructuredDocumentRegionContainer((CSSStyleDeclItemImpl) targetNode, region);
// psStructuredDocumentRegion indicates CSSStyleDeclItem
ICSSNode parentNode = targetNode.getParentNode();
fCreationContext.setTargetNode(parentNode);
ICSSNode next = null;
if (parentNode.hasChildNodes()) {
for (ICSSNode child = targetNode.getFirstChild(); child != null; child = child.getNextSibling()) {
if (child instanceof CSSStructuredDocumentRegionContainer && offset < ((CSSStructuredDocumentRegionContainer) child).getStartOffset()) {
next = child;
break;
}
}
}
fCreationContext.setNextNode(next);
return targetNode;
}
return null;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class CSSStyleDeclarationImpl method getDeclItemNode.
public ICSSStyleDeclItem getDeclItemNode(String propertyName) {
ICSSNode node = getLastChild();
propertyName = propertyName.trim();
while (node != null) {
if (node instanceof CSSStyleDeclItemImpl) {
ICSSStyleDeclItem item = (ICSSStyleDeclItem) node;
if (propertyName.compareToIgnoreCase(item.getPropertyName().trim()) == 0)
return item;
}
node = node.getPreviousSibling();
}
return null;
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method appendSpaceBefore.
/**
*/
protected void appendSpaceBefore(ICSSNode node, CompoundRegion toAppend, StringBuffer source) {
if (node == null || toAppend == null || source == null)
return;
if (isCleanup() && !getCleanupStrategy(node).isFormatSource())
// for not formatting case on cleanup action
return;
String type = toAppend.getType();
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
boolean needIndent = !(node instanceof ICSSStyleSheet);
if (type == CSSRegionContexts.CSS_COMMENT) {
// check whether previous region is 'S' and has CR-LF
String delim = getLineDelimiter(node);
RegionIterator it = new RegionIterator(toAppend.getDocumentRegion(), toAppend.getTextRegion());
it.prev();
ITextRegion prev = it.prev();
// bug390904
if (prev.getType() == CSSRegionContexts.CSS_LBRACE && TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, it.getStructuredDocumentRegion().getFullText(prev), 0)[0] > 0) {
source.append(delim);
source.append(getIndent(node));
source.append(getIndentString());
} else if (prev.getType() == CSSRegionContexts.CSS_S && TextUtilities.indexOf(DefaultLineTracker.DELIMITERS, it.getStructuredDocumentRegion().getText(prev), 0)[0] >= 0) {
source.append(delim);
source.append(getIndent(node));
if (needIndent)
source.append(getIndentString());
} else {
appendSpaceBefore(node, toAppend.getText(), source);
}
} else if (type == CSSRegionContexts.CSS_LBRACE && preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_NEWLINE_ON_OPEN_BRACE)) {
String delim = getLineDelimiter(node);
source.append(delim);
source.append(getIndent(node));
// } else if (type == CSSRegionContexts.CSS_CURLY_BRACE_CLOSE) {
// } else if (type == CSSRegionContexts.CSS_INCLUDES || type ==
// CSSRegionContexts.CSS_DASHMATCH) {
} else if (type == CSSRegionContexts.CSS_DECLARATION_SEPARATOR && node instanceof ICSSStyleDeclItem) {
int n = preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_PRE_DELIM);
// no delimiter case
while (n-- > 0) // $NON-NLS-1$
source.append(" ");
} else if (type == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR || type == CSSRegionContexts.CSS_DECLARATION_VALUE_PARENTHESIS_CLOSE) {
if (preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH) > 0 && (!preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR) || node.getOwnerDocument().getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
int length = getLastLineLength(node, source);
int append = 1;
if (length + append > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
source.append(getLineDelimiter(node));
source.append(getIndent(node));
if (needIndent)
source.append(getIndentString());
}
}
} else if (CSSRegionContexts.CSS_FOREIGN_ELEMENT == type || CSSRegionContexts.CSS_DECLARATION_DELIMITER == type) {
return;
} else
appendSpaceBefore(node, toAppend.getText(), source);
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method formatPre.
/**
*/
protected void formatPre(ICSSNode node, StringBuffer source) {
int start = ((IndexedRegion) node).getStartOffset();
int end = (node.getFirstChild() != null && ((IndexedRegion) node.getFirstChild()).getEndOffset() > 0) ? ((IndexedRegion) node.getFirstChild()).getStartOffset() : getChildInsertPos(node);
Preferences preferences = CSSCorePlugin.getDefault().getPluginPreferences();
if (end > 0) {
// format source
CSSCleanupStrategy stgy = getCleanupStrategy(node);
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
CompoundRegion[] regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
for (int i = 0; i < regions.length; i++) {
if (i != 0)
appendSpaceBefore(node, regions[i], source);
source.append(decoratedPropNameRegion(regions[i], stgy));
}
} else {
// generatoe source
ICSSStyleDeclItem item = (ICSSStyleDeclItem) node;
if (preferences.getInt(CSSCorePreferenceNames.CASE_PROPERTY_NAME) == CSSCorePreferenceNames.UPPER)
source.append(item.getPropertyName().toUpperCase());
else
source.append(item.getPropertyName());
int k = preferences.getInt(CSSCorePreferenceNames.FORMAT_PROP_PRE_DELIM);
if (preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH) > 0 && (!preferences.getBoolean(CSSCorePreferenceNames.WRAPPING_PROHIBIT_WRAP_ON_ATTR) || node.getOwnerDocument().getNodeType() != ICSSNode.STYLEDECLARATION_NODE)) {
int length = getLastLineLength(node, source);
int append = 1;
if (length + k + append > preferences.getInt(CSSCorePreferenceNames.LINE_WIDTH)) {
source.append(getLineDelimiter(node));
source.append(getIndent(node));
source.append(getIndentString());
// no space is necessary
k = 0;
}
}
// no delimiter case
while (k-- > 0) // $NON-NLS-1$
source.append(" ");
// $NON-NLS-1$
source.append(":");
}
if (node.getFirstChild() != null && (!isCleanup() || getCleanupStrategy(node).isFormatSource())) {
appendAfterColonSpace(node, source);
}
}
use of org.eclipse.wst.css.core.internal.provisional.document.ICSSStyleDeclItem 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;
}
Aggregations