Commit e559c6a4 authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

continued refactoring

parent bdfdee7d
......@@ -49,64 +49,64 @@ public class TypesHelper {
public static ASTTypeArgument getReferenceTypeFromOptional(ASTType type) {
Preconditions.checkArgument(isOptional(type));
return (ASTTypeArgument)((ASTTypeArguments)((ASTSimpleReferenceType)type).getTypeArguments().get()).getTypeArguments().get(0);
return (ASTTypeArgument) ((ASTTypeArguments) ((ASTSimpleReferenceType) type).getTypeArguments().get()).getTypeArguments().get(0);
}
public static ASTSimpleReferenceType getSimpleReferenceTypeFromOptional(ASTType type) {
Preconditions.checkArgument(isOptional(type));
ASTTypeArgument refType = getReferenceTypeFromOptional(type);
if(refType instanceof ASTWildcardType && ((ASTWildcardType)refType).getUpperBound().isPresent()) {
refType = (ASTTypeArgument)((ASTWildcardType)refType).getUpperBound().get();
if (refType instanceof ASTWildcardType && ((ASTWildcardType) refType).getUpperBound().isPresent()) {
refType = (ASTTypeArgument) ((ASTWildcardType) refType).getUpperBound().get();
}
Preconditions.checkState(refType instanceof ASTSimpleReferenceType);
return (ASTSimpleReferenceType)refType;
return (ASTSimpleReferenceType) refType;
}
public static String getReferenceNameFromOptional(ASTType type) {
Preconditions.checkArgument(isOptional(type));
ASTTypeArgument reference = (ASTTypeArgument)((ASTTypeArguments)((ASTSimpleReferenceType)type).getTypeArguments().get()).getTypeArguments().get(0);
if(reference instanceof ASTWildcardType && ((ASTWildcardType)reference).getUpperBound().isPresent()) {
reference = (ASTTypeArgument)((ASTWildcardType)reference).getUpperBound().get();
ASTTypeArgument reference = (ASTTypeArgument) ((ASTTypeArguments) ((ASTSimpleReferenceType) type).getTypeArguments().get()).getTypeArguments().get(0);
if (reference instanceof ASTWildcardType && ((ASTWildcardType) reference).getUpperBound().isPresent()) {
reference = (ASTTypeArgument) ((ASTWildcardType) reference).getUpperBound().get();
}
Preconditions.checkArgument(reference instanceof ASTSimpleReferenceType);
List names = ((ASTSimpleReferenceType)reference).getNames();
return names.isEmpty()?"":(String)names.get(names.size() - 1);
List names = ((ASTSimpleReferenceType) reference).getNames();
return names.isEmpty() ? "" : (String) names.get(names.size() - 1);
}
public static String getQualifiedReferenceNameFromOptional(ASTType type) {
Preconditions.checkArgument(isOptional(type));
ASTTypeArgument reference = (ASTTypeArgument)((ASTTypeArguments)((ASTSimpleReferenceType)type).getTypeArguments().get()).getTypeArguments().get(0);
if(reference instanceof ASTWildcardType && ((ASTWildcardType)reference).getUpperBound().isPresent()) {
reference = (ASTTypeArgument)((ASTWildcardType)reference).getUpperBound().get();
ASTTypeArgument reference = (ASTTypeArgument) ((ASTTypeArguments) ((ASTSimpleReferenceType) type).getTypeArguments().get()).getTypeArguments().get(0);
if (reference instanceof ASTWildcardType && ((ASTWildcardType) reference).getUpperBound().isPresent()) {
reference = (ASTTypeArgument) ((ASTWildcardType) reference).getUpperBound().get();
}
Preconditions.checkArgument(reference instanceof ASTSimpleReferenceType);
List names = ((ASTSimpleReferenceType)reference).getNames();
return names.isEmpty()?"": Names.getQualifiedName(names);
List names = ((ASTSimpleReferenceType) reference).getNames();
return names.isEmpty() ? "" : Names.getQualifiedName(names);
}
public static boolean isGenericTypeWithOneTypeArgument(ASTType type, String simpleRefTypeName) {
if(!(type instanceof ASTSimpleReferenceType)) {
if (!(type instanceof ASTSimpleReferenceType)) {
return false;
} else {
ASTSimpleReferenceType simpleRefType = (ASTSimpleReferenceType)type;
return Names.getQualifiedName(simpleRefType.getNames()).equals(simpleRefTypeName) && simpleRefType.getTypeArguments().isPresent() && ((ASTTypeArguments)simpleRefType.getTypeArguments().get()).getTypeArguments().size() == 1;
ASTSimpleReferenceType simpleRefType = (ASTSimpleReferenceType) type;
return Names.getQualifiedName(simpleRefType.getNames()).equals(simpleRefTypeName) && simpleRefType.getTypeArguments().isPresent() && ((ASTTypeArguments) simpleRefType.getTypeArguments().get()).getTypeArguments().size() == 1;
}
}
public static int getArrayDimensionIfArrayOrZero(ASTType astType) {
return astType instanceof ASTArrayType?((ASTArrayType)astType).getDimensions():0;
return astType instanceof ASTArrayType ? ((ASTArrayType) astType).getDimensions() : 0;
}
public static Optional<ASTSimpleReferenceType> getFirstTypeArgumentOfGenericType(ASTType type, String simpleRefTypeName) {
if(!isGenericTypeWithOneTypeArgument(type, simpleRefTypeName)) {
if (!isGenericTypeWithOneTypeArgument(type, simpleRefTypeName)) {
return Optional.empty();
} else {
ASTSimpleReferenceType simpleRefType = (ASTSimpleReferenceType)type;
ASTTypeArgument typeArgument = (ASTTypeArgument)((ASTTypeArguments)simpleRefType.getTypeArguments().get()).getTypeArguments().get(0);
return !(typeArgument instanceof ASTSimpleReferenceType)?Optional.empty():Optional.of((ASTSimpleReferenceType)typeArgument);
ASTSimpleReferenceType simpleRefType = (ASTSimpleReferenceType) type;
ASTTypeArgument typeArgument = (ASTTypeArgument) ((ASTTypeArguments) simpleRefType.getTypeArguments().get()).getTypeArguments().get(0);
return !(typeArgument instanceof ASTSimpleReferenceType) ? Optional.empty() : Optional.of((ASTSimpleReferenceType) typeArgument);
}
}
......@@ -117,8 +117,8 @@ public class TypesHelper {
public static String getSimpleName(ASTSimpleReferenceType simpleType) {
String name = "";
List qualifiedName = simpleType.getNames();
if(qualifiedName != null && !qualifiedName.isEmpty()) {
name = (String)qualifiedName.get(qualifiedName.size() - 1);
if (qualifiedName != null && !qualifiedName.isEmpty()) {
name = (String) qualifiedName.get(qualifiedName.size() - 1);
}
return name;
......@@ -129,7 +129,7 @@ public class TypesHelper {
}
public static String printType(ASTType type) {
if(isOptional(type)) {
if (isOptional(type)) {
ASTTypeArgument ref = getReferenceTypeFromOptional(type);
return printType(ref);
} else {
......@@ -142,80 +142,94 @@ public class TypesHelper {
}
public static String printType(ASTTypeArgument type) {
return type instanceof ASTWildcardType?TypesPrinter.printWildcardType((ASTWildcardType)type):printType((ASTType)type);
return type instanceof ASTWildcardType ? TypesPrinter.printWildcardType((ASTWildcardType) type) : printType((ASTType) type);
}
public static String printSimpleRefType(ASTType type) {
return isOptional(type)?printType((ASTType)getSimpleReferenceTypeFromOptional(type)):TypesPrinter.printType(type);
return isOptional(type) ? printType((ASTType) getSimpleReferenceTypeFromOptional(type)) : TypesPrinter.printType(type);
}
public static int getPrimitiveType(String typeName) {
if(Strings.isNullOrEmpty(typeName)) {
if (Strings.isNullOrEmpty(typeName)) {
return -1;
} else {
byte var2 = -1;
switch(typeName.hashCode()) {
case -1325958191:
if(typeName.equals("double")) {
var2 = 4;
}
break;
case 104431:
if(typeName.equals("int")) {
var2 = 5;
}
break;
case 3039496:
if(typeName.equals("byte")) {
var2 = 2;
}
break;
case 3052374:
if(typeName.equals("char")) {
var2 = 3;
}
break;
case 3327612:
if(typeName.equals("long")) {
var2 = 7;
}
break;
case 64711720:
if(typeName.equals("boolean")) {
var2 = 0;
}
break;
case 97526364:
if(typeName.equals("float")) {
var2 = 1;
}
break;
case 109413500:
if(typeName.equals("short")) {
var2 = 6;
}
}
switch(var2) {
updateVar2(var2, typeName);
int result = -1;
switch (var2) {
case 0:
return 1;
result = 1;
break;
case 1:
return 7;
result = 7;
break;
case 2:
return 2;
result = 2;
break;
case 3:
return 6;
result = 6;
break;
case 4:
return 8;
result = 8;
break;
case 5:
return 4;
result = 4;
break;
case 6:
return 3;
result = 3;
break;
case 7:
return 5;
result = 5;
break;
default:
return -1;
result = -1;
}
return result;
}
}
private static int updateVar2(int var2, String typeName) {
switch (typeName.hashCode()) {
case -1325958191:
if (typeName.equals("double")) {
var2 = 4;
}
break;
case 104431:
if (typeName.equals("int")) {
var2 = 5;
}
break;
case 3039496:
if (typeName.equals("byte")) {
var2 = 2;
}
break;
case 3052374:
if (typeName.equals("char")) {
var2 = 3;
}
break;
case 3327612:
if (typeName.equals("long")) {
var2 = 7;
}
break;
case 64711720:
if (typeName.equals("boolean")) {
var2 = 0;
}
break;
case 97526364:
if (typeName.equals("float")) {
var2 = 1;
}
break;
case 109413500:
if (typeName.equals("short")) {
var2 = 6;
}
}
return var2;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment