63 changes: 30 additions & 33 deletions src/net/sourceforge/plantuml/tim/TFunctionImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,36 @@ public class TFunctionImpl implements TFunction {
public TFunctionImpl(String functionName, List<TFunctionArgument> args, boolean unquoted,
TFunctionType functionType) {
final Set<String> names = new HashSet<>();
for (TFunctionArgument tmp : args) {
for (TFunctionArgument tmp : args)
names.add(tmp.getName());
}

this.signature = new TFunctionSignature(functionName, args.size(), names);
this.args = args;
this.unquoted = unquoted;
this.functionType = functionType;
}

public boolean canCover(int nbArg, Set<String> namedArguments) {
for (String n : namedArguments) {
if (signature.getNamedArguments().contains(n) == false) {
for (String n : namedArguments)
if (signature.getNamedArguments().contains(n) == false)
return false;
}
}
if (nbArg > args.size()) {

if (nbArg > args.size())
return false;
}

assert nbArg <= args.size();
int neededArgument = 0;
for (TFunctionArgument arg : args) {
if (namedArguments.contains(arg.getName())) {
if (namedArguments.contains(arg.getName()))
continue;
}
if (arg.getOptionalDefaultValue() == null) {

if (arg.getOptionalDefaultValue() == null)
neededArgument++;
}

}
if (nbArg < neededArgument) {
if (nbArg < neededArgument)
return false;
}

assert nbArg >= neededArgument;
return true;
}
Expand All @@ -108,9 +107,9 @@ private TMemory getNewMemory(TMemory memory, List<TValue> values, Map<String, TV
} else {
value = arg.getOptionalDefaultValue();
}
if (value == null) {
if (value == null)
throw new IllegalStateException();
}

result.put(arg.getName(), value);
}
return memory.forkFromGlobal(result);
Expand All @@ -125,11 +124,9 @@ public void addBody(StringLocated s) throws EaterExceptionLocated {
body.add(s);
if (s.getType() == TLineType.RETURN) {
this.containsReturn = true;
if (functionType == TFunctionType.PROCEDURE) {
if (functionType == TFunctionType.PROCEDURE)
throw EaterExceptionLocated
.located("A procedure cannot have !return directive. Declare it as a function instead ?", s);
// this.functionType = TFunctionType.RETURN;
}
}
}

Expand All @@ -147,39 +144,39 @@ public void executeProcedure(TContext context, TMemory memory, LineLocation loca

public void executeProcedureInternal(TContext context, TMemory memory, List<TValue> args, Map<String, TValue> named)
throws EaterException, EaterExceptionLocated {
if (functionType != TFunctionType.PROCEDURE && functionType != TFunctionType.LEGACY_DEFINELONG) {
if (functionType != TFunctionType.PROCEDURE && functionType != TFunctionType.LEGACY_DEFINELONG)
throw new IllegalStateException();
}

final TMemory copy = getNewMemory(memory, args, named);
context.executeLines(copy, body, TFunctionType.PROCEDURE, false);
}

public TValue executeReturnFunction(TContext context, TMemory memory, LineLocation location, List<TValue> args,
Map<String, TValue> named) throws EaterException, EaterExceptionLocated {
if (functionType == TFunctionType.LEGACY_DEFINE) {
if (functionType == TFunctionType.LEGACY_DEFINE)
return executeReturnLegacyDefine(location, context, memory, args);
}
if (functionType != TFunctionType.RETURN_FUNCTION) {

if (functionType != TFunctionType.RETURN_FUNCTION)
throw EaterException.unlocated("Illegal call here. Is there a return directive in your function?");
}

final TMemory copy = getNewMemory(memory, args, named);
final TValue result = context.executeLines(copy, body, TFunctionType.RETURN_FUNCTION, true);
if (result == null) {
if (result == null)
throw EaterException.unlocated("No return directive found in your function");
}

return result;
}

private TValue executeReturnLegacyDefine(LineLocation location, TContext context, TMemory memory, List<TValue> args)
throws EaterException, EaterExceptionLocated {
if (legacyDefinition == null) {
if (legacyDefinition == null)
throw new IllegalStateException();
}

final TMemory copy = getNewMemory(memory, args, Collections.<String, TValue>emptyMap());
final String tmp = context.applyFunctionsAndVariables(copy, location, legacyDefinition);
if (tmp == null) {
if (tmp == null)
return TValue.fromString("");
}

return TValue.fromString(tmp);
// eaterReturn.execute(context, copy);
// // System.err.println("s3=" + eaterReturn.getValue2());
Expand Down Expand Up @@ -211,9 +208,9 @@ public boolean hasBody() {
}

public void finalizeEnddefinelong() {
if (functionType != TFunctionType.LEGACY_DEFINELONG) {
if (functionType != TFunctionType.LEGACY_DEFINELONG)
throw new UnsupportedOperationException();
}

if (body.size() == 1) {
this.functionType = TFunctionType.LEGACY_DEFINE;
this.legacyDefinition = body.get(0).getString();
Expand Down
55 changes: 27 additions & 28 deletions src/net/sourceforge/plantuml/version/LicenseInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,27 @@ public static boolean retrieveNamedOrDistributorQuickIsValid() {

public static synchronized LicenseInfo retrieveNamedSlow() {
cache = LicenseInfo.NONE;
if (OptionFlags.ALLOW_INCLUDE == false) {
if (OptionFlags.ALLOW_INCLUDE == false)
return cache;
}

final String key = prefs.get("license", "");
if (key.length() > 0) {
cache = setIfValid(retrieveNamed(key), cache);
if (cache.isValid()) {
if (cache.isValid())
return cache;
}

}
for (SFile f : fileCandidates()) {
try {
if (f.exists() && f.canRead()) {
final LicenseInfo result = retrieve(f);
if (result == null) {
if (result == null)
return null;
}

cache = setIfValid(result, cache);
if (cache.isValid()) {
if (cache.isValid())
return cache;
}

}
} catch (IOException e) {
Log.info("Error " + e);
Expand Down Expand Up @@ -157,13 +157,13 @@ public static BufferedImage retrieveDistributorImage(LicenseInfo licenseInfo) {
}
try {
final byte[] s1 = PLSSignature.retrieveDistributorImageSignature();
if (SignatureUtils.toHexString(s1).equals(SignatureUtils.toHexString(licenseInfo.sha)) == false) {
if (SignatureUtils.toHexString(s1).equals(SignatureUtils.toHexString(licenseInfo.sha)) == false)
return null;
}

final InputStream dis = PSystemVersion.class.getResourceAsStream("/distributor.png");
if (dis == null) {
if (dis == null)
return null;
}

try {
final BufferedImage result = SImageIO.read(dis);
return result;
Expand All @@ -178,21 +178,20 @@ public static BufferedImage retrieveDistributorImage(LicenseInfo licenseInfo) {

public static LicenseInfo retrieveDistributor() {
final InputStream dis = PSystemVersion.class.getResourceAsStream("/distributor.txt");
if (dis == null) {
if (dis == null)
return null;
}

try {
final BufferedReader br = new BufferedReader(new InputStreamReader(dis));
final String licenseString = br.readLine();
br.close();
final LicenseInfo result = PLSSignature.retrieveDistributor(licenseString);
final Throwable creationPoint = new Throwable();
creationPoint.fillInStackTrace();
for (StackTraceElement ste : creationPoint.getStackTrace()) {
if (ste.toString().contains(result.context)) {
for (StackTraceElement ste : creationPoint.getStackTrace())
if (ste.toString().contains(result.context))
return result;
}
}

return null;
} catch (Exception e) {
Logme.error(e);
Expand All @@ -208,34 +207,34 @@ public static Collection<SFile> fileCandidates() {
if (s == null)
continue;
SFile dir = new SFile(s);
if (dir.isFile()) {
if (dir.isFile())
dir = dir.getParentFile();
}
if (dir != null && dir.isDirectory()) {

if (dir != null && dir.isDirectory())
result.add(dir.file("license.txt"));
}

}
return result;
}

private static LicenseInfo setIfValid(LicenseInfo value, LicenseInfo def) {
if (value.isValid() || def.isNone()) {
if (value.isValid() || def.isNone())
return value;
}

return def;
}

private static LicenseInfo retrieve(SFile f) throws IOException {
final BufferedReader br = f.openBufferedReader();
if (br == null) {
if (br == null)
return null;
}

try {
final String s = br.readLine();
final LicenseInfo result = retrieveNamed(s);
if (result != null) {
if (result != null)
Log.info("Reading license from " + f.getAbsolutePath());
}

return result;
} finally {
br.close();
Expand Down
2 changes: 1 addition & 1 deletion src/net/sourceforge/plantuml/version/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class Version {

// Warning, "version" should be the same in gradle.properties and Version.java
// Any idea anyone how to magically synchronize those :-) ?
private static final String version = "1.2023.9beta3";
private static final String version = "1.2023.9beta4";

public static String versionString() {
return version;
Expand Down