use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class JSPTranslator method isEmptyTag.
private boolean isEmptyTag(ITextRegionCollection customTag) {
ITextRegion lastRegion = customTag.getLastRegion();
// custom tag is embedded
if (customTag instanceof ITextRegionContainer) {
ITextRegionList regions = customTag.getRegions();
int size = customTag.getNumberOfRegions() - 1;
while (size > 0 && !(DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(lastRegion.getType()) || DOMRegionContext.XML_TAG_NAME.equals(lastRegion.getType()) || DOMRegionContext.XML_TAG_CLOSE.equals(lastRegion.getType()))) {
lastRegion = regions.get(--size);
}
}
return DOMRegionContext.XML_EMPTY_TAG_CLOSE.equals(lastRegion.getType());
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class JSPTranslator method addImportToMap.
/**
* new text can be something like: "import java.lang.Object;\n"
*
* but the reference region could have been something like: <%@page
* import="java.lang.Object, java.io.*, java.util.List"%>
*
* so the exact mapping has to be calculated carefully.
*
* isIndirect means that the import came from an included file (if true)
*
* @param importName
* @param jspReferenceRegion
*/
private void addImportToMap(String importName, ITextRegionCollection jspReferenceRegion) {
// massage text
// String jspText = importName.substring(importName.indexOf("import ")
// + 7, importName.indexOf(';'));
// String jspText = importName.trim();
// these positions will be updated below
Position javaRange = new Position(fOffsetInUserImports + 7, 1);
Position jspRange = new Position(jspReferenceRegion.getStart(), jspReferenceRegion.getLength());
// calculate JSP range by finding "import" attribute
ITextRegionList regions = jspReferenceRegion.getRegions();
int size = regions.size();
int start = -1;
int length = -1;
ITextRegion r = null;
for (int i = 0; i < size; i++) {
r = regions.get(i);
if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)
if (jspReferenceRegion.getText(r).trim().equals("import")) {
// get the attr value region
if (size > i + 2) {
r = regions.get(i + 2);
if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
String jspImportText = jspReferenceRegion.getText(r);
// the position in question (in the JSP) is what
// is bracketed below
// includes whitespace
// <%@page import="java.lang.Object,[ java.io.* ],
// java.util.List"%>
// in the java file
// import [ java.io.* ];
start = jspImportText.indexOf(importName);
length = importName.length();
// safety, don't add to map if bad positioning
if (start == -1 || length < 1)
break;
// update jsp range
jspRange.setOffset(jspReferenceRegion.getStartOffset(r) + start);
jspRange.setLength(length);
// update java range
javaRange.setLength(length);
break;
}
}
}
}
// safety for bad ranges
if (start != -1 && length > 1) {
// put ranges in java -> jsp range map
fImportRanges.put(javaRange, jspRange);
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class JSPTranslator method appendUseBeanToBuffer.
/**
* temp fix for 282295 until better mapping is in place
*
* @param newText
* @param jspReferenceRegion
*/
private void appendUseBeanToBuffer(String newText, ITextRegionCollection jspReferenceRegion, boolean isIndirect) throws Exception {
// java string looks like this (tokenized)
// Type id = new Classname();\n
// 0 1 2 3 4
// or
// Type id = null;\n // if there is no classname
// 0 1 2 3
// ----------------------
// calculate java ranges
// ----------------------
// $NON-NLS-1$
StringTokenizer st = new StringTokenizer(newText, " ", false);
int i = 0;
String[] parsedJava = new String[st.countTokens()];
while (st.hasMoreTokens()) parsedJava[i++] = st.nextToken();
// $NON-NLS-1$
String type = parsedJava[0] != null ? parsedJava[0] : "";
// $NON-NLS-1$
String id = parsedJava[1] != null ? parsedJava[1] : "";
// $NON-NLS-1$
String className = parsedJava.length > 4 ? parsedJava[4] : "";
Position javaTypeRange = new Position(fOffsetInUserCode, type.length());
Position javaIdRange = new Position(fOffsetInUserCode + type.length() + 1, id.length());
Position javaClassRange = new Position(fOffsetInUserCode + type.length() + 1 + id.length() + 7, 0);
/*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=212242 - Check for
* the existence of '(' first.
*/
int parenPos = -1;
if (className.length() >= 4 && (parenPos = className.indexOf('(')) >= 0) {
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=86132
int classNameLength = className.substring(0, parenPos).length();
javaClassRange = new Position(fOffsetInUserCode + type.length() + 1 + id.length() + 7, classNameLength);
}
// ---------------------
// calculate jsp ranges
// ---------------------
ITextRegionList regions = jspReferenceRegion.getRegions();
ITextRegion r = null;
// $NON-NLS-1$ //$NON-NLS-2$
String attrName = "", attrValue = "";
int quoteOffset = 0;
Position jspTypeRange = null;
Position jspIdRange = null;
Position jspClassRange = null;
for (int j = 0; j < regions.size(); j++) {
r = regions.get(j);
if (r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME) {
attrName = jspReferenceRegion.getText(r);
if (regions.size() > j + 2 && regions.get(j + 2).getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
// get attr value
r = regions.get(j + 2);
attrValue = jspReferenceRegion.getText(r);
// may have quotes
// $NON-NLS-1$ //$NON-NLS-2$
quoteOffset = (attrValue.startsWith("\"") || attrValue.startsWith("'")) ? 1 : 0;
if (// $NON-NLS-1$
attrName.equals("type"))
jspTypeRange = new Position(jspReferenceRegion.getStartOffset(r) + quoteOffset, StringUtils.stripQuotesLeaveInsideSpace(attrValue).length());
else if (// $NON-NLS-1$
attrName.equals("id"))
jspIdRange = new Position(jspReferenceRegion.getStartOffset(r) + quoteOffset, StringUtils.stripQuotesLeaveInsideSpace(attrValue).length());
else if (// $NON-NLS-1$
attrName.equals("class"))
jspClassRange = new Position(jspReferenceRegion.getStartOffset(r) + quoteOffset, StringUtils.stripQuotesLeaveInsideSpace(attrValue).length());
}
}
}
// put ranges in java -> jsp range map
if (!type.equals("") && jspTypeRange != null) {
// $NON-NLS-1$
fCodeRanges.put(javaTypeRange, jspTypeRange);
// note: don't update offsets for this map when result is built
// they'll be updated when code ranges offsets are updated
fUseBeanRanges.put(javaTypeRange, jspTypeRange);
if (isIndirect)
fIndirectRanges.put(javaTypeRange, jspTypeRange);
}
if (!id.equals("") && jspIdRange != null) {
// $NON-NLS-1$
fCodeRanges.put(javaIdRange, jspIdRange);
// note: don't update offsets for this map when result is built
// they'll be updated when code ranges offsets are updated
fUseBeanRanges.put(javaIdRange, jspTypeRange);
if (isIndirect)
fIndirectRanges.put(javaIdRange, jspTypeRange);
}
if (!className.equals("") && jspClassRange != null) {
// $NON-NLS-1$
fCodeRanges.put(javaClassRange, jspClassRange);
// note: don't update offsets for this map when result is built
// they'll be updated when code ranges offsets are updated
fUseBeanRanges.put(javaClassRange, jspTypeRange);
if (isIndirect)
fIndirectRanges.put(javaClassRange, jspTypeRange);
}
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class JSPTranslator method isUsebeanTag.
/**
* @param jspReferenceRegion
* @return
*/
private boolean isUsebeanTag(ITextRegionCollection jspReferenceRegion) {
ITextRegionList regions = jspReferenceRegion.getRegions();
ITextRegion r = null;
boolean isUseBean = false;
for (int i = 0; i < regions.size(); i++) {
r = regions.get(i);
// and saves the expensive getText.equals call
if (r.getType() == DOMRegionContext.XML_TAG_NAME) {
if (r.getTextLength() == 11 && jspReferenceRegion.getText(r).equals("jsp:useBean")) {
// $NON-NLS-1$
isUseBean = true;
}
// break no matter what if you hit tagname
break;
}
}
return isUseBean;
}
use of org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList in project webtools.sourceediting by eclipse.
the class JSPTranslator method translateXMLCommentNode.
/**
* Reparse and translate the contents of this XML comment as if it
* weren't.
*/
protected void translateXMLCommentNode(IStructuredDocumentRegion node) {
if (node.getNumberOfRegions() > 1 && DOMRegionContext.XML_COMMENT_OPEN.equals(node.getFirstRegion().getType())) {
ITextRegionList regions = node.getRegions();
int startOffset = node.getStartOffset(regions.get(1));
/*
* Make sure that an unclosed comment at the end of the file will
* still have its contents processed
*/
int endOffset = DOMRegionContext.XML_COMMENT_CLOSE.equals(node.getLastRegion().getType()) ? node.getStartOffset(node.getLastRegion()) : node.getEndOffset(node.getLastRegion());
try {
String text = fStructuredDocument.get(startOffset, endOffset - startOffset);
decodeScriptBlock(text, startOffset);
} catch (BadLocationException e) {
// Not sure *how* to recover from this...
Logger.logException(e);
}
}
}
Aggregations