Search in sources :

Example 81 with ITextRegion

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

the class JSONTextRegionFactory method createRegion.

public ITextRegion createRegion(String context, int start, int textLength, int length) {
    ITextRegion region = null;
    region = new ContextRegion(context, start, textLength, length);
    return region;
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) ContextRegion(org.eclipse.wst.sse.core.internal.parser.ContextRegion)

Example 82 with ITextRegion

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

the class JSPActionValidator method checkUnknownAttributes.

private boolean checkUnknownAttributes(IDOMElement element, CMElementDeclaration elementDecl, CMNamedNodeMap cmAttrs, IReporter reporter, IFile file, IStructuredDocument document, IStructuredDocumentRegion documentRegion) {
    boolean foundjspattribute = false;
    boolean dynamicAttributesAllowed = false;
    CMElementDeclaration decl = elementDecl;
    if (decl instanceof CMNodeWrapper)
        decl = (CMElementDeclaration) ((CMNodeWrapper) decl).getOriginNode();
    if (decl instanceof TLDElementDeclaration) {
        String dynamicAttributes = ((TLDElementDeclaration) decl).getDynamicAttributes();
        dynamicAttributesAllowed = dynamicAttributes != null ? Boolean.valueOf(dynamicAttributes).booleanValue() : false;
    }
    NamedNodeMap attrs = element.getAttributes();
    for (int i = 0; i < attrs.getLength(); i++) {
        Attr a = (Attr) attrs.item(i);
        CMAttributeDeclaration adec = (CMAttributeDeclaration) cmAttrs.getNamedItem(a.getName());
        if (adec == null) {
            /*
				 * No attr declaration was found. That is, the attr name is
				 * undefined. Disregard it includes JSP structure or this
				 * element supports dynamic attributes
				 */
            if (!hasJSPRegion(((IDOMNode) a).getNameRegion()) && fSeverityUnknownAttribute != ValidationMessage.IGNORE) {
                if (!dynamicAttributesAllowed) {
                    String msgText = NLS.bind(JSPCoreMessages.JSPDirectiveValidator_6, a.getName());
                    LocalizedMessage message = new LocalizedMessage(fSeverityUnknownAttribute, msgText, file);
                    int start = ((IDOMAttr) a).getNameRegionStartOffset();
                    int length = ((IDOMAttr) a).getNameRegionEndOffset() - start;
                    int lineNo = document.getLineOfOffset(start);
                    message.setLineNo(lineNo);
                    message.setOffset(start);
                    message.setLength(length);
                    reporter.addMessage(fMessageOriginator, message);
                }
            } else {
                foundjspattribute = true;
            }
        } else {
            if (fSeverityUnexpectedRuntimeExpression != ValidationMessage.IGNORE && adec instanceof TLDAttributeDeclaration) {
                // The attribute cannot have a runtime evaluation of an expression
                if (!isTrue(((TLDAttributeDeclaration) adec).getRtexprvalue())) {
                    IDOMAttr attr = (IDOMAttr) a;
                    if (checkRuntimeValue(attr) && !fIsELIgnored) {
                        String msg = NLS.bind(JSPCoreMessages.JSPActionValidator_1, a.getName());
                        LocalizedMessage message = new LocalizedMessage(fSeverityUnexpectedRuntimeExpression, msg, file);
                        ITextRegion region = attr.getValueRegion();
                        int start = attr.getValueRegionStartOffset();
                        int length = region != null ? region.getTextLength() : 0;
                        int lineNo = document.getLineOfOffset(start);
                        message.setLineNo(lineNo);
                        message.setOffset(start);
                        message.setLength(length);
                        reporter.addMessage(fMessageOriginator, message);
                    }
                }
            }
        }
    }
    return foundjspattribute;
}
Also used : IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) CMNodeWrapper(org.eclipse.wst.xml.core.internal.provisional.contentmodel.CMNodeWrapper) CMNamedNodeMap(org.eclipse.wst.xml.core.internal.contentmodel.CMNamedNodeMap) NamedNodeMap(org.w3c.dom.NamedNodeMap) TLDAttributeDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDAttributeDeclaration) Attr(org.w3c.dom.Attr) IDOMAttr(org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr) CMElementDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMElementDeclaration) TLDElementDeclaration(org.eclipse.jst.jsp.core.internal.contentmodel.tld.provisional.TLDElementDeclaration) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) CMAttributeDeclaration(org.eclipse.wst.xml.core.internal.contentmodel.CMAttributeDeclaration)

Example 83 with ITextRegion

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

the class JSPELValidator method validateELContent.

protected void validateELContent(ITextRegionCollection container, ITextRegion elOpenRegion, Iterator elRegions, IReporter reporter, IFile file) {
    int contentStart = elOpenRegion.getEnd();
    int contentDocStart = container.getEndOffset(elOpenRegion);
    int contentLength = container.getLength();
    int regionCount = 0;
    ITextRegion elRegion = null;
    /* Find the EL closing region, otherwise the last region will be used to calculate the EL content text */
    while (elRegions != null && elRegions.hasNext() && (regionCount++ < MAX_REGIONS)) {
        elRegion = (ITextRegion) elRegions.next();
        if (elRegion.getType() == DOMJSPRegionContexts.JSP_EL_CLOSE)
            break;
    }
    String elText = container.getFullText().substring(contentStart, (elRegion != null) ? elRegion.getStart() : (contentLength - 1));
    JSPELParser elParser = JSPELParser.createParser(elText);
    try {
        elParser.Expression();
    } catch (ParseException e) {
        int sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_EL_SYNTAX);
        if (sev != ValidationMessage.IGNORE) {
            Token curTok = e.currentToken;
            int problemStartOffset = contentDocStart + curTok.beginColumn;
            Message message = new LocalizedMessage(sev, JSPCoreMessages.JSPEL_Syntax);
            message.setOffset(problemStartOffset);
            message.setLength(curTok.endColumn - curTok.beginColumn + 1);
            message.setTargetObject(file);
            reporter.addMessage(fMessageOriginator, message);
        }
    } catch (TokenMgrError te) {
        int sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_EL_LEXER);
        if (sev != ValidationMessage.IGNORE) {
            Message message = new LocalizedMessage(IMessage.NORMAL_SEVERITY, JSPCoreMessages.JSPEL_Token);
            message.setOffset(contentDocStart);
            message.setLength(contentLength);
            message.setTargetObject(file);
            reporter.addMessage(fMessageOriginator, message);
        }
    }
}
Also used : ValidationMessage(org.eclipse.wst.sse.core.internal.validate.ValidationMessage) IMessage(org.eclipse.wst.validation.internal.provisional.core.IMessage) Message(org.eclipse.wst.validation.internal.core.Message) JSPELParser(org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParser) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Token(org.eclipse.jst.jsp.core.internal.java.jspel.Token) TokenMgrError(org.eclipse.jst.jsp.core.internal.java.jspel.TokenMgrError) ParseException(org.eclipse.jst.jsp.core.internal.java.jspel.ParseException)

Example 84 with ITextRegion

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

the class JSPELValidator method validateRegionContainer.

protected void validateRegionContainer(ITextRegionCollection container, IReporter reporter, IFile file) {
    ITextRegionCollection containerRegion = container;
    Iterator regions = containerRegion.getRegions().iterator();
    ITextRegion region = null;
    while (regions.hasNext() && !reporter.isCancelled()) {
        region = (ITextRegion) regions.next();
        String type = region.getType();
        if (type != null && region instanceof ITextRegionCollection) {
            ITextRegionCollection parentRegion = ((ITextRegionCollection) region);
            Iterator childRegions = parentRegion.getRegions().iterator();
            while (childRegions.hasNext() && !reporter.isCancelled()) {
                ITextRegion childRegion = (ITextRegion) childRegions.next();
                /* [136795] Validate everything in the EL container, not just JSP_EL_CONTENT */
                if (childRegion.getType() == DOMJSPRegionContexts.JSP_EL_OPEN)
                    validateELContent(parentRegion, childRegion, childRegions, reporter, file);
            }
        }
    }
}
Also used : ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion) Iterator(java.util.Iterator) ITextRegionCollection(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)

Example 85 with ITextRegion

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

the class JSPValidator method getAttributeValueRegion.

/**
 * @param sdr
 * @param attrName
 * @return the ITextRegion for the attribute value of the given attribute
 *         name, case sensitive, null if no matching attribute is found
 */
protected ITextRegion getAttributeValueRegion(ITextRegionCollection sdr, String attrName) {
    ITextRegion valueRegion = null;
    ITextRegionList subRegions = sdr.getRegions();
    for (int i = 0; i < subRegions.size(); i++) {
        ITextRegion subRegion = subRegions.get(i);
        if (subRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_NAME && sdr.getText(subRegion).equals(attrName)) {
            for (int j = i; j < subRegions.size(); j++) {
                subRegion = subRegions.get(j);
                if (subRegion.getType() == DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE) {
                    valueRegion = subRegion;
                    break;
                }
            }
            break;
        }
    }
    return valueRegion;
}
Also used : ITextRegionList(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList) ITextRegion(org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)

Aggregations

ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)447 ITextRegionList (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList)179 IStructuredDocumentRegion (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion)174 Iterator (java.util.Iterator)75 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)58 ArrayList (java.util.ArrayList)40 ITextRegionContainer (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionContainer)39 IndexedRegion (org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)35 IStructuredDocument (org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument)35 List (java.util.List)33 RegionIterator (org.eclipse.wst.css.core.internal.util.RegionIterator)31 BadLocationException (org.eclipse.jface.text.BadLocationException)30 RegionIterator (org.eclipse.wst.dtd.core.internal.text.RegionIterator)22 TextRegionListImpl (org.eclipse.wst.sse.core.internal.text.TextRegionListImpl)19 ITextRegionCollection (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionCollection)16 Node (org.w3c.dom.Node)16 ContextRegion (org.eclipse.wst.sse.core.internal.parser.ContextRegion)15 IOException (java.io.IOException)13 IRegion (org.eclipse.jface.text.IRegion)13 StyleRange (org.eclipse.swt.custom.StyleRange)13