/*
 * Copyright 2015 Marek Kaput
 *
 * 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 org.rustidea.psi.impl;

import com.intellij.extapi.psi.StubBasedPsiElementBase;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.StubBasedPsiElement;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NotNull;
import org.rustidea.psi.IRsPsiElement;
import org.rustidea.psi.RsElementVisitor;

public abstract class IRsStubPsiElement<T extends StubElement>
    extends StubBasedPsiElementBase<T> implements StubBasedPsiElement<T>, IRsPsiElement {
    public IRsStubPsiElement(@NotNull final T stub, @NotNull final IStubElementType nodeType) {
        super(stub, nodeType);
    }

    public IRsStubPsiElement(@NotNull final ASTNode node) {
        super(node);
    }

    @Override
    public PsiElement getParent() {
        // TODO This is copy-pasted from Java-psi-impl; is this ok?
        return getParentByStub();
    }

    @Override
    public void accept(@NotNull final PsiElementVisitor visitor) {
        if (visitor instanceof RsElementVisitor) {
            this.accept((RsElementVisitor) visitor);
        } else {
            visitor.visitElement(this);
        }
    }

    @NotNull
    @Override
    public String toString() {
        String clsName = PsiImplUtil.getPsiClassName(this);
        String psiName = getName();
        if (psiName != null) {
            return clsName + ":" + psiName;
        }
        return clsName;
    }
}

@@ -1088,16 +1088,20 @@
 Element%3C
+Stub
 T extend
@@ -1151,16 +1151,20 @@
 entBase%3C
+Stub
 T%3E imple
@@ -1189,16 +1189,20 @@
 Element%3C
+Stub
 T%3E, IRsP
@@ -1257,16 +1257,20 @@
 l final 
+Stub
 T stub, 

Rename type parameter name