Package protobuf.lang.psi.api.reference

Examples of protobuf.lang.psi.api.reference.PbRef


        super(node);
    }

    @Override
    public String getPackageName() {
        final PbRef packageRef = findChildByClass(PbRef.class);
        if(packageRef == null){
            return "";
        }
        PsiElement el = packageRef.getElement();
        String packageName = el != null ? el.getText() : null;
        return packageName;
    }
View Full Code Here


    }

    @Nullable
    @Override
    public PsiElement getQualifier() {
        PbRef ref = getQualifierRef(); // Call into the old method for finding the qualifying reference.
        PsiElement refEl = ref != null ? ref.resolve() : null; // If the reference exists, resolve its element.
        return refEl;
    }
View Full Code Here

        @Override
        public PsiElement resolve(@NotNull PsiReference refElement, boolean incompleteCode) {
            final PbRefImpl ref = (PbRefImpl) refElement;
            final ReferenceKind refKind = ref.getRefKind();
            final PbRef qualifier = ref.getQualifierRef();
            switch (refKind) {
                case FILE: {
                    //todo
                    final String relativePath = PbTextUtil.trim(ref.getText(),'\"');                   
                    if (relativePath.length() == 0) {
                        return null;
                    }
                    if (PbFileUtil.isPathToDirectory(relativePath)) {
                        return null;
                    }
                    final String fileName = new File(relativePath).getName();

                    //hack for test code
                    PsiFile psiFile = null;
                    PsiFile[] foundFiles = FilenameIndex.getFilesByName(ref.getProject(), fileName, ref.getResolveScope());
                    for (PsiFile foundFile : foundFiles) {
                        if (foundFile.getVirtualFile().getPath().equals(File.separator + relativePath)) {
                            psiFile = foundFile;
                        }
                    }
                    if (psiFile != null) return psiFile; //todo avoid such hacking

                    //real code
                    VirtualFile baseOfSearchPath;
                    if (ref.getNode().getElementType() == PbElementTypes.IMPORT_REF) {
                        baseOfSearchPath = ref.getContainingFile().getVirtualFile().getParent();
                    } else {
                        baseOfSearchPath = ref.getProject().getBaseDir();
                    }

                    VirtualFile vfile = baseOfSearchPath.findFileByRelativePath(relativePath);
                    if (vfile != null) {
                        return ref.getManager().findFile(vfile);
                    } else {
                        return null;
                    }
                }
                case PACKAGE: {
                    String qualifiedName = PbPsiUtil.getQualifiedReferenceText(ref);
                    JavaPsiFacade facade = JavaPsiFacade.getInstance(ref.getManager().getProject());
                    return facade.findPackage(qualifiedName);
                }
                case MESSAGE_OR_GROUP:
                case MESSAGE_OR_ENUM_OR_GROUP:
                case MESSAGE_OR_PACKAGE_OR_GROUP:
                case EXTEND_FIELD: {
                    if (qualifier != null) {    //foo.bar
                        final PsiElement resolvedElement = qualifier.resolve();
                        if (resolvedElement != null) {
                            return PbResolveUtil.resolveInScope(PbPsiUtil.getScope(resolvedElement), ref);
                        }
                    } else if (ref.findChildByType(DOT) != null) {  //.foo
                        return PbResolveUtil.resolveInScope(PbPsiUtil.getRootScope(ref), ref);
                    } else {    // foo
                        PsiElement upperScope = PbPsiUtil.getUpperScope(ref);
                        while (upperScope != null) {
                            PsiElement resolveResult = PbResolveUtil.resolveInScope(upperScope, ref);
                            if (resolveResult != null) {
                                return resolveResult;
                            }
                            upperScope = PbPsiUtil.getUpperScope(upperScope);
                        }
                    }
                }
                break;
                case MESSAGE_OR_GROUP_FIELD: {
                    if (qualifier != null) {
                        final PsiElement resolvedElement = qualifier.resolve();
                        if (resolvedElement != null) {
                            return PbResolveUtil.resolveInScope(PbPsiUtil.getTypeScope(resolvedElement), ref);
                        }
                    }
                }
View Full Code Here

        visitor.visitImportDefinition(this);
    }

    @Override
    public PbFile getAliasedFile() {
        PbRef ref = this.findChildByClass(PbRef.class);
        return ref != null ? (PbFile) ref.resolve() : null;
    }
View Full Code Here

    private static boolean appendName(PbRef ref, StringBuilder builder) {
        String refName = ref != null ? ref.getReferenceName() : null;
        if (refName == null) {
            return false;
        }
        PbRef qualifier = ref.getQualifierRef();
        if (qualifier != null) {
            appendName(qualifier, builder);
            builder.append(".");
        }
        builder.append(refName);
View Full Code Here

        return null;
    }

    public static PsiElement getTypeScope(final PsiElement element) {
        if (element instanceof PbFieldDef) {
            PbRef typeRef = ((PbFieldDef) element).getTypeRef();
            if (typeRef != null) {
                PsiElement resolvedElement = typeRef.resolve();
                if (resolvedElement != null) {
                    return getScope(resolvedElement);
                }
            }
            return null;
View Full Code Here

TOP

Related Classes of protobuf.lang.psi.api.reference.PbRef

Copyright © 2018 www.massapicom. 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.