001    /*
002     * Copyright 2010-2013 JetBrains s.r.o.
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    
017    package org.jetbrains.jet.asJava.light;
018    
019    import com.intellij.lang.java.JavaLanguage;
020    import com.intellij.openapi.util.TextRange;
021    import com.intellij.psi.*;
022    import com.intellij.psi.impl.light.LightElement;
023    import com.intellij.psi.javadoc.PsiDocComment;
024    import com.intellij.psi.search.SearchScope;
025    import com.intellij.util.IncorrectOperationException;
026    import org.jetbrains.annotations.NonNls;
027    import org.jetbrains.annotations.NotNull;
028    import org.jetbrains.annotations.Nullable;
029    import org.jetbrains.jet.lang.psi.JetProperty;
030    import org.jetbrains.jet.lang.resolve.java.jetAsJava.KotlinLightElement;
031    
032    // Copy of com.intellij.psi.impl.light.LightField
033    @SuppressWarnings("UnnecessaryFinalOnLocalVariableOrParameter")
034    public class KotlinLightField extends LightElement implements PsiField, KotlinLightElement<JetProperty, PsiField> {
035        private final JetProperty myOriginalProperty;
036        private final PsiField myField;
037        private final PsiClass myContainingClass;
038    
039        public KotlinLightField(
040                @NotNull final PsiManager manager,
041                @NotNull final JetProperty originalProperty,
042                @NotNull final PsiField field,
043                @NotNull final PsiClass containingClass
044        ) {
045            super(manager, JavaLanguage.INSTANCE);
046            myOriginalProperty = originalProperty;
047            myField = field;
048            myContainingClass = containingClass;
049        }
050    
051        @Override
052        public void setInitializer(@Nullable final PsiExpression initializer) throws IncorrectOperationException {
053            throw new IncorrectOperationException("Not supported");
054        }
055    
056        @NotNull
057        @Override
058        public SearchScope getUseScope() {
059            return myField.getUseScope();
060        }
061    
062        @Override
063        public String getName() {
064            return myField.getName();
065        }
066    
067        @NotNull
068        @Override
069        public PsiIdentifier getNameIdentifier() {
070            return myField.getNameIdentifier();
071        }
072    
073        @Override
074        public PsiDocComment getDocComment() {
075            return myField.getDocComment();
076        }
077    
078        @Override
079        public boolean isDeprecated() {
080            return myField.isDeprecated();
081        }
082    
083        @Override
084        public PsiClass getContainingClass() {
085            return myContainingClass;
086        }
087    
088        @NotNull
089        @Override
090        public PsiType getType() {
091            return myField.getType();
092        }
093    
094        @Override
095        public PsiTypeElement getTypeElement() {
096            return myField.getTypeElement();
097        }
098    
099        @Override
100        public PsiExpression getInitializer() {
101            return myField.getInitializer();
102        }
103    
104        @Override
105        public boolean hasInitializer() {
106            return myField.hasInitializer();
107        }
108    
109        @Override
110        public void normalizeDeclaration() throws IncorrectOperationException {
111            throw new IncorrectOperationException("Not supported");
112        }
113    
114        @Override
115        public Object computeConstantValue() {
116            return myField.computeConstantValue();
117        }
118    
119        @Override
120        public PsiElement setName(@NonNls @NotNull final String name) throws IncorrectOperationException {
121            throw new IncorrectOperationException("Not supported");
122        }
123    
124        @Override
125        public PsiModifierList getModifierList() {
126            return myField.getModifierList();
127        }
128    
129        @Override
130        public boolean hasModifierProperty(@NonNls @NotNull final String name) {
131            return myField.hasModifierProperty(name);
132        }
133    
134        @Override
135        public String getText() {
136            return myField.getText();
137        }
138    
139        @NotNull
140        @Override
141        public PsiElement copy() {
142            return new KotlinLightField(myManager, myOriginalProperty, (PsiField)myField.copy(), myContainingClass);
143        }
144    
145        @Override
146        public TextRange getTextRange() {
147            return new TextRange(-1, -1);
148        }
149    
150        @Override
151        public boolean isValid() {
152            return myContainingClass.isValid();
153        }
154    
155        @Override
156        public String toString() {
157            return "PsiField:" + getName();
158        }
159    
160        @NotNull
161        @Override
162        public JetProperty getOrigin() {
163            return myOriginalProperty;
164        }
165    
166        @NotNull
167        @Override
168        public PsiField getDelegate() {
169            return myField;
170        }
171    
172        @NotNull
173        @Override
174        public PsiElement getNavigationElement() {
175            return getOrigin();
176        }
177    }