Search in sources :

Example 1 with TaglibHelper

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();
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) IFile(org.eclipse.core.resources.IFile) TaglibHelper(org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) ITextRegionContainer(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IStructuredModel(org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)

Example 2 with TaglibHelper

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();
    }
}
Also used : TaglibHelper(org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper) IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ArrayList(java.util.ArrayList) CustomTag(org.eclipse.jst.jsp.core.internal.taglib.CustomTag) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IProject(org.eclipse.core.resources.IProject)

Example 3 with TaglibHelper

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();
    }
}
Also used : TaglibHelper(org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper) IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) ArrayList(java.util.ArrayList) CustomTag(org.eclipse.jst.jsp.core.internal.taglib.CustomTag) IStructuredDocument(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument) IProject(org.eclipse.core.resources.IProject)

Example 4 with TaglibHelper

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);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TaglibHelper(org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) CustomTag(org.eclipse.jst.jsp.core.internal.taglib.CustomTag) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) TaglibVariable(org.eclipse.jst.jsp.core.internal.taglib.TaglibVariable) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)4 IFile (org.eclipse.core.resources.IFile)4 TaglibHelper (org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper)4 CustomTag (org.eclipse.jst.jsp.core.internal.taglib.CustomTag)3 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)3 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)3 List (java.util.List)2 IProject (org.eclipse.core.resources.IProject)2 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 Path (org.eclipse.core.runtime.Path)1 TaglibVariable (org.eclipse.jst.jsp.core.internal.taglib.TaglibVariable)1 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)1 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)1 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)1 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)1 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)1 NodeList (org.w3c.dom.NodeList)1