Search in sources :

Example 1 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class LabelUtils method createLabelFromString.

/**
 * Canonicalizes the label (to the form [@external_workspace]//packagePath:packageRelativeTarget).
 * Returns null if the string does not represent a valid label.
 */
@Nullable
public static Label createLabelFromString(@Nullable BlazePackage blazePackage, @Nullable String labelString) {
    if (labelString == null) {
        return null;
    }
    int colonIndex = labelString.indexOf(':');
    if (isAbsolute(labelString)) {
        if (colonIndex == -1) {
            // add the implicit rule name
            labelString += ":" + PathUtil.getFileName(labelString);
        }
        return Label.createIfValid(labelString);
    }
    // package-relative label of the form '[:]relativePath'
    if (colonIndex > 0 || blazePackage == null) {
        return null;
    }
    Label packageLabel = blazePackage.getPackageLabel();
    return packageLabel != null ? packageLabel.withTargetName(labelString.substring(colonIndex + 1)) : null;
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label) Nullable(javax.annotation.Nullable)

Example 2 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class BlazePackage method getBuildLabelForChild.

/**
 * Formats the child file path as a BUILD label (i.e. "//package_path[:relative_path]")
 */
@Nullable
public Label getBuildLabelForChild(String filePath) {
    Label parentPackage = getPackageLabel();
    if (parentPackage == null) {
        return null;
    }
    String relativePath = getPackageRelativePath(filePath);
    return parentPackage.withTargetName(relativePath);
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label) Nullable(javax.annotation.Nullable)

Example 3 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class ProjectViewLabelReference method handleElementRename.

@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
    String currentString = myElement.getText();
    Label label = getLabel(currentString);
    if (label == null) {
        return myElement;
    }
    String ruleName = label.targetName().toString();
    String newRuleName = newElementName;
    // handle subdirectories
    int lastSlashIndex = ruleName.lastIndexOf('/');
    if (lastSlashIndex != -1) {
        newRuleName = ruleName.substring(0, lastSlashIndex + 1) + newElementName;
    }
    String packageString = LabelUtils.getPackagePathComponent(currentString);
    if (packageString.isEmpty() && !currentString.contains(":")) {
        return handleRename(newRuleName);
    }
    return handleRename(packageString + ":" + newRuleName);
}
Also used : Label(com.google.idea.blaze.base.model.primitives.Label)

Example 4 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class BlazeCommandRunConfiguration method updateTargetKindAsync.

/**
 * Queries the kind of the current target pattern, possibly asynchronously.
 *
 * @param asyncCallback if the kind is updated asynchronously, this will be run after the kind is
 *     updated. If it's updated synchronously, this will not be run.
 */
void updateTargetKindAsync(@Nullable Runnable asyncCallback) {
    TargetExpression expr = parseTarget(targetPattern);
    if (!(expr instanceof Label)) {
        updateTargetKind(null);
        return;
    }
    Label label = (Label) expr;
    ListenableFuture<TargetInfo> future = TargetFinder.findTargetInfoFuture(getProject(), label);
    if (future.isDone()) {
        updateTargetKind(FuturesUtil.getIgnoringErrors(future));
    } else {
        updateTargetKind(null);
        future.addListener(() -> {
            updateTargetKind(FuturesUtil.getIgnoringErrors(future));
            if (asyncCallback != null) {
                asyncCallback.run();
            }
        }, MoreExecutors.directExecutor());
    }
}
Also used : TargetInfo(com.google.idea.blaze.base.dependencies.TargetInfo) JBLabel(com.intellij.ui.components.JBLabel) Label(com.google.idea.blaze.base.model.primitives.Label) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression)

Example 5 with Label

use of com.google.idea.blaze.base.model.primitives.Label in project intellij by bazelbuild.

the class BlazeCommandRunConfiguration method getTargetKindName.

/**
 * @return The {@link Kind} name, if the target is a known rule. Otherwise, "target pattern" if it
 *     is a general {@link TargetExpression}, "unknown rule" if it is a {@link Label} without a
 *     known rule, and "unknown target" if there is no target.
 */
private String getTargetKindName() {
    Kind kind = targetKind;
    if (kind != null) {
        return kind.toString();
    }
    TargetExpression target = parseTarget(targetPattern);
    if (target instanceof Label) {
        return "unknown rule";
    } else if (target != null) {
        return "target pattern";
    } else {
        return "unknown target";
    }
}
Also used : Kind(com.google.idea.blaze.base.model.primitives.Kind) JBLabel(com.intellij.ui.components.JBLabel) Label(com.google.idea.blaze.base.model.primitives.Label) TargetExpression(com.google.idea.blaze.base.model.primitives.TargetExpression)

Aggregations

Label (com.google.idea.blaze.base.model.primitives.Label)48 File (java.io.File)15 Test (org.junit.Test)11 Nullable (javax.annotation.Nullable)8 BlazeTestResults (com.google.idea.blaze.base.run.testlogs.BlazeTestResults)7 BuildEventStreamProtos (com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos)6 BlazeTestResult (com.google.idea.blaze.base.run.testlogs.BlazeTestResult)6 AndroidResourceModuleRegistry (com.google.idea.blaze.android.sync.model.AndroidResourceModuleRegistry)5 TargetMap (com.google.idea.blaze.base.ideinfo.TargetMap)5 Kind (com.google.idea.blaze.base.model.primitives.Kind)5 TargetExpression (com.google.idea.blaze.base.model.primitives.TargetExpression)5 ArtifactLocation (com.google.idea.blaze.base.ideinfo.ArtifactLocation)4 BlazeProjectData (com.google.idea.blaze.base.model.BlazeProjectData)4 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)4 BuildEvent (com.google.devtools.build.lib.buildeventstream.BuildEventStreamProtos.BuildEvent)3 AndroidResourceModule (com.google.idea.blaze.android.sync.model.AndroidResourceModule)3 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)3 BuildFile (com.google.idea.blaze.base.lang.buildfile.psi.BuildFile)3 StatusOutput (com.google.idea.blaze.base.scope.output.StatusOutput)3 SourceToTargetMap (com.google.idea.blaze.base.targetmaps.SourceToTargetMap)3