diff --git a/hackathon/callref-rascal/META-INF/MANIFEST.MF b/hackathon/callref-rascal/META-INF/MANIFEST.MF new file mode 100644 index 0000000..8ffad25 --- /dev/null +++ b/hackathon/callref-rascal/META-INF/MANIFEST.MF @@ -0,0 +1,8 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Project1 +Bundle-SymbolicName: Project1 +Bundle-Version: 1.0.0 +Require-Bundle: org.eclipse.imp.pdb.values, + rascal +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 diff --git a/hackathon/callref-rascal/bin/File1.rsc b/hackathon/callref-rascal/bin/File1.rsc new file mode 100644 index 0000000..ca697f0 --- /dev/null +++ b/hackathon/callref-rascal/bin/File1.rsc @@ -0,0 +1,66 @@ +module File1 + +import lang::java::jdt::Java; +import lang::java::jdt::JavaADT; +import lang::java::jdt::JDT; + +import Set; + +public list[loc] projects = [|project://javaInheritance/|]; + +public rel[str, str, int] function1(list[loc] projects) + = { *function2(project) | loc project <- projects }; + +public list[str] function1(loc project) { + list[str] names = []; + + visit(createAstsFromProject(project)) { + // case anonymousClassDeclaration(list[AstNode] bodyDeclarations): ; + case enumDeclaration(_, str name, list[AstNode] implements, list[AstNode] enumConstants, list[AstNode] bodyDeclarations): names += name; + case typeDeclaration(list[Modifier] modifiers, str objectType, str name, list[AstNode] genericTypes, Option[AstNode] extends, list[AstNode] implements, list[AstNode] bodyDeclarations): names += name; + } + + return names; + +} + +public rel[str, str, int] function2(loc project) { + rel[str, str, int] nameRel = {}; + visit(createAstsFromProject(project)) { + case m:methodDeclaration(list[Modifier] modifiers, list[AstNode] genericTypes, Option[AstNode] returnType, str name, list[AstNode] parameters, list[AstNode] possibleExceptions, some(AstNode implementation)): nameRel += { <"", n, c> | <- function3(implementation) }; + } + return nameRel; +} + +public rel[str, int] function3(AstNode method) { + rel[str, int] names = {}; + visit(method) { + case forStatement(list[AstNode] initializers, Option[AstNode] optionalBooleanExpression, list[AstNode] updaters, AstNode body): + names += {<[""], function4(body,1,10)[0], function4(body,1,10)[0], function4(body,1,10)[0]>}; + case ifStatement(AstNode booleanExpression, AstNode thenStatement, Option[AstNode] elseStatement): + names[""] = function4(thenStatement,0,1); + // for -> function4( _ , 1, 10); + // while -> function4( _ , 0, 10); + // if -> function4( _ , 0, 1); + } + return names; +} + +public rel[str, int, int] function4(AstNode method, int lower, int upper) { + rel[str, int, int] names = {}; + visit(method) + { + case m:methodInvocation(Option[AstNode] optionalExpression, list[AstNode] genericTypes, str name, list[AstNode] typedArguments): + { + n = ""; + if(isEmpty(names[n])) names += ; + else + { + tuple[int,int] c = getOneFrom(names[n]); + names = names - {} + {}; + } + } + } + return names; +} + diff --git a/hackathon/callref-rascal/build.properties b/hackathon/callref-rascal/build.properties new file mode 100644 index 0000000..5f22cdd --- /dev/null +++ b/hackathon/callref-rascal/build.properties @@ -0,0 +1 @@ +bin.includes = META-INF/ diff --git a/hackathon/callref-rascal/src/File1.rsc b/hackathon/callref-rascal/src/File1.rsc new file mode 100644 index 0000000..451dcdc --- /dev/null +++ b/hackathon/callref-rascal/src/File1.rsc @@ -0,0 +1,82 @@ +module File1 + +import lang::java::jdt::Java; +import lang::java::jdt::JavaADT; +import lang::java::jdt::JDT; + +import Set; + +public list[loc] projects = [|project://javaInheritance/|]; + +public rel[str, str, int, bool, bool] function1(list[loc] projects) + = { *function2(project) | loc project <- projects }; + +public list[str] function1(loc project) { + list[str] names = []; + + visit(createAstsFromProject(project)) { + // case anonymousClassDeclaration(list[AstNode] bodyDeclarations): ; + case enumDeclaration(_, str name, list[AstNode] implements, list[AstNode] enumConstants, list[AstNode] bodyDeclarations): names += name; + case typeDeclaration(list[Modifier] modifiers, str objectType, str name, list[AstNode] genericTypes, Option[AstNode] extends, list[AstNode] implements, list[AstNode] bodyDeclarations): names += name; + } + + return names; + +} + +public rel[str, str, int, bool, bool] function2(loc project) { + rel[str, str, int, bool, bool] nameRel = {}; + visit(createAstsFromProject(project)) { + case m:methodDeclaration(list[Modifier] modifiers, list[AstNode] genericTypes, Option[AstNode] returnType, str name, list[AstNode] parameters, list[AstNode] possibleExceptions, some(AstNode implementation)): + nameRel += { <"", n, c, lower, upper> | <- function3(implementation) }; + } + return nameRel; +} + +//public rel[str, int, bool, bool] function3(AstNode method) { +// rel[str, int, bool, bool] names = {}; +// visit(method) { +// case forStatement(list[AstNode] initializers, Option[AstNode] optionalBooleanExpression, list[AstNode] updaters, AstNode body): +// { +// rel[str, int, bool, bool] r = function4(body,1,10); +// names += {<[""], function4(body,1,10)[0], function4(body,1,10)[0], function4(body,1,10)[0]>}; +// } +// case ifStatement(AstNode booleanExpression, AstNode thenStatement, Option[AstNode] elseStatement): +// names[""] = function4(thenStatement,0,1); +// // for -> function4( _ , 1, 10); +// // while -> function4( _ , 0, 10); +// // if -> function4( _ , 0, 1); +// } +// return names; +//} + +public rel[str, int, bool, bool] function3(AstNode method) { + rel[str, int, bool, bool] names = {}; + bool lower = false; + bool upper = false; + top-down visit (method) + { + case forStatement(list[AstNode] initializers, Option[AstNode] optionalBooleanExpression, list[AstNode] updaters, AstNode body): + upper = true; + case ifStatement(AstNode booleanExpression, AstNode thenStatement, Option[AstNode] elseStatement): + lower = true; + case switchStatement(AstNode expression, list[AstNode] statements): + lower = true; + case doStatement(AstNode body, AstNode whileExpression): + upper = true; + case whileStatement(AstNode expression, AstNode body): + upper = true; + case m:methodInvocation(Option[AstNode] optionalExpression, list[AstNode] genericTypes, str name, list[AstNode] typedArguments): + { + n = ""; + if(isEmpty(names[n])) names += ; + else + { + tuple[int,bool,bool] c = getOneFrom(names[n]); + names = names - {} + {}; + } + } + } + return names; +} +