congrats Icon
New! Announcing our next generation AI code completions
Read here
Tabnine Logo
ReflectionUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
ReflectionUtils
in
rocks.inspectit.server.diagnosis.engine.util

Best Java code snippets using rocks.inspectit.server.diagnosis.engine.util.ReflectionUtils (Showing top 20 results out of 315)

origin: inspectIT/inspectIT

T annotation = findAnnotation(interfaze, annotationClass);
if (null != annotation) {
  return annotation;
return findAnnotation(superClazz, annotationClass);
origin: inspectIT/inspectIT

  @Test(expectedExceptions = { RuntimeException.class })
  public void noDefaultConstructor() {
    ReflectionUtils.tryInstantiate(NoDefaultConstructorClass.class);
  }
}
origin: inspectIT/inspectIT

/**
 * Extracts the {@link SessionVariableInjection}s from the given class by processing the
 * {@link SessionVariable} annotations.
 *
 * @param clazz
 *            The class to be analyzed.
 * @return List of SessionVariableInjections
 * @throws RuleDefinitionException
 *             If {@link SessionVariableInjection} annotations are invalid.
 */
public static List<SessionVariableInjection> describeSessionParameterInjections(Class<?> clazz) throws RuleDefinitionException {
  return ReflectionUtils.visitFieldsAnnotatedWith(SessionVariable.class, clazz, new Visitor<SessionVariable, Field, SessionVariableInjection>() {
    @Override
    public SessionVariableInjection visit(SessionVariable annotation, Field field) {
      return new SessionVariableInjection(annotation.name(), annotation.optional(), field);
    }
  });
}
origin: inspectIT/inspectIT

Rule annotation = ReflectionUtils.findAnnotation(clazz, Rule.class);
if (annotation == null) {
  throw new RuleDefinitionException(clazz.getName() + " must be annotated with @Rule annotation.");
if (!ReflectionUtils.hasNoArgsConstructor(clazz)) {
  throw new RuleDefinitionException(clazz.getName() + " must define an empty default constructor.");
origin: inspectIT/inspectIT

  /**
   * Extracts the {@link ConditionMethod}s from the given class by processing the
   * {@link Condition} annotation.
   *
   * @param clazz
   *            The class to be analyzed.
   * @return List of ConditionMethods
   * @throws RuleDefinitionException
   *             If {@link ConditionMethod} annotations are invalid.
   */
  public static List<ConditionMethod> describeConditionMethods(Class<?> clazz) throws RuleDefinitionException {
    List<ConditionMethod> conditions = ReflectionUtils.visitMethodsAnnotatedWith(Condition.class, clazz, new Visitor<Condition, Method, ConditionMethod>() {
      @Override
      public ConditionMethod visit(Condition annotation, Method method) throws RuleDefinitionException {
        return new ConditionMethod(annotation.name(), annotation.hint(), method);
      }
    });
    return conditions;
  }
}
origin: inspectIT/inspectIT

@Test
public void noDefaultConstructor() {
  boolean constructor = ReflectionUtils.hasNoArgsConstructor(NoDefaultConstructorClass.class);
  assertThat(constructor, is(false));
}
origin: inspectIT/inspectIT

/**
 * Invokes the given method on the passed target.
 *
 * @param method
 *            Method to invoke per reflection.
 * @param target
 *            Object on which to invoke the method.
 * @return The result object.
 * @throws InvocationTargetException
 *             If invocation target is invalid.
 * @throws IllegalArgumentException
 *             If arguments are invalid.
 * @throws IllegalAccessException
 *             If method cannot be accessed.
 */
public static Object invokeMethod(Method method, Object target) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
  return invokeMethod(method, target, new Object[0]);
}
origin: inspectIT/inspectIT

/**
 * Extracts the {@link Action} from the given class by processing the {@link Action} annotation.
 *
 * @param clazz
 *            The class to be analyzed.
 * @return List of ActionMethod
 * @throws RuleDefinitionException
 *             If {@link Action} annotation is invalid.
 */
public static ActionMethod describeActionMethod(Class<?> clazz) throws RuleDefinitionException {
  List<ActionMethod> actionMethods = ReflectionUtils.visitMethodsAnnotatedWith(Action.class, clazz, new Visitor<Action, Method, ActionMethod>() {
    @Override
    public ActionMethod visit(Action annotation, Method method) throws RuleDefinitionException {
      return new ActionMethod(method, annotation.resultTag(), annotation.resultQuantity());
    }
  });
  if ((null == actionMethods) || (actionMethods.size() != 1)) {
    throw new RuleDefinitionException("A rule must define exactly one method annotated with @Action. Otherwise the rule could never be exectued.");
  } else {
    return actionMethods.get(0);
  }
}
origin: inspectIT/inspectIT

  @Test
  public void privateConstructor() {
    boolean constructor = ReflectionUtils.hasNoArgsConstructor(PrivateConstructorClass.class);
    assertThat(constructor, is(false));
  }
}
origin: inspectIT/inspectIT

/**
 * Executes the action. Throws: RuleExecutionException in case of any error
 *
 * @param context
 *            The current executing {@link ExecutionContext}
 * @return A collection of {@link Tags}s
 * @throws RuleExecutionException
 *             If rule execution fails with an exception.
 * @see ExecutionContext
 * @see Tag
 */
public Collection<Tag> execute(ExecutionContext context) throws RuleExecutionException {
  try {
    Object result = ReflectionUtils.invokeMethod(getMethod(), context.getInstance());
    return transform(result, context);
  } catch (Exception e) {
    throw new RuleExecutionException("Failed to invoke action method (" + getMethod().getName() + ")", context, e);
  }
}
origin: inspectIT/inspectIT

@Test(expectedExceptions = { NullPointerException.class })
public void visitorReturnsNull() throws RuleDefinitionException {
  ReflectionUtils.visitFieldsAnnotatedWith(TagValue.class, TestClass.class, new Visitor<TagValue, Field, String>() {
    @Override
    public String visit(TagValue annotation, Field field) {
      return field.getName().endsWith("2") ? null : "ok";
    }
  });
}
origin: inspectIT/inspectIT

@Test(expectedExceptions = { NullPointerException.class })
public void visitorReturnsNull() throws RuleDefinitionException {
  ReflectionUtils.visitMethodsAnnotatedWith(Action.class, TestClass.class, new Visitor<Action, Method, String>() {
    @Override
    public String visit(Action annotation, Method method) {
      return method.getName().endsWith("C") ? null : "ok";
    }
  });
}
origin: inspectIT/inspectIT

  @Test
  public void unavailableAnnotation() {
    Rule ruleAnnotation = ReflectionUtils.findAnnotation(NoDefaultConstructorClass.class, Rule.class);
    assertThat(ruleAnnotation, equalTo(null));
  }
}
origin: inspectIT/inspectIT

@Test
public void validClass() {
  TestClass instance = ReflectionUtils.tryInstantiate(TestClass.class);
  assertThat(instance.par1, is(1));
}
origin: inspectIT/inspectIT

@Test
public void defaultConstructor() {
  boolean constructor = ReflectionUtils.hasNoArgsConstructor(TestClass.class);
  assertThat(constructor, is(true));
}
origin: inspectIT/inspectIT

/**
 * Executes this {@link ConditionMethod}. If the #method does not succeed a
 * {@link ConditionFailure} is returned. Otherwise null is returned.
 *
 * @param context
 *            The current executing {@link ExecutionContext}
 * @return A {@link ConditionFailure} if condition fails, null otherwise
 * @throws RuleExecutionException
 *             If execution of the condition method fails with an exception.
 * @see ExecutionContext
 * @see ConditionFailure
 */
public ConditionFailure execute(ExecutionContext context) throws RuleExecutionException {
  try {
    boolean valid = (boolean) ReflectionUtils.invokeMethod(getMethod(), context.getInstance());
    if (!valid) {
      // Store information about the failed condition for later usage
      return new ConditionFailure(getName(), getHint());
    }
    return null;
  } catch (Exception e) {
    throw new RuleExecutionException("Invocation of condition method failed.", context, e);
  }
}
origin: inspectIT/inspectIT

/**
 * Extracts the {@link TagInjection}s from the given class by processing the
 * {@link TagInjection} annotations.
 *
 * @param clazz
 *            The class to be analyzed.
 * @return List of TagInjection
 * @throws RuleDefinitionException
 *             If {@link TagInjection} annotations are invalid. Contract is that a class must
 *             defined at least one field annotated with {@link TagValue}. Otherwise the rule
 *             could never fire, because no input could be determined.
 */
public static List<TagInjection> describeTagInjection(Class<?> clazz) throws RuleDefinitionException {
  List<TagInjection> tagInjections = ReflectionUtils.visitFieldsAnnotatedWith(TagValue.class, clazz, new Visitor<TagValue, Field, TagInjection>() {
    @Override
    public TagInjection visit(TagValue annotation, Field field) {
      return new TagInjection(annotation.type(), field, annotation.injectionStrategy());
    }
  });
  if (CollectionUtils.isEmpty(tagInjections)) {
    throw new RuleDefinitionException(clazz.getName() + " must annotate at least one field with @Value. Otherwise the " + "rule will never fire and is useless.");
  } else {
    return tagInjections;
  }
}
origin: inspectIT/inspectIT

  @Test(expectedExceptions = { RuleDefinitionException.class })
  public void explicitVisitorException() throws RuleDefinitionException {
    ReflectionUtils.visitMethodsAnnotatedWith(Action.class, TestClass.class, new Visitor<Action, Method, String>() {
      @Override
      public String visit(Action annotation, Method method) throws RuleDefinitionException {
        if (method.getName().endsWith("C")) {
          throw new RuleDefinitionException("test exception");
        } else {
          return "ok";
        }
      }
    });
  }
}
origin: inspectIT/inspectIT

@Test
public void availableAnnotation() {
  Rule ruleAnnotation = ReflectionUtils.findAnnotation(TestClass.class, Rule.class);
  assertThat(ruleAnnotation, not(equalTo(null)));
}
origin: inspectIT/inspectIT

@Override
public Session<I, R> makeObject() throws Exception {
  return new Session<>(ruleDefinitions, configuration.getResultCollector(), ReflectionUtils.tryInstantiate(configuration.getStorageClass()));
}
rocks.inspectit.server.diagnosis.engine.utilReflectionUtils

Javadoc

Class contains utility methods to work with reflection API.

Most used methods

  • findAnnotation
    Searches for the given annotation in the given class.
  • hasNoArgsConstructor
    Checks if a Class provides a public constructor without any arguments.
  • tryInstantiate
    Tries to instantiate a class. Intended to avoid boiler plate try/catch code.
  • visitFieldsAnnotatedWith
    Visits all fields of a class which are annotated with a certain annotation. The method utilizes a Vi
  • visitMethodsAnnotatedWith
    Visits all methods of a class which are annotated with a certain annotation. The method utilizes a V
  • invokeMethod
    Invokes the given method on the passed target with gieven arguments..

Popular in Java

  • Finding current android device location
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • putExtra (Intent)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • 21 Best Atom Packages for 2021
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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