use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class CSSRegionContainer method getCssText.
/**
* @return java.lang.String
*/
public String getCssText() {
if (fFirstRegion == null || fLastRegion == null)
return generateSource();
ITextRegionList regions = fParentRegion.getRegions();
StringBuffer source = new StringBuffer();
boolean bIn = false;
for (int i = 0; i < regions.size(); i++) {
ITextRegion current = regions.get(i);
if (bIn) {
source.append(fParentRegion.getFullText(current));
if (current == fLastRegion)
break;
} else {
if (current == fFirstRegion) {
bIn = true;
source.append(fParentRegion.getFullText(current));
if (current == fLastRegion)
break;
}
}
}
return source.toString();
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion 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.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method getRegions.
/**
*/
protected CompoundRegion[] getRegions(IStructuredDocument model, IRegion reg, IRegion exceptFor, String pickupType) {
int start = reg.getOffset();
int end = reg.getOffset() + reg.getLength();
int startE = (exceptFor != null) ? exceptFor.getOffset() : -1;
int endE = (exceptFor != null) ? exceptFor.getOffset() + exceptFor.getLength() : 0;
ArrayList list = new ArrayList();
IStructuredDocumentRegion flatNode = model.getRegionAtCharacterOffset(start);
boolean pickuped = false;
while (flatNode != null && flatNode.getStartOffset() < end) {
ITextRegionList regionList = flatNode.getRegions();
Iterator it = regionList.iterator();
while (it.hasNext()) {
ITextRegion region = (ITextRegion) it.next();
if (flatNode.getStartOffset(region) < start)
continue;
if (end <= flatNode.getStartOffset(region))
break;
if (startE >= 0 && startE <= flatNode.getStartOffset(region) && flatNode.getEndOffset(region) <= endE)
continue;
if (region.getType() == CSSRegionContexts.CSS_COMMENT || region.getType() == CSSRegionContexts.CSS_CDC || region.getType() == CSSRegionContexts.CSS_CDO)
list.add(new CompoundRegion(flatNode, region));
else if (!pickuped && region.getType() == pickupType) {
list.add(new CompoundRegion(flatNode, region));
pickuped = true;
}
}
flatNode = flatNode.getNext();
}
if (list.size() > 0) {
CompoundRegion[] regions = new CompoundRegion[list.size()];
list.toArray(regions);
return regions;
}
return new CompoundRegion[0];
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method getRegionsWithoutWhiteSpaces.
/**
*/
protected CompoundRegion[] getRegionsWithoutWhiteSpaces(IStructuredDocument model, IRegion reg, CSSCleanupStrategy stgy) {
int start = reg.getOffset();
int end = reg.getOffset() + reg.getLength() - 1;
ArrayList list = new ArrayList();
IStructuredDocumentRegion flatNode = model.getRegionAtCharacterOffset(start);
while (flatNode != null && flatNode.getStartOffset() <= end) {
ITextRegionList regionList = flatNode.getRegions();
Iterator it = regionList.iterator();
while (it.hasNext()) {
ITextRegion region = (ITextRegion) it.next();
if (flatNode.getStartOffset(region) < start)
continue;
if (end < flatNode.getStartOffset(region))
break;
if (// for
region.getType() != CSSRegionContexts.CSS_S || (isCleanup() && !stgy.isFormatSource()))
// not
// formatting
// case
// on
// cleanup
// action
list.add(new CompoundRegion(flatNode, region));
}
flatNode = flatNode.getNext();
}
if (list.size() > 0) {
CompoundRegion[] regions = new CompoundRegion[list.size()];
list.toArray(regions);
return regions;
}
return new CompoundRegion[0];
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class CounterFormatter method getAttrInsertPos.
/**
*/
public int getAttrInsertPos(ICSSNode node, String attrName) {
if (node == null || attrName == null || attrName.length() == 0)
return -1;
IndexedRegion iNode = (IndexedRegion) node;
if (ICounter.IDENTIFIER.equalsIgnoreCase(attrName)) {
ICSSAttr attr = (ICSSAttr) node.getAttributes().getNamedItem(ICounter.IDENTIFIER);
if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0)
return ((IndexedRegion) attr).getStartOffset();
if (iNode.getEndOffset() <= 0)
return -1;
IStructuredDocumentRegion flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(iNode.getEndOffset() - 1);
RegionIterator it = new RegionIterator(flatNode, flatNode.getRegionAtCharacterOffset(iNode.getEndOffset() - 1));
while (it.hasPrev()) {
ITextRegion region = it.prev();
if (region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
return it.getStructuredDocumentRegion().getEndOffset(region);
}
return ((IndexedRegion) node).getEndOffset();
} else if (ICounter.LISTSTYLE.equalsIgnoreCase(attrName)) {
ICSSAttr attr = (ICSSAttr) node.getAttributes().getNamedItem(ICounter.LISTSTYLE);
if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0)
return ((IndexedRegion) attr).getStartOffset();
IStructuredDocumentRegion flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(iNode.getEndOffset() - 1);
RegionIterator it = new RegionIterator(flatNode, flatNode.getRegionAtCharacterOffset(iNode.getEndOffset() - 1));
while (it.hasPrev()) {
ITextRegion region = it.prev();
if (region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR)
return it.getStructuredDocumentRegion().getEndOffset(region);
else if (region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
return it.getStructuredDocumentRegion().getEndOffset(region);
}
return ((IndexedRegion) node).getEndOffset();
} else if (ICounter.SEPARATOR.equalsIgnoreCase(attrName)) {
ICSSAttr attr = (ICSSAttr) node.getAttributes().getNamedItem(ICounter.SEPARATOR);
if (attr != null && ((IndexedRegion) attr).getEndOffset() > 0)
return ((IndexedRegion) attr).getStartOffset();
IStructuredDocumentRegion flatNode = node.getOwnerDocument().getModel().getStructuredDocument().getRegionAtCharacterOffset(iNode.getEndOffset() - 1);
RegionIterator it = new RegionIterator(flatNode, flatNode.getRegionAtCharacterOffset(iNode.getEndOffset() - 1));
boolean hasComma = false;
while (it.hasPrev()) {
ITextRegion region = it.prev();
if (region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_OPERATOR) {
if (!hasComma)
hasComma = true;
else
return it.getStructuredDocumentRegion().getEndOffset(region);
} else if (region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION)
return it.getStructuredDocumentRegion().getEndOffset(region);
}
return ((IndexedRegion) node).getEndOffset();
} else
return -1;
}
Aggregations