IDEADEV-26652
[fedora-idea.git] / plugins / IntelliLang / src / org / intellij / plugins / intelliLang / util / StringLiteralReference.java
blob1e2c8596a85611c14be4eff3b3d89b3a5809e64d
1 /*
2 * Copyright 2006 Sascha Weinreuter
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 org.intellij.plugins.intelliLang.util;
18 import com.intellij.openapi.util.TextRange;
19 import com.intellij.psi.ElementManipulators;
20 import com.intellij.psi.PsiElement;
21 import com.intellij.psi.PsiLiteralExpression;
22 import com.intellij.psi.PsiReference;
23 import com.intellij.util.IncorrectOperationException;
24 import org.jetbrains.annotations.Nullable;
25 import org.jetbrains.annotations.NotNull;
27 /**
28 * Base class for references in String literals.
30 public abstract class StringLiteralReference implements PsiReference {
31 protected final PsiLiteralExpression myValue;
33 public StringLiteralReference(PsiLiteralExpression value) {
34 myValue = value;
37 public PsiElement getElement() {
38 return myValue;
41 public TextRange getRangeInElement() {
42 return ElementManipulators.getValueTextRange(myValue);
45 public String getCanonicalText() {
46 return myValue.getText();
49 public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
50 return myValue;
53 public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
54 return myValue;
57 public boolean isReferenceTo(PsiElement element) {
58 return resolve() == element;
61 @Nullable
62 protected String getValue() {
63 return (String)myValue.getValue();