https://github.com/blackbeard334/jops
Java Operator Overloading Plugin
https://github.com/blackbeard334/jops
compiler-plugin experimental java javac-plugin operator-overloading pl
Last synced: about 1 month ago
JSON representation
Java Operator Overloading Plugin
- Host: GitHub
- URL: https://github.com/blackbeard334/jops
- Owner: blackbeard334
- License: gpl-3.0
- Created: 2019-07-26T21:50:26.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-24T16:30:49.000Z (about 6 years ago)
- Last Synced: 2025-07-06T06:19:22.642Z (8 months ago)
- Topics: compiler-plugin, experimental, java, javac-plugin, operator-overloading, pl
- Language: Java
- Homepage:
- Size: 249 KB
- Stars: 10
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.com/blackbeard334/jops)
# JOPS
**J**ava **O**perator Overloading **P**lugin
Originally JOPS stood for "Java Opcodes", but that didn't make sense anymore, so now it stands for **J**ava **O**perator Overloading **P**lugin.
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](https://github.com/blackbeard334/jops/blob/master/jops_plugin/src/main/java/com/jops/annotation/OperatorOverloading.java) annotation to the class with overloaded operators
- overload the operators with the following C++ syntax:
```java
@OperatorOverloading
public class Bla {
public Bla operator+(Bla b) {
return ...//something..or nothing
}
}
```
- ...
- write some code, and behold:
```java
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+`
1) `operator-`
1) `operator*`
1) `operator/`
1) `operator+=`
1) `operator-=`
1) `operator*=`
1) `operator/=`
## How to build/compile
### Maven
- include the _jops_plugin_ as a dependency(we need this for the _@OperatorOverloading_ annotation)
```xml
io.github.blackbeard334
jops_plugin
${jops_plugin.version}
```
- next you need to add the _jops_plugin_ as a compiler arg, and as a dependency for the _maven-compiler_plugin_
```xml
org.apache.maven.plugins
maven-compiler-plugin
3.8.1
11
11
-Xplugin:JOPSPlugin
io.github.blackbeard334
jops_plugin
${jops_plugin.version}
```
### Mavenless
* `javac -cp /path/jops -Xplugin:JOPSPlugin HelloWorld.java`
1) first we need to include the _jops_plugin_ in the classpath `-cp /path/jops`
1) then we tell the compiler that we want to use the _jops_plugin_ with the `-Xplugin:JOPSPlugin` switch
3) enjoy...
###### References
* [The Hitchhiker's Guide to javac](https://openjdk.java.net/groups/compiler/doc/hhgtjavac/index.html#source)
* [Java Compiler API - Compile Code to a File and Load it using Default Class Loader](https://www.logicbig.com/tutorials/core-java-tutorial/java-se-compiler-api/compiler-api-string-source.html)
* [ANNOTATION PROCESSING 101](http://hannesdorfmann.com/annotation-processing/annotationprocessing101)
* [Extending Java and Javac](https://blog.blackhc.net/2009/06/extending-java-and-javac/)
* [Creating a Java Compiler Plugin](https://www.baeldung.com/java-build-compiler-plugin)
* [Parser for C and Objective-C.](https://github.com/gcc-mirror/gcc/blob/master/gcc/c/c-parser.c)