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;
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.JetDeclaration;
030    
031    // Copied from com.intellij.psi.impl.light.LightField
032    public abstract class KotlinLightField<T extends JetDeclaration, D extends PsiField> extends LightElement
033            implements PsiField, KotlinLightElement<T, D> {
034        private final T origin;
035        private final D delegate;
036        private final PsiClass containingClass;
037    
038        public KotlinLightField(@NotNull PsiManager manager, @NotNull T origin, @NotNull D delegate, @NotNull PsiClass containingClass) {
039            super(manager, JavaLanguage.INSTANCE);
040            this.origin = origin;
041            this.delegate = delegate;
042            this.containingClass = containingClass;
043        }
044    
045        @NotNull
046        @Override
047        public abstract KotlinLightField<T, D> copy();
048    
049        @Override
050        public void setInitializer(@Nullable PsiExpression initializer) throws IncorrectOperationException {
051            throw new IncorrectOperationException("Not supported");
052        }
053    
054        @NotNull
055        @Override
056        public SearchScope getUseScope() {
057            return delegate.getUseScope();
058        }
059    
060        @Override
061        public String getName() {
062            return delegate.getName();
063        }
064    
065        @NotNull
066        @Override
067        public PsiIdentifier getNameIdentifier() {
068            return delegate.getNameIdentifier();
069        }
070    
071        @Override
072        public PsiDocComment getDocComment() {
073            return delegate.getDocComment();
074        }
075    
076        @Override
077        public boolean isDeprecated() {
078            return delegate.isDeprecated();
079        }
080    
081        @Override
082        public PsiClass getContainingClass() {
083            return containingClass;
084        }
085    
086        @NotNull
087        @Override
088        public PsiType getType() {
089            return delegate.getType();
090        }
091    
092        @Override
093        public PsiTypeElement getTypeElement() {
094            return delegate.getTypeElement();
095        }
096    
097        @Override
098        public PsiExpression getInitializer() {
099            return delegate.getInitializer();
100        }
101    
102        @Override
103        public boolean hasInitializer() {
104            return delegate.hasInitializer();
105        }
106    
107        @Override
108        public void normalizeDeclaration() throws IncorrectOperationException {
109            throw new IncorrectOperationException("Not supported");
110        }
111    
112        @Override
113        public Object computeConstantValue() {
114            return delegate.computeConstantValue();
115        }
116    
117        @Override
118        public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException {
119            throw new IncorrectOperationException("Not supported");
120        }
121    
122        @Override
123        public PsiModifierList getModifierList() {
124            return delegate.getModifierList();
125        }
126    
127        @Override
128        public boolean hasModifierProperty(@NonNls @NotNull String name) {
129            return delegate.hasModifierProperty(name);
130        }
131    
132        @Override
133        public String getText() {
134            return delegate.getText();
135        }
136    
137        @Override
138        public TextRange getTextRange() {
139            return new TextRange(-1, -1);
140        }
141    
142        @Override
143        public boolean isValid() {
144            return containingClass.isValid();
145        }
146    
147        @Override
148        public String toString() {
149            return "PsiField:" + getName();
150        }
151    
152        @NotNull
153        @Override
154        public T getOrigin() {
155            return origin;
156        }
157    
158        @NotNull
159        @Override
160        public D getDelegate() {
161            return delegate;
162        }
163    
164        @NotNull
165        @Override
166        public PsiElement getNavigationElement() {
167            return getOrigin();
168        }
169    }