use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class CSSModelParser method insertMediaRule.
/**
*/
private CSSNodeImpl insertMediaRule(IStructuredDocumentRegion flatNode, IStructuredDocumentRegion braceNode) {
CSSNodeImpl parent = fCreationContext.getTargetNode();
if (!fParseFloating && !(parent instanceof ICSSRuleContainer)) {
return null;
}
CSSMediaRuleImpl rule = fFeeder.getCSSMediaRule();
if (rule == null) {
return null;
}
ITextRegionList regions = new TextRegionListImpl(flatNode.getRegions());
// must be "@media"
regions.remove(0);
CSSUtil.stripSurroundingSpace(regions);
MediaListImpl mediaList = (MediaListImpl) rule.getMedia();
setMediaList(mediaList, flatNode, regions);
// setup flat container
rule.setRangeStructuredDocumentRegion(flatNode, braceNode);
// insert to tree
if (!fUpdateContext.isActive() && parent != null) {
propagateRangePreInsert(parent, rule);
CSSNodeImpl next = fCreationContext.getNextNode();
if (next != null) {
parent.insertBefore(rule, next);
} else {
parent.appendChild(rule);
}
}
fCreationContext.setTargetNode(rule);
return rule;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class CSSRegionContainer method getRegionCount.
/**
* @return int
*/
int getRegionCount() {
validateRange();
if (getFirstRegion() == null)
return 0;
if (getFirstRegion() == getLastRegion())
return 1;
ITextRegionList regions = fParentRegion.getRegions();
int j = 0;
for (int i = 0; i < regions.size(); i++) {
ITextRegion current = regions.get(i);
if (j != 0 || current == getFirstRegion())
j++;
if (current == getLastRegion())
break;
}
return j;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList 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.ITextRegionList 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.ITextRegionList 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];
}
Aggregations