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.psi.PsiElement;
020    import com.intellij.psi.impl.compiled.ClsMethodImpl;
021    import com.intellij.psi.impl.java.stubs.PsiMethodStub;
022    import com.intellij.psi.search.SearchScope;
023    import com.intellij.util.IncorrectOperationException;
024    import org.jetbrains.annotations.NotNull;
025    import org.jetbrains.jet.lang.psi.JetDeclaration;
026    import org.jetbrains.jet.lang.resolve.java.jetAsJava.JetClsMethod;
027    
028    public class JetClsMethodImpl extends ClsMethodImpl implements JetClsMethod {
029        @NotNull
030        private final PsiElement origin;
031    
032        public JetClsMethodImpl(@NotNull PsiMethodStub stub, @NotNull PsiElement origin) {
033            super(stub);
034            this.origin = origin;
035        }
036    
037        @Override
038        public PsiElement getMirror() {
039            return origin;
040        }
041    
042        @NotNull
043        @Override
044        public PsiElement getNavigationElement() {
045            return origin;
046        }
047    
048        @Override
049        public JetDeclaration getOrigin() {
050            return (JetDeclaration) origin;
051        }
052    
053        @Override
054        public void delete() throws IncorrectOperationException {
055            origin.delete();
056        }
057    
058        @Override
059        public boolean isEquivalentTo(PsiElement another) {
060            if (another instanceof JetClsMethod && getOrigin().equals(((JetClsMethod) another).getOrigin())) return true;
061            return super.isEquivalentTo(another);
062        }
063    
064        @NotNull
065        @Override
066        public SearchScope getUseScope() {
067            return origin.getUseScope();
068        }
069    }