Skip to content

Commit

Permalink
resource spec processing for Java
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlano authored Dec 4, 2024
1 parent c6f43da commit 7959431
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 8 deletions.
Binary file modified ASTCompositeTerm.class
Binary file not shown.
100 changes: 92 additions & 8 deletions ASTCompositeTerm.java
Original file line number Diff line number Diff line change
Expand Up @@ -26073,7 +26073,7 @@ else if ("hasNext".equals(called) ||
"hasMoreElements".equals(called) ||
"hasMoreTokens".equals(called))
{ String tt = ASTTerm.getType(args);
System.out.println(">>> Type of " + args + " is: " + tt);
JOptionPane.showInputDialog(">>> Type of " + args + " is: " + tt);

if ("OclIterator".equals(tt))
{ ASTTerm.setType(thisliteral,"boolean");
Expand All @@ -26091,7 +26091,8 @@ else if ("hasNext".equals(called) ||
return args + "." + calls;
}
}
else if (arg.isFile())
else if (arg.isFile() ||
"OclFile".equals(ASTTerm.getType(args) + ""))
{ return fileFeatureAccessToKM3(arg,args,call,called,
callterms,cargs);
}
Expand Down Expand Up @@ -26228,6 +26229,41 @@ else if ("toArray".equals(called))

return args + "->asSequence()";
} // But with parameter, take the type from the par.
else if ("getOrDefault".equals(called) &&
callterms.size() >= 2 && arg.isMap())
{ // ASTTerm.setType(thisliteral,"Sequence");

ASTTerm callarg1 = (ASTTerm) cargs.get(0);
ASTTerm callarg2 = (ASTTerm) cargs.get(1);
String callp1 = callarg1.toKM3();
String callp2 = callarg2.toKM3();

String p2type = ASTTerm.getType(callp2);
ASTTerm.setType(thisliteral, p2type);

// JOptionPane.showInputDialog("Type of " + thisliteral + " is " + p2type);

if (arg.expression != null &&
callarg1.expression != null &&
callarg2.expression != null)
{ Expression keysexpression =
new UnaryExpression("->keys", arg.expression);
Expression test =
new BinaryExpression("->includes", keysexpression,
callarg1.expression);
expression =
new ConditionalExpression(test,
new BinaryExpression("->at", arg.expression,
callarg1.expression),
callarg2.expression);
expression.setBrackets(true);
}

return "(if " + args + "->keys()->includes(" +
callp1 + " then " +
args + "->at(" + callp1 + ") else " + callp2 +
" endif)";
}
else if (("put".equals(called) ||
"setProperty".equals(called)) &&
callterms.size() >= 3 &&
Expand All @@ -26248,6 +26284,34 @@ else if (("put".equals(called) ||

return args + "[" + callp1 + "] := " + callp2;
}
else if ("putIfAbsent".equals(called) &&
callterms.size() >= 2 &&
arg.isMap())
{ ASTTerm callarg1 = (ASTTerm) cargs.get(0);
ASTTerm callarg2 = (ASTTerm) cargs.get(1);
String callp1 = callarg1.toKM3();
String callp2 = callarg2.toKM3();

if (arg.expression != null &&
callarg1.expression != null &&
callarg2.expression != null)
{ Expression lhs = BasicExpression.newIndexedBasicExpression(arg.expression, callarg1.expression);
Expression keysexpression =
new UnaryExpression("->keys", arg.expression);
Expression test =
new BinaryExpression("->includes", keysexpression,
callarg1.expression);
expression =
new ConditionalExpression(test, lhs, nullExpression);
Statement assignstatement =
new AssignStatement(lhs, callarg2.expression);
statement =
new ConditionalStatement(test, skipStatement,
assignstatement);
}

return "if " + args + "->keys()->includes(" + callp1 + ") then skip else " + args + "[" + callp1 + "] := " + callp2;
}
else if ("getProperty".equals(called) &&
cargs.size() >= 1 &&
arg.isMap())
Expand Down Expand Up @@ -26284,8 +26348,8 @@ else if ("store".equals(called) &&
ASTTerm callarg1 = (ASTTerm) cargs.get(0);
String callp1 = callarg1.toKM3();
expression =
BasicExpression.newCallBasicExpression(
"writeMap", callarg1.expression, arg.expression);
BasicExpression.newCallBasicExpression(
"writeMap", callarg1.expression, arg.expression);
statement =
InvocationStatement.newInvocationStatement(
expression, callarg1.expression);
Expand Down Expand Up @@ -26382,7 +26446,7 @@ else if ("set".equals(called) && arg.isCollection() && callterms.size() >= 3)
callarg2.expression != null)
{ Expression unit = new BasicExpression(1);
Expression incr =
new BinaryExpression("+", callarg1.expression, unit);
new BinaryExpression("+", callarg1.expression, unit);
Expression lhs = BasicExpression.newIndexedBasicExpression(arg.expression, incr);
expression = callarg2.expression;
statement =
Expand Down Expand Up @@ -31742,6 +31806,7 @@ else if (cls.literalForm().startsWith("Comparator"))

if ("Scanner".equals(cls.literalForm()))
{ ASTTerm.setType(this,"OclFile");

ASTTerm arg1 = (ASTTerm) cargs.get(0);
if (arg1.isString())
{ if (arg1.expression != null)
Expand All @@ -31753,6 +31818,7 @@ else if (cls.literalForm().startsWith("Comparator"))
"newOclFile_Read", "OclFile", pars);
expression.setType(new Type("OclFile", null));
}

return "OclFile.newOclFile_Read(OclFile.newOclFile(" + arg1.toKM3() + "))";
}

Expand Down Expand Up @@ -33320,6 +33386,8 @@ public String fileFeatureAccessToKM3(ASTTerm arg,
Vector cargs)
{ String thisliteral = this.literalForm();

JOptionPane.showInputDialog("fileFeatureAccessToKM3 " + args + called + cargs);

if ("next".equals(called) && arg.isFile())
{ ASTTerm.setType(thisliteral,"String");

Expand Down Expand Up @@ -33666,7 +33734,9 @@ else if ("next".equals(called) && arg.isFile())
}
}
else if ("nextInt".equals(called) && arg.isFile())
{ if (cargs.size() == 0)
{ JOptionPane.showInputDialog("NextInt");

if (cargs.size() == 0)
{ if (arg.expression != null)
{ BasicExpression rexp =
BasicExpression.newCallBasicExpression(
Expand Down Expand Up @@ -37213,8 +37283,17 @@ else if ("default".equals(terms.get(0) + ""))
initTerm = (ASTTerm) terms.get(3);
}

String km3type = typeTerm.toKM3();
Type actualType = (Type) typeTerm.modelElement;

// String km3type = typeTerm.toKM3();

String km3type = typeTerm.toKM3type();

Type actualType = null;
if (typeTerm.modelElement instanceof Type)
{ actualType = (Type) typeTerm.modelElement; }
else if (typeTerm.modelElement instanceof Entity)
{ actualType = new Type((Entity) typeTerm.modelElement); }
// Type actualType = (Type) typeTerm.modelElement;
String km3var = varTerm.toKM3();
String km3init = initTerm.toKM3();
CreationStatement cs =
Expand All @@ -37225,6 +37304,11 @@ else if ("default".equals(terms.get(0) + ""))
sstatements.addStatement(cs);
sstatements.addStatement(assgn);
statement = sstatements;

// JOptionPane.showInputDialog("Type of " + km3var + " is " + km3type);

ASTTerm.setType(km3var, km3type);

return " var " + km3var + " : " + actualType +
" := " + km3init + ";\n";
}
Expand Down

0 comments on commit 7959431

Please sign in to comment.