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