use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class RegExpAnnotator method visitRegExpChar.
@Override
public void visitRegExpChar(final RegExpChar ch) {
final PsiElement child = ch.getFirstChild();
final IElementType type = child.getNode().getElementType();
if (type == StringEscapesTokenTypes.INVALID_CHARACTER_ESCAPE_TOKEN) {
myHolder.createErrorAnnotation(ch, "Illegal/unsupported escape sequence");
return;
} else if (type == RegExpTT.BAD_HEX_VALUE) {
myHolder.createErrorAnnotation(ch, "Illegal hexadecimal escape sequence");
return;
} else if (type == RegExpTT.BAD_OCT_VALUE) {
myHolder.createErrorAnnotation(ch, "Illegal octal escape sequence");
return;
} else if (type == StringEscapesTokenTypes.INVALID_UNICODE_ESCAPE_TOKEN) {
myHolder.createErrorAnnotation(ch, "Illegal unicode escape sequence");
return;
}
final String text = ch.getUnescapedText();
if (type == RegExpTT.ESC_CTRL_CHARACTER && text.equals("\\b") && !myLanguageHosts.supportsLiteralBackspace(ch)) {
myHolder.createErrorAnnotation(ch, "Illegal/unsupported escape sequence");
}
if (text.startsWith("\\") && myLanguageHosts.isRedundantEscape(ch, text)) {
final ASTNode astNode = ch.getNode().getFirstChildNode();
if (astNode != null && astNode.getElementType() == RegExpTT.REDUNDANT_ESCAPE) {
final Annotation a = myHolder.createWeakWarningAnnotation(ch, "Redundant character escape");
registerFix(a, new RemoveRedundantEscapeAction(ch));
}
}
final RegExpChar.Type charType = ch.getType();
if (charType == RegExpChar.Type.HEX || charType == RegExpChar.Type.UNICODE) {
if (ch.getValue() == -1) {
myHolder.createErrorAnnotation(ch, "Illegal unicode escape sequence");
return;
}
if (text.charAt(text.length() - 1) == '}') {
if (!myLanguageHosts.supportsExtendedHexCharacter(ch)) {
myHolder.createErrorAnnotation(ch, "This hex character syntax is not supported in this regex dialect");
}
}
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class RegExpAnnotator method visitPosixBracketExpression.
@Override
public void visitPosixBracketExpression(RegExpPosixBracketExpression posixBracketExpression) {
final String className = posixBracketExpression.getClassName();
if (!POSIX_CHARACTER_CLASSES.contains(className)) {
final ASTNode node = posixBracketExpression.getNode().findChildByType(RegExpTT.NAME);
if (node != null) {
final Annotation annotation = myHolder.createErrorAnnotation(node, "Unknown POSIX character class");
annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
}
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class RegExpAnnotator method visitRegExpProperty.
@Override
public void visitRegExpProperty(RegExpProperty property) {
final ASTNode category = property.getCategoryNode();
if (category == null) {
return;
}
if (!myLanguageHosts.isValidCategory(category.getPsi(), category.getText())) {
final Annotation a = myHolder.createErrorAnnotation(category, "Unknown character category");
a.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class RegExpAnnotator method visitRegExpNamedGroupRef.
@Override
public void visitRegExpNamedGroupRef(RegExpNamedGroupRef groupRef) {
if (!myLanguageHosts.supportsNamedGroupRefSyntax(groupRef)) {
myHolder.createErrorAnnotation(groupRef, "This named group reference syntax is not supported in this regex dialect");
return;
}
if (groupRef.getGroupName() == null) {
return;
}
final RegExpGroup group = groupRef.resolve();
if (group == null) {
final ASTNode node = groupRef.getNode().findChildByType(RegExpTT.NAME);
if (node != null) {
final Annotation a = myHolder.createErrorAnnotation(node, "Unresolved named group reference");
a.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
}
} else if (PsiTreeUtil.isAncestor(group, groupRef, true)) {
myHolder.createWarningAnnotation(groupRef, "Group reference is nested into the named group it refers to");
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class InspectionValidatorWrapper method runXmlFileSchemaValidation.
private Map<ProblemDescriptor, HighlightDisplayLevel> runXmlFileSchemaValidation(@NotNull XmlFile xmlFile) {
final AnnotationHolderImpl holder = new AnnotationHolderImpl(new AnnotationSession(xmlFile));
final List<ExternalAnnotator> annotators = ExternalLanguageAnnotators.allForFile(StdLanguages.XML, xmlFile);
for (ExternalAnnotator<?, ?> annotator : annotators) {
processAnnotator(xmlFile, holder, annotator);
}
if (!holder.hasAnnotations())
return Collections.emptyMap();
Map<ProblemDescriptor, HighlightDisplayLevel> problemsMap = new LinkedHashMap<>();
for (final Annotation annotation : holder) {
final HighlightInfo info = HighlightInfo.fromAnnotation(annotation);
if (info.getSeverity() == HighlightSeverity.INFORMATION)
continue;
final PsiElement startElement = xmlFile.findElementAt(info.startOffset);
final PsiElement endElement = info.startOffset == info.endOffset ? startElement : xmlFile.findElementAt(info.endOffset - 1);
if (startElement == null || endElement == null)
continue;
final ProblemDescriptor descriptor = myInspectionManager.createProblemDescriptor(startElement, endElement, info.getDescription(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false);
final HighlightDisplayLevel level = info.getSeverity() == HighlightSeverity.ERROR ? HighlightDisplayLevel.ERROR : HighlightDisplayLevel.WARNING;
problemsMap.put(descriptor, level);
}
return problemsMap;
}
Aggregations