use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class SyntaxValidator method isEndTagCorrupted.
private boolean isEndTagCorrupted(ElementInfo info) {
ITextRegionList regions = info.endTag.getRegions();
if (regions == null || regions.isEmpty())
return false;
Iterator iter = regions.iterator();
while (iter.hasNext()) {
ITextRegion rgn = (ITextRegion) iter.next();
if (!isValidRegion(rgn))
// found invalid region type.
return true;
}
// all regions are valid.
return false;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class SyntaxValidator method getEndTagFullText.
private String getEndTagFullText(ElementInfo info) {
// $NON-NLS-1$
String hint = "";
ITextRegionList regions = info.endTag.getRegions();
Iterator iter = regions.iterator();
while (iter.hasNext()) {
ITextRegion rgn = (ITextRegion) iter.next();
String type = rgn.getType();
if (type == null)
continue;
if (type == DOMRegionContext.XML_END_TAG_OPEN || type == DOMRegionContext.XML_TAG_CLOSE)
continue;
hint += info.endTag.getFullText(rgn);
}
return hint;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class AbstractStructuredFoldingStrategy method getIndexedRegions.
/**
* <p>Gets all of the {@link IndexedRegion}s from the given {@link IStructuredModel} spanned by the given
* {@link IStructuredDocumentRegion}s.</p>
*
* @param model the {@link IStructuredModel} used to get the {@link IndexedRegion}s
* @param structRegions get the {@link IndexedRegion}s spanned by these {@link IStructuredDocumentRegion}s
* @return the {@link Set} of {@link IndexedRegion}s from the given {@link IStructuredModel} spanned by the
* given {@link IStructuredDocumentRegion}s.
*/
private Set getIndexedRegions(IStructuredModel model, IStructuredDocumentRegion[] structRegions) {
Set indexedRegions = new HashSet(structRegions.length);
// for each text region in each structured document region find the indexed region it spans/is in
for (int structRegionIndex = 0; structRegionIndex < structRegions.length && fProjectionAnnotationModel != null; ++structRegionIndex) {
IStructuredDocumentRegion structuredDocumentRegion = structRegions[structRegionIndex];
int offset = structuredDocumentRegion.getStartOffset();
IndexedRegion indexedRegion = model.getIndexedRegion(offset);
indexedRegions.add(indexedRegion);
if (structuredDocumentRegion.getEndOffset() <= indexedRegion.getEndOffset())
continue;
ITextRegionList textRegions = structuredDocumentRegion.getRegions();
int textRegionCount = textRegions.size();
for (int textRegionIndex = 1; textRegionIndex < textRegionCount; ++textRegionIndex) {
offset = structuredDocumentRegion.getStartOffset(textRegions.get(textRegionIndex));
indexedRegion = model.getIndexedRegion(offset);
indexedRegions.add(indexedRegion);
}
}
return indexedRegions;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class JsTranslator method translateInlineJSNode.
/* (non-Javadoc)
* @see org.eclipse.wst.jsdt.web.core.javascript.IJsTranslator#translateInlineJSNode(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)
*/
public void translateInlineJSNode(IStructuredDocumentRegion container) {
// System.out
// .println("JSPTranslator.translateInlineJSNode Entered
// w/ScriptOffset:"
// + scriptOffset);
// NodeHelper nh = new NodeHelper(container);
// System.out.println("inline js node looking at:\n" + nh);
/* start a function header.. will amend later */
ITextRegionList t = container.getRegions();
ITextRegion r;
Iterator regionIterator = t.iterator();
while (regionIterator.hasNext() && !isCanceled()) {
r = (ITextRegion) regionIterator.next();
if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
int start = r.getStart();
int offset = r.getTextEnd();
String tagAttrname = container.getText(r);
/*
* Attribute values aren't case sensative, also make sure next
* region is attrib value
*/
if (NodeHelper.isInArray(JsDataTypes.HTMLATREVENTS, tagAttrname)) {
if (regionIterator.hasNext()) {
regionIterator.next();
}
if (regionIterator.hasNext()) {
r = ((ITextRegion) regionIterator.next());
}
if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
int valStartOffset = container.getStartOffset(r);
// int valEndOffset = r.getTextEnd();
String rawText = container.getText(r);
if (rawText == null || rawText.length() == 0) {
continue;
}
/* Strip quotes */
switch(rawText.charAt(0)) {
case '\'':
case '"':
rawText = rawText.substring(1);
valStartOffset++;
}
if (rawText == null || rawText.length() == 0) {
continue;
}
switch(rawText.charAt(rawText.length() - 1)) {
case '\'':
case '"':
rawText = rawText.substring(0, rawText.length() - 1);
}
// Position inScript = new Position(scriptOffset,
// rawText.length());
/* Quoted text starts +1 and ends -1 char */
Position inHtml = new Position(valStartOffset, rawText.length());
/* need to pad the script text with spaces */
char[] spaces = Util.getPad(Math.max(0, valStartOffset - scriptOffset - EVENT_HANDLER_PRE_LENGTH));
for (int i = 0; i < spaces.length; i++) {
try {
char c = fStructuredDocument.getChar(scriptOffset + i);
if (c == '\n' || c == '\r' || c == '\t')
spaces[i] = c;
} catch (BadLocationException e) {
Logger.logException(e);
}
}
fScriptText.append(spaces);
fScriptText.append(EVENT_HANDLER_PRE);
appendAndTrack(rawText, valStartOffset);
// $NON-NLS-1$
if (ADD_SEMICOLON_AT_INLINE)
fScriptText.append(";");
if (r.getLength() > rawText.length()) {
fScriptText.append(EVENT_HANDLER_POST);
spaces = Util.getPad(Math.max(0, r.getLength() - rawText.length() - EVENT_HANDLER_POST_LENGTH));
fScriptText.append(spaces);
}
scriptOffset = container.getEndOffset(r);
}
}
}
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class NodeHelper method AttrToString.
public String AttrToString() {
if (region == null) {
return null;
}
// For debugging
ITextRegionList t = region.getRegions();
ITextRegion r;
Iterator regionIterator = t.iterator();
// $NON-NLS-1$ //$NON-NLS-2$
String structuredValue = Messages.NodeHelper00 + getTagName() + Messages.NodeHelper01;
while (regionIterator.hasNext()) {
r = (ITextRegion) regionIterator.next();
if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
// $NON-NLS-1$
structuredValue += "\t\t" + region.getText(r);
/*
* Theres a XML_TAG_ATTRIBUTE_EQUALS after the
* XML_TAG_ATTRIBUTE_NAME we have to get rid of
*/
if (regionIterator.hasNext()) {
regionIterator.next();
}
if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
if (regionIterator.hasNext()) {
r = ((ITextRegion) regionIterator.next());
}
if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
// $NON-NLS-1$ //$NON-NLS-2$
structuredValue += "\t\t" + stripEndQuotes(region.getText(r)) + "\n";
}
}
}
}
return structuredValue;
}
Aggregations