Search in sources :

Example 1 with BuckValue

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

the class BuckAnnotator method annotateErrors.

private void annotateErrors(PsiElement psiElement, AnnotationHolder annotationHolder) {
    BuckValue value = PsiTreeUtil.getParentOfType(psiElement, BuckValue.class);
    if (value == null) {
        return;
    }
    final Project project = psiElement.getProject();
    if (project == null) {
        return;
    }
    String target = psiElement.getText();
    if (target.matches("\".*\"") || target.matches("'.*'")) {
        target = target.substring(1, target.length() - 1);
    } else {
        return;
    }
    if (!BuckBuildUtil.isValidAbsoluteTarget(target)) {
        return;
    }
    VirtualFile buckDir = project.getBaseDir().findFileByRelativePath(BuckBuildUtil.extractAbsoluteTarget(target));
    VirtualFile targetBuckFile = buckDir != null ? buckDir.findChild("BUCK") : null;
    if (targetBuckFile == null) {
        TextRange range = new TextRange(psiElement.getTextRange().getStartOffset(), psiElement.getTextRange().getEndOffset());
        annotationHolder.createErrorAnnotation(range, ANNOTATOR_ERROR_CANNOT_LOCATE_TARGET);
        project.getMessageBus().syncPublisher(IntellijBuckAction.EVENT).consume(this.getClass().toString());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) BuckValue(com.facebook.buck.intellij.ideabuck.lang.psi.BuckValue) Project(com.intellij.openapi.project.Project) TextRange(com.intellij.openapi.util.TextRange)

Example 2 with BuckValue

use of com.facebook.buck.intellij.ideabuck.lang.psi.BuckValue 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

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