use of org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper in project webtools.sourceediting by eclipse.
the class TEIValidation method testCustomTagInAttribute.
public void testCustomTagInAttribute() throws Exception {
// $NON-NLS-1$
final String path = "/" + PROJECT_NAME + "/WebContent/test.jsp";
final IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(path));
IStructuredModel model = StructuredModelManager.getModelManager().getModelForRead(file);
try {
assertTrue("Not an IDOMModel", model instanceof IDOMModel);
NodeList divs = ((IDOMModel) model).getDocument().getElementsByTagName("div");
assertTrue("Missing a div", divs.getLength() > 0);
IDOMNode node = (IDOMNode) divs.item(0);
IStructuredDocumentRegion region = node.getStartStructuredDocumentRegion();
ITextRegionList regions = region.getRegions();
assertTrue(regions.size() > 2);
/* This test is failing as of 20180213 so until someone can debug and fix it, comment it out */
/* JSPJavaTranslatorCoreTest.waitForBuildAndValidation(getProject()); */
final TaglibHelper helper = new TaglibHelper(getProject());
final List problems = new ArrayList();
final IStructuredDocument document = model.getStructuredDocument();
ITextRegion embedded = regions.get(2);
assertTrue("Not a container region", embedded instanceof ITextRegionContainer);
helper.getCustomTag("test:foo", document, (ITextRegionContainer) embedded, problems);
/* assertEquals("No problems should be generated", 0, problems.size()); */
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorCoreTest method testTaglibHelperWrongHierarchy.
public void testTaglibHelperWrongHierarchy() 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); */
TaglibHelper helper = new TaglibHelper(project);
IFile testFile = project.getFile("/WebContent/iterationTester.jsp");
assertTrue("iterationTester.jsp is not accessible", testFile.isAccessible());
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(testFile);
IStructuredDocument doc = model.getStructuredDocument();
CustomTag tag = helper.getCustomTag("plain:list", doc, null, new ArrayList());
assertFalse("plain:list should not be an IterationTag", tag.isIterationTag());
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper in project webtools.sourceediting by eclipse.
the class JSPJavaTranslatorCoreTest method testTaglibHelperUnresolvedSupertype.
public void testTaglibHelperUnresolvedSupertype() throws Exception {
String testName = "testIterationTags";
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(testName);
if (!project.isAccessible()) {
// Create new project
project = BundleResourceUtil.createJavaWebProject(testName);
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); */
TaglibHelper helper = new TaglibHelper(project);
IFile testFile = project.getFile("/WebContent/iterationTester.jsp");
assertTrue("iterationTester.jsp is not accessible", testFile.isAccessible());
IDOMModel model = null;
try {
model = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(testFile);
IStructuredDocument doc = model.getStructuredDocument();
CustomTag tag = helper.getCustomTag("plain:uberloop", doc, null, new ArrayList());
assertTrue("plain:uberloop should be an IterationTag", tag.isIterationTag());
} finally {
if (model != null)
model.releaseFromRead();
}
}
use of org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper in project webtools.sourceediting by eclipse.
the class JSPTranslator method addStartTagVariable.
private void addStartTagVariable(String tagToAdd, ITextRegionCollection customTag, int index) {
IFile f = getFile();
if (f == null || !f.exists())
return;
TaglibHelper helper = TaglibHelperManager.getInstance().getTaglibHelper(f);
// $NON-NLS-1$
String decl = "";
List problems = new ArrayList();
CustomTag tag = helper.getCustomTag(tagToAdd, getStructuredDocument(), customTag, problems);
TaglibVariable[] taglibVars = tag.getTagVariables();
fTranslationProblems.addAll(problems);
Set scopedVarNames = new HashSet(0);
/*
* Add AT_BEGIN variables
*/
for (int i = 0; i < taglibVars.length; i++) {
if (taglibVars[i].getScope() == VariableInfo.AT_BEGIN) {
scopedVarNames.add(taglibVars[i].getVarName());
boolean declaredInParentScope = false;
/*
* Check to see if we have already declared this variable
* once, if so then just reassign it instead. Declaring twice
* in the same scope should cause an error, so we're only
* checking parent scopes and the current scope.
*/
RegionTags[] parentTags = (RegionTags[]) fTagToVariableMap.values().toArray(new RegionTags[fTagToVariableMap.size()]);
String varName = taglibVars[i].getVarName();
for (int j = 0; j < parentTags.length && !declaredInParentScope; j++) {
declaredInParentScope |= parentTags[j].scopedVarNames.contains(varName);
}
Set currentAtBeginVars = (Set) fAtBeginVariableMap.get(fAtBeginScopeStack.peek());
boolean declaredInCurrentScope = currentAtBeginVars != null && currentAtBeginVars.contains(varName);
if (declaredInParentScope || declaredInCurrentScope) {
decl = taglibVars[i].getDeclarationString(false, fContext, TaglibVariable.M_REASSIGN);
} else {
decl = taglibVars[i].getDeclarationString(fContext);
if (currentAtBeginVars == null) {
currentAtBeginVars = new HashSet();
currentAtBeginVars.add(varName);
fAtBeginVariableMap.put(fAtBeginScopeStack.peek(), currentAtBeginVars);
} else {
currentAtBeginVars.add(varName);
}
}
appendToBuffer(decl, fUserCode, true, customTag);
}
}
boolean isEmptyTag = false;
if (index != -1)
isEmptyTag = isEmptyTag(customTag, index);
else
isEmptyTag = isEmptyTag(customTag);
/*
* Add a single { to limit the scope of NESTED variables
*/
StringBuffer text = new StringBuffer();
if (!isEmptyTag && tag.isIterationTag() && tag.getTagClassName() != null) {
// $NON-NLS-1$
text.append("\nwhile(true) ");
}
// $NON-NLS-1$
text.append("{ // <");
text.append(tagToAdd);
if (isEmptyTag)
// $NON-NLS-1$
text.append("/>\n");
else
// $NON-NLS-1$
text.append(">\n");
appendToBuffer(text.toString(), fUserCode, false, customTag);
for (int i = 0; i < taglibVars.length; i++) {
if (taglibVars[i].getScope() == VariableInfo.NESTED) {
scopedVarNames.add(taglibVars[i].getVarName());
decl = taglibVars[i].getDeclarationString(fContext);
appendToBuffer(decl, fUserCode, true, customTag);
}
}
/*
* For empty tags, add the corresponding } and AT_END variables immediately.
*/
if (isEmptyTag) {
text = new StringBuffer();
// $NON-NLS-1$
text.append("} // <");
text.append(tagToAdd);
// $NON-NLS-1$
text.append("/>\n");
appendToBuffer(text.toString(), fUserCode, false, customTag);
/* Treat this as the end for empty tags */
for (int i = 0; i < taglibVars.length; i++) {
if (taglibVars[i].getScope() == VariableInfo.AT_END) {
decl = taglibVars[i].getDeclarationString(fContext);
appendToBuffer(decl, fUserCode, false, customTag);
}
}
} else {
/*
* For non-empty tags, remember the variable information
*/
fTagToVariableMap.push(tagToAdd, new RegionTags(customTag, tag, scopedVarNames));
fAtBeginScopeStack.push(tagToAdd);
}
}
Aggregations