use of org.eclipse.wst.jsdt.core.IJavaScriptElement in project webtools.sourceediting by eclipse.
the class JsQueryParticipant method search.
/**
* @see org.eclipse.wst.jsdt.ui.search.IQueryParticipant#search(org.eclipse.wst.jsdt.ui.search.ISearchRequestor,
* org.eclipse.wst.jsdt.ui.search.QuerySpecification,
* org.eclipse.core.runtime.IProgressMonitor)
*/
public void search(ISearchRequestor requestor, QuerySpecification querySpecification, IProgressMonitor monitor) throws CoreException {
// do search based on the particular Java query
if (querySpecification instanceof ElementQuerySpecification) {
// element search (eg. from global find references in Java file)
ElementQuerySpecification elementQuery = (ElementQuerySpecification) querySpecification;
IJavaScriptElement element = elementQuery.getElement();
if (JsQueryParticipant.DEBUG) {
// $NON-NLS-1$
System.out.println("JSP Query Participant searching on ELEMENT: " + element);
}
SearchRequestor jspRequestor = new JsSearchRequestor(requestor);
// pa_TODO need to adapt JavaSearchScope to a JSPSearchScope
JsSearchSupport.getInstance().search(element, new JsSearchScope(), jspRequestor);
} else if (querySpecification instanceof PatternQuerySpecification) {
// pattern search (eg. from Java search page)
PatternQuerySpecification patternQuery = (PatternQuerySpecification) querySpecification;
String pattern = patternQuery.getPattern();
if (JsQueryParticipant.DEBUG) {
// $NON-NLS-1$
System.out.println("JSP Query Participant searching on PATTERN: " + pattern);
}
SearchRequestor jspRequestor = new JsSearchRequestor(requestor);
JsSearchSupport.getInstance().search(pattern, new JsSearchScope(), patternQuery.getSearchFor(), patternQuery.getLimitTo(), SearchPattern.R_PATTERN_MATCH, false, jspRequestor);
}
}
use of org.eclipse.wst.jsdt.core.IJavaScriptElement in project webtools.sourceediting by eclipse.
the class JSDTHyperlinkDetector method createHyperlink.
private IHyperlink createHyperlink(IJsTranslation jsTranslation, IJavaScriptElement element, IRegion region, IDocument document) {
IHyperlink link = null;
if (region != null) {
// open local variable in the JSP file...
if (element instanceof ISourceReference) {
IFile file = null;
IPath outsidePath = null;
int jspOffset = 0;
IStructuredModel sModel = null;
// try to locate the file in the workspace
try {
sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (sModel != null) {
// URIResolver resolver = sModel.getResolver();
// if (resolver != null) {
// String uriString = resolver.getFileBaseLocation();
String uriString = sModel.getBaseLocation();
file = getFile(uriString);
// }
}
} finally {
if (sModel != null) {
sModel.releaseFromRead();
}
}
// get Java range, translate coordinate to JSP
try {
ISourceRange range = null;
if (jsTranslation != null) {
// link to local variable definitions
if (element instanceof ILocalVariable) {
range = ((ILocalVariable) element).getNameRange();
IJavaScriptElement unit = ((ILocalVariable) element).getParent();
IJavaScriptUnit myUnit = jsTranslation.getCompilationUnit();
while (!(unit instanceof IJavaScriptUnit || unit instanceof IClassFile || unit == null)) {
unit = ((JavaElement) unit).getParent();
}
if (unit instanceof IJavaScriptUnit) {
IJavaScriptUnit cu = (IJavaScriptUnit) unit;
if (cu != myUnit) {
file = getFile(cu.getPath().toString());
if (file == null) {
outsidePath = cu.getPath();
}
}
} else if (unit instanceof IClassFile) {
IClassFile cu = (IClassFile) unit;
if (cu != myUnit) {
file = getFile(cu.getPath().toString());
if (file == null) {
outsidePath = cu.getPath();
}
}
}
} else // linking to fields of the same compilation unit
if (element.getElementType() == IJavaScriptElement.FIELD) {
Object cu = ((IField) element).getJavaScriptUnit();
if (cu != null && cu.equals(jsTranslation.getCompilationUnit())) {
range = ((ISourceReference) element).getSourceRange();
}
} else // linking to methods of the same compilation unit
if (element.getElementType() == IJavaScriptElement.METHOD) {
Object cu = ((IFunction) element).getJavaScriptUnit();
if (cu != null && cu.equals(jsTranslation.getCompilationUnit())) {
range = ((ISourceReference) element).getSourceRange();
}
}
}
if (range != null && file != null) {
jspOffset = range.getOffset();
if (jspOffset >= 0) {
link = new WorkspaceFileHyperlink(region, file, new Region(jspOffset, range.getLength()));
}
} else if (range != null && outsidePath != null) {
jspOffset = range.getOffset();
if (jspOffset >= 0) {
link = new ExternalFileHyperlink(region, outsidePath.toFile());
}
}
} catch (JavaScriptModelException jme) {
Logger.log(Logger.WARNING_DEBUG, jme.getMessage(), jme);
}
}
if (link == null) {
link = new JSDTHyperlink(region, element);
}
}
return link;
}
use of org.eclipse.wst.jsdt.core.IJavaScriptElement in project webtools.sourceediting by eclipse.
the class JSPJavaSelectionProvider method getSelection.
static IJavaScriptElement[] getSelection(ITextEditor textEditor) {
IJavaScriptElement[] elements = null;
IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
ISelection selection = textEditor.getSelectionProvider().getSelection();
if (selection instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection) selection;
// get the JSP translation object for this editor's document
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model instanceof IDOMModel) {
IDOMModel xmlModel = (IDOMModel) model;
IDOMDocument xmlDoc = xmlModel.getDocument();
JsTranslationAdapter adapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
if (adapter != null) {
IJsTranslation translation = adapter.getJsTranslation(true);
elements = translation.getElementsFromJsRange(translation.getJavaScriptOffset(textSelection.getOffset()), translation.getJavaScriptOffset(textSelection.getOffset() + textSelection.getLength()));
}
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
}
if (elements == null) {
elements = new IJavaScriptElement[0];
}
return elements;
}
use of org.eclipse.wst.jsdt.core.IJavaScriptElement in project webtools.sourceediting by eclipse.
the class ShowHistoryAction method selectionChanged.
public void selectionChanged(IAction action, ISelection selection) {
setSelection(selection);
IJavaScriptElement[] elements = JsElementActionProxy.getJsElementsFromSelection(getCurrentSelection());
for (int i = 0; i < elements.length; i++) {
if (elements[i].isVirtual()) {
IResource resource = getHostResource(elements[i]);
if (resource == null || !resource.exists()) {
action.setEnabled(false);
}
}
}
}
use of org.eclipse.wst.jsdt.core.IJavaScriptElement in project webtools.sourceediting by eclipse.
the class ShowInScriptExplorerAction method selectionChanged.
public void selectionChanged(IAction action, ISelection selection) {
setSelection(selection);
IJavaScriptElement[] elements = JsElementActionProxy.getJsElementsFromSelection(getCurrentSelection());
for (int i = 0; i < elements.length; i++) {
if (elements[i].isVirtual()) {
IResource resource = getHostResource(elements[i]);
if (resource == null || !resource.exists()) {
action.setEnabled(false);
}
}
}
}
Aggregations