Search in sources :

Example 1 with ZeroStructuredDocumentRegion

use of org.eclipse.jst.jsp.core.internal.util.ZeroStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class TLDCMDocumentManager method handlePreludes.

void handlePreludes() {
    IStructuredDocumentRegion anchor = new ZeroStructuredDocumentRegion(null, -1);
    fProcessIncludes = false;
    IPath currentPath = getCurrentParserPath();
    if (currentPath != null) {
        PropertyGroup[] propertyGroups = DeploymentDescriptorPropertyCache.getInstance().getPropertyGroups(currentPath);
        for (int k = 0; k < propertyGroups.length; k++) {
            IPath[] preludes = propertyGroups[k].getIncludePrelude();
            for (int i = 0; i < preludes.length; i++) {
                if (!getIncludes().contains(preludes[i]) && !preludes[i].equals(currentPath)) {
                    getIncludes().push(preludes[i]);
                    if (getParser() != null) {
                        IncludeHelper includeHelper = new IncludeHelper(anchor, getParser());
                        includeHelper.parse(preludes[i]);
                        List references = includeHelper.taglibReferences;
                        fTLDCMReferencesMap.put(preludes[i], references);
                        if (getParser() instanceof JSPCapableParser) {
                            for (int j = 0; j < references.size(); j++) {
                                TLDCMDocumentReference reference = (TLDCMDocumentReference) references.get(j);
                                // $NON-NLS-1$
                                ((JSPCapableParser) getParser()).addNestablePrefix(new TagMarker(reference.prefix + ":"));
                            }
                        }
                    } else
                        // $NON-NLS-1$ //$NON-NLS-2$
                        Logger.log(Logger.WARNING, "Warning: parser text was requested by " + getClass().getName() + " but none was available; taglib support disabled");
                    getIncludes().pop();
                }
            }
        }
    }
    fProcessIncludes = true;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) PropertyGroup(org.eclipse.jst.jsp.core.internal.contenttype.DeploymentDescriptorPropertyCache.PropertyGroup) IPath(org.eclipse.core.runtime.IPath) List(java.util.List) ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ArrayList(java.util.ArrayList) JSPCapableParser(org.eclipse.wst.sse.core.internal.ltk.parser.JSPCapableParser) TagMarker(org.eclipse.wst.sse.core.internal.ltk.parser.TagMarker) ZeroStructuredDocumentRegion(org.eclipse.jst.jsp.core.internal.util.ZeroStructuredDocumentRegion)

Example 2 with ZeroStructuredDocumentRegion

use of org.eclipse.jst.jsp.core.internal.util.ZeroStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class JSPTranslator method translate.

/**
 * the main control loop for translating the document, driven by the
 * structuredDocument nodes
 */
public void translate() {
    if (fTagToVariableMap == null) {
        fTagToVariableMap = new StackMap();
    }
    if (fAtBeginVariableMap == null) {
        fAtBeginVariableMap = new HashMap();
    }
    fAtBeginScopeStack.clear();
    // need to existing scope for top level customtags
    fAtBeginScopeStack.push("__root__");
    fTranslationProblems.clear();
    setCurrentNode(new ZeroStructuredDocumentRegion(fStructuredDocument, 0));
    translatePreludes();
    setCurrentNode(fStructuredDocument.getFirstStructuredDocumentRegion());
    while (getCurrentNode() != null && !isCanceled()) {
        // no code has been translated for this region yet
        fCodeTranslated = false;
        // basically this part will handle any "embedded" JSP containers
        if (getCurrentNode().getType() == DOMRegionContext.XML_COMMENT_TEXT || getCurrentNode().getType() == DOMRegionContext.XML_CDATA_TEXT || getCurrentNode().getType() == DOMRegionContext.UNDEFINED) {
            translateXMLCommentNode(getCurrentNode());
        } else {
            // iterate through each region in the flat node
            translateRegionContainer(getCurrentNode(), STANDARD_JSP);
        }
        // if no code was translated for this region then found "non translated code"
        if (!fCodeTranslated) {
            fFoundNonTranslatedCode = true;
        }
        if (getCurrentNode() != null)
            advanceNextNode();
    }
    writePlaceHolderForNonTranslatedCode();
    setCurrentNode(new ZeroStructuredDocumentRegion(fStructuredDocument, fStructuredDocument.getLength()));
    translateCodas();
    /*
		 * Any contents left in the map indicate start tags that never had end
		 * tags. While the '{' that is present without the matching '}' should
		 * cause a Java translation fault, that's not particularly helpful to
		 * a user who may only know how to use custom tags as tags. Ultimately
		 * unbalanced custom tags should just be reported as unbalanced tags,
		 * and unbalanced '{'/'}' only reported when the user actually
		 * unbalanced them with scriptlets.
		 */
    Iterator regionAndTaglibVariables = fTagToVariableMap.values().iterator();
    while (regionAndTaglibVariables.hasNext()) {
        RegionTags regionTag = (RegionTags) regionAndTaglibVariables.next();
        ITextRegionCollection extraStartRegion = regionTag.region;
        IJSPProblem missingEndTag = createJSPProblem(IJSPProblem.EndCustomTagMissing, IJSPProblem.F_PROBLEM_ID_LITERAL, NLS.bind(JSPCoreMessages.JSPTranslator_5, regionTag.tag.getTagName()), extraStartRegion.getStartOffset(), extraStartRegion.getEndOffset());
        fTranslationProblems.add(missingEndTag);
        StringBuffer text = new StringBuffer();
        // Account for iteration tags that have a missing end tag
        if (regionTag.tag.isIterationTag())
            doAfterBody(text, regionTag);
        // $NON-NLS-1$
        text.append("} // [</");
        text.append(regionTag.tag.getTagName());
        // $NON-NLS-1$
        text.append(">]");
        appendToBuffer(text.toString(), fUserCode, false, fStructuredDocument.getLastStructuredDocumentRegion());
    }
    fTagToVariableMap.clear();
    fAtBeginVariableMap.clear();
    /*
		 * Now do the same for jsp:useBean tags, whose contents get their own
		 * { & }
		 */
    while (!fUseBeansStack.isEmpty()) {
        // $NON-NLS-1$
        appendToBuffer("}", fUserCode, false, fStructuredDocument.getLastStructuredDocumentRegion());
        ITextRegionCollection extraStartRegion = (ITextRegionCollection) fUseBeansStack.pop();
        IJSPProblem missingEndTag = createJSPProblem(IJSPProblem.UseBeanEndTagMissing, IJSPProblem.F_PROBLEM_ID_LITERAL, NLS.bind(JSPCoreMessages.JSPTranslator_5, JSP11Namespace.ElementName.USEBEAN), extraStartRegion.getStartOffset(), extraStartRegion.getEndOffset());
        fTranslationProblems.add(missingEndTag);
    }
    buildResult(true);
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection) ZeroStructuredDocumentRegion(org.eclipse.jst.jsp.core.internal.util.ZeroStructuredDocumentRegion)

Aggregations

ZeroStructuredDocumentRegion (org.eclipse.jst.jsp.core.internal.util.ZeroStructuredDocumentRegion)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IPath (org.eclipse.core.runtime.IPath)1 PropertyGroup (org.eclipse.jst.jsp.core.internal.contenttype.DeploymentDescriptorPropertyCache.PropertyGroup)1 JSPCapableParser (org.eclipse.wst.sse.core.internal.ltk.parser.JSPCapableParser)1 TagMarker (org.eclipse.wst.sse.core.internal.ltk.parser.TagMarker)1 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)1 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)1 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)1