use of org.eclipse.wst.css.core.internal.document.CSSRegionContainer in project webtools.sourceediting by eclipse.
the class CSSHyperlinkDetector method getHyperlinkRegion.
private IRegion getHyperlinkRegion(ICSSNode node, String href) {
CSSRegionContainer uriRegion = null;
switch(node.getNodeType()) {
case ICSSNode.PRIMITIVEVALUE_NODE:
uriRegion = (CSSRegionContainer) node;
break;
case ICSSNode.IMPORTRULE_NODE:
// $NON-NLS-1$
ICSSNode attribute = node.getAttributes().getNamedItem("href");
if (attribute instanceof CSSRegionContainer) {
uriRegion = (CSSRegionContainer) attribute;
}
break;
}
if (uriRegion != null) {
final int start = uriRegion.getStartOffset();
final int end = uriRegion.getEndOffset();
if (end > start)
return new Region(start, end - start);
}
return null;
}
use of org.eclipse.wst.css.core.internal.document.CSSRegionContainer in project webtools.sourceediting by eclipse.
the class StyleDeclItemFormatter method formatBefore.
/**
*/
protected void formatBefore(ICSSNode node, ICSSNode child, String toAppend, StringBuffer source, IRegion exceptFor) {
ICSSNode prev = (child != null) ? child.getPreviousSibling() : node.getLastChild();
int start = (prev != null) ? ((IndexedRegion) prev).getEndOffset() : 0;
int end = (child != null) ? ((IndexedRegion) child).getStartOffset() : 0;
if (start > 0 && start < end) {
CSSCleanupStrategy stgy = getCleanupStrategy(node);
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
// get meaning regions
CompoundRegion[] regions = null;
if (exceptFor == null)
regions = getRegionsWithoutWhiteSpaces(structuredDocument, new FormatRegion(start, end - start), stgy);
else {
regions = getRegions(structuredDocument, new FormatRegion(start, end - start), exceptFor, null);
}
// generate source
for (int i = 0; i < regions.length; i++) {
appendSpaceBefore(node, regions[i], source);
// must
source.append(decoratedRegion(regions[i], 2, stgy));
// be
// comments
}
}
if (child != null) {
boolean append = true;
if (child instanceof ICSSPrimitiveValue) {
if (((ICSSPrimitiveValue) child).getPrimitiveType() == ICSSPrimitiveValue.CSS_COMMA)
// $NON-NLS-1$
toAppend = ",";
else if (((ICSSPrimitiveValue) child).getPrimitiveType() == ICSSPrimitiveValue.CSS_SLASH)
// $NON-NLS-1$
toAppend = "/";
ICSSNode prevSibling = child.getPreviousSibling();
if (prevSibling instanceof ICSSPrimitiveValue) {
if (((ICSSPrimitiveValue) prevSibling).getPrimitiveType() == ICSSPrimitiveValue.CSS_SLASH)
append = false;
if (prevSibling instanceof CSSRegionContainer) {
// If the previous region was unknown, don't append whitespace
final ITextRegion region = ((CSSRegionContainer) prevSibling).getFirstRegion();
if (region != null && CSSRegionContexts.CSS_UNKNOWN.equals(region.getType()))
append = false;
}
}
}
if (child instanceof CSSRegionContainer) {
final ITextRegion region = ((CSSRegionContainer) child).getFirstRegion();
// If the current region is unknown, don't append whitespace
if (region != null && CSSRegionContexts.CSS_UNKNOWN.equals(region.getType()))
append = false;
}
if (toAppend != null && !toAppend.equals(",") && !toAppend.equals("/") && !toAppend.equals(")") && append) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
appendSpaceBefore(node, toAppend, source);
}
}
}
Aggregations