Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ina-lang into completion-engine-revamp
  • Loading branch information
nadeeshaan committed Jan 31, 2020
2 parents b4aa67a + 8d41dd9 commit 6dd26e5
Show file tree
Hide file tree
Showing 276 changed files with 8,820 additions and 7,085 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.ballerinalang.jvm.scheduling.Strand;
import org.ballerinalang.jvm.types.AnnotatableType;
import org.ballerinalang.jvm.types.AttachedFunction;
import org.ballerinalang.jvm.types.BFunctionType;
import org.ballerinalang.jvm.types.BObjectType;
import org.ballerinalang.jvm.types.BServiceType;
import org.ballerinalang.jvm.types.BType;
Expand Down Expand Up @@ -92,4 +93,19 @@ public static void processFPValueAnnotations(FPValue fpValue, MapValue globalAnn
type.setAnnotations((MapValue<String, Object>) globalAnnotMap.get(name));
}
}

/**
* Returns true if given {@link FPValue} is annotated to be run concurrently.
*
* @param fpValue function pointer to be invoked
* @return true if should run concurrently
*/
public static boolean isConcurrent(FPValue fpValue) {
Object value = ((BFunctionType) fpValue.getType()).getAnnotation("ballerina/lang" +
".annotations", "strand");
if (value != null) {
return ((MapValue) value).get("thread") == "any";
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.ballerinalang.jvm.values.ErrorValue;
import org.ballerinalang.jvm.values.MapValue;
import org.ballerinalang.jvm.values.MapValueImpl;
import org.ballerinalang.jvm.values.StringValue;
import org.ballerinalang.jvm.values.api.BString;

import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -60,10 +62,16 @@ public class BallerinaErrors {
public static final String GENERATE_PKG_STOP = "___stop_";
public static final String GENERATE_OBJECT_CLASS_PREFIX = ".$value$";

@Deprecated
public static ErrorValue createError(String reason) {
return new ErrorValue(reason, new MapValueImpl<>(BTypes.typeErrorDetail));
}

public static ErrorValue createError(BString reason) {
return new ErrorValue((StringValue) reason, new MapValueImpl<>(BTypes.typeErrorDetail));
}

@Deprecated
public static ErrorValue createError(String reason, String detail) {
MapValueImpl<String, Object> detailMap = new MapValueImpl<>(BTypes.typeErrorDetail);
if (detail != null) {
Expand All @@ -72,6 +80,15 @@ public static ErrorValue createError(String reason, String detail) {
return new ErrorValue(reason, detailMap);
}

public static ErrorValue createError(BString reason, String detail) {
MapValueImpl<String, Object> detailMap = new MapValueImpl<>(BTypes.typeErrorDetail);
if (detail != null) {
detailMap.put(ERROR_MESSAGE_FIELD, detail);
}
return new ErrorValue((StringValue) reason, detailMap);
}

@Deprecated
public static ErrorValue createError(BType type, String reason, String detail) {
MapValueImpl<String, Object> detailMap = new MapValueImpl<>(BTypes.typeErrorDetail);
if (detail != null) {
Expand All @@ -80,10 +97,23 @@ public static ErrorValue createError(BType type, String reason, String detail) {
return new ErrorValue(type, reason, detailMap);
}

public static ErrorValue createError(BType type, BString reason, String detail) {
MapValueImpl<String, Object> detailMap = new MapValueImpl<>(BTypes.typeErrorDetail);
if (detail != null) {
detailMap.put(ERROR_MESSAGE_FIELD, detail);
}
return new ErrorValue(type, (StringValue) reason, detailMap);
}

@Deprecated
public static ErrorValue createError(String reason, MapValue detailMap) {
return new ErrorValue(reason, detailMap);
}

public static ErrorValue createError(BString reason, MapValue detailMap) {
return new ErrorValue((StringValue) reason, detailMap);
}

public static ErrorValue createError(Throwable error) {
if (error instanceof ErrorValue) {
return (ErrorValue) error;
Expand Down
Loading

0 comments on commit 6dd26e5

Please sign in to comment.