use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class XMLJavaHyperlinkDetector method isJspJavaContent.
private boolean isJspJavaContent(IDocument document, IRegion region) {
JSPTranslation translation = null;
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model instanceof IDOMModel) {
IDOMModel xmlModel = (IDOMModel) model;
if (xmlModel != null) {
final IDOMDocument xmlDoc = xmlModel.getDocument();
final JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
if (adapter != null) {
translation = adapter.getJSPTranslation();
if (translation != null) {
int javaOffset = translation.getJavaOffset(region.getOffset());
if (javaOffset > -1) {
return true;
}
}
}
}
}
} finally {
if (model != null) {
model.releaseFromRead();
}
}
return false;
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPJavaSelectionProvider method getSelection.
static IJavaElement[] getSelection(ITextEditor textEditor) {
IJavaElement[] 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 = StructuredModelManager.getModelManager().getExistingModelForRead(document);
try {
if (model instanceof IDOMModel) {
IDOMModel xmlModel = (IDOMModel) model;
IDOMDocument xmlDoc = xmlModel.getDocument();
JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
if (adapter != null) {
JSPTranslation translation = adapter.getJSPTranslation();
elements = translation.getElementsFromJspRange(textSelection.getOffset(), textSelection.getOffset() + textSelection.getLength());
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
}
if (elements == null) {
elements = new IJavaElement[0];
}
return elements;
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPTypeMoveRequestor method getRenameText.
/**
* @see org.eclipse.jst.jsp.ui.internal.java.refactoring.BasicRefactorSearchRequestor#getRenameText(org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate, org.eclipse.jdt.core.search.SearchMatch)
*/
protected String getRenameText(JavaSearchDocumentDelegate searchDoc, SearchMatch javaMatch) {
String renameText = getElement().getElementName();
JSPTranslation trans = searchDoc.getJspTranslation();
String matchText = trans.getJavaText().substring(javaMatch.getOffset(), javaMatch.getOffset() + javaMatch.getLength());
// if it's an import or jsp:useBean, we need to add the package name as well
if (trans.isImport(javaMatch.getOffset()) || trans.isUseBean(javaMatch.getOffset()) || isFullyQualified(matchText)) {
if (// $NON-NLS-1$
!getNewName().equals(""))
// getNewName() is the pkg name
// $NON-NLS-1$
renameText = getNewName() + "." + renameText;
}
// if the rename text is the same as the match text then, don't want to bother renaming anything
if (renameText.equals(matchText)) {
renameText = null;
}
return renameText;
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPTypeRenameRequestor method getRenameText.
protected String getRenameText(JavaSearchDocumentDelegate searchDoc, SearchMatch javaMatch) {
String renameText = getNewName();
String pkg = getType().getPackageFragment().getElementName();
IJavaElement parent = getType().getParent();
String parentName = (parent != null) ? parent.getElementName() : null;
JSPTranslation trans = searchDoc.getJspTranslation();
String matchText = trans.getJavaText().substring(javaMatch.getOffset(), javaMatch.getOffset() + javaMatch.getLength());
// else if starts with parent name such as "MyClass.Enum" then need to add the parent name as well
if (trans.isImport(javaMatch.getOffset()) || isFullyQualified(matchText)) {
if (// $NON-NLS-1$
!pkg.equals(""))
// $NON-NLS-1$
renameText = pkg + "." + renameText;
} else if (parentName != null && matchText.startsWith(parentName)) {
// $NON-NLS-1$
renameText = parentName + "." + renameText;
}
return renameText;
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslation in project webtools.sourceediting by eclipse.
the class JSPCompletionProcessor method computeCompletionProposals.
/**
* The same as the normal <code>computeCompeltaionProposals</code> except the calculated
* java position is offset by the given extra offset.
*
* @param viewer
* the viewer whose document is used to compute the proposals
* @param documentPosition
* an offset within the document for which completions should
* be computed
* @param javaPositionExtraOffset
* the extra offset for the java position
* @return an array of completion proposals or <code>null</code> if no
* proposals are possible
*/
protected ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int pos, int javaPositionExtraOffset) {
initialize(pos);
JSPProposalCollector collector = null;
IDOMModel xmlModel = null;
try {
if (viewer instanceof StructuredTextViewer)
fViewer = (StructuredTextViewer) viewer;
xmlModel = (IDOMModel) StructuredModelManager.getModelManager().getExistingModelForRead(fViewer.getDocument());
IDOMDocument xmlDoc = xmlModel.getDocument();
if (fTranslationAdapter == null || xmlModel.getId() != fModelId) {
fTranslationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
fModelId = xmlModel.getId();
}
if (fTranslationAdapter != null) {
JSPTranslation translation = fTranslationAdapter.getJSPTranslation();
fJavaPosition = translation.getJavaOffset(getDocumentPosition()) + javaPositionExtraOffset;
if (DEBUG)
System.out.println(debug(translation));
try {
ICompilationUnit cu = translation.getCompilationUnit();
// or without a valid position
if (cu == null || -1 == fJavaPosition)
return new ICompletionProposal[0];
collector = getProposalCollector(cu, translation);
synchronized (cu) {
cu.codeComplete(fJavaPosition, collector, (WorkingCopyOwner) null);
}
} catch (CoreException coreEx) {
// a possible Java Model Exception due to not being a Web
// (Java) Project
coreEx.printStackTrace();
}
}
} catch (Exception exc) {
exc.printStackTrace();
// throw out exceptions on code assist.
} finally {
if (xmlModel != null) {
xmlModel.releaseFromRead();
}
}
ICompletionProposal[] results = new ICompletionProposal[0];
if (collector != null) {
results = collector.getJSPCompletionProposals();
if (results == null || results.length < 1)
fErrorMessage = JSPUIMessages.Java_Content_Assist_is_not_UI_;
}
return results;
}
Aggregations