Search in sources :

Example 1 with BuckLanguage

use of com.facebook.buck.intellij.ideabuck.lang.BuckLanguage in project buck by facebook.

the class BuckGotoProvider method getGotoDeclarationTarget.

@Override
public PsiElement getGotoDeclarationTarget(@Nullable PsiElement source, Editor editor) {
    if (source != null && source.getLanguage() instanceof BuckLanguage) {
        // The parent type of the element must be BuckValue.
        BuckValue value = PsiTreeUtil.getParentOfType(source, BuckValue.class);
        if (value == null) {
            return null;
        }
        final Project project = editor.getProject();
        if (project == null) {
            return null;
        }
        String target = source.getText();
        if ((target.startsWith("'") && target.endsWith("'")) || (target.startsWith("\"") && target.endsWith("\""))) {
            target = target.substring(1, target.length() - 1);
        }
        VirtualFile targetFile = // Try to find the BUCK file
        Optional.fromNullable(BuckBuildUtil.getBuckFileFromAbsoluteTarget(project, target)).or(Optional.fromNullable(source.getContainingFile().getParent().getVirtualFile().findFileByRelativePath(target))).orNull();
        if (targetFile == null) {
            return null;
        }
        project.getMessageBus().syncPublisher(IntellijBuckAction.EVENT).consume(this.getClass().toString());
        return PsiManager.getInstance(project).findFile(targetFile);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BuckValue(com.facebook.buck.intellij.ideabuck.lang.psi.BuckValue) Project(com.intellij.openapi.project.Project) BuckLanguage(com.facebook.buck.intellij.ideabuck.lang.BuckLanguage)

Aggregations

BuckLanguage (com.facebook.buck.intellij.ideabuck.lang.BuckLanguage)1 BuckValue (com.facebook.buck.intellij.ideabuck.lang.psi.BuckValue)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1