From ee932892c6dd07989f650322cf5ebf4c72015e5e Mon Sep 17 00:00:00 2001 From: Fayez Abu Alia Date: Fri, 5 Apr 2019 10:43:09 +0200 Subject: [PATCH] subString durch contains ersetzt --- .../java/de/dhbwstuttgart/bytecode/BytecodeGen.java | 4 ++-- .../bytecode/descriptor/DescriptorToString.java | 12 ++++++------ src/test/resources/bytecode/javFiles/TypedID.jav | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java index b013f495..8ae7da1e 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/BytecodeGen.java @@ -356,7 +356,7 @@ public class BytecodeGen implements ASTVisitor { System.out.println(acc); /*Prüfe, ob die Rückgabe-Type der Methode eine Type-Variable ist*/ - boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.subSequence(0, 4).equals("TPH ") || + boolean hasGenInParameterList = genericsAndBounds.containsKey(retType) || retType.contains("TPH ") || resultSet.resolveType(method.getReturnType()).resolvedType.acceptTV(new TypeToSignature()).contains("<"); /*Wenn die Rückgabe-Type eine Typ-variable ist, erzeuge direkt die Signature, wenn nicht, * prüfe, ob einer der Parameter Typ-Variable als Typ hat*/ @@ -364,7 +364,7 @@ public class BytecodeGen implements ASTVisitor { for(String paramName : methodParamsAndTypes.keySet()) { String typeOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToDescriptor()); String sigOfParam = methodParamsAndTypes.get(paramName).acceptTV(new TypeToSignature()); - if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.substring(0, 4).equals("TPH ")||sigOfParam.contains("<")) { + if(genericsAndBounds.containsKey(typeOfParam)||typeOfParam.contains("TPH ")||sigOfParam.contains("<")) { hasGenInParameterList = true; break; } diff --git a/src/main/java/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java b/src/main/java/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java index d4d6b430..3fd10cf5 100644 --- a/src/main/java/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java +++ b/src/main/java/de/dhbwstuttgart/bytecode/descriptor/DescriptorToString.java @@ -162,7 +162,7 @@ public class DescriptorToString implements DescriptorVisitor{ while(itr.hasNext()) { FormalParameter fp = itr.next(); String d = resultSet.resolveType(fp.getType()).resolvedType.acceptTV(new TypeToDescriptor()); - if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) { + if(d.contains("TPH ") ||d.contains("<")) { desc += "L"+Type.getInternalName(Object.class)+ ";"; }else { desc = desc + "L"+ d + ";"; @@ -171,7 +171,7 @@ public class DescriptorToString implements DescriptorVisitor{ String retType = resultSet.resolveType(lambdaExpression.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor()); - if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){ + if(retType.contains("TPH ")|| retType.contains("<")){ desc += ")L"+Type.getInternalName(Object.class)+ ";"; }else { desc = desc + ")"+"L"+retType+";"; @@ -187,7 +187,7 @@ public class DescriptorToString implements DescriptorVisitor{ RefTypeOrTPHOrWildcardOrGeneric rt = itr.next(); String d = resultSet.resolveType(rt).resolvedType.acceptTV(new TypeToDescriptor()); - if(d.substring(0, 4).equals("TPH ") ||d.contains("<")) { + if(d.contains("TPH ") ||d.contains("<")) { desc += "L"+Type.getInternalName(Object.class)+ ";"; }else { desc += "L"+ d + ";"; @@ -196,7 +196,7 @@ public class DescriptorToString implements DescriptorVisitor{ } String retType = resultSet.resolveType(samMethod.getReturnType()).resolvedType.acceptTV(new TypeToDescriptor()); - if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<")){ + if(retType.contains("TPH ")|| retType.contains("<")){ desc += ")L"+Type.getInternalName(Object.class)+ ";"; }else { desc = desc + ")"+"L"+retType+";"; @@ -210,7 +210,7 @@ public class DescriptorToString implements DescriptorVisitor{ for(Expression e : methodFromMethodCall.getArgList().getArguments()) { String d = resultSet.resolveType(e.getType()).resolvedType.acceptTV(new TypeToDescriptor()); - if(d.substring(0, 4).equals("TPH ") ||d.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")) { + if(d.contains("TPH ") ||d.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")) { desc += "L"+Type.getInternalName(Object.class)+ ";"; }else { if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(d)) { @@ -227,7 +227,7 @@ public class DescriptorToString implements DescriptorVisitor{ System.out.println("DescriptorToString retType = " + retType); if(retType.equals("void")) { desc += ")V"; - }else if(retType.substring(0, 4).equals("TPH ")|| retType.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")){ + }else if(retType.contains("TPH ")|| retType.contains("<") || methodFromMethodCall.getReceiverName().contains("$$")){ desc += ")L"+Type.getInternalName(Object.class)+ ";"; }else { if(methodFromMethodCall.getGenericsAndBoundsMethod().containsKey(retType)) { diff --git a/src/test/resources/bytecode/javFiles/TypedID.jav b/src/test/resources/bytecode/javFiles/TypedID.jav index 8ff8d4b6..6e2477a5 100644 --- a/src/test/resources/bytecode/javFiles/TypedID.jav +++ b/src/test/resources/bytecode/javFiles/TypedID.jav @@ -1,6 +1,6 @@ -public class TypedID { +public class TypedID/* */ { - id(L b){ + id(K b){ return b; } } \ No newline at end of file