/*
 * Copyright 2000-2013 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.psi.impl.light;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import org.jetbrains.annotations.NonNls;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiIdentifier;
import com.intellij.psi.PsiManager;
import com.intellij.psi.PsiModifierList;
import com.intellij.psi.PsiType;
import com.intellij.psi.PsiTypeElement;
import com.intellij.psi.javadoc.PsiDocComment;
import com.intellij.psi.search.SearchScope;
import com.intellij.util.IncorrectOperationException;

public class LightField extends LightElement implements PsiField {
  private final PsiField myField;
  private final PsiClass myContainingClass;

  public LightField(@Nonnull final PsiManager manager, @Nonnull final PsiField field, @Nonnull final PsiClass containingClass) {
    super(manager, JavaLanguage.INSTANCE);
    myField = field;
    myContainingClass = containingClass;
  }

  @Override
  public void setInitializer(@Nullable final PsiExpression initializer) throws IncorrectOperationException {
    throw new IncorrectOperationException("Not supported");
  }

  @Nonnull
  @Override
  public SearchScope getUseScope() {
    return myField.getUseScope();
  }

  @Override
  public String getName() {
    return myField.getName();
  }

  @Nonnull
  @Override
  public PsiIdentifier getNameIdentifier() {
    return myField.getNameIdentifier();
  }

  @Override
  public PsiDocComment getDocComment() {
    return myField.getDocComment();
  }

  @Override
  public boolean isDeprecated() {
    return myField.isDeprecated();
  }

  @Override
  public PsiClass getContainingClass() {
    return myContainingClass;
  }

  @Nonnull
  @Override
  public PsiType getType() {
    return myField.getType();
  }

  @Override
  public PsiTypeElement getTypeElement() {
    return myField.getTypeElement();
  }

  @Override
  public PsiExpression getInitializer() {
    return myField.getInitializer();
  }

  @Override
  public boolean hasInitializer() {
    return myField.hasInitializer();
  }

  @Override
  public void normalizeDeclaration() throws IncorrectOperationException {
    throw new IncorrectOperationException("Not supported");
  }

  @Override
  public Object computeConstantValue() {
    return myField.computeConstantValue();
  }

  @Override
  public PsiElement setName(@NonNls @Nonnull final String name) throws IncorrectOperationException {
    throw new IncorrectOperationException("Not supported");
  }

  @Override
  public PsiModifierList getModifierList() {
    return myField.getModifierList();
  }

  @Override
  public boolean hasModifierProperty(@NonNls @Nonnull final String name) {
    return myField.hasModifierProperty(name);
  }

  @Override
  public String getText() {
    return myField.getText();
  }

  @Override
  public PsiElement copy() {
    return new LightField(myManager, (PsiField)myField.copy(), myContainingClass);
  }

  @Override
  public TextRange getTextRange() {
    return new TextRange(-1, -1);
  }

  @Override
  public boolean isValid() {
    return myContainingClass.isValid();
  }

  @Override
  public String toString() {
    return "PsiField:" + getName();
  }
}

@@ -636,117 +636,8 @@
 t;%0A%0A
-import javax.annotation.Nonnull;%0Aimport javax.annotation.Nullable;%0A%0Aimport org.jetbrains.annotations.NonNls;%0A
 impo
@@ -744,24 +744,17 @@
 lij.psi.
-PsiClass
+*
 ;%0Aimport
@@ -771,22 +771,33 @@
 lij.psi.
-PsiEle
+javadoc.PsiDocCom
 ment;%0Aim
@@ -822,389 +822,242 @@
 psi.
-PsiExpression;%0Aimport com.intellij.psi.PsiField;%0Aimport com.intellij.psi.PsiIdentifier;%0Aimport com.intellij.psi.PsiManager;%0Aimport com.intellij.psi.PsiModifierList;%0Aimport com.intellij.psi.PsiType;%0Aimport com.intellij.psi.PsiTypeElement
+search.SearchScope;%0Aimport com.intellij.util.IncorrectOperationException;%0Aimport consulo.annotation.access.RequiredReadAction;%0Aimport org.jetbrains.annotations.NonNls
 ;%0A
+%0A
 import 
-com.intellij.psi.javadoc.PsiDocComment;%0Aimport com.intellij.psi.search.SearchScope;%0Aimport com.intellij.util.IncorrectOperationException
+javax.annotation.Nonnull;%0Aimport javax.annotation.Nullable
 ;%0A%0Ap
@@ -3211,32 +3211,54 @@
 rty(name);%0A  %7D%0A%0A
+  @RequiredReadAction%0A
   @Override%0A  pu
@@ -3437,32 +3437,65 @@
 ingClass);%0A  %7D%0A%0A
+  @RequiredReadAction%0A  @Nonnull%0A
   @Override%0A  pu
@@ -3537,20 +3537,27 @@
  return 
-new 
+myField.get
 TextRang
@@ -3562,14 +3562,8 @@
 nge(
--1, -1
 );%0A 

fix creating invalid text range