use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class JSDTHtmlCompletionProcessor method getEndScriptProposal.
public ICompletionProposal getEndScriptProposal(ITextViewer viewer, int offset) {
/* add </script if necisary */
IJsTranslation tran = getJSPTranslation(viewer);
if (tran == null)
return null;
int missingAtOffset = tran.getMissingTagStart();
if (offset >= missingAtOffset && missingAtOffset > -1) {
String allText = viewer.getDocument().get();
// $NON-NLS-1$
String text = "</script>";
int startInTag = -1;
for (int i = 0; i < text.length() && allText.length() > offset - 1; i++) {
if (allText.charAt(offset - 1) == text.charAt(i)) {
startInTag = i;
break;
}
}
if (startInTag == -1) {
// $NON-NLS-1$
String displayText = Messages.getString("JSDTHtmlCompletionProcessor.1");
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return new CustomCompletionProposal("\n" + text + "\n", offset, 0, offset, null, displayText, null, Messages.getString("JSDTHtmlCompletionProcessor.4"), 100);
}
String text1 = allText.substring(offset - startInTag - 1, offset).toLowerCase();
String text2 = text.substring(0, startInTag + 1).toLowerCase();
if (startInTag > -1 && text2.compareTo(text1) == 0) {
// $NON-NLS-1$
String displayText = Messages.getString("JSDTHtmlCompletionProcessor.5");
// $NON-NLS-1$
return new CustomCompletionProposal(text, offset - startInTag - 1, 0, text.length(), null, displayText, null, Messages.getString("JSDTHtmlCompletionProcessor.6"), 100);
}
}
return null;
}
use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class BasicJsSearchRequestor method acceptSearchMatch.
/**
* Maps java search coordinates to corresponding JSP coordinates. Adds the
* matches to the Search Results view.
*
* @see org.eclipse.wst.jsdt.core.search.SearchRequestor#acceptSearchMatch(org.eclipse.wst.jsdt.core.search.SearchMatch)
*/
public void acceptSearchMatch(SearchMatch match) throws CoreException {
if (JsSearchSupport.getInstance().isCanceled()) {
return;
}
String matchDocumentPath = match.getResource().getFullPath().toString();
SearchDocument searchDoc = JsSearchSupport.getInstance().getSearchDocument(matchDocumentPath);
if (searchDoc != null && searchDoc instanceof JSDTSearchDocumentDelegate) {
JSDTSearchDocumentDelegate javaSearchDoc = (JSDTSearchDocumentDelegate) searchDoc;
int jspStart = match.getOffset();
int jspEnd = match.getOffset() + match.getLength();
IJsTranslation trans = javaSearchDoc.getJspTranslation();
String jspText = trans.getHtmlText();
String javaText = javaSearchDoc.getJavaText();
if (BasicJsSearchRequestor.DEBUG) {
displayDebugInfo(match, jspStart, jspEnd, jspText, javaText);
}
if (jspStart > -1 && jspEnd > -1) {
addSearchMatch(new Document(trans.getHtmlText()), javaSearchDoc.getFile(), jspStart, jspEnd, jspText);
}
}
}
use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class JsFindOccurrencesProcessor method getJavaElementsForCurrentSelection.
/**
* uses JSPTranslation to get currently selected Java elements.
*
* @return currently selected IJavaElements
*/
private IJavaScriptElement[] getJavaElementsForCurrentSelection(IDocument document, ITextSelection selection) {
IJavaScriptElement[] elements = new IJavaScriptElement[0];
// get JSP translation object for this viewer's document
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model != null && model instanceof IDOMModel) {
IDOMDocument xmlDoc = ((IDOMModel) model).getDocument();
JsTranslationAdapter adapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
if (adapter != null) {
IJsTranslation translation = adapter.getJsTranslation(false);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=102211
elements = translation.getElementsFromJsRange(translation.getJavaScriptOffset(selection.getOffset()), translation.getJavaScriptOffset(selection.getOffset() + selection.getLength()));
}
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
return elements;
}
use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class JsSearchDocument 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() || (this.fCUPath == UNKNOWN_PATH)) {
IJsTranslation trans = getJSTranslation();
if (trans != null) {
this.fCUPath = trans.getJavaPath();
// save since it's expensive to calculate again later
fCachedCharContents = trans.getJsText().toCharArray();
}
}
return fCUPath != null ? fCUPath : UNKNOWN_PATH;
}
use of org.eclipse.wst.jsdt.web.core.javascript.IJsTranslation in project webtools.sourceediting by eclipse.
the class JsSearchDocument method getJSTranslation.
/**
* It's not recommended for clients to hold on to this JSPTranslation
* since it's kind of large. If possible, hold on to the
* JSPSearchDocument, which is more of a lightweight proxy.
*
* @return the JSPTranslation for the jsp file, or null if it's an
* unsupported file.
*/
public final IJsTranslation getJSTranslation() {
IJsTranslation translation = null;
IFile jspFile = getFile();
if (!JsSearchSupport.isJsp(jspFile)) {
return translation;
}
IStructuredModel model = null;
try {
// get existing model for read, then get document from it
IModelManager modelManager = getModelManager();
if (modelManager != null) {
model = modelManager.getModelForRead(jspFile);
}
// handle unsupported
if (model instanceof IDOMModel) {
IDOMModel xmlModel = (IDOMModel) model;
JsTranslationAdapterFactory.setupAdapterFactory(xmlModel);
IDOMDocument doc = xmlModel.getDocument();
JsTranslationAdapter adapter = (JsTranslationAdapter) doc.getAdapterFor(IJsTranslation.class);
translation = adapter.getJsTranslation(false);
}
} catch (IOException e) {
Logger.logException(e);
} catch (CoreException e) {
Logger.logException(e);
} catch (UnsupportedCharsetExceptionWithDetail e) {
// no need to log this. Just consider it an invalid file for our
// purposes.
// Logger.logException(e);
} finally {
if (model != null) {
model.releaseFromRead();
}
}
return translation;
}
Aggregations