Skip to content

blackbeard334/jops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

JOPS

Java Operator Overloading Plugin

Originally JOPS stood for "Java Opcodes", but that didn't make sense anymore, so now it stands for Java Operator Overloading Plugin.

I know I know, it should be called JOOP instead, but I like JOPS better. Oh yeah, the 'S' stands for Syntactic Sugar Edition.

How to use

  • add @OperatorOverloading annotation to the class with overloaded operators
  • overload the operators with the following C++ syntax:
@OperatorOverloading
public class Bla {       
    public Bla operator+(Bla b) {
        return ...//something..or nothing
    }                 
}
  • ...
  • write some code, and behold:
public class BlaTest {       
    public static void main(String[]args) {
        Bla a = new Bla();
        Bla b = new Bla();
        Bla c = a + b;
        System.out.println("operator overloading banzai!");
    }                     
}
Currently only the following single operand operators are supported:
  1. operator+
  2. operator-
  3. operator*
  4. operator/
  5. operator+=
  6. operator-=
  7. operator*=
  8. operator/=

How to build/compile

Maven

  • include the jops_plugin as a dependency(we need this for the @OperatorOverloading annotation)
<dependencies>
    <dependency>
        <groupId>io.github.blackbeard334</groupId>
        <artifactId>jops_plugin</artifactId>
        <version>${jops_plugin.version}</version>
    </dependency> 
</dependencies>
  • next you need to add the jops_plugin as a compiler arg, and as a dependency for the maven-compiler_plugin
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>11</source>
                <target>11</target>
                <compilerArgs>
                    <arg>-Xplugin:JOPSPlugin</arg>
                </compilerArgs>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>io.github.blackbeard334</groupId>
                    <artifactId>jops_plugin</artifactId>
                    <version>${jops_plugin.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

Mavenless

  • javac -cp /path/jops -Xplugin:JOPSPlugin HelloWorld.java
    1. first we need to include the jops_plugin in the classpath -cp /path/jops
    2. then we tell the compiler that we want to use the jops_plugin with the -Xplugin:JOPSPlugin switch
    3. enjoy...
References