/* * java.cs * * This source file is part of the FoundationDB open source project * * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; namespace vexillographer { class java : BindingWriter { private static string formatComment(int indentTabs, string commentText) { string tabs = ""; for(int i=0; i "\n" + tabs + " * " + line.Trim() ) ) + "\n" + tabs + " *" + "/"; } private static string replaceTicks(string input) { int startIdx = input.IndexOf("``"); int lastReplaceEnd = 0; string output = ""; while (startIdx >= 0) { output += input.Substring(lastReplaceEnd, startIdx - lastReplaceEnd); int closingIdx = input.IndexOf("``", startIdx + 2); if (closingIdx < 0) throw new InvalidDataException("No closing double tick"); output += "{@code " + input.Substring(startIdx + 2, closingIdx - startIdx - 2) + "}"; lastReplaceEnd = closingIdx + 2; startIdx = input.IndexOf("``", lastReplaceEnd); } output += input.Substring(lastReplaceEnd); return output; } private static string getEnum(Option o) { string mainComment = o.comment == "" ? "Currently undocumented." : o.comment; if (!mainComment.EndsWith(".")) mainComment += "."; mainComment = replaceTicks(mainComment); return formatComment(1, mainComment) + String.Format("\n{2}\t{0}({1})", o.name.ToUpper(), o.code, o.isDeprecated() ? "\t@Deprecated\n" : ""); } class ScopeOptions { public bool isPublic; public bool isSettableOption; public String comment; public ScopeOptions(bool isSettable, String comment, bool isPublic = true) { this.isPublic = isPublic; this.isSettableOption = isSettable; this.comment = comment; } } private static Dictionary scopeDocOptions = new Dictionary() { { Scope.NetworkOption, new ScopeOptions(true, "A set of options that can be set globally for the {@link FDB FoundationDB API}.") }, { Scope.DatabaseOption, new ScopeOptions(true, "A set of options that can be set on a {@link Database}.") }, { Scope.TransactionOption, new ScopeOptions(true, "A set of options that can be set on a {@link Transaction}.") }, { Scope.StreamingMode, new ScopeOptions(false, "Options that control the way the Java binding performs range reads. These options can be passed to {@link Transaction#getRange(byte[], byte[], int, boolean, StreamingMode) Transaction.getRange(...)}.") }, { Scope.MutationType, new ScopeOptions(false, "A set of operations that can be performed atomically on a database. These are used as parameters to {@link Transaction#mutate(MutationType, byte[], byte[])}.") }, { Scope.ConflictRangeType, new ScopeOptions(false, "Conflict range types used internally by the C API.", false) }, { Scope.ErrorPredicate, new ScopeOptions(true, "Error code predicates for binding writers and non-standard layer implementers.") }, }; private static bool scopeIsSettableOption(Scope s) { return s != Scope.StreamingMode && s != Scope.MutationType && s != Scope.ConflictRangeType; } private static string toCamelCase(string optionName) { return string.Join("", optionName .Split('_') .Select( s=>s.Substring(0,1).ToUpper() + s.Substring(1) ) ); } private static string toSetFuncName(string optionName) { return "set" + toCamelCase(optionName); } private static string toPredicateFuncName(string optionName) { return "is" + toCamelCase(optionName); } private static string getJavaTypeName(ParamType t) { switch (t) { case ParamType.Int: return "long"; case ParamType.Bytes: return "byte[]"; case ParamType.String: return "String"; default: throw new InvalidDataException("Unsupported operation type"); } } private static void writeOptionsClass(TextWriter outFile, Scope scope, IEnumerable