use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class JSPSyntaxColoringPage method applyStyles.
/**
* Color the text in the sample area according to the current preferences
*/
void applyStyles() {
if (fText == null || fText.isDisposed())
return;
IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion();
while (documentRegion != null) {
ITextRegionList regions = documentRegion.getRegions();
for (int i = 0; i < regions.size(); i++) {
ITextRegion currentRegion = regions.get(i);
// lookup the local coloring type and apply it
String namedStyle = (String) fContextToStyleMap.get(currentRegion.getType());
if (namedStyle == null)
continue;
TextAttribute attribute = getAttributeFor(namedStyle);
if (attribute == null)
continue;
StyleRange style = new StyleRange(documentRegion.getStartOffset(currentRegion), currentRegion.getTextLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle());
style.strikeout = (attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0;
style.underline = (attribute.getStyle() & TextAttribute.UNDERLINE) != 0;
fText.setStyleRange(style);
}
documentRegion = documentRegion.getNext();
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class UnitTests method testDeepEmbeddedJSP3.
public void testDeepEmbeddedJSP3() {
// CMVC 245586
// this is a test to make sure ContextRegionContainer returns what we expect
setUpJSP();
String startString = "<html><head><script> <%! String testvar = \"testvar\"; %> var test = <%= testvar %> </script></head></html>";
String expectedText = "<%! String testvar = \"testvar\"; %>";
// $NON-NLS-1$
((XMLSourceParser) fModel.getParser()).addBlockMarker(new BlockMarker("script", null, DOMRegionContext.BLOCK_TEXT, false));
fModel.setText(null, startString);
fModel.getRegionList();
IStructuredDocumentRegion scriptBlockRegion = fModel.getRegionAtCharacterOffset(21);
ITextRegionList blockRegions = scriptBlockRegion.getRegions();
ITextRegionContainer jspDecl = (ITextRegionContainer) blockRegions.get(1);
String fullText = jspDecl.getFullText();
// assertTrue("ContextRegionContainer.getFullText()", fullText.equals(expectedText));
assertEquals("ContextRegionContainer.getFullText() value incorrect: ", expectedText, fullText);
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class UnitTests method testDeepEmbeddedJSP.
public void testDeepEmbeddedJSP() {
setUpJSP();
eventCase = GENERIC_REGIONS_REPLACED_EVENT_CASE;
String startString = "<script><a >c</a></script>";
String changes = "<%= b %>";
String expectedString = "<script><a <%= b %> >c</a></script>";
int startOfChanges = 11;
int lengthToReplace = 0;
fModel.setText(null, startString);
fModel.replaceText(null, startOfChanges, lengthToReplace, changes);
String resultString = fModel.getText();
boolean result = (expectedString.equals(resultString));
assertTrue("text update", result);
assertTrue("event type", eventResult);
IStructuredDocumentRegion testR = fModel.getRegionAtCharacterOffset(11);
String testText = testR.getText();
assertTrue("text retrieve", testText.equals("<a <%= b %> >"));
testText = testR.getFullText();
assertTrue("text retrieve", testText.equals("<a <%= b %> >"));
ITextRegionList regionList = testR.getRegions();
ITextRegion region = regionList.get(0);
testText = testR.getText(region);
assertTrue("text retrieve", testText.equals("<"));
region = regionList.get(1);
testText = testR.getText(region);
assertTrue("text retrieve", testText.equals("a"));
testText = testR.getFullText(region);
assertTrue("text retrieve", testText.equals("a "));
region = regionList.get(2);
testText = testR.getText(region);
assertTrue("text retrieve", testText.equals("<%= b %>"));
testText = testR.getFullText(region);
assertTrue("text retrieve", testText.equals("<%= b %> "));
// ===
ITextRegionContainer cRegion = (ITextRegionContainer) region;
ITextRegionList eRegions = cRegion.getRegions();
ITextRegion eRegion = eRegions.get(0);
testText = cRegion.getText(eRegion);
assertTrue("text retrieve", testText.equals("<%="));
testText = cRegion.getFullText(eRegion);
assertTrue("text retrieve", testText.equals("<%="));
eRegion = eRegions.get(1);
testText = cRegion.getText(eRegion);
assertTrue("text retrieve", testText.equals(" b "));
testText = cRegion.getFullText(eRegion);
assertTrue("text retrieve", testText.equals(" b "));
eRegion = eRegions.get(2);
testText = cRegion.getText(eRegion);
assertTrue("text retrieve", testText.equals("%>"));
testText = cRegion.getFullText(eRegion);
assertTrue("text retrieve", testText.equals("%>"));
eRegion = eRegions.get(3);
testText = cRegion.getText(eRegion);
assertTrue("text retrieve", testText.equals(""));
testText = cRegion.getFullText(eRegion);
assertTrue("text retrieve", testText.equals(" "));
// ====
region = regionList.get(3);
testText = testR.getText(region);
assertTrue("text retrieve", testText.equals(">"));
testText = testR.getFullText(region);
assertTrue("text retrieve", testText.equals(">"));
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class MarkupValidator method checkForAttributeValue.
private void checkForAttributeValue(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
if (structuredDocumentRegion.isDeleted()) {
return;
}
// check for attributes without a value
// track the attribute/equals/value sequence using a state of 0, 1 ,2
// representing the name, =, and value, respectively
int attrState = 0;
ITextRegionList textRegions = structuredDocumentRegion.getRegions();
// ReconcileAnnotationKey key = createKey(structuredDocumentRegion,
// getScope());
int errorCount = 0;
for (int i = 0; (i < textRegions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT); i++) {
ITextRegion textRegion = textRegions.get(i);
if ((textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) || isTagCloseTextRegion(textRegion)) {
// dangling name and '='
if ((attrState == 2) && (i >= 2)) {
// create annotation
ITextRegion nameRegion = textRegions.get(i - 2);
if (!(nameRegion instanceof ITextRegionContainer)) {
Object[] args = { structuredDocumentRegion.getText(nameRegion) };
String messageText = NLS.bind(XMLUIMessages.Attribute__is_missing_a_value, args);
int start = structuredDocumentRegion.getStartOffset(nameRegion);
int end = structuredDocumentRegion.getEndOffset();
int lineNo = getLineNumber(start);
int textLength = structuredDocumentRegion.getText(nameRegion).trim().length();
LocalizedMessage message = new LocalizedMessage(SEVERITY_ATTRIBUTE_HAS_NO_VALUE, messageText);
message.setOffset(start);
message.setLength(textLength);
message.setLineNo(lineNo);
// quick fix info
ITextRegion equalsRegion = textRegions.get(i - 2 + 1);
int insertOffset = structuredDocumentRegion.getTextEndOffset(equalsRegion) - end;
Object[] additionalFixInfo = { structuredDocumentRegion.getText(nameRegion), new Integer(insertOffset) };
if (reporter instanceof IncrementalReporter) {
MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
processor.setProblemId(ProblemIDsXML.MissingAttrValue);
processor.setAdditionalFixInfo(additionalFixInfo);
message.setAttribute(QUICKASSISTPROCESSOR, processor);
AnnotationInfo info = new AnnotationInfo(message);
((IncrementalReporter) reporter).addAnnotationInfo(this, info);
} else {
reporter.addMessage(this, message);
}
errorCount++;
}
} else // name but no '=' (XML only)
if ((attrState == 1) && (i >= 1)) {
// create annotation
ITextRegion previousRegion = textRegions.get(i - 1);
if (!(previousRegion instanceof ITextRegionContainer)) {
Object[] args = { structuredDocumentRegion.getText(previousRegion) };
String messageText = NLS.bind(XMLUIMessages.Attribute__has_no_value, args);
int start = structuredDocumentRegion.getStartOffset(previousRegion);
int textLength = structuredDocumentRegion.getText(previousRegion).trim().length();
int lineNo = getLineNumber(start);
LocalizedMessage message = new LocalizedMessage(SEVERITY_ATTRIBUTE_HAS_NO_VALUE, messageText);
message.setOffset(start);
message.setLength(textLength);
message.setLineNo(lineNo);
if (reporter instanceof IncrementalReporter) {
MarkupQuickAssistProcessor processor = new MarkupQuickAssistProcessor();
processor.setProblemId(ProblemIDsXML.NoAttrValue);
processor.setAdditionalFixInfo(structuredDocumentRegion.getText(previousRegion));
message.setAttribute(QUICKASSISTPROCESSOR, processor);
AnnotationInfo info = new AnnotationInfo(message);
((IncrementalReporter) reporter).addAnnotationInfo(this, info);
} else {
reporter.addMessage(this, message);
}
errorCount++;
}
}
attrState = 1;
} else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
attrState = 2;
} else if (textRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
attrState = 0;
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class MarkupValidator method checkQuotesForAttributeValues.
private void checkQuotesForAttributeValues(IStructuredDocumentRegion structuredDocumentRegion, IReporter reporter) {
ITextRegionList regions = structuredDocumentRegion.getRegions();
ITextRegion r = null;
// $NON-NLS-1$
String attrValueText = "";
int errorCount = 0;
for (int i = 0; (i < regions.size()) && (errorCount < AbstractStructuredTextReconcilingStrategy.ELEMENT_ERROR_LIMIT); i++) {
r = regions.get(i);
if (r.getType() != DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
continue;
}
attrValueText = structuredDocumentRegion.getText(r);
// attribute value includes quotes in the string
// split up attribute value on quotes
/*
* WORKAROUND till
* http://dev.icu-project.org/cgi-bin/icu-bugs/incoming?findid=5207
* is fixed. (Also see BUG143628)
*/
// $NON-NLS-1$
java.util.StringTokenizer st = new java.util.StringTokenizer(attrValueText, "\"'", true);
int size = st.countTokens();
// get the pieces of the attribute value
// $NON-NLS-1$ //$NON-NLS-2$
String one = "", two = "";
if (size > 0) {
one = st.nextToken();
}
if (size > 1) {
two = st.nextToken();
}
if (size > 2) {
// and <element attr='a"b"c' /> is legal
continue;
}
if (size == 1) {
if (one.equals(DQUOTE) || one.equals(SQUOTE)) {
// missing closing quote
String message = XMLUIMessages.ReconcileStepForMarkup_0;
addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.Unclassified, structuredDocumentRegion, reporter, SEVERITY_MISSING_CLOSING_QUOTE);
errorCount++;
} else {
// missing both
String message = XMLUIMessages.ReconcileStepForMarkup_1;
addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.AttrValueNotQuoted, structuredDocumentRegion, reporter, SEVERITY_MISSING_QUOTES);
errorCount++;
}
} else if (size == 2) {
if ((one.equals(SQUOTE) && !two.equals(SQUOTE)) || (one.equals(DQUOTE) && !two.equals(DQUOTE))) {
// missing closing quote
String message = XMLUIMessages.ReconcileStepForMarkup_0;
addAttributeError(message, attrValueText, structuredDocumentRegion.getStartOffset(r), attrValueText.trim().length(), ProblemIDsXML.Unclassified, structuredDocumentRegion, reporter, SEVERITY_MISSING_CLOSING_QUOTE);
errorCount++;
}
}
}
// end of region for loop
}
Aggregations