2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.util
.xml
.highlighting
;
18 import com
.intellij
.codeInsight
.daemon
.impl
.analysis
.XmlHighlightVisitor
;
19 import com
.intellij
.codeInspection
.LocalQuickFix
;
20 import com
.intellij
.lang
.annotation
.HighlightSeverity
;
21 import com
.intellij
.psi
.PsiReference
;
22 import com
.intellij
.psi
.PsiElement
;
23 import com
.intellij
.psi
.xml
.XmlAttributeValue
;
24 import com
.intellij
.util
.xml
.GenericDomValue
;
25 import com
.intellij
.openapi
.util
.TextRange
;
26 import com
.intellij
.openapi
.util
.Pair
;
27 import org
.jetbrains
.annotations
.NotNull
;
32 class DomElementResolveProblemDescriptorImpl
extends DomElementProblemDescriptorImpl
implements DomElementResolveProblemDescriptor
{
33 @NotNull private final PsiReference myReference
;
35 public DomElementResolveProblemDescriptorImpl(@NotNull final GenericDomValue domElement
, @NotNull final PsiReference reference
, LocalQuickFix
... quickFixes
) {
36 super(domElement
, XmlHighlightVisitor
.getErrorDescription(reference
), HighlightSeverity
.ERROR
, quickFixes
);
37 myReference
= reference
;
41 public PsiReference
getPsiReference() {
46 public GenericDomValue
getDomElement() {
47 return (GenericDomValue
)super.getDomElement();
51 protected Pair
<TextRange
, PsiElement
> computeProblemRange() {
52 final PsiReference reference
= myReference
;
53 PsiElement element
= reference
.getElement();
54 if (element
instanceof XmlAttributeValue
&& element
.getTextLength() == 0) return NO_PROBLEM
;
56 final TextRange referenceRange
= reference
.getRangeInElement();
57 if (referenceRange
.isEmpty()) {
58 return element
instanceof XmlAttributeValue
59 ? Pair
.create(TextRange
.from(referenceRange
.getStartOffset() - 1, 2), element
)
60 : Pair
.create(TextRange
.from(referenceRange
.getStartOffset(), 1), element
);
62 return Pair
.create(referenceRange
, element
);