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;
}
Aggregations