Skip to content

raydac/meta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

111 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

License Apache 2.0 Maven central Java 11+ PayPal donation Yandex.Money donation

Introduction

It is a small general-purpose library includes:

  • set of run-time annotations to mark code
  • set of utility classes
  • shaded com.google.code.findbugs:jsr305 annotation library
  • maven plugin to log info about some annotations and check java class version

Change log

  • 1.2.1 (14-dec-2024)

  • added annotations PureFunction and DisableSelfInvocation

  • added check functions into TimeGuard

  • fixed search for classes in META-INF for checker

  • refactoring

  • 1.2.0 (10-dec-2024)

  • minimal JDK 11

  • minimal Maven 3.8.1

  • removed vulnerable dependencies

  • minor renaming of methods

  • use of Joda Time replaced by Java Time API

  • updated dependencies and improved new JDK support

  • refactoring and typo fixing

Annotations

It contains number annotations to mark code, plus JSR-305 annotations provided by the shaded findbugs annotation library.

  • ImplementationNote
  • UiThread
  • Critical
  • Constraint
  • Determined
  • NonDetermined
  • LazyInited
  • Link
  • MayContainNull
  • MustNotContainNull
  • NeedsRefactoring
  • OneWayChange
  • PureFunction
  • ReturnsOriginal
  • Risky
  • ToDo
  • Warning
  • Weight
  • ThrowsRuntimeException
  • ThrowsRuntimeExceptions
  • Experimental
  • TimeComplexity
  • MemoryComplexity

How to add the annotation library into maven project

To use annotations just add dependency to the library

<dependency>
    <groupId>com.igormaznitsa</groupId>
    <artifactId>meta-annotations</artifactId>
    <version>1.2.1</version>
</dependency>

It shades JSR-305 annotations from the FindBugs library so that they also will be available for usage automatically.

Utilities

Since 1.1.0 utility classes extracted into separated module which is available in maven central Just add the lines below into build section.

<dependency>
    <groupId>com.igormaznitsa</groupId>
    <artifactId>meta-utils</artifactId>
    <version>1.2.1</version>
</dependency>

com.igormaznitsa.meta.common.utils.Deferrers

It allows to defer some operations, like it works in Go but unfortunately the call to process all deferred operations must be placed into try...finally block to ensure the call. It checks stack frames and all deferred operations will be processed by Deferrers.processDeferredActions() only for actual stack depth, it means that deferred operations added on higher stack levels will be ignored.

    try {
      // it processes runnable, the code will be executed
      Deferrers.defer(new Runnable() {public void run() { System.out.println("Hello world");}});
      final InputStream is = new FileInputStream("/home/test/nonexistfile.txt");
      // it processes closeable, registered closeable object will be closed automatically
      Deferrers.defer(is);
    }
    finally {
      Deferrers.processDeferredActions();
    }

com.igormaznitsa.meta.common.utils.TimeGuard

    final TimeGuard.TimeAlertListener listener = new TimeGuard.TimeAlertListener() {
      @Override
      public void onTimeAlert(long l, TimeGuard.TimeData td) {
        System.out.println("Too long delay for " + td.getAlertMessage());
      }
    };

    try {
      TimeGuard.addGuard("Checkpoint1", 100L, listener);
      Thread.sleep(200L);
    }
    finally {
      TimeGuard.check();
    }

How to use the maven plugin

I have also published some maven plugin which allows to check compiled classes for the annotations and print some information and check that methods marked by nullable and nonnull annotations. Also the plugin allows to fail build process if detected some annotations, it allows to avoid publishing of project with to-do or experimental stuff.

<plugin>
    <groupId>com.igormaznitsa</groupId>
    <artifactId>meta-checker</artifactId>
    <version>1.2.1</version>
    <configuration>
        <restrictClassFormat>7</restrictClassFormat>
        <failForAnnotations>
            <param>risky</param>
        </failForAnnotations>
    </configuration>
    <executions>
        <execution>
            <goals>
              <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

About

Set of annotations to mark code and some utility classes

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors