use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPJavaHyperlinkDetector method detectHyperlinks.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer,
* org.eclipse.jface.text.IRegion, boolean)
*/
public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
List hyperlinks = new ArrayList(0);
if (region != null && textViewer != null) {
IDocument document = textViewer.getDocument();
JSPTranslation jspTranslation = getJSPTranslation(document);
if (jspTranslation != null) {
// check if we are in JSP Java content
int javaOffset = jspTranslation.getJavaOffset(region.getOffset());
if (javaOffset > -1) {
// included files)
if (!jspTranslation.isIndirect(javaOffset)) {
// get Java elements
IJavaElement[] elements = jspTranslation.getElementsFromJspRange(region.getOffset(), region.getOffset() + region.getLength());
if (elements != null && elements.length > 0) {
// create a JSPJavaHyperlink for each Java element
for (int i = 0; i < elements.length; ++i) {
IJavaElement element = elements[i];
// find hyperlink range for Java element
IRegion hyperlinkRegion = selectWord(document, region.getOffset());
IHyperlink link = createHyperlink(element, hyperlinkRegion, document);
if (link != null) {
hyperlinks.add(link);
}
}
}
}
}
}
}
if (hyperlinks.isEmpty())
return null;
return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[0]);
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPSearchDocument method getPath.
/**
* the path to the Java compilation unit
*
* @see org.eclipse.jdt.core.search.SearchDocument#getPath()
*/
public String getPath() {
// important that isDirty() check is second to cache modification stamp
if (this.fCUPath == null || isDirty()) {
JSPTranslation trans = getJSPTranslation();
if (trans != null) {
this.fCUPath = trans.getJavaPath();
// save since it's expensive to calculate again later
fCachedCharContents = trans.getJavaText().toCharArray();
}
}
return fCUPath;
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPSearchDocument method getCharContents.
/**
* @see org.eclipse.jdt.core.search.SearchDocument#getCharContents()
*/
public char[] getCharContents() {
if (fCachedCharContents == null || isDirty()) {
JSPTranslation trans = getJSPTranslation();
fCachedCharContents = trans != null ? trans.getJavaText().toCharArray() : new char[0];
fCUPath = trans.getJavaPath();
}
return fCachedCharContents;
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPTranslationTest method testXMLJSPTranslationText.
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=86382
*/
public void testXMLJSPTranslationText() {
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/xml-jsp/most-tags-xml-jsp.jsp"));
DOMModelForJSP sModel = (DOMModelForJSP) getStructuredModelForRead(f);
try {
setupAdapterFactory(sModel);
JSPTranslationAdapter adapter = (JSPTranslationAdapter) sModel.getDocument().getAdapterFor(IJSPTranslation.class);
JSPTranslation translation = adapter.getJSPTranslation();
String javaText = translation.getJavaText();
// named as .bin so no line conversion occurs (\n is in use)
InputStream in = getClass().getResourceAsStream("translated_xml_jsp.bin");
String knownTranslationText = loadChars(in);
assertEquals(knownTranslationText, javaText);
} finally {
if (sModel != null)
sModel.releaseFromRead();
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPTranslationTest method testTranslatePositions.
public void testTranslatePositions() {
IDOMModel model = getIncludeTestModelForRead();
JSPTranslationAdapter adapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
JSPTranslation translation = adapter.getJSPTranslation();
try {
HashMap java2jsp = translation.getJava2JspMap();
assertEquals("java2jsp map size:", 11, java2jsp.size());
HashMap jsp2java = translation.getJsp2JavaMap();
assertEquals("jsp2java map size:", 3, jsp2java.size());
// some test positions (out.print("" + | );)
// we need to ignore the classname length in our comparisons
// with java offsets that we get from the translation
// since it can vary depending on workspace location
int classnameLength = translation.getClassname().length();
int jspTestPosition = translation.getJspText().indexOf("<%= ") + 4;
int javaOffset = translation.getJavaOffset(jspTestPosition) - classnameLength;
assertEquals("JSPTranslation java offset:", 1277, javaOffset);
// (<%= | %>)
int javaTestPostition = translation.getJavaText().indexOf("out.print( );") + 10;
// dont' need to worry about classname length here because we are comparing
// with a position in the JSP document (which doesn't contain classname)
int jspOffset = translation.getJspOffset(javaTestPostition);
assertEquals("JSPTranslation jsp offset:", 564, jspOffset);
} finally {
if (model != null)
model.releaseFromRead();
}
}
Aggregations