changeset 3520:54649cba25f1

Cleanup: Encapsulate the uses of the flag VALUE_CAPABLE
author sadayapalam
date Thu, 06 Oct 2016 11:34:59 +0530
parents a7d38b363cf5
children ef0142d1ab9a
files src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ValueCapableClassAttr.java
diffstat 4 files changed, 25 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Tue Oct 04 15:56:08 2016 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Symbol.java	Thu Oct 06 11:34:59 2016 +0530
@@ -406,6 +406,12 @@
         return name == name.table.names.init;
     }
 
+    /**
+     * Is this a value capable class ?
+     */
+    public boolean isValueCapable() {
+        return (flags() & VALUE_CAPABLE) != 0;
+    }
     /** The fully qualified name of this symbol.
      *  This is the same as the symbol's name except for class symbols,
      *  which are handled separately.
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Tue Oct 04 15:56:08 2016 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java	Thu Oct 06 11:34:59 2016 +0530
@@ -313,7 +313,7 @@
     }
 
     public boolean isValueCapable(Type t) {
-        return t != null && t.tsym != null && (t.tsym.flags_field & VALUE_CAPABLE) != 0;
+        return t != null && t.tsym != null && t.tsym.isValueCapable();
     }
 
     public boolean requiresThreadLocalBackingBuffer(Type t) {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Tue Oct 04 15:56:08 2016 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java	Thu Oct 06 11:34:59 2016 +0530
@@ -2256,7 +2256,7 @@
                     JCVariableDecl field = (JCVariableDecl) l.head;
                     if (!field.sym.isStatic()) {
                         Type fieldType = field.sym.type;
-                        if (types.isValue(fieldType) || (fieldType.tsym.flags() & Flags.VALUE_CAPABLE) != 0) {
+                        if (types.isValue(fieldType) || types.isValueCapable(fieldType)) {
                             checkNonCyclicMembership((ClassSymbol) fieldType.tsym, field.pos());
                         }
                     }
@@ -2277,7 +2277,7 @@
                 c.flags_field |= LOCKED;
                 for (Symbol fld : c.members().getSymbols(s -> s.kind == VAR &&
                                                               !s.isStatic() &&
-                        (types.isValue(s.type) || (s.type.tsym.flags() & VALUE_CAPABLE) != 0), NON_RECURSIVE)) {
+                        (types.isValue(s.type) || types.isValueCapable(s.type)), NON_RECURSIVE)) {
                     checkNonCyclicMembership((ClassSymbol) fld.type.tsym, pos);
                 }
             } finally {
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ValueCapableClassAttr.java	Tue Oct 04 15:56:08 2016 +0530
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ValueCapableClassAttr.java	Thu Oct 06 11:34:59 2016 +0530
@@ -27,7 +27,6 @@
 
 import com.sun.tools.javac.code.*;
 
-import static com.sun.tools.javac.code.Flags.VALUE_CAPABLE;
 import static com.sun.tools.javac.code.Flags.asFlagSet;
 import static com.sun.tools.javac.code.Kinds.Kind.*;
 import com.sun.tools.javac.code.Symbol.MethodSymbol;
@@ -84,7 +83,7 @@
                 JCAnnotation a = al.head;
                 if (a.annotationType.type == syms.deriveValueType && a.args.isEmpty()) {
                     inValue = true;
-                    tree.sym.flags_field |= VALUE_CAPABLE;
+                    tree.sym.flags_field |= Flags.VALUE_CAPABLE;
                     break;
                 }
             }
@@ -107,7 +106,7 @@
         JCMethodDecl previousMethod = currentMethod;
         try {
             currentMethod = tree;
-            if (tree.sym != null && (tree.sym.owner.flags() & VALUE_CAPABLE) != 0) {
+            if (tree.sym != null && tree.sym.owner.isValueCapable()) {
                 if ((tree.sym.flags() & (Flags.SYNCHRONIZED | Flags.STATIC)) == Flags.SYNCHRONIZED) {
                     log.error(tree.pos(), "mod.not.allowed.here", asFlagSet(Flags.SYNCHRONIZED));
                 }
@@ -142,13 +141,13 @@
     }
 
     public void visitVarDef(JCVariableDecl tree) {
-        if (tree.sym != null && tree.sym.owner.kind == TYP && (tree.sym.owner.flags() & VALUE_CAPABLE) != 0) {
+        if (tree.sym != null && tree.sym.owner.kind == TYP && tree.sym.owner.isValueCapable()) {
             if ((tree.mods.flags & (Flags.FINAL | Flags.STATIC)) == 0) {
                 log.error(tree.pos(), "value.field.must.be.final");
             }
         }
         if (tree.init != null && tree.init.type != null && tree.init.type.hasTag(TypeTag.BOT)) {
-            if ((tree.vartype.type.tsym.flags() & VALUE_CAPABLE) != 0)
+            if (types.isValueCapable(tree.vartype.type))
                 log.error(tree.init.pos(), "prob.found.req", diags.fragment("inconvertible.types", syms.botType, tree.vartype.type));
         }
         super.visitVarDef(tree);
@@ -158,7 +157,7 @@
     public void visitAssign(JCAssign tree) {
         if (tree.rhs.type != null && tree.rhs.type.hasTag(TypeTag.BOT)) {
             Type lType = tree.lhs.type;
-            if (lType != null && (lType.tsym.flags() & VALUE_CAPABLE) != 0) {
+            if (lType != null && types.isValueCapable(lType)) {
                 log.error(tree.rhs.pos(), "prob.found.req", diags.fragment("inconvertible.types", syms.botType, lType));
             }
         }
@@ -168,7 +167,7 @@
     @Override
     public void visitReturn(JCReturn tree) {
         if (currentMethod != null && tree.expr != null && tree.expr.type != null && tree.expr.type.hasTag(TypeTag.BOT)) {
-            if (currentMethod.restype != null && (currentMethod.restype.type.tsym.flags() & VALUE_CAPABLE) != 0) {
+            if (currentMethod.restype != null && types.isValueCapable(currentMethod.restype.type)) {
                 log.error(tree.expr.pos(), "prob.found.req", diags.fragment("inconvertible.types", syms.botType, currentMethod.restype.type));
             }
         }
@@ -178,7 +177,7 @@
     @Override
     public void visitTypeTest(JCInstanceOf tree) {
         if (tree.expr.type.hasTag(TypeTag.BOT)) {
-            if ((tree.clazz.type.tsym.flags() & VALUE_CAPABLE) != 0) {
+            if (types.isValueCapable(tree.clazz.type)) {
                 log.error(tree.expr.pos(), "prob.found.req", diags.fragment("inconvertible.types", syms.botType, tree.clazz.type));
             }
         }
@@ -188,7 +187,7 @@
     @Override
     public void visitTypeCast(JCTypeCast tree) {
         if (tree.expr.type != null && tree.expr.type.hasTag(TypeTag.BOT) &&
-                tree.clazz.type != null && (tree.clazz.type.tsym.flags() & VALUE_CAPABLE) != 0) {
+                tree.clazz.type != null && types.isValueCapable(tree.clazz.type)) {
             log.error(tree.expr.pos(), "prob.found.req", diags.fragment("inconvertible.types", syms.botType, tree.clazz.type));
         }
         super.visitTypeCast(tree);
@@ -204,15 +203,15 @@
                 right != null && !right.isErroneous()) {
             int opc = ((OperatorSymbol)operator).opcode;
             if ((opc == ByteCodes.if_acmpeq || opc == ByteCodes.if_acmpne)) {
-                if ((left.hasTag(TypeTag.BOT) && (right.tsym.flags() & VALUE_CAPABLE) != 0) ||
-                        (right.hasTag(TypeTag.BOT) && (left.tsym.flags() & VALUE_CAPABLE) != 0)) {
+                if ((left.hasTag(TypeTag.BOT) && types.isValueCapable(right)) ||
+                        (right.hasTag(TypeTag.BOT) && types.isValueCapable(left))) {
                     log.error(tree.pos(), "incomparable.types", left, right);
                 }
             }
             // this is likely to change.
             if (operator.name.contentEquals("==") || operator.name.contentEquals("!=")) {
-                if ((tree.lhs.type.tsym.flags() & VALUE_CAPABLE) != 0 ||
-                        (tree.rhs.type.tsym.flags() & VALUE_CAPABLE) != 0)
+                if (types.isValueCapable(tree.lhs.type) ||
+                        types.isValueCapable(tree.rhs.type))
                     log.error(tree.pos(), "value.does.not.support", tree.operator.name.toString());
             }
         }
@@ -221,7 +220,7 @@
 
     @Override
     public void visitSynchronized(JCSynchronized tree) {
-        if ((tree.lock.type.tsym.flags() & VALUE_CAPABLE) != 0) {
+        if (types.isValueCapable(tree.lock.type)) {
             log.error(tree.pos(), "type.found.req", tree.lock.type, diags.fragment("type.req.ref"));
         }
         super.visitSynchronized(tree);
@@ -231,7 +230,7 @@
         final Symbol method = TreeInfo.symbolFor(tree);
         if (method != null && method.kind != ERR) {
             if (method.name.contentEquals("identityHashCode") && method.owner.type == syms.systemType) {
-                if ((tree.args.length() == 1) && ((tree.args.head.type.tsym.flags() & VALUE_CAPABLE) != 0))
+                if ((tree.args.length() == 1) && types.isValueCapable(tree.args.head.type))
                     log.error(tree.pos(), "value.does.not.support", "identityHashCode");
             }
 
@@ -244,7 +243,7 @@
                     case SELECT:
                         final Symbol symbol = TreeInfo.symbol(((JCFieldAccess)tree.meth).selected);
                         receiverIsValue = symbol != null &&
-                                (symbol.name == names._super ? inValue : (symbol.type.tsym.flags() & VALUE_CAPABLE) != 0);
+                                symbol.name == names._super ? inValue : types.isValueCapable(symbol.type);
                         break;
                 }
                 if (receiverIsValue) {
@@ -257,7 +256,7 @@
                 if (arg.type != null && arg.type.hasTag(TypeTag.BOT)) {
                     Type param = i < parameterTypes.size() ? parameterTypes.get(i) :
                             types.elemtype(parameterTypes.get(parameterTypes.size() - 1));
-                    if ((param.tsym.flags() & VALUE_CAPABLE) != 0)
+                    if (types.isValueCapable(param))
                         log.error(arg.pos(), "prob.found.req", diags.fragment("inconvertible.types", syms.botType, param));
                 }
             }