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.
21 package com
.intellij
.refactoring
.extractclass
.usageInfo
;
23 import com
.intellij
.openapi
.project
.Project
;
24 import com
.intellij
.psi
.*;
25 import com
.intellij
.psi
.search
.GlobalSearchScope
;
26 import com
.intellij
.refactoring
.util
.FixableUsageInfo
;
27 import com
.intellij
.util
.IncorrectOperationException
;
29 public class BindJavadocReference
extends FixableUsageInfo
{
30 private final String myQualifiedName
;
31 private final String myFieldName
;
33 public BindJavadocReference(final PsiElement element
, final String qualifiedName
, final String fieldName
) {
35 myQualifiedName
= qualifiedName
;
36 myFieldName
= fieldName
;
39 public void fixUsage() throws IncorrectOperationException
{
40 final PsiElement element
= getElement();
41 if (element
!= null && element
.isValid()) {
42 final Project project
= element
.getProject();
43 final PsiClass psiClass
= JavaPsiFacade
.getInstance(project
).findClass(myQualifiedName
, GlobalSearchScope
.projectScope(project
));
44 if (psiClass
!= null) {
45 final PsiField field
= psiClass
.findFieldByName(myFieldName
, false);
47 final PsiReference reference
= element
.getReference();
48 if (reference
!= null) {
49 reference
.bindToElement(field
);