Package protobuf.lang.psi.impl.auxiliary

Source Code of protobuf.lang.psi.impl.auxiliary.PbNamedElementImpl

package protobuf.lang.psi.impl.auxiliary;

import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElement;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import protobuf.lang.psi.api.auxiliary.PbNamedElement;
import protobuf.lang.psi.impl.PbPsiElementImpl;
import protobuf.lang.psi.utils.PbPsiUtil;

/**
* @author Nikolay Matveev
*/

public abstract class PbNamedElementImpl extends PbPsiElementImpl implements PbNamedElement {

    public PbNamedElementImpl(ASTNode node) {
        super(node);
    }

    @Override
    public abstract PsiElement getNameElement();

    @Override
    public final PsiElement setName(@NotNull String newName) throws IncorrectOperationException{
        PsiElement nameElement = getNameElement();
        if(nameElement == null){           
            throw new IncorrectOperationException();
        }
        ASTNode nameNode = nameElement.getNode();
        nameNode.getTreeParent().replaceChild(nameNode,PbPsiUtil.createSimpleNodeWithText(newName,getProject()));
        return this;
    }

    @Override
    public final String getName() {
        PsiElement nameElement = getNameElement();
        if (nameElement != null) {
            return nameElement.getText();
        }
        return null;
    }

    @Override
    public final int getTextOffset() {
        PsiElement nameElement = getNameElement();
        if(nameElement != null){
            return super.getTextOffset() + nameElement.getStartOffsetInParent();
        }
        return super.getTextOffset();
    }
}
TOP

Related Classes of protobuf.lang.psi.impl.auxiliary.PbNamedElementImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.