use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class ExternalAnnotatorInspectionVisitor method convertToProblemDescriptors.
@NotNull
private static ProblemDescriptor[] convertToProblemDescriptors(@NotNull final List<Annotation> annotations, @NotNull final InspectionManager manager, @NotNull final PsiFile file) {
if (annotations.isEmpty()) {
return ProblemDescriptor.EMPTY_ARRAY;
}
List<ProblemDescriptor> problems = ContainerUtil.newArrayListWithCapacity(annotations.size());
IdentityHashMap<IntentionAction, LocalQuickFix> quickFixMappingCache = ContainerUtil.newIdentityHashMap();
for (Annotation annotation : annotations) {
if (annotation.getSeverity() == HighlightSeverity.INFORMATION || annotation.getStartOffset() == annotation.getEndOffset()) {
continue;
}
final PsiElement startElement = file.findElementAt(annotation.getStartOffset());
final PsiElement endElement = file.findElementAt(annotation.getEndOffset() - 1);
if (startElement == null || endElement == null) {
continue;
}
LocalQuickFix[] quickFixes = toLocalQuickFixes(annotation.getQuickFixes(), quickFixMappingCache);
ProblemDescriptor descriptor = manager.createProblemDescriptor(startElement, endElement, annotation.getMessage(), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false, quickFixes);
problems.add(descriptor);
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class XPathAnnotator method visitXPath2TypeElement.
@Override
public void visitXPath2TypeElement(XPath2TypeElement o) {
final ContextProvider contextProvider = o.getXPathContext();
checkPrefixReferences(myHolder, o, contextProvider);
if (o.getDeclaredType() == XPathType.UNKNOWN) {
final PsiReference[] references = o.getReferences();
for (PsiReference reference : references) {
if (reference instanceof XsltReferenceContributor.SchemaTypeReference) {
if (!reference.isSoft() && reference.resolve() == null) {
final String message = ((EmptyResolveMessageProvider) reference).getUnresolvedMessagePattern();
final Annotation annotation = myHolder.createErrorAnnotation(reference.getRangeInElement().shiftRight(o.getTextOffset()), message);
annotation.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
}
}
}
}
super.visitXPath2TypeElement(o);
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class XPathAnnotator method visitXPathNumber.
@Override
public void visitXPathNumber(XPathNumber number) {
if (number.getXPathVersion() == XPathVersion.V2) {
final PsiElement leaf = PsiTreeUtil.nextLeaf(number);
if (leaf != null) {
final IElementType elementType = leaf.getNode().getElementType();
if (elementType != XPathTokenTypes.STAR && XPath2TokenTypes.KEYWORDS.contains(elementType)) {
final TextRange range = TextRange.create(number.getTextRange().getStartOffset(), leaf.getTextRange().getEndOffset());
final Annotation annotation = myHolder.createErrorAnnotation(range, "Number literal must be followed by whitespace in XPath 2");
final XPathBinaryExpression expression = PsiTreeUtil.getParentOfType(number, XPathBinaryExpression.class, true);
if (expression != null) {
final XPathExpression lOperand = expression.getLOperand();
if (number == lOperand) {
final XPathExpression rOperand = expression.getROperand();
if (rOperand != null) {
final String display = number.getText() + " " + expression.getOperationSign();
final String replacement = display + " " + rOperand.getText();
assert PsiEquivalenceUtil.areElementsEquivalent(expression, XPathChangeUtil.createExpression(expression, replacement));
annotation.registerFix(new ExpressionReplacementFix(replacement, display, expression));
}
} else if (number == expression.getROperand()) {
final PsiElement next = PsiTreeUtil.getParentOfType(PsiTreeUtil.nextLeaf(expression), XPathExpression.class, true);
if (next instanceof XPathBinaryExpression) {
final XPathBinaryExpression left = (XPathBinaryExpression) next;
final XPathExpression rOperand = left.getROperand();
if (rOperand != null && lOperand != null) {
final String display = number.getText() + " " + left.getOperationSign();
final String replacement = lOperand.getText() + " " + expression.getOperationSign() + " " + display + " " + rOperand.getText();
assert PsiEquivalenceUtil.areElementsEquivalent(next, XPathChangeUtil.createExpression(next, replacement));
annotation.registerFix(new ExpressionReplacementFix(replacement, display, (XPathExpression) next));
}
}
}
}
}
}
} else {
if (((XPathNumberImpl) number).isScientificNotation()) {
myHolder.createErrorAnnotation(number, "Number literals in scientific notation are not allowed in XPath 1.0");
}
}
super.visitXPathNumber(number);
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class XPathAnnotator method markUnresolvedVariable.
private static void markUnresolvedVariable(XPathVariableReference reference, AnnotationHolder holder) {
final String referencedName = reference.getReferencedName();
// missing name is already flagged by parser
if (referencedName.length() > 0) {
final TextRange range = reference.getTextRange().shiftRight(1).grown(-1);
final Annotation ann = holder.createErrorAnnotation(range, "Unresolved variable '" + referencedName + "'");
ann.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
final VariableContext variableContext = ContextProvider.getContextProvider(reference).getVariableContext();
if (variableContext != null) {
final IntentionAction[] fixes = variableContext.getUnresolvedVariableFixes(reference);
for (IntentionAction fix : fixes) {
ann.registerFix(fix);
}
}
}
}
use of com.intellij.lang.annotation.Annotation in project intellij-community by JetBrains.
the class XPathAnnotator method checkPrefixReferences.
private static void checkPrefixReferences(AnnotationHolder holder, QNameElement element, ContextProvider myProvider) {
final PsiReference[] references = element.getReferences();
for (PsiReference reference : references) {
if (reference instanceof PrefixReference) {
final PrefixReference pr = ((PrefixReference) reference);
if (!pr.isSoft() && pr.isUnresolved()) {
final TextRange range = pr.getRangeInElement().shiftRight(pr.getElement().getTextRange().getStartOffset());
final Annotation a = holder.createErrorAnnotation(range, "Unresolved namespace prefix '" + pr.getCanonicalText() + "'");
a.setHighlightType(ProblemHighlightType.LIKE_UNKNOWN_SYMBOL);
final NamespaceContext namespaceContext = myProvider.getNamespaceContext();
final PrefixedName qName = element.getQName();
if (namespaceContext != null && qName != null) {
final IntentionAction[] fixes = namespaceContext.getUnresolvedNamespaceFixes(reference, qName.getLocalName());
for (IntentionAction fix : fixes) {
a.registerFix(fix);
}
}
}
}
}
}
Aggregations