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);
}
}
}
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;
}
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);
}
}
}
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;
}
Aggregations