Search in sources :

Example 76 with Optional

use of com.google.common.base.Optional in project bazel by bazelbuild.

the class RuleContext method getPrerequisites.

/**
   * Returns the list of transitive info collections that feed into this target through the
   * specified attribute. Note that you need to specify the correct mode for the attribute,
   * otherwise an assertion will be raised.
   */
public List<? extends TransitiveInfoCollection> getPrerequisites(String attributeName, Mode mode) {
    Attribute attributeDefinition = attributes().getAttributeDefinition(attributeName);
    if ((mode == Mode.TARGET) && (attributeDefinition.hasSplitConfigurationTransition())) {
        // TODO(bazel-team): If you request a split-configured attribute in the target configuration,
        // we return only the list of configured targets for the first architecture; this is for
        // backwards compatibility with existing code in cases where the call to getPrerequisites is
        // deeply nested and we can't easily inject the behavior we want. However, we should fix all
        // such call sites.
        checkAttribute(attributeName, Mode.SPLIT);
        Map<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> map = getSplitPrerequisites(attributeName);
        return map.isEmpty() ? ImmutableList.<TransitiveInfoCollection>of() : map.entrySet().iterator().next().getValue();
    }
    checkAttribute(attributeName, mode);
    return targetMap.get(attributeName);
}
Also used : Optional(com.google.common.base.Optional) Attribute(com.google.devtools.build.lib.packages.Attribute)

Example 77 with Optional

use of com.google.common.base.Optional in project bazel by bazelbuild.

the class PublicXmlResourceValue method from.

@SuppressWarnings("deprecation")
public static XmlResourceValue from(SerializeFormat.DataValueXml proto) {
    Map<String, String> protoValues = proto.getMappedStringValue();
    ImmutableMap.Builder<ResourceType, Optional<Integer>> typeToId = ImmutableMap.builder();
    for (Entry<String, String> entry : protoValues.entrySet()) {
        ResourceType type = ResourceType.getEnum(entry.getKey());
        Preconditions.checkNotNull(type);
        Optional<Integer> id = MISSING_ID_VALUE.equals(entry.getValue()) ? Optional.<Integer>absent() : Optional.of(Integer.decode(entry.getValue()));
        typeToId.put(type, id);
    }
    return of(typeToId.build());
}
Also used : Optional(com.google.common.base.Optional) ResourceType(com.android.resources.ResourceType) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 78 with Optional

use of com.google.common.base.Optional in project bazel by bazelbuild.

the class SkylarkRuleContext method buildSplitAttributeInfo.

private static SkylarkClassObject buildSplitAttributeInfo(Collection<Attribute> attributes, RuleContext ruleContext) {
    ImmutableMap.Builder<String, Object> splitAttrInfos = ImmutableMap.builder();
    for (Attribute attr : attributes) {
        if (attr.hasSplitConfigurationTransition()) {
            Map<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> splitPrereqs = ruleContext.getSplitPrerequisites(attr.getName());
            Map<Object, Object> splitPrereqsMap = new LinkedHashMap<>();
            for (Entry<Optional<String>, ? extends List<? extends TransitiveInfoCollection>> splitPrereq : splitPrereqs.entrySet()) {
                Object value;
                if (attr.getType() == BuildType.LABEL) {
                    Preconditions.checkState(splitPrereq.getValue().size() == 1);
                    value = splitPrereq.getValue().get(0);
                } else {
                    // BuildType.LABEL_LIST
                    value = SkylarkList.createImmutable(splitPrereq.getValue());
                }
                if (splitPrereq.getKey().isPresent()) {
                    splitPrereqsMap.put(splitPrereq.getKey().get(), value);
                } else {
                    // If the split transition is not in effect, then the key will be missing since there's
                    // nothing to key on because the dependencies aren't split and getSplitPrerequisites()
                    // behaves like getPrerequisites(). This also means there should be only one entry in
                    // the map. Use None in Skylark to represent this.
                    Preconditions.checkState(splitPrereqs.size() == 1);
                    splitPrereqsMap.put(Runtime.NONE, value);
                }
            }
            splitAttrInfos.put(attr.getPublicName(), SkylarkDict.copyOf(null, splitPrereqsMap));
        }
    }
    return NativeClassObjectConstructor.STRUCT.create(splitAttrInfos.build(), "No attribute '%s' in split_attr. Make sure that this attribute is defined with a " + "split configuration.");
}
Also used : Optional(com.google.common.base.Optional) Attribute(com.google.devtools.build.lib.packages.Attribute) SkylarkClassObject(com.google.devtools.build.lib.packages.SkylarkClassObject) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap)

Example 79 with Optional

use of com.google.common.base.Optional in project che by eclipse.

the class LanguageServerSignatureHelp method signatureHelp.

@Override
public Promise<Optional<SignatureHelp>> signatureHelp(Document document, int offset) {
    TextDocumentPositionParamsDTO paramsDTO = helper.createTDPP(document, offset);
    Promise<SignatureHelpDTO> promise = client.signatureHelp(paramsDTO);
    return promise.then(new Function<SignatureHelpDTO, Optional<SignatureHelp>>() {

        @Override
        public Optional<SignatureHelp> apply(SignatureHelpDTO arg) throws FunctionException {
            if (arg == null) {
                return Optional.absent();
            }
            return Optional.<SignatureHelp>of(new SignatureHelpImpl(arg));
        }
    }).catchError(new Function<PromiseError, Optional<SignatureHelp>>() {

        @Override
        public Optional<SignatureHelp> apply(PromiseError arg) throws FunctionException {
            notificationManager.notify(arg.getMessage(), StatusNotification.Status.FAIL, StatusNotification.DisplayMode.EMERGE_MODE);
            return Optional.absent();
        }
    });
}
Also used : TextDocumentPositionParamsDTO(org.eclipse.che.api.languageserver.shared.lsapi.TextDocumentPositionParamsDTO) Function(org.eclipse.che.api.promises.client.Function) PromiseError(org.eclipse.che.api.promises.client.PromiseError) Optional(com.google.common.base.Optional) SignatureHelpDTO(org.eclipse.che.api.languageserver.shared.lsapi.SignatureHelpDTO) FunctionException(org.eclipse.che.api.promises.client.FunctionException) SignatureHelp(org.eclipse.che.ide.api.editor.signature.SignatureHelp)

Example 80 with Optional

use of com.google.common.base.Optional in project che by eclipse.

the class OrionEditorPresenter method showSignatureHelp.

private void showSignatureHelp() {
    //TODO XXX
    SignatureHelpProvider signatureHelpProvider = getConfiguration().getSignatureHelpProvider();
    if (document != null && signatureHelpProvider != null) {
        Promise<Optional<SignatureHelp>> promise = signatureHelpProvider.signatureHelp(document, getCursorOffset());
        PositionConverter.PixelCoordinates coordinates = getPositionConverter().offsetToPixel(getCursorOffset());
        signatureHelpView.showSignature(promise, coordinates.getX(), coordinates.getY() - editorWidget.getTextView().getLineHeight());
    }
}
Also used : Optional(com.google.common.base.Optional) SignatureHelpProvider(org.eclipse.che.ide.api.editor.signature.SignatureHelpProvider) PositionConverter(org.eclipse.che.ide.api.editor.position.PositionConverter)

Aggregations

Optional (com.google.common.base.Optional)159 RevFeature (org.locationtech.geogig.api.RevFeature)42 Test (org.junit.Test)38 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)28 ImmutableList (com.google.common.collect.ImmutableList)24 List (java.util.List)24 File (java.io.File)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)20 ArrayList (java.util.ArrayList)18 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)18 Function (com.google.common.base.Function)17 SimpleFeatureBuilder (org.geotools.feature.simple.SimpleFeatureBuilder)17 ObjectId (org.locationtech.geogig.api.ObjectId)17 SimpleFeature (org.opengis.feature.simple.SimpleFeature)16 Resource (org.eclipse.che.ide.api.resources.Resource)15 AddOp (org.locationtech.geogig.api.porcelain.AddOp)14 ImmutableMap (com.google.common.collect.ImmutableMap)13 RevObject (org.locationtech.geogig.api.RevObject)13 NodeRef (org.locationtech.geogig.api.NodeRef)12 Feature (org.opengis.feature.Feature)12