Object wird standardmäßig importiert. TestFiles angefügt

This commit is contained in:
JanUlrich 2014-05-07 21:57:29 +02:00
parent c6ddc8036d
commit 4a67a4a58e
12 changed files with 678 additions and 25 deletions

View File

@ -1092,6 +1092,9 @@ public class SourceFile
Modifiers mod = new Modifiers(); Modifiers mod = new Modifiers();
mod.addModifier(new Public()); mod.addModifier(new Public());
//Für Object:
//TODO: toString()-Methode gerät nicht in die BasicAssumptions
imports.add(new UsedId("java.lang.Object",-1));
// Für jede einzelne Klasse // Für jede einzelne Klasse
while (imports.size()>0) { while (imports.size()>0) {

View File

@ -11,4 +11,5 @@ import mycompiler.mytype.GenericTypeVar;
*/ */
public interface Generic { public interface Generic {
public void setGenericParameter(Vector<GenericTypeVar> params); public void setGenericParameter(Vector<GenericTypeVar> params);
//public int getGenericParameterOffset();
} }

View File

@ -91,7 +91,7 @@ public class TypeInsertPoint implements Comparable<TypeInsertPoint>{
if(! (obj instanceof TypeInsertPoint))return false; if(! (obj instanceof TypeInsertPoint))return false;
TypeInsertPoint equals = (TypeInsertPoint) obj; TypeInsertPoint equals = (TypeInsertPoint) obj;
if(!(equals.getInsertNode().equals(this.getInsertNode())))return false; if(!(equals.getInsertNode().equals(this.getInsertNode())))return false;
if(!(equals.resultSet.equals(this.resultSet)))return false; if(!(equals.resultSet.equals(this.resultSet)))return false; //ResultSet spielt bei Equals keine Rolle
if(!(equals.getInsertType().equals(this.getInsertType())))return false; if(!(equals.getInsertType().equals(this.getInsertType())))return false;
return true; return true;

View File

@ -35,17 +35,15 @@ public class TypeInsertSet {
* @param typeInsertPoint * @param typeInsertPoint
* @return * @return
*/ */
public Vector<TypePlaceholder> add(TypeInsertPoint typeInsertPoint) { public void add(TypeInsertPoint typeInsertPoint) {
if( typeInsertPoint!=null && ! this.points.contains(typeInsertPoint)){ //Nur falls typeInsertPoint noch nicht im Set vorhanden ist: if( typeInsertPoint!=null && ! this.points.contains(typeInsertPoint)){ //Nur falls typeInsertPoint noch nicht im Set vorhanden ist:
points.add(typeInsertPoint); points.add(typeInsertPoint);
return typeInsertPoint.getUnresolvedTPH();
} }
return new Vector<TypePlaceholder>();
} }
public void add(GenericTypeInsertPoint typeInsertPoint) { public void add(GenericTypeInsertPoint typeInsertPoint) {
//this.add((TypeInsertPoint)typeInsertPoint); //this.add((TypeInsertPoint)typeInsertPoint);
this.genericTypeInsertPoints.add(typeInsertPoint); if(!this.genericTypeInsertPoints.contains(typeInsertPoint))this.genericTypeInsertPoints.add(typeInsertPoint);
} }
/** /**
@ -107,13 +105,20 @@ public class TypeInsertSet {
if(! (obj instanceof TypeInsertSet))return false; if(! (obj instanceof TypeInsertSet))return false;
TypeInsertSet equals = (TypeInsertSet) obj; TypeInsertSet equals = (TypeInsertSet) obj;
if(points.size()!=equals.points.size())return false; if(points.size()!=equals.points.size())return false;
for(TypeInsertPoint point : points){ for(TypeInsertPoint point : points){
//Jeder TypeInsertPoint muss auch in equals vorkommen: //Jeder TypeInsertPoint muss auch in equals vorkommen:
if(!equals.points.contains(point))return false; if(!equals.points.contains(point))
return false;
//... aber nicht öfter als 1x : //... aber nicht öfter als 1x :
if(equals.points.lastIndexOf(point)!=equals.points.indexOf(point))return false; if(equals.points.lastIndexOf(point)!=equals.points.indexOf(point))return false;
} }
for(GenericTypeInsertPoint point : this.genericTypeInsertPoints){
//Jeder TypeInsertPoint muss auch in equals vorkommen:
if(!equals.genericTypeInsertPoints.contains(point))return false;
//... aber nicht öfter als 1x :
if(equals.genericTypeInsertPoints.lastIndexOf(point)!=equals.genericTypeInsertPoints.indexOf(point))return false;
}
return true; return true;
} }

View File

@ -1,3 +1,5 @@
import java.util.Vector;
class BasicAssumptionsTest{ class BasicAssumptionsTest{
varString; varString;
@ -5,6 +7,6 @@ var = 2;
void methode(){ void methode(){
var = 1; var = 1;
varString = varString.toString(); varString.add(var);
} }
} }

View File

@ -18,7 +18,7 @@ public class TestAssign extends TestCase{
@Test @Test
public void test() { public void test() {
variableTypeAssumptions.put("stringVar", "String"); variableTypeAssumptions.put("stringVar", "java.lang.String");
executeTest(); executeTest();
} }

View File

@ -24,7 +24,6 @@ public class TestMethodCall {
public void executeTest(){ public void executeTest(){
LambdaTest tester = new LambdaTest(exampleJavFile); LambdaTest tester = new LambdaTest(exampleJavFile);
tester.runTestAndCheckResultSet(classname, variableTypeAssumptions); tester.runTestAndCheckResultSet(classname, variableTypeAssumptions);
} }
} }

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,10 @@
import java.util.Vector;
class ImportTest{
Vector<String> var;
var2;
methode(){
var.add(var2);
}
}

View File

@ -0,0 +1,48 @@
package plugindevelopment;
import java.io.File;
import java.io.IOException;
import java.util.Vector;
import junit.framework.TestCase;
import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.myparser.JavaParser.yyException;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import org.junit.Test;
import typinferenz.TypeInsertSet;
public class TypeInsertSetEqualTest {
private static final String TEST_FILE = "TypeInsertSetEqualTest.jav";
@Test
public void run(){
String inferedSource = "";
MyCompilerAPI compiler = MyCompiler.getAPI();
try {
compiler.parse(new File(TypeInsertTester.rootDirectory + TEST_FILE));
Vector<TypeinferenceResultSet> results = compiler.typeReconstruction();
//TestCase.assertTrue("Es darf nicht mehr als eine Lösungsmöglichkeit geben und nicht "+results.size(), results.size()==1);
Vector<TypeInsertSet> insertSets = new Vector<TypeInsertSet>();
for(TypeinferenceResultSet result : results){
TypeInsertSet point = result.getTypeInsertionPoints();
if(!insertSets.contains(point))insertSets.add(point);
//TestCase.assertTrue("Es muss mindestens ein TypeInsertSet vorhanden sein", points.size()>0);
}
if(insertSets.size()!=1){
TestCase.fail("Es darf nur ein TypeInsertSet geben und nicht "+insertSets.size());
}
} catch (IOException | yyException e) {
e.printStackTrace();
TestCase.fail();
}
}
}

View File

@ -0,0 +1,6 @@
class IntTest{
var;
int methode(){
return var;
}
}

View File

@ -0,0 +1,18 @@
package plugindevelopment.TypeInsertTests;
import java.util.Vector;
import org.junit.Test;
public class IntTest {
private static final String TEST_FILE = "IntTest.jav";
@Test
public void run(){
Vector<String> mustContain = new Vector<String>();
mustContain.add("int var");
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}