Java Code Examples for java.lang.reflect.Modifier#VOLATILE
The following examples show how to use
java.lang.reflect.Modifier#VOLATILE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmaliClassDetailLoader.java From PATDroid with Apache License 2.0 | 8 votes |
private static int translateAccessFlags(int accessFlags) { int f = 0; f |= (AccessFlags.ABSTRACT.isSet(accessFlags) ? Modifier.ABSTRACT : 0); // f |= (AccessFlags.ANNOTATION.isSet(accessFlags) ? Modifier.ANNOTATION : 0); // f |= (AccessFlags.BRIDGE.isSet(accessFlags) ? Modifier.BRIDGE : 0); // f |= (AccessFlags.CONSTRUCTOR.isSet(accessFlags) ? Modifier.CONSTRUCTOR : 0); // f |= (AccessFlags.DECLARED_SYNCHRONIZED.isSet(accessFlags) ? Modifier.DECLARED_SYNCHRONIZED : 0); // f |= (AccessFlags.ENUM.isSet(accessFlags) ? Modifier.ENUM : 0); f |= (AccessFlags.FINAL.isSet(accessFlags) ? Modifier.FINAL : 0); f |= (AccessFlags.INTERFACE.isSet(accessFlags) ? Modifier.INTERFACE : 0); f |= (AccessFlags.NATIVE.isSet(accessFlags) ? Modifier.NATIVE : 0); f |= (AccessFlags.PRIVATE.isSet(accessFlags) ? Modifier.PRIVATE : 0); f |= (AccessFlags.PROTECTED.isSet(accessFlags) ? Modifier.PROTECTED : 0); f |= (AccessFlags.PUBLIC.isSet(accessFlags) ? Modifier.PUBLIC : 0); f |= (AccessFlags.STATIC.isSet(accessFlags) ? Modifier.STATIC : 0); f |= (AccessFlags.STRICTFP.isSet(accessFlags) ? Modifier.STRICT : 0); f |= (AccessFlags.SYNCHRONIZED.isSet(accessFlags) ? Modifier.SYNCHRONIZED : 0); // f |= (AccessFlags.SYNTHETIC.isSet(accessFlags) ? Modifier.SYNTHETIC : 0); f |= (AccessFlags.TRANSIENT.isSet(accessFlags) ? Modifier.TRANSIENT : 0); // f |= (AccessFlags.VARARGS.isSet(accessFlags) ? Modifier.VARARGS : 0); f |= (AccessFlags.VOLATILE.isSet(accessFlags) ? Modifier.VOLATILE : 0); return f; }
Example 2
Source File: toStringTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 8 votes |
public static void main(String [] argv) { int allMods = Modifier.PUBLIC | Modifier.PROTECTED | Modifier.PRIVATE | Modifier.ABSTRACT | Modifier.STATIC | Modifier.FINAL | Modifier.TRANSIENT | Modifier.VOLATILE | Modifier.SYNCHRONIZED | Modifier.NATIVE | Modifier.STRICT | Modifier.INTERFACE; String allModsString = "public protected private abstract static " + "final transient volatile synchronized native strictfp interface"; /* zero should have an empty string */ testString(0, ""); /* test to make sure all modifiers print out in the proper order */ testString(allMods, allModsString); /* verify no extraneous modifiers are printed */ testString(~0, allModsString); }
Example 3
Source File: ClassInfo.java From ModTheSpire with MIT License | 6 votes |
/** * Convert an ASM access mask to a reflection Modifier mask. * * @param asmAccessMask the ASM access mask * * @return the Modifier mask */ private int convertAccessMaskToModifierMask(int asmAccessMask) { int modifier = 0; // Convert the ASM access info into Reflection API modifiers. if ((asmAccessMask & Opcodes.ACC_FINAL) != 0) modifier |= Modifier.FINAL; if ((asmAccessMask & Opcodes.ACC_NATIVE) != 0) modifier |= Modifier.NATIVE; if ((asmAccessMask & Opcodes.ACC_INTERFACE) != 0) modifier |= Modifier.INTERFACE; if ((asmAccessMask & Opcodes.ACC_ABSTRACT) != 0) modifier |= Modifier.ABSTRACT; if ((asmAccessMask & Opcodes.ACC_PRIVATE) != 0) modifier |= Modifier.PRIVATE; if ((asmAccessMask & Opcodes.ACC_PROTECTED) != 0) modifier |= Modifier.PROTECTED; if ((asmAccessMask & Opcodes.ACC_PUBLIC) != 0) modifier |= Modifier.PUBLIC; if ((asmAccessMask & Opcodes.ACC_STATIC) != 0) modifier |= Modifier.STATIC; if ((asmAccessMask & Opcodes.ACC_STRICT) != 0) modifier |= Modifier.STRICT; if ((asmAccessMask & Opcodes.ACC_SYNCHRONIZED) != 0) modifier |= Modifier.SYNCHRONIZED; if ((asmAccessMask & Opcodes.ACC_TRANSIENT) != 0) modifier |= Modifier.TRANSIENT; if ((asmAccessMask & Opcodes.ACC_VOLATILE) != 0) modifier |= Modifier.VOLATILE; return modifier; }
Example 4
Source File: AtomicFieldUpdater.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private static <T, V> Field getTheOnlyVolatileFieldOfClass(@Nonnull Class<T> ownerClass, @Nonnull Class<V> fieldType) { Field[] declaredFields = ownerClass.getDeclaredFields(); Field found = null; for (Field field : declaredFields) { if ((field.getModifiers() & (Modifier.STATIC | Modifier.FINAL)) != 0) { continue; } if (fieldType.isAssignableFrom(field.getType())) { if (found == null) { found = field; } else { throw new IllegalArgumentException("Two fields of " + fieldType + " found in the " + ownerClass + ": " + found.getName() + " and " + field.getName()); } } } if (found == null) { throw new IllegalArgumentException("No (non-static, non-final) field of " + fieldType + " found in the " + ownerClass); } found.setAccessible(true); if ((found.getModifiers() & Modifier.VOLATILE) == 0) { throw new IllegalArgumentException("Field " + found + " in the " + ownerClass + " must be volatile"); } return found; }
Example 5
Source File: ModifierUtil.java From kalang with MIT License | 6 votes |
private static int parseSingleModfier(String s) throws InvalidModifierException { switch (s) { case "public": return Modifier.PUBLIC; case "protected": return Modifier.PROTECTED; case "private": return Modifier.PRIVATE; case "static": return Modifier.STATIC; case "final": return Modifier.FINAL; case "abstract": return Modifier.ABSTRACT; case "native": return Modifier.NATIVE; case "synchronized": return Modifier.SYNCHRONIZED; case "transient": return Modifier.TRANSIENT; case "volatile": return Modifier.VOLATILE; default: throw new InvalidModifierException("unrecognized modifier:" + s); } }
Example 6
Source File: DexMaker.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Declares a field. * * @param flags a bitwise combination of {@link Modifier#PUBLIC}, {@link * Modifier#PRIVATE}, {@link Modifier#PROTECTED}, {@link Modifier#STATIC}, * {@link Modifier#FINAL}, {@link Modifier#VOLATILE}, and {@link * Modifier#TRANSIENT}. * @param staticValue a constant representing the initial value for the * static field, possibly null. This must be null if this field is * non-static. */ public void declare(FieldId<?, ?> fieldId, int flags, Object staticValue) { TypeDeclaration typeDeclaration = getTypeDeclaration(fieldId.declaringType); if (typeDeclaration.fields.containsKey(fieldId)) { throw new IllegalStateException("already declared: " + fieldId); } int supportedFlags = Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL | Modifier.VOLATILE | Modifier.TRANSIENT; if ((flags & ~supportedFlags) != 0) { throw new IllegalArgumentException("Unexpected flag: " + Integer.toHexString(flags)); } if ((flags & Modifier.STATIC) == 0 && staticValue != null) { throw new IllegalArgumentException("staticValue is non-null, but field is not static"); } FieldDeclaration fieldDeclaration = new FieldDeclaration(fieldId, flags, staticValue); typeDeclaration.fields.put(fieldId, fieldDeclaration); }
Example 7
Source File: AtomicFieldUpdater.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private static <T,V> Field getTheOnlyVolatileFieldOfClass(@Nonnull Class<T> ownerClass, @Nonnull Class<V> fieldType) { Field[] declaredFields = ownerClass.getDeclaredFields(); Field found = null; for (Field field : declaredFields) { if ((field.getModifiers() & (Modifier.STATIC | Modifier.FINAL)) != 0) { continue; } if (fieldType.isAssignableFrom(field.getType())) { if (found == null) { found = field; } else { throw new IllegalArgumentException("Two fields of "+fieldType+" found in the "+ownerClass+": "+found.getName() + " and "+field.getName()); } } } if (found == null) { throw new IllegalArgumentException("No (non-static, non-final) field of "+fieldType+" found in the "+ownerClass); } found.setAccessible(true); if ((found.getModifiers() & Modifier.VOLATILE) == 0) { throw new IllegalArgumentException("Field "+found+" in the "+ownerClass+" must be volatile"); } return found; }
Example 8
Source File: CustomCodeView.java From netbeans with Apache License 2.0 | 5 votes |
/** * Writes edited code back to the CustomCodeData structure. */ CustomCodeData retreiveCodeData() { retreiveCodeData(CodeCategory.CREATE_AND_INIT); retreiveCodeData(CodeCategory.DECLARATION); VariableDeclaration decl = codeData.getDeclarationData(); boolean local = variableValues[variableCombo.getSelectedIndex()]; int modifiers; if (local != decl.local) { modifiers = local ? lastLocalModifiers : lastFieldModifiers; if (finalCheckBox.isSelected()) // only final makes sense for both local and field scope modifiers |= Modifier.FINAL; else modifiers &= ~Modifier.FINAL; } else { modifiers = accessValues[accessCombo.getSelectedIndex()]; if (staticCheckBox.isSelected()) modifiers |= Modifier.STATIC; if (finalCheckBox.isSelected()) modifiers |= Modifier.FINAL; if (transientCheckBox.isSelected()) modifiers |= Modifier.TRANSIENT; if (volatileCheckBox.isSelected()) modifiers |= Modifier.VOLATILE; if (local) modifiers &= ~(Modifier.STATIC | Modifier.TRANSIENT | Modifier.VOLATILE); } decl.local = local; decl.modifiers = modifiers; return codeData; }
Example 9
Source File: DocEnv.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Convert modifier bits from private coding used by * the compiler to that of java.lang.reflect.Modifier. */ static int translateModifiers(long flags) { int result = 0; if ((flags & Flags.ABSTRACT) != 0) result |= Modifier.ABSTRACT; if ((flags & Flags.FINAL) != 0) result |= Modifier.FINAL; if ((flags & Flags.INTERFACE) != 0) result |= Modifier.INTERFACE; if ((flags & Flags.NATIVE) != 0) result |= Modifier.NATIVE; if ((flags & Flags.PRIVATE) != 0) result |= Modifier.PRIVATE; if ((flags & Flags.PROTECTED) != 0) result |= Modifier.PROTECTED; if ((flags & Flags.PUBLIC) != 0) result |= Modifier.PUBLIC; if ((flags & Flags.STATIC) != 0) result |= Modifier.STATIC; if ((flags & Flags.SYNCHRONIZED) != 0) result |= Modifier.SYNCHRONIZED; if ((flags & Flags.TRANSIENT) != 0) result |= Modifier.TRANSIENT; if ((flags & Flags.VOLATILE) != 0) result |= Modifier.VOLATILE; return result; }
Example 10
Source File: DocEnv.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Convert modifier bits from private coding used by * the compiler to that of java.lang.reflect.Modifier. */ static int translateModifiers(long flags) { int result = 0; if ((flags & Flags.ABSTRACT) != 0) result |= Modifier.ABSTRACT; if ((flags & Flags.FINAL) != 0) result |= Modifier.FINAL; if ((flags & Flags.INTERFACE) != 0) result |= Modifier.INTERFACE; if ((flags & Flags.NATIVE) != 0) result |= Modifier.NATIVE; if ((flags & Flags.PRIVATE) != 0) result |= Modifier.PRIVATE; if ((flags & Flags.PROTECTED) != 0) result |= Modifier.PROTECTED; if ((flags & Flags.PUBLIC) != 0) result |= Modifier.PUBLIC; if ((flags & Flags.STATIC) != 0) result |= Modifier.STATIC; if ((flags & Flags.SYNCHRONIZED) != 0) result |= Modifier.SYNCHRONIZED; if ((flags & Flags.TRANSIENT) != 0) result |= Modifier.TRANSIENT; if ((flags & Flags.VOLATILE) != 0) result |= Modifier.VOLATILE; return result; }
Example 11
Source File: DocEnv.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Convert modifier bits from private coding used by * the compiler to that of java.lang.reflect.Modifier. */ static int translateModifiers(long flags) { int result = 0; if ((flags & Flags.ABSTRACT) != 0) result |= Modifier.ABSTRACT; if ((flags & Flags.FINAL) != 0) result |= Modifier.FINAL; if ((flags & Flags.INTERFACE) != 0) result |= Modifier.INTERFACE; if ((flags & Flags.NATIVE) != 0) result |= Modifier.NATIVE; if ((flags & Flags.PRIVATE) != 0) result |= Modifier.PRIVATE; if ((flags & Flags.PROTECTED) != 0) result |= Modifier.PROTECTED; if ((flags & Flags.PUBLIC) != 0) result |= Modifier.PUBLIC; if ((flags & Flags.STATIC) != 0) result |= Modifier.STATIC; if ((flags & Flags.SYNCHRONIZED) != 0) result |= Modifier.SYNCHRONIZED; if ((flags & Flags.TRANSIENT) != 0) result |= Modifier.TRANSIENT; if ((flags & Flags.VOLATILE) != 0) result |= Modifier.VOLATILE; return result; }
Example 12
Source File: DocEnv.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Convert modifier bits from private coding used by * the compiler to that of java.lang.reflect.Modifier. */ static int translateModifiers(long flags) { int result = 0; if ((flags & Flags.ABSTRACT) != 0) result |= Modifier.ABSTRACT; if ((flags & Flags.FINAL) != 0) result |= Modifier.FINAL; if ((flags & Flags.INTERFACE) != 0) result |= Modifier.INTERFACE; if ((flags & Flags.NATIVE) != 0) result |= Modifier.NATIVE; if ((flags & Flags.PRIVATE) != 0) result |= Modifier.PRIVATE; if ((flags & Flags.PROTECTED) != 0) result |= Modifier.PROTECTED; if ((flags & Flags.PUBLIC) != 0) result |= Modifier.PUBLIC; if ((flags & Flags.STATIC) != 0) result |= Modifier.STATIC; if ((flags & Flags.SYNCHRONIZED) != 0) result |= Modifier.SYNCHRONIZED; if ((flags & Flags.TRANSIENT) != 0) result |= Modifier.TRANSIENT; if ((flags & Flags.VOLATILE) != 0) result |= Modifier.VOLATILE; return result; }
Example 13
Source File: DocEnv.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Convert modifier bits from private coding used by * the compiler to that of java.lang.reflect.Modifier. */ static int translateModifiers(long flags) { int result = 0; if ((flags & Flags.ABSTRACT) != 0) result |= Modifier.ABSTRACT; if ((flags & Flags.FINAL) != 0) result |= Modifier.FINAL; if ((flags & Flags.INTERFACE) != 0) result |= Modifier.INTERFACE; if ((flags & Flags.NATIVE) != 0) result |= Modifier.NATIVE; if ((flags & Flags.PRIVATE) != 0) result |= Modifier.PRIVATE; if ((flags & Flags.PROTECTED) != 0) result |= Modifier.PROTECTED; if ((flags & Flags.PUBLIC) != 0) result |= Modifier.PUBLIC; if ((flags & Flags.STATIC) != 0) result |= Modifier.STATIC; if ((flags & Flags.SYNCHRONIZED) != 0) result |= Modifier.SYNCHRONIZED; if ((flags & Flags.TRANSIENT) != 0) result |= Modifier.TRANSIENT; if ((flags & Flags.VOLATILE) != 0) result |= Modifier.VOLATILE; return result; }
Example 14
Source File: DocEnv.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Convert modifier bits from private coding used by * the compiler to that of java.lang.reflect.Modifier. */ static int translateModifiers(long flags) { int result = 0; if ((flags & Flags.ABSTRACT) != 0) result |= Modifier.ABSTRACT; if ((flags & Flags.FINAL) != 0) result |= Modifier.FINAL; if ((flags & Flags.INTERFACE) != 0) result |= Modifier.INTERFACE; if ((flags & Flags.NATIVE) != 0) result |= Modifier.NATIVE; if ((flags & Flags.PRIVATE) != 0) result |= Modifier.PRIVATE; if ((flags & Flags.PROTECTED) != 0) result |= Modifier.PROTECTED; if ((flags & Flags.PUBLIC) != 0) result |= Modifier.PUBLIC; if ((flags & Flags.STATIC) != 0) result |= Modifier.STATIC; if ((flags & Flags.SYNCHRONIZED) != 0) result |= Modifier.SYNCHRONIZED; if ((flags & Flags.TRANSIENT) != 0) result |= Modifier.TRANSIENT; if ((flags & Flags.VOLATILE) != 0) result |= Modifier.VOLATILE; return result; }
Example 15
Source File: DocEnv.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Convert modifier bits from private coding used by * the compiler to that of java.lang.reflect.Modifier. */ static int translateModifiers(long flags) { int result = 0; if ((flags & Flags.ABSTRACT) != 0) result |= Modifier.ABSTRACT; if ((flags & Flags.FINAL) != 0) result |= Modifier.FINAL; if ((flags & Flags.INTERFACE) != 0) result |= Modifier.INTERFACE; if ((flags & Flags.NATIVE) != 0) result |= Modifier.NATIVE; if ((flags & Flags.PRIVATE) != 0) result |= Modifier.PRIVATE; if ((flags & Flags.PROTECTED) != 0) result |= Modifier.PROTECTED; if ((flags & Flags.PUBLIC) != 0) result |= Modifier.PUBLIC; if ((flags & Flags.STATIC) != 0) result |= Modifier.STATIC; if ((flags & Flags.SYNCHRONIZED) != 0) result |= Modifier.SYNCHRONIZED; if ((flags & Flags.TRANSIENT) != 0) result |= Modifier.TRANSIENT; if ((flags & Flags.VOLATILE) != 0) result |= Modifier.VOLATILE; return result; }
Example 16
Source File: DocEnv.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Convert modifier bits from private coding used by * the compiler to that of java.lang.reflect.Modifier. */ static int translateModifiers(long flags) { int result = 0; if ((flags & Flags.ABSTRACT) != 0) result |= Modifier.ABSTRACT; if ((flags & Flags.FINAL) != 0) result |= Modifier.FINAL; if ((flags & Flags.INTERFACE) != 0) result |= Modifier.INTERFACE; if ((flags & Flags.NATIVE) != 0) result |= Modifier.NATIVE; if ((flags & Flags.PRIVATE) != 0) result |= Modifier.PRIVATE; if ((flags & Flags.PROTECTED) != 0) result |= Modifier.PROTECTED; if ((flags & Flags.PUBLIC) != 0) result |= Modifier.PUBLIC; if ((flags & Flags.STATIC) != 0) result |= Modifier.STATIC; if ((flags & Flags.SYNCHRONIZED) != 0) result |= Modifier.SYNCHRONIZED; if ((flags & Flags.TRANSIENT) != 0) result |= Modifier.TRANSIENT; if ((flags & Flags.VOLATILE) != 0) result |= Modifier.VOLATILE; return result; }
Example 17
Source File: BuilderUtil.java From CodeGen with MIT License | 4 votes |
/** * 计算默认的 serialVersionUID * * @see java.io.ObjectStreamClass#lookup(Class) * @see java.io.ObjectStreamClass#computeDefaultSUID(Class) */ public static long computeDefaultSUID(String className, List<Field> fields) { try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dout = new DataOutputStream(bout); // simple class name dout.writeUTF(className); int classMods = Modifier.PUBLIC & (Modifier.PUBLIC | Modifier.FINAL | Modifier.INTERFACE | Modifier.ABSTRACT); dout.writeInt(classMods); // interface name dout.writeUTF("java.io.Serializable"); // fields // fields.sort(Comparator.comparing(Field::getField)); for (Field field : fields) { int mods = Modifier.PRIVATE & (Modifier.PUBLIC | Modifier.PRIVATE | Modifier.PROTECTED | Modifier.STATIC | Modifier.FINAL | Modifier.VOLATILE | Modifier.TRANSIENT); if (((mods & Modifier.PRIVATE) == 0) || ((mods & (Modifier.STATIC | Modifier.TRANSIENT)) == 0)) { dout.writeUTF(field.getField()); dout.writeInt(mods); dout.writeUTF(field.getFieldType()); } } // method ignore dout.flush(); MessageDigest md = MessageDigest.getInstance("SHA"); byte[] hashBytes = md.digest(bout.toByteArray()); long hash = 0; for (int i = Math.min(hashBytes.length, 8) - 1; i >= 0; i--) { hash = (hash << 8) | (hashBytes[i] & 0xFF); } return hash; } catch (Exception e) { // ignore } return 1; }
Example 18
Source File: SrcAnnotated.java From manifold with Apache License 2.0 | 4 votes |
public static long modifiersFrom( Set<javax.lang.model.element.Modifier> modifiers ) { long mods = 0; for( javax.lang.model.element.Modifier mod : modifiers ) { switch( mod ) { case PUBLIC: mods |= Modifier.PUBLIC; break; case PROTECTED: mods |= Modifier.PROTECTED; break; case PRIVATE: mods |= Modifier.PRIVATE; break; case ABSTRACT: mods |= Modifier.ABSTRACT; break; case DEFAULT: mods |= Flags.DEFAULT; break; case STATIC: mods |= Modifier.STATIC; break; case FINAL: mods |= Modifier.FINAL; break; case TRANSIENT: mods |= Modifier.TRANSIENT; break; case VOLATILE: mods |= Modifier.VOLATILE; break; case SYNCHRONIZED: mods |= Modifier.SYNCHRONIZED; break; case NATIVE: mods |= Modifier.NATIVE; break; case STRICTFP: mods |= Flags.STRICTFP; break; } } return mods; }
Example 19
Source File: SrcAnnotated.java From manifold with Apache License 2.0 | 4 votes |
protected String renderModifiers( StringBuilder sb, long modifiers, boolean isDefault, int defModifier ) { if( isDefault ) { sb.append( "default " ); } if( (modifiers & Modifier.PUBLIC) != 0 ) { sb.append( "public " ); } else if( (modifiers & Modifier.PROTECTED) != 0 ) { sb.append( "protected " ); } else if( (modifiers & Modifier.PRIVATE) != 0 ) { sb.append( "private " ); } else if( defModifier != 0 ) { renderModifiers( sb, defModifier, false, 0 ); } // Canonical order if( (modifiers & Modifier.ABSTRACT) != 0 ) { sb.append( "abstract " ); } if( (modifiers & Modifier.STATIC) != 0 ) { sb.append( "static " ); } if( (modifiers & Modifier.FINAL) != 0 ) { sb.append( "final " ); } if( (modifiers & Modifier.TRANSIENT) != 0 ) { sb.append( "transient " ); } if( (modifiers & Modifier.VOLATILE) != 0 ) { sb.append( "volatile " ); } if( (modifiers & Modifier.SYNCHRONIZED) != 0 ) { sb.append( "synchronized " ); } if( (modifiers & Modifier.INTERFACE) != 0 ) { sb.append( "interface " ); } return ""; }
Example 20
Source File: PropertyNodeUtils.java From groovy with Apache License 2.0 | 2 votes |
/** * Fields within the AST that have no explicit visibility are deemed to be properties * and represented by a PropertyNode. The Groovy compiler creates accessor methods and * a backing field for such property nodes. During this process, all modifiers * from the property are carried over to the backing field (so a property marked as * {@code transient} will have a {@code transient} backing field) but when creating * the accessor methods we don't carry over modifier values which don't make sense for * methods (this includes VOLATILE and TRANSIENT) but other modifiers are carried over, * for example {@code static}. * * @param propNode the original property node * @return the modifiers which make sense for an accessor method */ public static int adjustPropertyModifiersForMethod(PropertyNode propNode) { // GROOVY-3726: clear volatile, transient modifiers so that they don't get applied to methods return ~(Modifier.TRANSIENT | Modifier.VOLATILE) & propNode.getModifiers(); }