From d0b2d1e1b447b2bb7b5f5275dfbc3bbd44b6c87b Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 20 Oct 2015 19:02:53 +0100 Subject: Extract typeOf(Type) --- .../java/org/zwobble/couscous/frontends/java/JavaReader.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java b/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java index 22d42ab..04ed784 100644 --- a/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java +++ b/src/main/java/org/zwobble/couscous/frontends/java/JavaReader.java @@ -26,6 +26,7 @@ import org.eclipse.jdt.core.dom.SingleVariableDeclaration; import org.eclipse.jdt.core.dom.Statement; import org.eclipse.jdt.core.dom.StringLiteral; import org.eclipse.jdt.core.dom.ThisExpression; +import org.eclipse.jdt.core.dom.Type; import org.eclipse.jdt.core.dom.TypeDeclaration; import org.eclipse.jdt.core.dom.VariableDeclarationFragment; import org.eclipse.jdt.core.dom.VariableDeclarationStatement; @@ -88,7 +89,7 @@ public class JavaReader { private static void readField(FieldDeclaration field, ClassNodeBuilder classBuilder) { for (val fragment : field.fragments()) { val name = ((VariableDeclarationFragment)fragment).getName().getIdentifier(); - classBuilder.field(name, typeOf(field.getType().resolveBinding())); + classBuilder.field(name, typeOf(field.getType())); } } @@ -145,7 +146,7 @@ public class JavaReader { private static List readVariableDeclarationStatement(VariableDeclarationStatement statement) { @SuppressWarnings("unchecked") val fragments = (List)statement.fragments(); - val type = typeOf(statement.getType().resolveBinding()); + val type = typeOf(statement.getType()); return Lists.transform(fragments, fragment -> localVariableDeclaration( fragment.resolveBinding().getKey(), @@ -203,7 +204,7 @@ public class JavaReader { } private static ExpressionNode readVariableBinding(IVariableBinding binding) { - val type = typeOf(binding.getType()); + val type = typeOf(binding); if (binding.getDeclaringClass() == null) { return reference(var( binding.getKey(), @@ -295,6 +296,10 @@ public class JavaReader { return typeOf(variableBinding.getType()); } + private static TypeName typeOf(Type type) { + return typeOf(type.resolveBinding()); + } + private static TypeName typeOf(ITypeBinding typeBinding) { return TypeName.of(typeBinding.getQualifiedName()); } -- cgit v1.2.3