From 8657960943b25e0fa03c3820574a05df7b445328 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 28 Dec 2010 12:32:46 -0800 Subject: [PATCH] Don't try to resolve the type of the RHS if its a primitive. --- src/main/java/org/ductilej/detyper/Detype.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/ductilej/detyper/Detype.java b/src/main/java/org/ductilej/detyper/Detype.java index 05ae6c4..a4f72d4 100644 --- a/src/main/java/org/ductilej/detyper/Detype.java +++ b/src/main/java/org/ductilej/detyper/Detype.java @@ -1184,11 +1184,14 @@ protected boolean inStatic () protected boolean isConstDecl (JCVariableDecl tree) { - // the declared type must be (resolvable and) a primitive or a string - Type vtype = _resolver.resolveType(_env, tree.vartype, Kinds.TYP); - if (vtype != null && tree.vartype.getTag() != JCTree.TYPEIDENT && - !_types.isSameType(vtype, _syms.stringType)) { - return false; + // if the type of the RHS is not a primitive... + if (tree.vartype.getTag() != JCTree.TYPEIDENT) { + // ...then the only other possible const expression is a string + Type vtype = _resolver.resolveType(_env, tree.vartype, Kinds.TYP); + // if we could not resolve the type of the RHS, it's definitely not a string literal + if (vtype == null || !_types.isSameType(vtype, _syms.stringType)) { + return false; + } } // it must be explicitly declared final or be an interface field member (which is