Search in sources :

Example 51 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion 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 52 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class CSSSyntaxColoringPage method getNamedStyleAtOffset.

private String getNamedStyleAtOffset(int offset) {
    // ensure the offset is clean
    if (offset >= fDocument.getLength())
        return getNamedStyleAtOffset(fDocument.getLength() - 1);
    else if (offset < 0)
        return getNamedStyleAtOffset(0);
    IStructuredDocumentRegion documentRegion = fDocument.getFirstStructuredDocumentRegion();
    while (documentRegion != null && !documentRegion.containsOffset(offset)) {
        documentRegion = documentRegion.getNext();
    }
    if (documentRegion != null) {
        // find the ITextRegion's Context at this offset
        ITextRegion interest = documentRegion.getRegionAtCharacterOffset(offset);
        if (interest == null)
            return null;
        if (offset > documentRegion.getTextEndOffset(interest))
            return null;
        String regionContext = interest.getType();
        if (regionContext == null)
            return null;
        // find the named style (internal/selectable name) for that
        // context
        String namedStyle = (String) fContextToStyleMap.get(regionContext);
        if (namedStyle != null) {
            return namedStyle;
        }
    }
    return null;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Example 53 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class LineStyleProviderForEmbeddedCSS method prepareRegions.

public boolean prepareRegions(ITypedRegion typedRegion, int lineRequestStart, int lineRequestLength, Collection holdResults) {
    int regionStart = typedRegion.getOffset();
    int regionEnd = regionStart + typedRegion.getLength();
    IStructuredDocumentRegion wholeRegion = getDocument().getRegionAtCharacterOffset(regionStart);
    if (wholeRegion == null)
        return false;
    List tokens = null;
    int offset = typedRegion.getOffset();
    List cache = getCachedParsingResult(wholeRegion);
    if (cache == null) {
        try {
            String content = getDocument().get(typedRegion.getOffset(), typedRegion.getLength());
            // if region is an XML tag then in CSS style attribute, else in style tag
            int mode;
            if (wholeRegion.getType() == DOMRegionContext.XML_TAG_NAME) {
                mode = CSSTextParser.MODE_DECLARATION;
            } else {
                mode = CSSTextParser.MODE_STYLESHEET;
            }
            CSSTextParser parser = new CSSTextParser(mode, content);
            tokens = parser.getTokenList();
            cacheParsingResult(wholeRegion, tokens);
        } catch (BadLocationException e) {
            Logger.logException("Given a bad ITypedRegion: " + typedRegion, e);
        }
    } else {
        tokens = cache;
    }
    boolean result = false;
    if (tokens != null && 0 < tokens.size()) {
        int start = offset;
        int end = start;
        Iterator i = tokens.iterator();
        while (i.hasNext()) {
            CSSTextToken token = (CSSTextToken) i.next();
            end = start + token.length;
            int styleLength = token.length;
            /* The token starts in the region */
            if (regionStart <= start && start < regionEnd) {
                /* [239415] The region may not span the total length of the token -
					 * Adjust the length so that it doesn't overlap with other style ranges */
                if (regionEnd < end)
                    styleLength = regionEnd - start;
                addStyleRange(holdResults, getAttributeFor(token.kind), start, styleLength);
            } else /* The region starts in the token */
            if (start <= regionStart && regionStart < end) {
                /* The token may not span the total length of the region */
                if (end < regionEnd)
                    styleLength = end - regionStart;
                else
                    /* Bugzilla 282218 */
                    styleLength = regionEnd - regionStart;
                addStyleRange(holdResults, getAttributeFor(token.kind), regionStart, styleLength);
            }
            start += token.length;
        }
        result = true;
    }
    return result;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) Iterator(java.util.Iterator) CSSTextToken(org.eclipse.wst.css.core.internal.parserz.CSSTextToken) List(java.util.List) CSSTextParser(org.eclipse.wst.css.core.internal.parserz.CSSTextParser) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 54 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class StructuredAutoEditStrategyCSS method getIndentFor.

/**
 */
protected String getIndentFor(CompoundRegion region, boolean indentForNextRegion) {
    if (region == null)
        return null;
    IStructuredDocumentRegion flatNode = region.getDocumentRegion();
    if (flatNode == null)
        return null;
    try {
        if (region.getType() == CSSRegionContexts.CSS_LBRACE || region.getType() == CSSRegionContexts.CSS_DELIMITER || region.getType() == CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
            // get meanful flat node
            RegionIterator it = new RegionIterator(flatNode, region.getTextRegion());
            it.prev();
            while (it.hasPrev()) {
                ITextRegion r = it.prev();
                region = new CompoundRegion(it.getStructuredDocumentRegion(), r);
                if (region.getType() != CSSRegionContexts.CSS_S)
                    break;
            }
            flatNode = region.getDocumentRegion();
            // get indent string
            int position = flatNode.getStart();
            int line = structuredDocument.getLineOfOffset(position);
            int start = structuredDocument.getLineOffset(line);
            int end = findEndOfWhiteSpace(structuredDocument, start, position);
            return structuredDocument.get(start, end - start);
        } else if (region.getType() == CSSRegionContexts.CSS_SELECTOR_ATTRIBUTE_START || // region.getType() == CSSRegionContexts.CSS_PARENTHESIS_OPEN ||
        region.getType() == CSSRegionContexts.CSS_DECLARATION_VALUE_FUNCTION || region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) {
            int position = flatNode.getStart() + region.getStart();
            int line = structuredDocument.getLineOfOffset(position);
            int start = structuredDocument.getLineOffset(line);
            int end = findEndOfWhiteSpace(structuredDocument, start, position);
            StringBuffer buf = new StringBuffer(structuredDocument.get(start, end - start));
            position += region.getText().length();
            if (indentForNextRegion) {
                int tokenStart = findEndOfWhiteSpace(structuredDocument, position, structuredDocument.getLineOffset(line) + structuredDocument.getLineLength(line) - 1);
                if (tokenStart < structuredDocument.getLineOffset(line) + structuredDocument.getLineLength(line) - 1) {
                    position = tokenStart;
                }
            }
            while (position - end > 0) {
                // $NON-NLS-1$
                buf.append(" ");
                end++;
            }
            return buf.toString();
        } else
            // $NON-NLS-1$
            return "";
    } catch (BadLocationException excp) {
        Logger.logException(excp);
    }
    return null;
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.css.core.internal.util.RegionIterator) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 55 with IStructuredDocumentRegion

use of org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion in project webtools.sourceediting by eclipse.

the class CSSProposalGeneratorForDeclarationValue method checkSemiColon.

/**
 */
private void checkSemiColon() {
    fAppendSemiColon = false;
    ITextRegion targetRegion = fContext.getTargetRegion();
    if (targetRegion != null && targetRegion.getType() != CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
        // find trailing ":" or ";"
        // if ":" before ";" is found, add ";"
        RegionIterator iterator = fContext.getRegionIterator();
        IStructuredDocumentRegion container = iterator.getStructuredDocumentRegion();
        while (iterator.hasNext()) {
            ITextRegion region = iterator.next();
            if (iterator.getStructuredDocumentRegion() != container) {
                break;
            }
            if (region.getType() == CSSRegionContexts.CSS_DECLARATION_SEPARATOR) {
                fAppendSemiColon = true;
                break;
            }
        }
        if (!fAppendSemiColon) {
            // second chance:
            // leading IStructuredDocumentRegion is not ";"
            IStructuredDocumentRegion nextStructuredDocumentRegion = CSSUtil.findNextSignificantNode(container);
            if (CSSUtil.getStructuredDocumentRegionType(nextStructuredDocumentRegion) != CSSRegionContexts.CSS_DECLARATION_DELIMITER) {
                fAppendSemiColon = true;
            }
        }
    }
}
Also used : IStructuredDocumentRegion(org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) RegionIterator(org.eclipse.wst.css.core.internal.util.RegionIterator)

Aggregations

IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)439 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)174 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)99 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)87 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)70 List (java.util.List)40 BadLocationException (org.eclipse.jface.text.BadLocationException)39 ArrayList (java.util.ArrayList)38 Iterator (java.util.Iterator)35 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)35 Node (org.w3c.dom.Node)30 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)26 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)19 IDOMModel (org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel)19 CustomCompletionProposal (org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal)17 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)15 CMElementDeclaration (org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration)15 ICSSNode (org.eclipse.wst.css.core.internal.provisional.document.ICSSNode)14 CMNamedNodeMap (org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap)13 NodeList (org.w3c.dom.NodeList)13