use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class XMLJSPRegionHelper method getRegionName.
protected String getRegionName(IStructuredDocumentRegion sdRegion) {
// $NON-NLS-1$
String nameStr = "";
ITextRegionList regions = sdRegion.getRegions();
for (int i = 0; i < regions.size(); i++) {
ITextRegion r = regions.get(i);
if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
nameStr = fTextToParse.substring(sdRegion.getStartOffset(r), sdRegion.getTextEndOffset(r));
break;
}
}
return nameStr.trim();
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class CSSSyntaxColoringPage method getNamedStyleAtOffset.
private String getNamedStyleAtOffset(int offset) {
// ensure the offset is clean
if (offset >= fDocument.getLength())
return getNamedStyleAtOffset(fDocument.getLength() - 1);
else if (offset < 0)
return getNamedStyleAtOffset(0);
IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion();
while (documentRegion != null && !documentRegion.containsOffset(offset)) {
documentRegion = documentRegion.getNext();
}
if (documentRegion != null) {
// find the ITextRegion's Context at this offset
ITextRegion interest = documentRegion.getRegionAtCharacterOffset(offset);
if (interest == null)
return null;
if (offset > documentRegion.getTextEndOffset(interest))
return null;
String regionContext = interest.getType();
if (regionContext == null)
return null;
// find the named style (internal/selectable name) for that
// context
String namedStyle = (String) fContextToStyleMap.get(regionContext);
if (namedStyle != null) {
return namedStyle;
}
}
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class StructuredAutoEditStrategyCSS method getIndentFor.
/**
*/
protected String getIndentFor(CompoundRegion region, boolean indentForNextRegion) {
if (region == null)
return null;
IStructuredDocumentRegion flatNode = region.getDocumentRegion();
if (flatNode == null)
return null;
try {
if (region.getType() == CSSRegionContexts.CSS_LBRACE || region.getType() == CSSRegionContexts.CSS_DELIMITER || region.getType() == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
// get meanful flat node
RegionIterator it = new RegionIterator(flatNode, region.getTextRegion());
it.prev();
while (it.hasPrev()) {
ITextRegion r = it.prev();
region = new CompoundRegion(it.getStructuredDocumentRegion(), r);
if (region.getType() != CSSRegionContexts.CSS_S)
break;
}
flatNode = region.getDocumentRegion();
// get indent string
int position = flatNode.getStart();
int line = structuredDocument.getLineOfOffset(position);
int start = structuredDocument.getLineOffset(line);
int end = findEndOfWhiteSpace(structuredDocument, start, position);
return structuredDocument.get(start, end - start);
} else if (region.getType() == CSSRegionContexts.CSS_SELECTOR_ATTRIBUTE_START || // region.getType() == CSSRegionContexts.CSS_PARENTHESIS_OPEN ||
region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION || region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) {
int position = flatNode.getStart() + region.getStart();
int line = structuredDocument.getLineOfOffset(position);
int start = structuredDocument.getLineOffset(line);
int end = findEndOfWhiteSpace(structuredDocument, start, position);
StringBuffer buf = new StringBuffer(structuredDocument.get(start, end - start));
position += region.getText().length();
if (indentForNextRegion) {
int tokenStart = findEndOfWhiteSpace(structuredDocument, position, structuredDocument.getLineOffset(line) + structuredDocument.getLineLength(line) - 1);
if (tokenStart < structuredDocument.getLineOffset(line) + structuredDocument.getLineLength(line) - 1) {
position = tokenStart;
}
}
while (position - end > 0) {
// $NON-NLS-1$
buf.append(" ");
end++;
}
return buf.toString();
} else
// $NON-NLS-1$
return "";
} catch (BadLocationException excp) {
Logger.logException(excp);
}
return null;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class CSSProposalGenerator method checkLeadingColon.
/**
*/
protected boolean checkLeadingColon() {
boolean hasLeadingColon = false;
ITextRegion targetRegion = fContext.getTargetRegion();
if (targetRegion == null && 0 < fContext.getCursorPos()) {
targetRegion = fContext.getRegionByOffset(fContext.getCursorPos() - 1);
if (targetRegion != null && targetRegion.getType() == CSSRegionContexts.CSS_SELECTOR_PSEUDO) {
hasLeadingColon = true;
}
} else if (targetRegion != null) {
// The target region should be the CSS_SELECTOR_PSEUDO now
if (targetRegion.getType() == CSSRegionContexts.CSS_SELECTOR_PSEUDO) {
hasLeadingColon = true;
}
}
return hasLeadingColon;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion in project webtools.sourceediting by eclipse.
the class CSSProposalGeneratorForDeclarationValue method checkSemiColon.
/**
*/
private void checkSemiColon() {
fAppendSemiColon = false;
ITextRegion targetRegion = fContext.getTargetRegion();
if (targetRegion != null && targetRegion.getType() != CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
// find trailing ":" or ";"
// if ":" before ";" is found, add ";"
RegionIterator iterator = fContext.getRegionIterator();
IStructuredDocumentRegion container = iterator.getStructuredDocumentRegion();
while (iterator.hasNext()) {
ITextRegion region = iterator.next();
if (iterator.getStructuredDocumentRegion() != container) {
break;
}
if (region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) {
fAppendSemiColon = true;
break;
}
}
if (!fAppendSemiColon) {
// second chance:
// leading IStructuredDocumentRegion is not ";"
IStructuredDocumentRegion nextStructuredDocumentRegion = CSSUtil.findNextSignificantNode(container);
if (CSSUtil.getStructuredDocumentRegionType(nextStructuredDocumentRegion) != CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
fAppendSemiColon = true;
}
}
}
}
Aggregations