/*
 * Copyright 2000-2010 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.lang.java;

import com.intellij.lang.Language;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.impl.source.tree.java.ImportStatementElement;
import com.intellij.usages.UsageToPsiElementProvider;

/**
 * @author Konstantin Bulenkov
 */
public class JavaUsageToPsiElementProvider extends UsageToPsiElementProvider {
  private static final Language JAVA = Language.findLanguageByID("JAVA");
  private static final int MAX_HOPES = 17;

  @Override
  public PsiElement getAppropriateParentFrom(PsiElement element) {
    if (element.getLanguage() == JAVA) {
      int hopes = 0;
      while (hopes++ < MAX_HOPES && element != null) {
        if (element instanceof PsiField ||
            element instanceof PsiMethod ||
            element instanceof ImportStatementElement ||
            element instanceof PsiClass
          ) return element;

        element = element.getParent();
      }
    }
    return null;
  }
}

@@ -1,13 +1,10 @@
 /
-*%0A *
+/
  Copyrig
@@ -14,17 +14,17 @@
 2000-201
-0
+8
  JetBrai
@@ -36,772 +36,203 @@
 r.o.
-%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.intellij.lang.java;%0A%0Aimport com.intellij.lang.Language;%0Aimport com.intellij.psi.PsiClass;%0Aimport com.intellij.psi.PsiElement;%0Aimport com.intellij.psi.PsiField;%0Aimport com.intellij.psi.PsiMethod
+ Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.%0Apackage com.intellij.lang.java;%0A%0Aimport com.intellij.lang.Language;%0Aimport com.intellij.psi.*
 ;%0Aim
@@ -825,24 +825,78 @@
 PsiField %7C%7C%0A
+            element instanceof PsiClassInitializer %7C%7C%0A
             

add PsiClassInitializer