use of org.eclipse.wst.css.core.internal.util.RegionIterator in project webtools.sourceediting by eclipse.
the class StructuredAutoEditStrategyCSS method getPrevKeyRegion.
/**
*/
protected CompoundRegion getPrevKeyRegion(int position, CompoundRegion currentRegion) {
if (currentRegion == null) {
if (structuredDocument.getLastStructuredDocumentRegion() == null)
return null;
}
if (currentRegion != null && (currentRegion.getType() == CSSRegionContexts.CSS_RBRACE || currentRegion.getType() == CSSRegionContexts.CSS_SELECTOR_ATTRIBUTE_END || currentRegion.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_PARENTHESIS_CLOSE)) {
return prevCorrespondence(currentRegion);
}
RegionIterator it = new RegionIterator(structuredDocument, position - 1);
while (it.hasPrev()) {
ITextRegion r = it.prev();
CompoundRegion region = new CompoundRegion(it.getStructuredDocumentRegion(), r);
if (region.getType() == CSSRegionContexts.CSS_LBRACE || // region.getType() == CSSRegionContexts.CSS_RBRACE ||
region.getType() == CSSRegionContexts.CSS_SELECTOR_ATTRIBUTE_START || // CSSRegionContexts.CSS_PARENTHESIS_CLOSE ||
region.getType() == CSSRegionContexts.CSS_DELIMITER || region.getType() == CSSRegionContexts.CSS_DECLARATION_DELIMITER || // ||
region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION) {
return region;
} else if (region.getType() == CSSRegionContexts.CSS_RBRACE || region.getType() == CSSRegionContexts.CSS_SELECTOR_ATTRIBUTE_END || region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_PARENTHESIS_CLOSE) {
// skip to LBRACE
CompoundRegion pc = prevCorrespondence(region);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=111318
if (pc == null)
break;
it.reset(pc.getDocumentRegion(), pc.getTextRegion());
it.prev();
} else if (region.getType() == CSSRegionContexts.CSS_STRING) {
RegionIterator itTmp = new RegionIterator(structuredDocument, position);
if (region == itTmp.prev())
// position is inside of string
return region;
} else if (region.getType() == CSSRegionContexts.CSS_COMMENT) {
RegionIterator itTmp = new RegionIterator(structuredDocument, position);
if (region == itTmp.prev())
// position is inside of comment
return region;
} else if (region.getType() == CSSRegionContexts.CSS_UNKNOWN) {
String str = region.getText();
if (str.charAt(str.length() - 1) == '\\')
return region;
} else if (region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) {
RegionIterator itPrev = new RegionIterator(region.getDocumentRegion(), region.getTextRegion());
while (itPrev.hasPrev()) {
ITextRegion regionPrev = itPrev.prev();
if (regionPrev.getType() == CSSRegionContexts.CSS_RBRACE) {
break;
} else if (regionPrev.getType() == CSSRegionContexts.CSS_DELIMITER || regionPrev.getType() == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
return region;
} else if (regionPrev.getType() == CSSRegionContexts.CSS_LBRACE) {
while (itPrev.hasPrev()) {
regionPrev = itPrev.prev();
if (regionPrev.getType() == CSSRegionContexts.CSS_MEDIA)
break;
if (regionPrev.getType() == CSSRegionContexts.CSS_LBRACE || regionPrev.getType() == CSSRegionContexts.CSS_RBRACE || regionPrev.getType() == CSSRegionContexts.CSS_DELIMITER || regionPrev.getType() == CSSRegionContexts.CSS_DECLARATION_DELIMITER)
return region;
}
if (regionPrev.getType() == CSSRegionContexts.CSS_MEDIA)
break;
else
return region;
}
}
}
}
return null;
}
use of org.eclipse.wst.css.core.internal.util.RegionIterator in project webtools.sourceediting by eclipse.
the class StructuredAutoEditStrategyCSS method needShift.
/**
*/
protected int needShift(CompoundRegion region, int position) {
int shift = 0;
if (region == null || region.getType() == CSSRegionContexts.CSS_DELIMITER || region.getType() == CSSRegionContexts.CSS_DECLARATION_DELIMITER || region.getType() == CSSRegionContexts.CSS_LBRACE) {
// get non space region
CompoundRegion cr = getRegion(position - 1);
RegionIterator it = new RegionIterator(cr.getDocumentRegion(), cr.getTextRegion());
ITextRegion nearestRegion = null;
while (it.hasPrev()) {
nearestRegion = it.prev();
if (nearestRegion.getType() != CSSRegionContexts.CSS_S && nearestRegion.getType() != CSSRegionContexts.CSS_COMMENT)
break;
}
if (nearestRegion != null && (nearestRegion.getType() == CSSRegionContexts.CSS_LBRACE || nearestRegion.getType() == CSSRegionContexts.CSS_RBRACE || nearestRegion.getType() == CSSRegionContexts.CSS_DELIMITER || nearestRegion.getType() == CSSRegionContexts.CSS_DECLARATION_DELIMITER))
shift--;
else if (region == null)
shift--;
shift++;
}
if (region != null && region.getType() == CSSRegionContexts.CSS_LBRACE) {
RegionIterator it = new RegionIterator(structuredDocument, position);
if (!it.hasPrev() || it.prev().getType() != CSSRegionContexts.CSS_RBRACE)
shift++;
else
shift = 0;
}
return shift;
}
use of org.eclipse.wst.css.core.internal.util.RegionIterator in project webtools.sourceediting by eclipse.
the class CSSStructuredDocumentReParser method getUpdateRangeForUnknownRegion.
private ReparseRange getUpdateRangeForUnknownRegion(int start, int end) {
int newStart = start;
RegionIterator iterator = new RegionIterator(fStructuredDocument, start - 1);
if (iterator.hasPrev()) {
// skip myself
iterator.prev();
}
while (iterator.hasPrev()) {
ITextRegion region = iterator.prev();
if (region != null && region.getType() == CSSRegionContexts.CSS_UNKNOWN) {
newStart = iterator.getStructuredDocumentRegion().getStartOffset(region);
} else {
break;
}
}
if (start != newStart) {
return new ReparseRange(newStart, end);
}
return null;
}
use of org.eclipse.wst.css.core.internal.util.RegionIterator in project webtools.sourceediting by eclipse.
the class StyleSheetFormatter method getChildInsertPos.
/**
*/
public int getChildInsertPos(ICSSNode node) {
int n = ((IndexedRegion) node).getEndOffset();
if (n > 0) {
IStructuredDocument structuredDocument = node.getOwnerDocument().getModel().getStructuredDocument();
IStructuredDocumentRegion flatNode = structuredDocument.getRegionAtCharacterOffset(n - 1);
ITextRegion region = flatNode.getRegionAtCharacterOffset(n - 1);
RegionIterator it = new RegionIterator(flatNode, region);
while (it.hasPrev()) {
ITextRegion reg = it.prev();
if (reg.getType() == CSSRegionContexts.CSS_CDC)
return it.getStructuredDocumentRegion().getStartOffset(reg);
}
return n;
}
return -1;
}
use of org.eclipse.wst.css.core.internal.util.RegionIterator in project webtools.sourceediting by eclipse.
the class AbstractCSSSourceFormatter method getOutsideRegions.
/**
*/
protected CompoundRegion[] getOutsideRegions(IStructuredDocument model, IRegion reg) {
CompoundRegion[] ret = new CompoundRegion[2];
RegionIterator it = new RegionIterator(model, reg.getOffset());
it.prev();
if (it.hasPrev()) {
ITextRegion textRegion = it.prev();
IStructuredDocumentRegion documentRegion = it.getStructuredDocumentRegion();
ret[0] = new CompoundRegion(documentRegion, textRegion);
} else {
ret[0] = null;
}
it.reset(model, reg.getOffset() + reg.getLength());
if (it.hasNext()) {
ITextRegion textRegion = it.next();
IStructuredDocumentRegion documentRegion = it.getStructuredDocumentRegion();
ret[1] = new CompoundRegion(documentRegion, textRegion);
} else {
ret[1] = null;
}
return ret;
}
Aggregations