Java Code Examples for java.lang.reflect.Modifier#isSynchronized()
The following examples show how to use
java.lang.reflect.Modifier#isSynchronized() .
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: OcniExtractor.java From j2objc with Apache License 2.0 | 6 votes |
@Override public void endVisit(MethodDeclaration node) { int modifiers = node.getModifiers(); if (Modifier.isNative(modifiers)) { NativeStatement nativeStmt = extractNativeStatement(node); if (nativeStmt != null) { Block body = new Block(); body.addStatement(nativeStmt); node.setBody(body); node.removeModifiers(Modifier.NATIVE); } } if (Modifier.isSynchronized(modifiers)) { TypeElement declaringClass = ElementUtil.getDeclaringClass(node.getExecutableElement()); SynchronizedStatement syncStmt = new SynchronizedStatement( Modifier.isStatic(modifiers) ? new TypeLiteral(declaringClass.asType(), typeUtil) : new ThisExpression(declaringClass.asType())); syncStmt.setBody(TreeUtil.remove(node.getBody())); Block newBody = new Block(); newBody.addStatement(syncStmt); node.setBody(newBody); node.removeModifiers(Modifier.SYNCHRONIZED); } }
Example 2
Source File: WorkManagerImpl.java From ironjacamar with Eclipse Public License 1.0 | 6 votes |
/** * Checks, if Work implementation class method is synchronized * @param workClass - implementation class * @param methodName - could be "run" or "release" * @return true, if method is synchronized, false elsewhere */ private boolean isWorkMethodSynchronized(Class<? extends Work> workClass, String methodName) { try { Method method = SecurityActions.getMethod(workClass, methodName, new Class[0]); if (Modifier.isSynchronized(method.getModifiers())) return true; } catch (NoSuchMethodException e) { //Never happens, Work implementation should have these methods } return false; }
Example 3
Source File: ModifiedFragment.java From httpdoc with Apache License 2.0 | 5 votes |
@Override public <T extends LineAppender<T>> void joinTo(T appender, Preference preference) throws IOException { if (Modifier.isPublic(modifier)) appender.append("public "); if (Modifier.isProtected(modifier)) appender.append("protected "); if (Modifier.isPrivate(modifier)) appender.append("private "); if (Modifier.isAbstract(modifier)) appender.append("abstract "); if (Modifier.isStatic(modifier)) appender.append("static "); if (Modifier.isFinal(modifier)) appender.append("final "); if (Modifier.isInterface(modifier)) appender.append("interface "); if (Modifier.isVolatile(modifier)) appender.append("volatile "); if (Modifier.isNative(modifier)) appender.append("native "); if (Modifier.isStrict(modifier)) appender.append("strict "); if (Modifier.isSynchronized(modifier)) appender.append("synchronized "); if (Modifier.isTransient(modifier)) appender.append("transient "); }
Example 4
Source File: TestSynchronization.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Test all the public, unsynchronized methods of the given class. If * isSelfTest is true, this is a self-test to ensure that the test program * itself is working correctly. Should help ensure correctness of this * program if it changes. * <p/> * @param aClass - the class to test * @param isSelfTest - true if this is the special self-test class * @throws SecurityException */ private static void testClass(Class<?> aClass, boolean isSelfTest) throws Exception { // Get all unsynchronized public methods via reflection. We don't need // to test synchronized methods. By definition. they are already doing // the right thing. List<Method> methods = Arrays.asList(aClass.getDeclaredMethods()); for (Method m : methods) { // skip synthetic methods, like default interface methods and lambdas if (m.isSynthetic()) { continue; } int modifiers = m.getModifiers(); if (Modifier.isPublic(modifiers) && !Modifier.isSynchronized(modifiers)) { try { testMethod(aClass, m); } catch (TestFailedException e) { if (isSelfTest) { String methodName = e.getMethod().getName(); switch (methodName) { case "should_pass": throw new RuntimeException( "Test failed: self-test failed. The 'should_pass' method did not pass the synchronization test. Check the test code."); case "should_fail": break; default: throw new RuntimeException( "Test failed: something is amiss with the test. A TestFailedException was generated on a call to " + methodName + " which we didn't expect to test in the first place."); } } else { throw new RuntimeException("Test failed: the method " + e.getMethod().toString() + " should be synchronized, but isn't."); } } } } }
Example 5
Source File: TestSynchronization.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Test all the public, unsynchronized methods of the given class. If * isSelfTest is true, this is a self-test to ensure that the test program * itself is working correctly. Should help ensure correctness of this * program if it changes. * <p/> * @param aClass - the class to test * @param isSelfTest - true if this is the special self-test class * @throws SecurityException */ private static void testClass(Class<?> aClass, boolean isSelfTest) throws Exception { // Get all unsynchronized public methods via reflection. We don't need // to test synchronized methods. By definition. they are already doing // the right thing. List<Method> methods = Arrays.asList(aClass.getDeclaredMethods()); for (Method m : methods) { // skip synthetic methods, like default interface methods and lambdas if (m.isSynthetic()) { continue; } int modifiers = m.getModifiers(); if (Modifier.isPublic(modifiers) && !Modifier.isSynchronized(modifiers)) { try { testMethod(aClass, m); } catch (TestFailedException e) { if (isSelfTest) { String methodName = e.getMethod().getName(); switch (methodName) { case "should_pass": throw new RuntimeException( "Test failed: self-test failed. The 'should_pass' method did not pass the synchronization test. Check the test code."); case "should_fail": break; default: throw new RuntimeException( "Test failed: something is amiss with the test. A TestFailedException was generated on a call to " + methodName + " which we didn't expect to test in the first place."); } } else { throw new RuntimeException("Test failed: the method " + e.getMethod().toString() + " should be synchronized, but isn't."); } } } } }
Example 6
Source File: ModifiedFragment.java From halo-docs with Apache License 2.0 | 5 votes |
@Override public <T extends LineAppender<T>> void joinTo(T appender, Preference preference) throws IOException { if (Modifier.isPublic(modifier)) appender.append("public "); if (Modifier.isProtected(modifier)) appender.append("protected "); if (Modifier.isPrivate(modifier)) appender.append("private "); if (Modifier.isAbstract(modifier)) appender.append("abstract "); if (Modifier.isStatic(modifier)) appender.append("static "); if (Modifier.isFinal(modifier)) appender.append("final "); if (Modifier.isInterface(modifier)) appender.append("interface "); if (Modifier.isVolatile(modifier)) appender.append("volatile "); if (Modifier.isNative(modifier)) appender.append("native "); if (Modifier.isStrict(modifier)) appender.append("strict "); if (Modifier.isSynchronized(modifier)) appender.append("synchronized "); if (Modifier.isTransient(modifier)) appender.append("transient "); }
Example 7
Source File: TestSynchronization.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * Test all the public, unsynchronized methods of the given class. If * isSelfTest is true, this is a self-test to ensure that the test program * itself is working correctly. Should help ensure correctness of this * program if it changes. * <p/> * @param aClass - the class to test * @param isSelfTest - true if this is the special self-test class * @throws SecurityException */ private static void testClass(Class<?> aClass, boolean isSelfTest) throws Exception { // Get all unsynchronized public methods via reflection. We don't need // to test synchronized methods. By definition. they are already doing // the right thing. List<Method> methods = Arrays.asList(aClass.getDeclaredMethods()); for (Method m : methods) { // skip synthetic methods, like default interface methods and lambdas if (m.isSynthetic()) { continue; } int modifiers = m.getModifiers(); if (Modifier.isPublic(modifiers) && !Modifier.isSynchronized(modifiers)) { try { testMethod(aClass, m); } catch (TestFailedException e) { if (isSelfTest) { String methodName = e.getMethod().getName(); switch (methodName) { case "should_pass": throw new RuntimeException( "Test failed: self-test failed. The 'should_pass' method did not pass the synchronization test. Check the test code."); case "should_fail": break; default: throw new RuntimeException( "Test failed: something is amiss with the test. A TestFailedException was generated on a call to " + methodName + " which we didn't expect to test in the first place."); } } else { throw new RuntimeException("Test failed: the method " + e.getMethod().toString() + " should be synchronized, but isn't."); } } } } }
Example 8
Source File: TestSynchronization.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Test all the public, unsynchronized methods of the given class. If * isSelfTest is true, this is a self-test to ensure that the test program * itself is working correctly. Should help ensure correctness of this * program if it changes. * <p/> * @param aClass - the class to test * @param isSelfTest - true if this is the special self-test class * @throws SecurityException */ private static void testClass(Class<?> aClass, boolean isSelfTest) throws Exception { // Get all unsynchronized public methods via reflection. We don't need // to test synchronized methods. By definition. they are already doing // the right thing. List<Method> methods = Arrays.asList(aClass.getDeclaredMethods()); for (Method m : methods) { // skip synthetic methods, like default interface methods and lambdas if (m.isSynthetic()) { continue; } int modifiers = m.getModifiers(); if (Modifier.isPublic(modifiers) && !Modifier.isSynchronized(modifiers)) { try { testMethod(aClass, m); } catch (TestFailedException e) { if (isSelfTest) { String methodName = e.getMethod().getName(); switch (methodName) { case "should_pass": throw new RuntimeException( "Test failed: self-test failed. The 'should_pass' method did not pass the synchronization test. Check the test code."); case "should_fail": break; default: throw new RuntimeException( "Test failed: something is amiss with the test. A TestFailedException was generated on a call to " + methodName + " which we didn't expect to test in the first place."); } } else { throw new RuntimeException("Test failed: the method " + e.getMethod().toString() + " should be synchronized, but isn't."); } } } } }
Example 9
Source File: TestSynchronization.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Test all the public, unsynchronized methods of the given class. If * isSelfTest is true, this is a self-test to ensure that the test program * itself is working correctly. Should help ensure correctness of this * program if it changes. * <p/> * @param aClass - the class to test * @param isSelfTest - true if this is the special self-test class * @throws SecurityException */ private static void testClass(Class<?> aClass, boolean isSelfTest) throws Exception { // Get all unsynchronized public methods via reflection. We don't need // to test synchronized methods. By definition. they are already doing // the right thing. List<Method> methods = Arrays.asList(aClass.getDeclaredMethods()); for (Method m : methods) { // skip synthetic methods, like default interface methods and lambdas if (m.isSynthetic()) { continue; } int modifiers = m.getModifiers(); if (Modifier.isPublic(modifiers) && !Modifier.isSynchronized(modifiers)) { try { testMethod(aClass, m); } catch (TestFailedException e) { if (isSelfTest) { String methodName = e.getMethod().getName(); switch (methodName) { case "should_pass": throw new RuntimeException( "Test failed: self-test failed. The 'should_pass' method did not pass the synchronization test. Check the test code."); case "should_fail": break; default: throw new RuntimeException( "Test failed: something is amiss with the test. A TestFailedException was generated on a call to " + methodName + " which we didn't expect to test in the first place."); } } else { throw new RuntimeException("Test failed: the method " + e.getMethod().toString() + " should be synchronized, but isn't."); } } } } }
Example 10
Source File: TestSynchronization.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Test all the public, unsynchronized methods of the given class. If * isSelfTest is true, this is a self-test to ensure that the test program * itself is working correctly. Should help ensure correctness of this * program if it changes. * <p/> * @param aClass - the class to test * @param isSelfTest - true if this is the special self-test class * @throws SecurityException */ private static void testClass(Class<?> aClass, boolean isSelfTest) throws Exception { // Get all unsynchronized public methods via reflection. We don't need // to test synchronized methods. By definition. they are already doing // the right thing. List<Method> methods = Arrays.asList(aClass.getDeclaredMethods()); for (Method m : methods) { // skip synthetic methods, like default interface methods and lambdas if (m.isSynthetic()) { continue; } int modifiers = m.getModifiers(); if (Modifier.isPublic(modifiers) && !Modifier.isSynchronized(modifiers)) { try { testMethod(aClass, m); } catch (TestFailedException e) { if (isSelfTest) { String methodName = e.getMethod().getName(); switch (methodName) { case "should_pass": throw new RuntimeException( "Test failed: self-test failed. The 'should_pass' method did not pass the synchronization test. Check the test code."); case "should_fail": break; default: throw new RuntimeException( "Test failed: something is amiss with the test. A TestFailedException was generated on a call to " + methodName + " which we didn't expect to test in the first place."); } } else { throw new RuntimeException("Test failed: the method " + e.getMethod().toString() + " should be synchronized, but isn't."); } } } } }
Example 11
Source File: ExecutableMemberDocImpl.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Return true if this method is synchronized */ public boolean isSynchronized() { return Modifier.isSynchronized(getModifiers()); }
Example 12
Source File: ClassFieldDescription.java From chart-fx with Apache License 2.0 | 4 votes |
protected ClassFieldDescription(final Class<?> referenceClass, final Field field, final ClassFieldDescription parent, final int recursionLevel) { super(); hierarchyDepth = recursionLevel; this.parent = parent == null ? Optional.empty() : Optional.of(parent); if (referenceClass == null) { if (field == null) { throw new IllegalArgumentException("field must not be null"); } this.field = field; classType = field.getType(); fieldName = field.getName(); if (this.parent.isPresent()) { final String relativeName = this.parent.get().isRoot() ? "" : (this.parent.get().getFieldNameRelative() + "."); fieldNameRelative = relativeName + fieldName; } else { fieldNameRelative = fieldName; } modifierID = field.getModifiers(); } else { this.field = null; // it's a root, no field definition available classType = referenceClass; fieldName = classType.getName(); fieldNameRelative = ""; modifierID = classType.getModifiers(); } dataType = dataTypeFomClassType(classType); typeName = ClassDescriptions.translateClassName(classType.getTypeName()); modPublic = Modifier.isPublic(modifierID); modProtected = Modifier.isProtected(modifierID); modPrivate = Modifier.isPrivate(modifierID); modAbstract = Modifier.isAbstract(modifierID); modStatic = Modifier.isStatic(modifierID); modFinal = Modifier.isFinal(modifierID); modTransient = Modifier.isTransient(modifierID); modVolatile = Modifier.isVolatile(modifierID); modSynchronized = Modifier.isSynchronized(modifierID); modNative = Modifier.isNative(modifierID); modStrict = Modifier.isStrict(modifierID); modInterface = classType.isInterface(); // additional fields isprimitive = classType.isPrimitive(); isclass = !isprimitive && !modInterface; isEnum = Enum.class.isAssignableFrom(classType); serializable = !modTransient && !modStatic; }
Example 13
Source File: StringUtils.java From arthas with Apache License 2.0 | 4 votes |
/** * 翻译Modifier值 * * @param mod modifier * @return 翻译值 */ public static String modifier(int mod, char splitter) { StringBuilder sb = new StringBuilder(); if (Modifier.isAbstract(mod)) { sb.append("abstract").append(splitter); } if (Modifier.isFinal(mod)) { sb.append("final").append(splitter); } if (Modifier.isInterface(mod)) { sb.append("interface").append(splitter); } if (Modifier.isNative(mod)) { sb.append("native").append(splitter); } if (Modifier.isPrivate(mod)) { sb.append("private").append(splitter); } if (Modifier.isProtected(mod)) { sb.append("protected").append(splitter); } if (Modifier.isPublic(mod)) { sb.append("public").append(splitter); } if (Modifier.isStatic(mod)) { sb.append("static").append(splitter); } if (Modifier.isStrict(mod)) { sb.append("strict").append(splitter); } if (Modifier.isSynchronized(mod)) { sb.append("synchronized").append(splitter); } if (Modifier.isTransient(mod)) { sb.append("transient").append(splitter); } if (Modifier.isVolatile(mod)) { sb.append("volatile").append(splitter); } if (sb.length() > 0) { sb.deleteCharAt(sb.length() - 1); } return sb.toString(); }
Example 14
Source File: Solution.java From JavaRushTasks with MIT License | 4 votes |
public static boolean isAllModifiersContainSpecificModifier(int allModifiers, int specificModifier) { if (Modifier.isAbstract(allModifiers) && Modifier.isAbstract(specificModifier)) return true; if (Modifier.isFinal(allModifiers) && Modifier.isFinal(specificModifier)) return true; if (Modifier.isInterface(allModifiers) && Modifier.isInterface(specificModifier)) return true; if (Modifier.isNative(allModifiers) && Modifier.isNative(specificModifier)) return true; if (Modifier.isPrivate(allModifiers) && Modifier.isPrivate(specificModifier)) return true; if (Modifier.isProtected(allModifiers) && Modifier.isProtected(specificModifier)) return true; if (Modifier.isPublic(allModifiers) && Modifier.isPublic(specificModifier)) return true; if (Modifier.isStatic(allModifiers) && Modifier.isStatic(specificModifier)) return true; if (Modifier.isStrict(allModifiers) && Modifier.isStrict(specificModifier)) return true; if (Modifier.isSynchronized(allModifiers) && Modifier.isSynchronized(specificModifier)) return true; if (Modifier.isTransient(allModifiers) && Modifier.isTransient(specificModifier)) return true; if (Modifier.isVolatile(allModifiers) && Modifier.isVolatile(specificModifier)) return true; if (Modifier.isVolatile(allModifiers) && Modifier.isVolatile(specificModifier)) return true; return false; }
Example 15
Source File: ExecutableMemberDocImpl.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Return true if this method is synchronized */ public boolean isSynchronized() { return Modifier.isSynchronized(getModifiers()); }
Example 16
Source File: ExecutableMemberDocImpl.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Return true if this method is synchronized */ public boolean isSynchronized() { return Modifier.isSynchronized(getModifiers()); }
Example 17
Source File: ExecutableMemberDocImpl.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Return true if this method is synchronized */ public boolean isSynchronized() { return Modifier.isSynchronized(getModifiers()); }
Example 18
Source File: ReflectMethod.java From Diorite with MIT License | 2 votes |
/** * Returns true if given method is synchronized. * * @return true if given method is synchronized. */ default boolean isSynchronized() { return Modifier.isSynchronized(this.getModifiers()); }
Example 19
Source File: Element.java From codebuff with BSD 2-Clause "Simplified" License | 2 votes |
/** Returns true if the method is synchronized. */ public final boolean isSynchronized() { return Modifier.isSynchronized(getModifiers()); }
Example 20
Source File: Element.java From codebuff with BSD 2-Clause "Simplified" License | 2 votes |
/** Returns true if the method is synchronized. */ public final boolean isSynchronized() { return Modifier.isSynchronized(getModifiers()); }