Search in sources :

Example 1 with TaglibVariable

use of org.eclipse.jst.jsp.core.internal.taglib.TaglibVariable in project webtools.sourceediting by eclipse.

the class JSPTranslator method translateAttributeDirectiveAttributes.

private void translateAttributeDirectiveAttributes(Iterator regions) {
    ITextRegion r = null;
    String attrName, attrValue;
    // $NON-NLS-1$ // the default class...
    String varType = "java.lang.String";
    String varName = null;
    // $NON-NLS-1$
    String description = "";
    boolean isFragment = false;
    // iterate all attributes
    while (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() != DOMJSPRegionContexts.JSP_CLOSE) {
        attrName = attrValue = null;
        if (r.getType().equals(DOMRegionContext.XML_TAG_ATTRIBUTE_NAME)) {
            attrName = getCurrentNode().getText(r).trim();
            if (attrName.length() > 0) {
                if (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_EQUALS) {
                    if (regions.hasNext() && (r = (ITextRegion) regions.next()) != null && r.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
                        attrValue = StringUtils.strip(getCurrentNode().getText(r));
                    }
                // has equals, but no value?
                }
                if (attrName.equals(JSP11Namespace.ATTR_NAME_TYPE)) {
                    varType = attrValue;
                } else if (attrName.equals(JSP20Namespace.ATTR_NAME_FRAGMENT)) {
                    isFragment = Boolean.valueOf(attrValue).booleanValue();
                } else if (attrName.equals(JSP11Namespace.ATTR_NAME_NAME)) {
                    varName = attrValue;
                } else if (attrName.equals(JSP20Namespace.ATTR_NAME_DESCRIPTION)) {
                    description = attrValue;
                }
            }
        }
    }
    if (varName != null) {
        if (isFragment) {
            // 2.0:JSP.8.5.2
            // $NON-NLS-1$
            varType = "javax.servlet.jsp.tagext.JspFragment";
        }
        // $NON-NLS-1$
        String declaration = new TaglibVariable(varType, varName, "", description).getDeclarationString(true, fContext, TaglibVariable.M_PRIVATE);
        appendToBuffer(declaration, fUserDeclarations, false, fCurrentNode);
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) TaglibVariable(org.eclipse.jst.jsp.core.internal.taglib.TaglibVariable)

Example 2 with TaglibVariable

use of org.eclipse.jst.jsp.core.internal.taglib.TaglibVariable in project webtools.sourceediting by eclipse.

the class JSPTranslator method addEndTagVariable.

private void addEndTagVariable(String tagToAdd, ITextRegionCollection customTag) {
    IFile f = getFile();
    if (f == null || !f.exists())
        return;
    // $NON-NLS-1$
    String decl = "";
    RegionTags regionTag = (RegionTags) fTagToVariableMap.pop(tagToAdd);
    if (regionTag != null) {
        // even an empty array will indicate a need for a closing brace
        TaglibVariable[] taglibVars = regionTag.tag.getTagVariables();
        StringBuffer text = new StringBuffer();
        if (regionTag.tag.isIterationTag())
            doAfterBody(text, regionTag);
        // $NON-NLS-1$
        text.append("} // </");
        text.append(tagToAdd);
        // $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.AT_END) {
                decl = taglibVars[i].getDeclarationString(fContext);
                appendToBuffer(decl, fUserCode, true, customTag);
            }
        }
        fAtBeginVariableMap.remove(fAtBeginScopeStack.pop());
    } else {
        /*
			 * Since something should have been in the map because of a
			 * start tag, its absence now means an unbalanced end tag.
			 * Extras will be checked later to flag unbalanced start tags.
			 */
        IJSPProblem missingStartTag = createJSPProblem(IJSPProblem.StartCustomTagMissing, IJSPProblem.F_PROBLEM_ID_LITERAL, NLS.bind(JSPCoreMessages.JSPTranslator_4, tagToAdd), customTag.getStartOffset(), customTag.getEndOffset());
        fTranslationProblems.add(missingStartTag);
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) TaglibVariable(org.eclipse.jst.jsp.core.internal.taglib.TaglibVariable) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint)

Example 3 with TaglibVariable

use of org.eclipse.jst.jsp.core.internal.taglib.TaglibVariable 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

TaglibVariable (org.eclipse.jst.jsp.core.internal.taglib.TaglibVariable)3 IFile (org.eclipse.core.resources.IFile)2 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 CustomTag (org.eclipse.jst.jsp.core.internal.taglib.CustomTag)1 TaglibHelper (org.eclipse.jst.jsp.core.internal.taglib.TaglibHelper)1 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)1 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)1