public GoConsoleFilter(@NotNull Project project, @Nullable Module module, @Nullable String workingDirectoryUrl) { myProject = project; myModule = module; myWorkingDirectoryUrl = ObjectUtils.chooseNotNull(workingDirectoryUrl, VfsUtilCore.pathToUrl(System.getProperty("user.dir"))); }
public BallerinaConsoleFilter(@NotNull Project project, @Nullable Module module, @Nullable String workingDirectoryUrl) { myProject = project; myModule = module; myWorkingDirectoryUrl = ObjectUtils.chooseNotNull(workingDirectoryUrl, VfsUtilCore.pathToUrl(System.getProperty("user.dir"))); }
@Nullable @Override protected VirtualFile getInitialFile() { return ObjectUtils.chooseNotNull(super.getInitialFile(), GoSdkUtil.suggestSdkDirectory()); } }
@Nullable @Contract("null, _ -> null") public static <T extends PsiElement> T getNonStrictTopmostParentOfType(@Nullable PsiElement element, @NotNull Class<T> aClass) { T first = PsiTreeUtil.getNonStrictParentOfType(element, aClass); T topMost = PsiTreeUtil.getTopmostParentOfType(first, aClass); return ObjectUtils.chooseNotNull(topMost, first); }
@NotNull private LookupElement createKeywordLookupElement(@NotNull String keyword) { InsertHandler<LookupElement> insertHandler = ObjectUtils.chooseNotNull(myInsertHandler, createTemplateBasedInsertHandler("go_lang_" + keyword)); LookupElement result = createKeywordLookupElement(keyword, myPriority, insertHandler); return myCompletionPolicy != null ? myCompletionPolicy.applyPolicy(result) : result; }
@Nullable @Override protected VirtualFile getInitialFile() { return ObjectUtils.chooseNotNull(super.getInitialFile(), BallerinaSdkUtil.suggestSdkDirectory()); } }
@Override public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state) { if (element.equals(o)) return !result.add(new PsiElementResolveResult(element)); String name = ObjectUtils.chooseNotNull(state.get(ACTUAL_NAME), element instanceof PsiNamedElement ? ((PsiNamedElement)element).getName() : null); if (name != null && o.getIdentifier().textMatches(name)) { result.add(new PsiElementResolveResult(element)); return false; } return true; } };
@Nullable public static GoExpression getRecvExpression(@NotNull GoRecvStatement recvStatement) { return getLastExpressionAfter(recvStatement.getExpressionList(), ObjectUtils.chooseNotNull(recvStatement.getAssign(), recvStatement.getVarAssign())); }
@NotNull public static List<GoExpression> getLeftExpressionsList(@NotNull GoRecvStatement recvStatement) { return getExpressionsBefore(recvStatement.getExpressionList(), ObjectUtils.chooseNotNull(recvStatement.getAssign(), recvStatement.getVarAssign())); }
@Nullable @Override public String getLocationString() { GoFile file = getContainingFile(); String fileName = file.getName(); String importPath = ObjectUtils.chooseNotNull(file.getImportPath(vendoringEnabled), file.getPackageName()); return "in " + (importPath != null ? importPath + "/" + fileName : fileName); }
@Nullable public static VirtualFile suggestSdkDirectory() { if (SystemInfo.isWindows) { return ObjectUtils.chooseNotNull(LocalFileSystem.getInstance().findFileByPath("C:\\Go"), LocalFileSystem.getInstance().findFileByPath("C:\\cygwin")); } if (SystemInfo.isMac || SystemInfo.isLinux) { String fromEnv = suggestSdkDirectoryPathFromEnv(); if (fromEnv != null) { return LocalFileSystem.getInstance().findFileByPath(fromEnv); } VirtualFile usrLocal = LocalFileSystem.getInstance().findFileByPath("/usr/local/go"); if (usrLocal != null) return usrLocal; } if (SystemInfo.isMac) { String macPorts = "/opt/local/lib/go"; String homeBrew = "/usr/local/Cellar/go"; File file = FileUtil.findFirstThatExist(macPorts, homeBrew); if (file != null) { return LocalFileSystem.getInstance().findFileByIoFile(file); } } return null; }
@Nullable public static VirtualFile suggestSdkDirectory() { if (SystemInfo.isWindows) { return ObjectUtils.chooseNotNull(LocalFileSystem.getInstance().findFileByPath("C:\\ballerina"), null); } if (SystemInfo.isMac || SystemInfo.isLinux) { String fromEnv = suggestSdkDirectoryPathFromEnv(); if (fromEnv != null) { return LocalFileSystem.getInstance().findFileByPath(fromEnv); } VirtualFile usrLocal = LocalFileSystem.getInstance().findFileByPath("/usr/local/ballerina"); if (usrLocal != null) { return usrLocal; } } if (SystemInfo.isMac) { String macPorts = "/opt/local/lib/ballerina"; String homeBrew = "/usr/local/Cellar/ballerina"; File file = FileUtil.findFirstThatExist(macPorts, homeBrew); if (file != null) { return LocalFileSystem.getInstance().findFileByIoFile(file); } } return null; }
TokenType(@Nullable IElementType delegate, @NotNull String name, @NotNull LivePreviewLanguage language) { super(name, language); this.delegate = ObjectUtils.chooseNotNull(delegate, this); } }
@Override public String get() { return ObjectUtils.chooseNotNull(innerValue(), defValue); } };
static Object info(Runnable info) { Object task = info; String extra = null; if (task instanceof FutureTask) { extra = ((FutureTask)task).isCancelled() ? " (future cancelled)" : ((FutureTask)task).isDone() ? " (future done)" : null; task = ObjectUtils.chooseNotNull(ReflectionUtil.getField(task.getClass(), task, Callable.class, "callable"), task); } if (task instanceof Callable && task.getClass().getName().equals("java.util.concurrent.Executors$RunnableAdapter")) { task = ObjectUtils.chooseNotNull(ReflectionUtil.getField(task.getClass(), task, Runnable.class, "task"), task); } return extra == null ? task : task == null ? extra : task.getClass() + extra; }
@NotNull private ConsumeType getRuleConsumeType(@NotNull BnfRule rule) { ConsumeType forcedConsumeType = ExpressionGeneratorHelper.fixForcedConsumeType(myExpressionHelper, rule, null, null); return ObjectUtils.chooseNotNull(forcedConsumeType, ConsumeType.forRule(rule)); }
String signature, String[] exceptions) { final MethodInfo m = getMethodInfo(myInfo.name, name, ObjectUtils.chooseNotNull(signature, desc)); m.modifiers = access; m.methodType = "<init>".equals(name)? MethodType.CONSTRUCTOR :
private void generateTokenSets() { if (myTokenSets.isEmpty()) { return; } newLine(); out("interface %s {", TOKEN_SET_HOLDER_NAME); Map<String, String> reverseMap = ContainerUtil.newHashMap(); myTokenSets.forEach((name, tokens) -> { String value = String.format("TokenSet.create(%s)", tokenSetString(tokens)); String alreadyRendered = reverseMap.putIfAbsent(value, name); out("TokenSet %s = %s;", name, ObjectUtils.chooseNotNull(alreadyRendered, value)); }); out("}"); }
@NotNull public static ConsumeType forRule(@NotNull BnfRule rule) { String value = getAttribute(rule, KnownAttribute.CONSUME_TOKEN_METHOD); for (ConsumeType method : values()) { if (StringUtil.equalsIgnoreCase(value, method.name())) return method; } return ObjectUtils.chooseNotNull(forMethod(value), DEFAULT); }
@NotNull public RuleGraphHelper.Cardinality fixCardinality(BnfRule rule, PsiElement tree, RuleGraphHelper.Cardinality type) { if (type.optional()) return type; // in Expression parsing mode REQUIRED may go OPTIONAL ExpressionHelper.ExpressionInfo info = getExpressionInfo(rule); ExpressionHelper.OperatorInfo operatorInfo = info == null ? null : info.operatorMap.get(rule); if (operatorInfo == null || operatorInfo.type == ExpressionHelper.OperatorType.ATOM) return type; // emulate expr-parsing pin processing if ((operatorInfo.type == OperatorType.BINARY || operatorInfo.type == OperatorType.N_ARY || operatorInfo.type == OperatorType.POSTFIX) && ObjectUtils.chooseNotNull(operatorInfo.arg1, info.rootRule) == tree || isRealAncestor(rule, operatorInfo.operator, tree)) { // pinned! return as is return type; } else { return type.and(OPTIONAL); } }