001 /* 002 * Copyright 2010-2015 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.kotlin.asJava; 018 019 import com.intellij.lang.Language; 020 import com.intellij.lang.java.JavaLanguage; 021 import com.intellij.openapi.util.TextRange; 022 import com.intellij.psi.*; 023 import com.intellij.psi.impl.light.LightElement; 024 import com.intellij.psi.javadoc.PsiDocComment; 025 import com.intellij.psi.search.SearchScope; 026 import com.intellij.util.IncorrectOperationException; 027 import org.jetbrains.annotations.NonNls; 028 import org.jetbrains.annotations.NotNull; 029 import org.jetbrains.annotations.Nullable; 030 import org.jetbrains.kotlin.idea.JetLanguage; 031 import org.jetbrains.kotlin.psi.JetDeclaration; 032 033 // Copied from com.intellij.psi.impl.light.LightField 034 public abstract class KotlinLightField<T extends JetDeclaration, D extends PsiField> extends LightElement 035 implements PsiField, KotlinLightElement<T, D> { 036 private final T origin; 037 private final D delegate; 038 private final PsiClass containingClass; 039 040 public KotlinLightField(@NotNull PsiManager manager, @NotNull T origin, @NotNull D delegate, @NotNull PsiClass containingClass) { 041 super(manager, JavaLanguage.INSTANCE); 042 this.origin = origin; 043 this.delegate = delegate; 044 this.containingClass = containingClass; 045 } 046 047 @NotNull 048 @Override 049 public abstract KotlinLightField<T, D> copy(); 050 051 @Override 052 public void setInitializer(@Nullable PsiExpression initializer) throws IncorrectOperationException { 053 throw new IncorrectOperationException("Not supported"); 054 } 055 056 @NotNull 057 @Override 058 public SearchScope getUseScope() { 059 return origin.getUseScope(); 060 } 061 062 @Override 063 public String getName() { 064 return delegate.getName(); 065 } 066 067 @NotNull 068 @Override 069 public PsiIdentifier getNameIdentifier() { 070 return delegate.getNameIdentifier(); 071 } 072 073 @Override 074 public PsiDocComment getDocComment() { 075 return delegate.getDocComment(); 076 } 077 078 @Override 079 public boolean isDeprecated() { 080 return delegate.isDeprecated(); 081 } 082 083 @Override 084 public PsiClass getContainingClass() { 085 return containingClass; 086 } 087 088 @NotNull 089 @Override 090 public PsiType getType() { 091 return delegate.getType(); 092 } 093 094 @Override 095 public PsiTypeElement getTypeElement() { 096 return delegate.getTypeElement(); 097 } 098 099 @Override 100 public PsiExpression getInitializer() { 101 return delegate.getInitializer(); 102 } 103 104 @Override 105 public boolean hasInitializer() { 106 return delegate.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 delegate.computeConstantValue(); 117 } 118 119 @Override 120 public PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException { 121 throw new IncorrectOperationException("Not supported"); 122 } 123 124 @Override 125 public PsiModifierList getModifierList() { 126 return delegate.getModifierList(); 127 } 128 129 @Override 130 public boolean hasModifierProperty(@NonNls @NotNull String name) { 131 return delegate.hasModifierProperty(name); 132 } 133 134 @Override 135 public String getText() { 136 return delegate.getText(); 137 } 138 139 @Override 140 public TextRange getTextRange() { 141 return new TextRange(-1, -1); 142 } 143 144 @Override 145 public boolean isValid() { 146 return containingClass.isValid(); 147 } 148 149 @Override 150 public String toString() { 151 return "PsiField:" + getName(); 152 } 153 154 @NotNull 155 @Override 156 public T getOrigin() { 157 return origin; 158 } 159 160 @NotNull 161 @Override 162 public D getDelegate() { 163 return delegate; 164 } 165 166 @NotNull 167 @Override 168 public PsiElement getNavigationElement() { 169 return getOrigin(); 170 } 171 172 @NotNull 173 @Override 174 public Language getLanguage() { 175 return JetLanguage.INSTANCE; 176 } 177 178 @Override 179 public boolean isEquivalentTo(PsiElement another) { 180 if (another instanceof KotlinLightField && origin.isEquivalentTo(((KotlinLightField) another).getOrigin())) { 181 return true; 182 } 183 return super.isEquivalentTo(another); 184 } 185 }