List of usage examples for org.objectweb.asm Opcodes ACC_PRIVATE
int ACC_PRIVATE
To view the source code for org.objectweb.asm Opcodes ACC_PRIVATE.
Click Source Link
From source file:org.openspotlight.bundle.language.java.resolver.JavaGraphNodeSupport.java
License:Open Source License
/** * Insert field data./*w ww.j av a2 s .com*/ * * @param field the field * @param fieldType the field type * @param access the access * @param isArray the is array * @param dimension the dimension * @throws Exception the exception */ private void insertFieldData(final JavaDataField field, final JavaType fieldType, final int access, final boolean isArray, final int dimension) throws Exception { final DataType fieldTypeLink = session.addLink(DataType.class, field, fieldType, false); fieldTypeLink.setArray(isArray); fieldTypeLink.setArrayDimension(dimension); final boolean isFieldPublic = (access & Opcodes.ACC_PUBLIC) != 0; final boolean isFieldPrivate = (access & Opcodes.ACC_PRIVATE) != 0; final boolean isFieldStatic = (access & Opcodes.ACC_STATIC) != 0; final boolean isFieldFinal = (access & Opcodes.ACC_FINAL) != 0; final boolean isFieldProtected = (access & Opcodes.ACC_PROTECTED) != 0; final boolean isFieldTransient = (access & Opcodes.ACC_TRANSIENT) != 0; final boolean isFieldVolatile = (access & Opcodes.ACC_VOLATILE) != 0; field.setPublic(isFieldPublic); field.setPrivate(isFieldPrivate); field.setStatic(isFieldStatic); field.setFinal(isFieldFinal); field.setProtected(isFieldProtected); field.setTransient(isFieldTransient); field.setVolatile(isFieldVolatile); }
From source file:org.openspotlight.bundle.language.java.resolver.JavaGraphNodeSupport.java
License:Open Source License
/** * Sets the method data./*from www . jav a2 s. c o m*/ * * @param method the method * @param access the access */ private void setMethodData(final JavaMethod method, final int access) { final boolean isMethodPublic = (access & Opcodes.ACC_PUBLIC) != 0; final boolean isMethodPrivate = (access & Opcodes.ACC_PRIVATE) != 0; final boolean isMethodStatic = (access & Opcodes.ACC_STATIC) != 0; final boolean isMethodFinal = (access & Opcodes.ACC_FINAL) != 0; final boolean isMethodProtected = (access & Opcodes.ACC_PROTECTED) != 0; final boolean isMethodSynchronized = (access & Opcodes.ACC_SYNCHRONIZED) != 0; method.setPublic(isMethodPublic); method.setPrivate(isMethodPrivate); method.setStatic(isMethodStatic); method.setFinal(isMethodFinal); method.setProtected(isMethodProtected); method.setSynchronized(isMethodSynchronized); }
From source file:org.osjava.jardiff.Tools.java
License:Apache License
private static boolean isAccessIncompatible(int oldAccess, int newAccess) { if (has(newAccess, Opcodes.ACC_PUBLIC)) { return false; } else if (has(newAccess, Opcodes.ACC_PROTECTED)) { return has(oldAccess, Opcodes.ACC_PUBLIC); } else if (has(newAccess, Opcodes.ACC_PRIVATE)) { return not(oldAccess, Opcodes.ACC_PRIVATE); } else {//from w ww. java 2 s. co m // new access is package, it is incompatible if old access was public or protected return has(oldAccess, Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED); } }
From source file:org.osjava.jardiff.Tools.java
License:Apache License
/** * Returns whether a field's newAccess is incompatible with oldAccess * following <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html">Java Language Specification, Java SE 7 Edition</a>: * <ul>/*from w w w . j a v a2 s . co m*/ * <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.9">13.4.7 Access to Members and Constructors</a><ul> * <li>Changing the declared access of a member or constructor to permit less access * <b>may break compatibility</b> with pre-existing binaries, causing a linkage error to be thrown when these binaries are resolved. * </li> * <li>The binary format is defined so that changing a member or constructor to be more accessible does not cause a * linkage error when a subclass (already) defines a method to have less access. * </li> * </ul></li> * <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.9">13.4.9 final Fields and Constants</a><ul> * <li>If a field that was not declared final is changed to be declared final, * then it <b>can break compatibility</b> with pre-existing binaries that attempt to assign new values to the field.</li> * <li>Deleting the keyword final or changing the value to which a <i>non-final</i> field is initialized * <b>does not break compatibility</b> with existing binaries.</li> * <li>If a field is a constant variable (4.12.4), * then deleting the keyword final or changing its value * will <i>not break compatibility</i> with pre-existing binaries by causing them not to run, * but they will not see any new value for the usage of the field unless they are recompiled. * This is true even if the usage itself is not a compile-time constant expression (15.28). * Such changes <b>break functional backward compatibility</b>!</li> * </ul></li> * <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.10">13.4.10 static Fields</a><ul> * <li>If a field that is not declared private was not declared static * and is changed to be declared static, or vice versa, * then a linkage error, specifically an IncompatibleClassChangeError, * will result if the field is used by a pre-existing binary which expected a field of the other kind. * Such changes <b>break backward compatibility</b>!</li> * </ul></li> * <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.11">13.4.11. transient Fields </a><ul> * <li>Adding or deleting a transient modifier of a field * <b>does not break compatibility</b> with pre-existing binaries.</li> * </ul></li> * <li><a href="http://www.wsu.edu/UNIX_Systems/java/langspec-1.0/13.doc.html#45194">13.4.11 volatile Fields (JLS 1.0)</a><ul> * <li>If a field that is not declared private was not declared volatile * and is changed to be declared volatile, or vice versa, then a linkage time error, * specifically an IncompatibleClassChangeError, may result if the field is used * by a preexisting binary that expected a field of the opposite volatility. * Such changes <b>break backward compatibility</b>!</li> * </ul></li> * </ul> * * @param oldAccess * @param newAccess * @return */ public static boolean isFieldAccessChange(final int oldAccess, final int newAccess) { if (isAccessIncompatible(oldAccess, newAccess)) { return true; // 13.4.7 } if (not(oldAccess, Opcodes.ACC_FINAL) && has(newAccess, Opcodes.ACC_FINAL)) { return true; // 13.4.9 #1 } else { final int compatibleChanges = Opcodes.ACC_FINAL | // 13.4.9 #2 Opcodes.ACC_TRANSIENT; // 13.4.11 #1 final int accessPermissions = Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE; final int oldAccess2 = oldAccess & ~compatibleChanges & ~accessPermissions; final int newAccess2 = newAccess & ~compatibleChanges & ~accessPermissions; return oldAccess2 != newAccess2; } }
From source file:org.osjava.jardiff.Tools.java
License:Apache License
/** * Returns whether a method's newAccess is incompatible with oldAccess * following <a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html">Java Language Specification, Java SE 7 Edition</a>: * <ul>// ww w . ja v a2 s . c o m * <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.9">13.4.7 Access to Members and Constructors</a><ul> * <li>Changing the declared access of a member or constructor to permit less access * <b>may break compatibility</b> with pre-existing binaries, causing a linkage error to be thrown when these binaries are resolved. * </li> * <li>The binary format is defined so that changing a member or constructor to be more accessible does not cause a * linkage error when a subclass (already) defines a method to have less access. * </li> * </ul></li> * <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.16">13.4.16 abstract Methods</a><ul> * <li>Changing a method that is declared abstract to no longer be declared abstract * <b>does not break compatibility</b> with pre-existing binaries.</li> * <li>Changing a method that is not declared abstract to be declared abstract * <b>will break compatibility</b> with pre-existing binaries that previously invoked the method, causing an AbstractMethodError.</li> * </ul></li> * <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.17">13.4.17 final</a><ul> * <li>Changing a method that is declared final to no longer be declared final * <b>does not break compatibility</b> with pre-existing binaries.</li> * <li>Changing an instance method that is not declared final to be declared final * <b>may break compatibility</b> with existing binaries that depend on the ability to override the method.</li> * <li>Changing a class (static) method that is not declared final to be declared final * <b>does not break compatibility</b> with existing binaries, because the method could not have been overridden.</li> * </ul></li> * <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.18">13.4.18 native Methods</a><ul> * <li>Adding or deleting a native modifier of a method * <b>does not break compatibility</b> with pre-existing binaries.</li> * </ul></li> * <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.19">13.4.19 static Methods</a><ul> * <li>If a method that is not declared private is also declared static (that is, a class method) * and is changed to not be declared static (that is, to an instance method), or vice versa, * then <i>compatibility with pre-existing binaries may be broken</i>, resulting in a linkage time error, * namely an IncompatibleClassChangeError, if these methods are used by the pre-existing binaries. * Such changes <b>break functional backward compatibility</b>!</li> * </ul></li> * <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.20">13.4.20 synchronized Methods</a><ul> * <li>Adding or deleting a synchronized modifier of a method * <b>does not break compatibility</b> with pre-existing binaries.</li> * </ul></li> * <li><a href="http://docs.oracle.com/javase/specs/jls/se7/html/jls-13.html#jls-13.4.21">13.4.21 Method and Constructor Throws</a><ul> * <li>Changes to the throws clause of methods or constructors * <b>do not break compatibility</b> with pre-existing binaries; these clauses are checked only at compile time.</li> * </ul></li> * </ul> * * @param oldAccess * @param newAccess * @return */ public static boolean isMethodAccessChange(final int oldAccess, final int newAccess) { if (isAccessIncompatible(oldAccess, newAccess)) { return true; // 13.4.7 } if (not(oldAccess, Opcodes.ACC_ABSTRACT) && has(newAccess, Opcodes.ACC_ABSTRACT)) { return true; // 13.4.16 #2 } else if (not(oldAccess, Opcodes.ACC_FINAL) && not(oldAccess, Opcodes.ACC_STATIC) && has(newAccess, Opcodes.ACC_FINAL)) { return true; // 13.4.17 #2 excluding and #3 } else { final int compatibleChanges = Opcodes.ACC_ABSTRACT | // 13.4.16 #1 Opcodes.ACC_FINAL | // 13.4.17 #1 Opcodes.ACC_NATIVE | // 13.4.18 #1 Opcodes.ACC_SYNCHRONIZED; // 13.4.20 #1 final int accessPermissions = Opcodes.ACC_PUBLIC | Opcodes.ACC_PROTECTED | Opcodes.ACC_PRIVATE; final int oldAccess2 = oldAccess & ~compatibleChanges & ~accessPermissions; final int newAccess2 = newAccess & ~compatibleChanges & ~accessPermissions; return oldAccess2 != newAccess2; } }
From source file:org.osjava.jardiff.ToolsTest.java
License:Apache License
@Test public void isFieldAccessChange() { // A field can't become final. assertTrue(Tools.isFieldAccessChange(0, Opcodes.ACC_FINAL)); assertTrue(Tools.isFieldAccessChange(0, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL)); // ... but can become non-final. assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_FINAL, 0)); assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_FINAL + Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC)); // A field can become more accessible assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PUBLIC)); assertFalse(Tools.isFieldAccessChange(0, Opcodes.ACC_PUBLIC)); assertFalse(Tools.isFieldAccessChange(0, Opcodes.ACC_PROTECTED)); assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_PRIVATE, Opcodes.ACC_PUBLIC)); assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_PRIVATE, Opcodes.ACC_PROTECTED)); assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_PRIVATE, 0)); // ...but can't become less accessible assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_FINAL + Opcodes.ACC_PUBLIC, 0)); assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PROTECTED)); assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PRIVATE)); assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_PROTECTED, 0)); assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PRIVATE)); assertTrue(Tools.isFieldAccessChange(0, Opcodes.ACC_PRIVATE)); // A field can't change static assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_STATIC, 0)); assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC)); // A field can't change volatile assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_VOLATILE, 0)); assertTrue(Tools.isFieldAccessChange(Opcodes.ACC_VOLATILE + Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC)); // A field can change transient assertFalse(Tools.isFieldAccessChange(0, Opcodes.ACC_TRANSIENT)); assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC + Opcodes.ACC_TRANSIENT)); assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_TRANSIENT, 0)); assertFalse(Tools.isFieldAccessChange(Opcodes.ACC_PUBLIC + Opcodes.ACC_TRANSIENT, Opcodes.ACC_PUBLIC)); }
From source file:org.osjava.jardiff.ToolsTest.java
License:Apache License
@Test public void isMethodAccessChange() { // A non-static method can't become final. assertTrue(Tools.isMethodAccessChange(0, Opcodes.ACC_FINAL)); assertTrue(Tools.isMethodAccessChange(0, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL)); // ... but can become non-final. assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_FINAL, 0)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_FINAL + Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC)); // ... but a static method can become final! assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_STATIC, Opcodes.ACC_STATIC + Opcodes.ACC_FINAL)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC, Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL)); // A method can become more accessible assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PUBLIC)); assertFalse(Tools.isMethodAccessChange(0, Opcodes.ACC_PUBLIC)); assertFalse(Tools.isMethodAccessChange(0, Opcodes.ACC_PROTECTED)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PRIVATE, Opcodes.ACC_PUBLIC)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PRIVATE, Opcodes.ACC_PROTECTED)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PRIVATE, 0)); // ...but can't become less accessible assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_FINAL + Opcodes.ACC_PUBLIC, 0)); assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PROTECTED)); assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PRIVATE)); assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PROTECTED, 0)); assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PRIVATE)); assertTrue(Tools.isMethodAccessChange(0, Opcodes.ACC_PRIVATE)); // A class or method can become concrete. assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_ABSTRACT, 0)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_ABSTRACT + Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC)); assertFalse(//ww w . ja va 2 s. c o m Tools.isMethodAccessChange(Opcodes.ACC_ABSTRACT + Opcodes.ACC_PROTECTED, Opcodes.ACC_PROTECTED)); // ...but can't become abstract assertTrue(Tools.isMethodAccessChange(0, Opcodes.ACC_ABSTRACT)); assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT)); assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_PROTECTED, Opcodes.ACC_PROTECTED + Opcodes.ACC_ABSTRACT)); // A method can't change static assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_STATIC, 0)); assertTrue(Tools.isMethodAccessChange(Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC)); // A method can change synchronized assertFalse(Tools.isMethodAccessChange(0, Opcodes.ACC_SYNCHRONIZED)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC + Opcodes.ACC_SYNCHRONIZED)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_SYNCHRONIZED, 0)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC + Opcodes.ACC_SYNCHRONIZED, Opcodes.ACC_PUBLIC)); // A method can change native assertFalse(Tools.isMethodAccessChange(0, Opcodes.ACC_NATIVE)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC, Opcodes.ACC_PUBLIC + Opcodes.ACC_NATIVE)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_NATIVE, 0)); assertFalse(Tools.isMethodAccessChange(Opcodes.ACC_PUBLIC + Opcodes.ACC_NATIVE, Opcodes.ACC_PUBLIC)); }
From source file:org.rascalmpl.library.lang.java.m3.internal.JarConverter.java
License:Open Source License
private IConstructor mapFieldAccesCode(int code, int where) { // Check the original M3 implementation for possible IConstructor types. switch (code) { case Opcodes.ACC_PUBLIC: return constructModifierNode("public"); case Opcodes.ACC_PRIVATE: return constructModifierNode("private"); case Opcodes.ACC_PROTECTED: return constructModifierNode("protected"); case Opcodes.ACC_STATIC: return constructModifierNode("static"); case Opcodes.ACC_FINAL: return constructModifierNode("final"); case Opcodes.ACC_SYNCHRONIZED: if (where == CLASSE) return null; return constructModifierNode("synchronized"); case Opcodes.ACC_ABSTRACT: return constructModifierNode("abstract"); case Opcodes.ACC_VOLATILE: return constructModifierNode("volatile"); case Opcodes.ACC_TRANSIENT: return constructModifierNode("transient"); case Opcodes.ACC_NATIVE: return constructModifierNode("native"); // TODO: GIT PULL/MERGE ORIGINAL RASCAL VERSION < 2013-11-30 (Shahin commit) // case Opcodes.ACC_DEPRECATED: // return constructModifierNode("deprecated"); default:/*from w w w .j a va 2s. co m*/ return null; } }
From source file:org.sonar.java.bytecode.asm.AsmAccessFlags.java
License:Open Source License
public static boolean isPrivate(int accessFlags) { return (accessFlags & Opcodes.ACC_PRIVATE) != 0; }
From source file:org.sonar.java.resolve.FlagsTest.java
License:Open Source License
/** * Flags can be easily loaded from class-files into symbols. *//*ww w . ja v a2 s . c o m*/ @Test public void flags_match_asm_opcodes() { assertThat(Flags.PUBLIC).isEqualTo(Opcodes.ACC_PUBLIC); assertThat(Flags.PRIVATE).isEqualTo(Opcodes.ACC_PRIVATE); assertThat(Flags.PROTECTED).isEqualTo(Opcodes.ACC_PROTECTED); assertThat(Flags.STATIC).isEqualTo(Opcodes.ACC_STATIC); assertThat(Flags.FINAL).isEqualTo(Opcodes.ACC_FINAL); assertThat(Flags.SYNCHRONIZED).isEqualTo(Opcodes.ACC_SYNCHRONIZED); assertThat(Flags.VOLATILE).isEqualTo(Opcodes.ACC_VOLATILE); assertThat(Flags.TRANSIENT).isEqualTo(Opcodes.ACC_TRANSIENT); assertThat(Flags.NATIVE).isEqualTo(Opcodes.ACC_NATIVE); assertThat(Flags.INTERFACE).isEqualTo(Opcodes.ACC_INTERFACE); assertThat(Flags.ABSTRACT).isEqualTo(Opcodes.ACC_ABSTRACT); assertThat(Flags.STRICTFP).isEqualTo(Opcodes.ACC_STRICT); assertThat(Flags.SYNTHETIC).isEqualTo(Opcodes.ACC_SYNTHETIC); assertThat(Flags.ANNOTATION).isEqualTo(Opcodes.ACC_ANNOTATION); assertThat(Flags.ENUM).isEqualTo(Opcodes.ACC_ENUM); }