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);
}
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());
}
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.");
}
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();
}
});
}
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());
}
}
Aggregations