use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPFindOccurrencesProcessor method getJavaElementsForCurrentSelection.
/**
* uses JSPTranslation to get currently selected Java elements.
*
* @return currently selected IJavaElements
*/
private IJavaElement[] getJavaElementsForCurrentSelection(IDocument document, ITextSelection selection) {
IJavaElement[] elements = new IJavaElement[0];
// get JSP translation object for this viewer's document
IStructuredModel model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
try {
if (model != null && model instanceof IDOMModel) {
IDOMDocument xmlDoc = ((IDOMModel) model).getDocument();
JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
if (adapter != null) {
JSPTranslation translation = adapter.getJSPTranslation();
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102211
elements = translation.getElementsFromJspRange(selection.getOffset(), selection.getOffset() + selection.getLength());
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
return elements;
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPJavaJavadocHoverProcessor method getHoverInfo.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer,
* org.eclipse.jface.text.IRegion)
*/
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
// get JSP translation object for this viewer's document
IDOMModel xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(textViewer.getDocument());
try {
if (xmlModel != null) {
IDOMDocument xmlDoc = xmlModel.getDocument();
JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
if (adapter != null) {
JSPTranslation translation = adapter.getJSPTranslation();
IJavaElement[] result = translation.getElementsFromJspRange(hoverRegion.getOffset(), hoverRegion.getOffset() + hoverRegion.getLength());
return translation.fixupMangledName(getHoverInfo(result));
}
}
} finally {
if (xmlModel != null)
xmlModel.releaseFromRead();
}
return null;
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPSearchTests method testSearchLocalVariable.
public void testSearchLocalVariable() {
IDOMModel xmlModel = null;
try {
IPath jspTestFilePath = new Path("judo/SEARCH/searchTestJSP3.jsp");
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(jspTestFilePath);
xmlModel = (IDOMModel) getStructuredModelForRead(file);
ModelHandlerForJSP.ensureTranslationAdapterFactory(xmlModel);
IDOMDocument doc = xmlModel.getDocument();
JSPTranslationAdapter adapter = (JSPTranslationAdapter) doc.getAdapterFor(IJSPTranslation.class);
JSPTranslation translation = adapter.getJSPTranslation();
IJavaElement element = translation.getElementsFromJspRange(377, 384)[0];
TestJspSearchRequestor requestor = new TestJspSearchRequestor();
requestor.addCheckMatch("searchTestJSP3.jsp", 377, 384);
JSPSearchSupport.getInstance().search(element, new JSPSearchScope(), requestor, new NullProgressMonitor());
assertTrue("did not find all expected matches: search*", requestor.checkValid());
} finally {
if (xmlModel != null)
xmlModel.releaseFromRead();
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPTranslationTest method testUseBeanNoSpace.
/**
* Makes sure both beans are translated even though they are
* right next to each other with no space.
*
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=103004
*/
public void testUseBeanNoSpace() {
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("INCLUDES_TESTS/useBean_tester.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();
boolean bean1 = javaText.indexOf("javax.swing.JButton x = null;") != -1;
boolean bean2 = javaText.indexOf("javax.swing.JButton y = null;") != -1;
assertTrue(bean1);
assertTrue(bean2);
} 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 testXMLJSPMapping.
public void testXMLJSPMapping() {
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();
HashMap jsp2java = translation.getJsp2JavaMap();
Object[] jspRanges = jsp2java.keySet().toArray();
Position jspPos = null;
Position javaPos = null;
for (int i = 0; i < jspRanges.length; i++) {
jspPos = (Position) jspRanges[i];
javaPos = (Position) jsp2java.get(jspPos);
// System.out.println("jsp:" + printPos(jspPos) + " >> java:" + printPos(javaPos));
checkPosition(jspPos, javaPos);
}
} finally {
if (sModel != null)
sModel.releaseFromRead();
}
}
Aggregations