use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationUtil in project webtools.sourceediting by eclipse.
the class FormattingStrategyJSPJava method format.
/*
* @see org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy#format()
*/
public void format() {
super.format();
final IDocument document = (IDocument) fDocuments.removeFirst();
final TypedPosition partition = (TypedPosition) fPartitions.removeFirst();
if (document != null && partition != null) {
try {
JSPTranslationUtil translationUtil = new JSPTranslationUtil(document);
ICompilationUnit cu = translationUtil.getCompilationUnit();
if (cu != null) {
String cuSource = cu.getSource();
/*
* Format the entire compilation unit, but only create
* edits for the requested JSP partition's range in the
* Java source
*/
TextEdit textEdit = formatString(CodeFormatter.K_COMPILATION_UNIT, cuSource, translationUtil.getTranslation().getJavaOffset(partition.getOffset()), partition.getLength(), TextUtilities.getDefaultLineDelimiter(document), getPreferences());
TextEdit jspEdit = translationUtil.getTranslation().getJspEdit(textEdit);
if (jspEdit != null && jspEdit.hasChildren())
jspEdit.apply(document);
}
} catch (MalformedTreeException exception) {
Logger.logException(exception);
} catch (BadLocationException exception) {
// Can only happen on concurrent document modification - log
// and bail out
Logger.logException(exception);
} catch (JavaModelException exception) {
Logger.logException(exception);
}
}
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationUtil in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorCoreTest method test_109721.
public void test_109721() throws Exception {
/*
* https://bugs.eclipse.org/109721 JSP editor does not find taglib
* directives in include-prelude or jsp:include, make sure the
* contents were processed
*/
String testName = "bug_109721";
// Create new project
final IProject project = BundleResourceUtil.createSimpleProject(testName, null, null);
assertTrue(project.isAccessible());
BundleResourceUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + testName, "/" + testName);
BundleResourceUtil.copyBundleEntryIntoWorkspace("/testfiles/struts.jar", "/" + testName + "/WebContent/WEB-INF/lib/struts.jar");
waitForBuildAndValidation(project);
String filename = "/WebContent/main.jsp";
IStructuredModel sm = StructuredModelManager.getModelManager().getModelForRead(project.getFile(filename));
assertNotNull("couldn't load JSP for test", sm);
JSPTranslationUtil translationUtil = new JSPTranslationUtil(sm.getStructuredDocument());
String translation = translationUtil.getTranslation().getJavaText();
sm.releaseFromRead();
assertTrue("Java content from Fragment included by web.xml is missing", translation.indexOf("int alpha = 5;") > 0);
assertTrue("Tag that could only be known by processing Fragment included only by web.xml is not in the translation", translation.indexOf("org.apache.struts.taglib.bean.DefineTag") > 0);
}
use of org.eclipse.jst.jsp.core.internal.java.JSPTranslationUtil in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorTest method testMultipleJSPSectionsInJavascript.
public void testMultipleJSPSectionsInJavascript() throws Exception {
String filename = "testfiles/jspInJavascript2.jsp";
IStructuredModel sm = getStructuredModelForRead(filename);
assertNotNull("couldn't load JSP for test", sm);
JSPTranslationUtil translationUtil = new JSPTranslationUtil(sm.getStructuredDocument());
String javaText = StringUtils.replace(translationUtil.getTranslation().getJavaText(), "\r\n", "\n");
javaText = StringUtils.replace(javaText, "\r", "\n");
sm.releaseFromRead();
String translatedText = loadContents("testfiles/jspInJavascript2.javasource");
assertEquals("translated contents are not as expected", translatedText, javaText);
}
Aggregations