Search in sources :

Example 16 with JSPTranslation

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;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 17 with JSPTranslation

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;
}
Also used : IJavaElement(org.eclipse.jdt.core.IJavaElement) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 18 with JSPTranslation

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();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IJavaElement(org.eclipse.jdt.core.IJavaElement) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) JSPSearchScope(org.eclipse.jst.jsp.core.internal.java.search.JSPSearchScope) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 19 with JSPTranslation

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();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) DOMModelForJSP(org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Example 20 with JSPTranslation

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();
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslation(org.eclipse.jst.jsp.core.internal.java.JSPTranslation) DOMModelForJSP(org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP) HashMap(java.util.HashMap) Position(org.eclipse.jface.text.Position) IJSPTranslation(org.eclipse.jst.jsp.core.internal.java.IJSPTranslation) JSPTranslationAdapter(org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)

Aggregations

JSPTranslation (org.eclipse.jst.jsp.core.internal.java.JSPTranslation)24 IJSPTranslation (org.eclipse.jst.jsp.core.internal.java.IJSPTranslation)21 JSPTranslationAdapter (org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter)14 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)12 IDOMDocument (org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument)9 IFile (org.eclipse.core.resources.IFile)6 IJavaElement (org.eclipse.jdt.core.IJavaElement)6 IPath (org.eclipse.core.runtime.IPath)5 Path (org.eclipse.core.runtime.Path)5 DOMModelForJSP (org.eclipse.jst.jsp.core.internal.domdocument.DOMModelForJSP)4 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 CoreException (org.eclipse.core.runtime.CoreException)3 IDocument (org.eclipse.jface.text.IDocument)3 Position (org.eclipse.jface.text.Position)3 ArrayList (java.util.ArrayList)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 ICompletionProposal (org.eclipse.jface.text.contentassist.ICompletionProposal)2