use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPSearchDocument method getJSPTranslation.
/**
* 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 JSPTranslationExtension getJSPTranslation() {
JSPTranslationExtension translation = null;
IFile jspFile = getFile();
if (!JSPSearchSupport.isJsp(jspFile))
return translation;
IStructuredModel model = null;
try {
// get existing model for read, then get document from it
IModelManager modelManager = getModelManager();
if (modelManager != null) {
jspFile.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
model = modelManager.getModelForRead(jspFile);
}
// handle unsupported
if (model instanceof IDOMModel) {
IDOMModel xmlModel = (IDOMModel) model;
setupAdapterFactory(xmlModel);
IDOMDocument doc = xmlModel.getDocument();
JSPTranslationAdapter adapter = (JSPTranslationAdapter) doc.getAdapterFor(IJSPTranslation.class);
translation = adapter.getJSPTranslation();
}
} 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;
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPJavaValidator method performValidation.
void performValidation(IFile f, IReporter reporter, IStructuredModel model) {
for (int i = 0; i < DEPEND_ONs.length; i++) {
addDependsOn(f.getProject().getFile(DEPEND_ONs[i]));
}
if (model instanceof IDOMModel) {
IDOMModel domModel = (IDOMModel) model;
ModelHandlerForJSP.ensureTranslationAdapterFactory(domModel);
IDOMDocument xmlDoc = domModel.getDocument();
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class);
IJSPTranslation translation = translationAdapter.getJSPTranslation();
if (!reporter.isCancelled()) {
loadPreferences(f);
// only update task markers if the model is the same as what's on disk
boolean updateJavaTasks = UPDATE_JAVA_TASKS && !domModel.isDirty() && f != null && f.isAccessible();
if (updateJavaTasks) {
// remove old Java task markers
try {
IMarker[] foundMarkers = f.findMarkers(JAVA_TASK_MARKER_TYPE, true, IResource.DEPTH_ONE);
for (int i = 0; i < foundMarkers.length; i++) {
foundMarkers[i].delete();
}
} catch (CoreException e) {
Logger.logException(e);
}
}
translation.setProblemCollectingActive(true);
translation.reconcileCompilationUnit();
List problems = translation.getProblems();
// add new messages
for (int i = 0; i < problems.size() && !reporter.isCancelled(); i++) {
IProblem problem = (IProblem) problems.get(i);
/*
* Possible error in problem collection; EL translation is
* extensible, so we must be paranoid about this.
*/
if (problem == null)
continue;
IMessage m = createMessageFromProblem(problem, f, translation, domModel.getStructuredDocument());
if (m != null) {
if (problem.getID() == IProblem.Task) {
if (updateJavaTasks) {
// add new Java task marker
try {
IMarker task = f.createMarker(JAVA_TASK_MARKER_TYPE);
task.setAttribute(IMarker.LINE_NUMBER, new Integer(m.getLineNumber()));
task.setAttribute(IMarker.CHAR_START, new Integer(m.getOffset()));
task.setAttribute(IMarker.CHAR_END, new Integer(m.getOffset() + m.getLength()));
task.setAttribute(IMarker.MESSAGE, m.getText());
task.setAttribute(IMarker.USER_EDITABLE, Boolean.FALSE);
switch(m.getSeverity()) {
case IMessage.HIGH_SEVERITY:
{
task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_HIGH));
task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
}
break;
case IMessage.LOW_SEVERITY:
{
task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_LOW));
task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_INFO));
}
break;
default:
{
task.setAttribute(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_NORMAL));
task.setAttribute(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_WARNING));
}
}
} catch (CoreException e) {
Logger.logException(e);
}
}
} else {
reporter.addMessage(fMessageOriginator, m);
}
}
}
}
}
unloadPreferences();
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorCoreTest method testIterationTagsIncomplete.
/**
* Tests that an iteration tag will generate
* @throws Exception
*/
public void testIterationTagsIncomplete() throws Exception {
String testName = "testIterationTags";
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
if (!project.isAccessible()) {
// Create new project
project = BundleResourceUtil.createSimpleProject(testName, null, null);
assertTrue(project.exists());
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
}
/* This test is failing as of 20180213 so until someone can debug and fix it, comment it out */
/* waitForBuildAndValidation(project); */
IFile testFile = project.getFile("/WebContent/test_missing_end_tag.jsp");
assertTrue("test_missing_end_tag.jsp is not accessible", testFile.isAccessible());
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(testFile);
ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
JSPTranslationExtension translation = translationAdapter.getJSPTranslation();
String javaText = translation.getJavaText();
int startOffset = javaText.indexOf("} // [</plain:loop>]");
assertTrue("Missing end tag was not accounted for.", startOffset != -1);
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorCoreTest method testIterationTags.
public void testIterationTags() throws Exception {
String testName = "testIterationTags";
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
if (!project.isAccessible()) {
// Create new project
project = BundleResourceUtil.createSimpleProject(testName, null, null);
assertTrue(project.exists());
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
}
/* This test is failing as of 20180213 so until someone can debug and fix it, comment it out */
/* waitForBuildAndValidation(project); */
IFile testFile = project.getFile("/WebContent/test.jsp");
assertTrue("test.jsp is not accessible", testFile.isAccessible());
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(testFile);
ModelHandlerForJSP.ensureTranslationAdapterFactory(model);
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) model.getDocument().getAdapterFor(IJSPTranslation.class);
JSPTranslationExtension translation = translationAdapter.getJSPTranslation();
translation.setProblemCollectingActive(true);
assertNotNull("No Java translation found", translation);
translation.reconcileCompilationUnit();
translation.setProblemCollectingActive(false);
List<IProblem> problems = translation.getProblems();
assertNotNull("Translation had a null problems list.", problems);
Iterator<IProblem> it = problems.iterator();
String javaText = translation.getJavaText();
int startOffset = javaText.indexOf("<plain:simple>");
assertTrue("<plan:simple> scope not found.", startOffset > 0);
int endOffset = javaText.indexOf("</plain:simple>", startOffset);
assertTrue("</plan:simple> scope not found.", endOffset > 0);
// Finds all errors caused by "continue cannot be used outside of a loop" - should only occur between <plain:simple></plain:simple>
while (it.hasNext()) {
IProblem problem = it.next();
if (problem.isError()) {
if ("continue cannot be used outside of a loop".equals(problem.getMessage())) {
assertTrue("'continue cannot be used outside of a loop' outside of iteration tag: ", problem.getSourceStart() > startOffset && problem.getSourceEnd() < endOffset);
}
}
}
} finally {
if (model != null)
model.releaseFromEdit();
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorCoreTest method test_518987.
// http://bugs.eclipse.org/518987
public void test_518987() throws Exception {
String testName = "bug_518987";
// Create new project
IProject project = BundleResourceUtil.createJavaWebProject(testName);
assertTrue(project.exists());
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
// TEI class needs to already be compiled
// waitForBuildAndValidation(project);
// project.build(IncrementalProjectBuilder.FULL_BUILD, "org.eclipse.jdt.internal.core.builder.JavaBuilder", null, null);
project.getWorkspace().checkpoint(true);
IFile file1 = project.getFile("/WebContent/test1.jsp");
IDOMModel structuredModel1 = null;
try {
structuredModel1 = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(file1);
ModelHandlerForJSP.ensureTranslationAdapterFactory(structuredModel1);
JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) structuredModel1.getDocument().getAdapterFor(IJSPTranslation.class);
final String translation = translationAdapter.getJSPTranslation().getJavaText();
assertFalse("The unprocessed custom action's attribute value pair should not be in the translated source, was the custom tag not parsed?", translation.indexOf("insert=") > 0);
assertTrue("The 'insert' integer declared by a TEI class was not found, was the custom tag not parsed?\n\n" + translation, translation.indexOf("java.lang.Integer insert") > 0);
} finally {
if (structuredModel1 != null)
structuredModel1.releaseFromRead();
}
}
Aggregations