Tabnine Logo
Class.getEnclosingMethod
Code IndexAdd Tabnine to your IDE (free)

How to use
getEnclosingMethod
method
in
java.lang.Class

Best Java code snippets using java.lang.Class.getEnclosingMethod (Showing top 20 results out of 837)

origin: spring-projects/spring-loaded

public static Method callGetEnclosingMethod(Class thiz)
{
  return thiz.getEnclosingMethod();
}
origin: stackoverflow.com

public class SomeClass {
 public void foo(){
  class Local {};
  String name = Local.class.getEnclosingMethod().getName();
 }
}
origin: awaitility/awaitility

  private String generateMethodDescription(Callable<Boolean> matcher) {
    String methodDescription = "";
    Method enclosingMethod = matcher.getClass().getEnclosingMethod();
    if (enclosingMethod != null) {
      methodDescription = " defined in " + enclosingMethod.toString();
    }
    return methodDescription;
  }
}
origin: prestodb/presto

/**
 * @since 2.7
 */
public static boolean hasEnclosingMethod(Class<?> cls) {
  return !isObjectOrPrimitive(cls) && (cls.getEnclosingMethod() != null);
}
origin: redisson/redisson

/**
 * @since 2.7
 */
public static boolean hasEnclosingMethod(Class<?> cls) {
  return !isObjectOrPrimitive(cls) && (cls.getEnclosingMethod() != null);
}
origin: google/guava

 private boolean mayNeedHiddenThis() {
  Class<?> declaringClass = constructor.getDeclaringClass();
  if (declaringClass.getEnclosingConstructor() != null) {
   // Enclosed in a constructor, needs hidden this
   return true;
  }
  Method enclosingMethod = declaringClass.getEnclosingMethod();
  if (enclosingMethod != null) {
   // Enclosed in a method, if it's not static, must need hidden this.
   return !Modifier.isStatic(enclosingMethod.getModifiers());
  } else {
   // Strictly, this doesn't necessarily indicate a hidden 'this' in the case of
   // static initializer. But there seems no way to tell in that case. :(
   // This may cause issues when an anonymous class is created inside a static initializer,
   // and the class's constructor's first parameter happens to be the enclosing class.
   // In such case, we may mistakenly think that the class is within a non-static context
   // and the first parameter is the hidden 'this'.
   return declaringClass.getEnclosingClass() != null
     && !Modifier.isStatic(declaringClass.getModifiers());
  }
 }
}
origin: awaitility/awaitility

private String generateMethodDescription(ThrowingRunnable supplier) {
  String methodDescription = "";
  Method enclosingMethod = null;
  try {
    enclosingMethod = supplier.getClass().getEnclosingMethod();
  } catch (Error ignored) {
    // A java.lang.InternalError could be thrown when using the Groovy extension using Groovy 2.3.7 for some reason. Bug in Groovy?!
  }
  if (enclosingMethod != null) {
    methodDescription = " defined in " + enclosingMethod.toString();
  }
  return methodDescription;
}
origin: stackoverflow.com

String name = new Object(){}.getClass().getEnclosingMethod().getName();
origin: org.codehaus.jackson/jackson-mapper-asl

/**
 * Method for finding enclosing class for non-static inner classes
 * 
 * @since 1.9
 */
public static Class<?> getOuterClass(Class<?> type)
{
  // as above, GAE has some issues...
  try {
    // one more: method locals, anonymous, are not good:
    if (type.getEnclosingMethod() != null) {
      return null;
    }
    if (!Modifier.isStatic(type.getModifiers())) {
      return type.getEnclosingClass();
    }
  } catch (SecurityException e) { }
  catch (NullPointerException e) { }
  return null;
}

origin: prestodb/presto

 private boolean mayNeedHiddenThis() {
  Class<?> declaringClass = constructor.getDeclaringClass();
  if (declaringClass.getEnclosingConstructor() != null) {
   // Enclosed in a constructor, needs hidden this
   return true;
  }
  Method enclosingMethod = declaringClass.getEnclosingMethod();
  if (enclosingMethod != null) {
   // Enclosed in a method, if it's not static, must need hidden this.
   return !Modifier.isStatic(enclosingMethod.getModifiers());
  } else {
   // Strictly, this doesn't necessarily indicate a hidden 'this' in the case of
   // static initializer. But there seems no way to tell in that case. :(
   // This may cause issues when an anonymous class is created inside a static initializer,
   // and the class's constructor's first parameter happens to be the enclosing class.
   // In such case, we may mistakenly think that the class is within a non-static context
   // and the first parameter is the hidden 'this'.
   return declaringClass.getEnclosingClass() != null
     && !Modifier.isStatic(declaringClass.getModifiers());
  }
 }
}
origin: robovm/robovm

/**
 * Tests whether the class represented by this {@code Class} is defined
 * locally.
 */
public boolean isLocalClass() {
  boolean enclosed = (getEnclosingMethod() != null ||
           getEnclosingConstructor() != null);
  return enclosed && !isAnonymousClass();
}
origin: apache/drill

/**
 * @since 2.7
 */
public static boolean hasEnclosingMethod(Class<?> cls) {
  return !isObjectOrPrimitive(cls) && (cls.getEnclosingMethod() != null);
}
origin: wildfly/wildfly

 private boolean mayNeedHiddenThis() {
  Class<?> declaringClass = constructor.getDeclaringClass();
  if (declaringClass.getEnclosingConstructor() != null) {
   // Enclosed in a constructor, needs hidden this
   return true;
  }
  Method enclosingMethod = declaringClass.getEnclosingMethod();
  if (enclosingMethod != null) {
   // Enclosed in a method, if it's not static, must need hidden this.
   return !Modifier.isStatic(enclosingMethod.getModifiers());
  } else {
   // Strictly, this doesn't necessarily indicate a hidden 'this' in the case of
   // static initializer. But there seems no way to tell in that case. :(
   // This may cause issues when an anonymous class is created inside a static initializer,
   // and the class's constructor's first parameter happens to be the enclosing class.
   // In such case, we may mistakenly think that the class is within a non-static context
   // and the first parameter is the hidden 'this'.
   return declaringClass.getEnclosingClass() != null
     && !Modifier.isStatic(declaringClass.getModifiers());
  }
 }
}
origin: robovm/robovm

private static GenericDeclaration nextLayer(GenericDeclaration decl) {
  if (decl instanceof Class) {
    // FIXME: Is the following hierarchy correct?:
    Class cl = (Class)decl;
    // RoboVM note: Start of change. Do what the old 4.1.1 code did instead
    // of AnnotationAccess.getEnclosingMethodOrConstructor(cl) in 4.4.3.
    decl = cl.getEnclosingMethod();
    if (decl != null) {
      return decl;
    }
    decl = cl.getEnclosingConstructor();
    if (decl != null) {
      return decl;
    }
    // RoboVM note: End of change,
    return cl.getEnclosingClass();
  } else if (decl instanceof Method) {
    return ((Method)decl).getDeclaringClass();
  } else if (decl instanceof Constructor) {
    return ((Constructor)decl).getDeclaringClass();
  } else {
    throw new AssertionError();
  }
}
origin: org.codehaus.jackson/jackson-mapper-asl

if (type.getEnclosingMethod() != null) {
  return "local/anonymous";
origin: org.testng/testng

@Test
@Parameters({ "testdata" })
public void filterOutInJectedTypesFromOptionalValuesTest(XmlTest xmlTest, @Optional("optionaltestdata") String testdata) {
 JDK15AnnotationFinder finder = new JDK15AnnotationFinder(null);
 Method curMethod = new Object() {}.getClass().getEnclosingMethod();
 FilterOutInJectedTypesResult filterOutResult = org.testng.internal.Parameters.filterOutInJectedTypesFromOptionalValues(
     curMethod.getParameterTypes(), finder.findOptionalValues(curMethod));
 Assert.assertEquals(filterOutResult.getOptionalValues()[0], "optionaltestdata");
 Assert.assertEquals(filterOutResult.getParameterTypes()[0], String.class);  
  
}
origin: awaitility/awaitility

@Override
protected String getCallableDescription(final Callable<T> supplier) {
  final Class<? extends Callable> supplierClass = supplier.getClass();
  Method enclosingMethod = supplierClass.getEnclosingMethod();
  if (isFieldSupplier(supplierClass)) {
    return generateFieldSupplierErrorMessage(supplier);
  } else if (supplierClass.isAnonymousClass() && enclosingMethod != null) {
    return enclosingMethod.getDeclaringClass().getName() + "." + enclosingMethod.getName() + " Callable";
  } else if (isLambdaClass(supplierClass)) {
    return generateLambdaErrorMessagePrefix(supplierClass, true);
  } else {
    return supplierClass.getName();
  }
}
origin: google/j2objc

 private boolean mayNeedHiddenThis() {
  Class<?> declaringClass = constructor.getDeclaringClass();
  if (declaringClass.getEnclosingConstructor() != null) {
   // Enclosed in a constructor, needs hidden this
   return true;
  }
  Method enclosingMethod = declaringClass.getEnclosingMethod();
  if (enclosingMethod != null) {
   // Enclosed in a method, if it's not static, must need hidden this.
   return !Modifier.isStatic(enclosingMethod.getModifiers());
  } else {
   // Strictly, this doesn't necessarily indicate a hidden 'this' in the case of
   // static initializer. But there seems no way to tell in that case. :(
   // This may cause issues when an anonymous class is created inside a static initializer,
   // and the class's constructor's first parameter happens to be the enclosing class.
   // In such case, we may mistakenly think that the class is within a non-static context
   // and the first parameter is the hidden 'this'.
   return declaringClass.getEnclosingClass() != null
     && !Modifier.isStatic(declaringClass.getModifiers());
  }
 }
}
origin: redisson/redisson

/**
 * {@inheritDoc}
 */
public MethodDescription.InDefinedShape getEnclosingMethod() {
  Method enclosingMethod = type.getEnclosingMethod();
  Constructor<?> enclosingConstructor = type.getEnclosingConstructor();
  if (enclosingMethod != null) {
    return new MethodDescription.ForLoadedMethod(enclosingMethod);
  } else if (enclosingConstructor != null) {
    return new MethodDescription.ForLoadedConstructor(enclosingConstructor);
  } else {
    return MethodDescription.UNDEFINED;
  }
}
origin: cbeust/testng

 @Test
 @Parameters({"testdata"})
 @SuppressWarnings("unused")
 public void filterOutInJectedTypesFromOptionalValuesTest(
   XmlTest xmlTest, @Optional("optionaltestdata") String testdata) {
  JDK15AnnotationFinder finder = new JDK15AnnotationFinder(null);
  Method curMethod = new Object() {}.getClass().getEnclosingMethod();
  FilterOutInJectedTypesResult filterOutResult =
    org.testng.internal.Parameters.filterOutInJectedTypesFromOptionalValues(
      curMethod.getParameterTypes(), finder.findOptionalValues(curMethod));
  Assert.assertEquals(filterOutResult.getOptionalValues()[0], "optionaltestdata");
  Assert.assertEquals(filterOutResult.getParameterTypes()[0], String.class);
 }
}
java.langClassgetEnclosingMethod

Javadoc

Returns the enclosing Method of this Class, if it is an anonymous or local/automatic class; otherwise null.

Popular methods of Class

  • getName
    Returns the name of the class represented by this Class. For a description of the format which is us
  • getSimpleName
  • getClassLoader
  • isAssignableFrom
    Determines if the class or interface represented by this Class object is either the same as, or is a
  • forName
    Returns the Class object associated with the class or interface with the given string name, using th
  • newInstance
    Returns a new instance of the class represented by this Class, created by invoking the default (that
  • getMethod
    Returns a Method object that reflects the specified public member method of the class or interface r
  • getResourceAsStream
  • getSuperclass
    Returns the Class representing the superclass of the entity (class, interface, primitive type or voi
  • getConstructor
  • cast
    Casts an object to the class or interface represented by this Class object.
  • isInstance
  • cast,
  • isInstance,
  • getCanonicalName,
  • getDeclaredField,
  • isArray,
  • getAnnotation,
  • getDeclaredFields,
  • getResource,
  • getDeclaredMethod,
  • getMethods

Popular in Java

  • Parsing JSON documents to java classes using gson
  • setRequestProperty (URLConnection)
  • setScale (BigDecimal)
  • getResourceAsStream (ClassLoader)
  • BufferedWriter (java.io)
    Wraps an existing Writer and buffers the output. Expensive interaction with the underlying reader is
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • Collectors (java.util.stream)
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now