Search in sources :

Example 1 with Token

use of org.eclipse.jst.jsp.core.internal.java.jspel.Token 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 2 with Token

use of org.eclipse.jst.jsp.core.internal.java.jspel.Token in project webtools.sourceediting by eclipse.

the class JSPELContentAssistProcessor method getPrefix.

protected String getPrefix(int relativePosition, String elText) {
    java.io.StringReader reader = new java.io.StringReader(elText);
    JSPELParserTokenManager scanner = new JSPELParserTokenManager(new SimpleCharStream(reader, 1, 1));
    Token curToken = null, lastIdentifier = null;
    while (JSPELParserConstants.EOF != (curToken = scanner.getNextToken()).kind) {
        if (JSPELParserConstants.COLON == curToken.kind && curToken.endColumn == relativePosition && null != lastIdentifier) {
            return (lastIdentifier.image);
        }
        if (JSPELParserConstants.IDENTIFIER == curToken.kind) {
            lastIdentifier = curToken;
        } else {
            lastIdentifier = null;
        }
    }
    return null;
}
Also used : SimpleCharStream(org.eclipse.jst.jsp.core.internal.java.jspel.SimpleCharStream) Token(org.eclipse.jst.jsp.core.internal.java.jspel.Token) JSPELParserTokenManager(org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParserTokenManager)

Example 3 with Token

use of org.eclipse.jst.jsp.core.internal.java.jspel.Token in project webtools.sourceediting by eclipse.

the class JSPELValidator method validateXMLNode.

protected void validateXMLNode(ITextRegionCollection container, ITextRegion region, IReporter reporter, IFile file) {
    String elText = container.getText(region);
    JSPELParser elParser = JSPELParser.createParser(elText);
    int contentStart = container.getStartOffset(region);
    int contentLength = container.getLength();
    try {
        elParser.Expression();
    } catch (ParseException e) {
        int sev = getMessageSeverity(JSPCorePreferenceNames.VALIDATION_EL_SYNTAX);
        if (sev != ValidationMessage.IGNORE) {
            Token curTok = e.currentToken;
            int problemStartOffset = contentStart + 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(contentStart);
            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) 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 4 with Token

use of org.eclipse.jst.jsp.core.internal.java.jspel.Token in project webtools.sourceediting by eclipse.

the class JSPELCompletionProposalComputer method getPrefix.

/**
 * <p>Gets the EL prefix from the relative position and the given EL text</p>
 *
 * @param relativePosition
 * @param elText
 * @return
 */
private String getPrefix(int relativePosition, String elText) {
    java.io.StringReader reader = new java.io.StringReader(elText);
    JSPELParserTokenManager scanner = new JSPELParserTokenManager(new SimpleCharStream(reader, 1, 1));
    Token curToken = null, lastIdentifier = null;
    while (JSPELParserConstants.EOF != (curToken = scanner.getNextToken()).kind) {
        if (JSPELParserConstants.COLON == curToken.kind && curToken.endColumn == relativePosition && null != lastIdentifier) {
            return (lastIdentifier.image);
        }
        if (JSPELParserConstants.IDENTIFIER == curToken.kind) {
            lastIdentifier = curToken;
        } else {
            lastIdentifier = null;
        }
    }
    return null;
}
Also used : SimpleCharStream(org.eclipse.jst.jsp.core.internal.java.jspel.SimpleCharStream) Token(org.eclipse.jst.jsp.core.internal.java.jspel.Token) JSPELParserTokenManager(org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParserTokenManager)

Aggregations

Token (org.eclipse.jst.jsp.core.internal.java.jspel.Token)4 JSPELParser (org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParser)2 JSPELParserTokenManager (org.eclipse.jst.jsp.core.internal.java.jspel.JSPELParserTokenManager)2 ParseException (org.eclipse.jst.jsp.core.internal.java.jspel.ParseException)2 SimpleCharStream (org.eclipse.jst.jsp.core.internal.java.jspel.SimpleCharStream)2 TokenMgrError (org.eclipse.jst.jsp.core.internal.java.jspel.TokenMgrError)2 ValidationMessage (org.eclipse.wst.sse.core.internal.validate.ValidationMessage)2 Message (org.eclipse.wst.validation.internal.core.Message)2 IMessage (org.eclipse.wst.validation.internal.provisional.core.IMessage)2 ITextRegion (org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion)1