use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class TestOrphan method getJSPDoc.
private Document getJSPDoc() {
IDOMModel structuredModel = (IDOMModel) StructuredModelManager.getModelManager().createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP);
Document doc = structuredModel.getDocument();
return doc;
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class TestModelIncludes method testTranslateSingleLineIncludedFileWithNoSpacesButScriptletInInclude.
/**
* Verify included files are translated properly when they contain a
* single line and document region and no trailing white space.
*
* @throws Exception
*/
public void testTranslateSingleLineIncludedFileWithNoSpacesButScriptletInInclude() throws Exception {
String projectName = "prj119576_b";
BundleResourceUtil.createSimpleProject(projectName, null, null);
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + projectName, "/" + projectName);
assertTrue("project could not be created", ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).exists());
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path("/" + projectName + "/WebContent/body3.jsp"));
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(file);
assertTrue("model has no content", model.getStructuredDocument().getLength() > 0);
ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
JSPTranslationAdapter adapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
String source = adapter.getJSPTranslation().getJavaText();
assertTrue("scriptlet with variable declaration not found", source.indexOf("java.util.Date headerDate") > -1);
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class JsJfaceNode method getTranslation.
// private Method[] getMethods(){
// // returns the methods this class supports (as declared in interfaces)
// Class[] interfaces = getClass().getInterfaces();
// Vector vMethods = new Vector();
// for(int i = 0;i<interfaces.length;i++){
// Method methods[] = interfaces[i].getDeclaredMethods();
// vMethods.addAll(Arrays.asList(methods));
// }
//
// return (Method[])vMethods.toArray();
// }
// public Object invoke(Object proxy, Method method, Object[] args) throws
// Throwable {
// Object result;
// Method[] myMethods = getMethods();
//
// try {
// for(int i = 0;i<myMethods.length;i++){
// if(myMethods[i]==method){
// return method.invoke(this, args);
// }
// }
// result = method.invoke(parentType, args);
// } catch (InvocationTargetException e) {
// throw e.getTargetException();
// } catch (Exception e) {
// throw new RuntimeException("unexpected invocation exception: " +
// e.getMessage());
// }
//
// return result;
// }
/*
* (non-Javadoc)
*
* @see org.eclipse.wst.xml.core.internal.document.NodeImpl#getStructuredDocument()
*/
public IJsTranslation getTranslation() {
IStructuredModel model = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
IDOMDocument xmlDoc = null;
try {
if (modelManager != null) {
IStructuredDocument doc = getStructuredDocument();
model = modelManager.getExistingModelForRead(doc);
// model = modelManager.getModelForRead(doc);
}
IDOMModel domModel = (IDOMModel) model;
xmlDoc = domModel.getDocument();
} catch (Exception e) {
Logger.logException(e);
} finally {
if (model != null) {
// model.changedModel();
model.releaseFromRead();
}
}
if (xmlDoc == null) {
return null;
}
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
return translationAdapter.getJsTranslation(true);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class JFaceNodeAdapterForJs method getTranslation.
private IJsTranslation getTranslation(Node node) {
IStructuredModel model = null;
IModelManager modelManager = StructuredModelManager.getModelManager();
IDOMDocument xmlDoc = null;
try {
if (modelManager != null) {
IStructuredDocument doc = ((NodeImpl) node).getStructuredDocument();
model = modelManager.getExistingModelForRead(doc);
// model = modelManager.getModelForRead(doc);
}
IDOMModel domModel = (IDOMModel) model;
xmlDoc = domModel.getDocument();
} catch (Exception e) {
Logger.logException(e);
} finally {
if (model != null) {
// model.changedModel();
model.releaseFromRead();
}
}
if (xmlDoc == null) {
return null;
}
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) xmlDoc.getAdapterFor(IJsTranslation.class);
return translationAdapter.getJsTranslation(true);
}
use of org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel in project webtools.sourceediting by eclipse.
the class ShowTranslationHandler method execute.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands
* .ExecutionEvent)
*/
public Object execute(final ExecutionEvent event) throws ExecutionException {
// IDE.openEditor(event.getApplicationContext(), createEditorInput(),
// JavaUI.ID_CU_EDITOR, true);
ISelection selection = HandlerUtil.getCurrentSelection(event);
if (selection instanceof IStructuredSelection) {
List list = ((IStructuredSelection) selection).toList();
if (!list.isEmpty()) {
if (list.get(0) instanceof IDOMNode) {
final IDOMModel model = ((IDOMNode) list.get(0)).getModel();
INodeAdapter adapter = model.getDocument().getAdapterFor(IJsTranslation.class);
if (adapter != null) {
Job opener = new UIJob("Opening JavaScript Translation") {
public IStatus runInUIThread(IProgressMonitor monitor) {
JsTranslationAdapter translationAdapter = (JsTranslationAdapter) model.getDocument().getAdapterFor(IJsTranslation.class);
final IJsTranslation translation = translationAdapter.getJsTranslation(false);
// create an IEditorInput for the Java editor
final IStorageEditorInput input = new JSTranslationEditorInput(translation, model.getBaseLocation());
try {
IEditorPart editor = IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), input, JavaScriptUI.ID_CU_EDITOR, true);
// Now add the problems we found
if (editor instanceof ITextEditor) {
IAnnotationModel annotationModel = ((ITextEditor) editor).getDocumentProvider().getAnnotationModel(input);
translation.reconcileCompilationUnit();
List problemsList = translation.getProblems();
IProblem[] problems = (IProblem[]) problemsList.toArray(new IProblem[problemsList.size()]);
AnnotationTypeLookup lookup = new AnnotationTypeLookup();
for (int i = 0; i < problems.length; i++) {
int length = problems[i].getSourceEnd() - problems[i].getSourceStart() + 1;
Position position = new Position(problems[i].getSourceStart(), length);
Annotation annotation = null;
String type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_INFO);
if (problems[i].isError()) {
type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_ERROR);
} else if (problems[i].isWarning()) {
type = lookup.getAnnotationType(IMarker.PROBLEM, IMarker.SEVERITY_WARNING);
}
annotation = new Annotation(type, false, problems[i].getMessage());
if (annotation != null) {
annotationModel.addAnnotation(annotation, position);
}
}
}
} catch (PartInitException e) {
e.printStackTrace();
Display.getCurrent().beep();
}
return Status.OK_STATUS;
}
};
opener.setSystem(false);
opener.setUser(true);
opener.schedule();
}
}
}
}
return null;
}
Aggregations