diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 10dc99f..0000000 --- a/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -*~ -*.class -bin/ -out/ -target/ -.idea/ -*.iml -/javac-oo -/javac8-oo -/nb-javac-oo diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 8776b4f..0000000 --- a/.gitmodules +++ /dev/null @@ -1,6 +0,0 @@ -[submodule "eclipse-oo"] - path = eclipse-oo - url = https://github.com/amelentev/eclipse.jdt-oo.git -[submodule "eclipse-oo-site"] - path = eclipse-oo-site - url = https://github.com/amelentev/eclipse.jdt-oo-site diff --git a/.hgignore b/.hgignore deleted file mode 100644 index af4c431..0000000 --- a/.hgignore +++ /dev/null @@ -1,6 +0,0 @@ -syntax: glob -target -.idea -*.iml -*~ -bin diff --git a/.hgsub b/.hgsub deleted file mode 100644 index 0aa3176..0000000 --- a/.hgsub +++ /dev/null @@ -1,4 +0,0 @@ -javac-oo = ssh://hg@bitbucket.org/amelentev/javac-oo -javac8-oo = ssh://hg@bitbucket.org/amelentev/javac8-oo -eclipse.jdt-oo = [git]git@github.com:amelentev/eclipse.jdt-oo.git -lombok-oo = [git]git@github.com:amelentev/lombok-oo.git diff --git a/.hgsubstate b/.hgsubstate deleted file mode 100644 index 3fd5393..0000000 --- a/.hgsubstate +++ /dev/null @@ -1,3 +0,0 @@ -1e4b5af95af9a1105d766bf91265629fd804e855 eclipse-oo -cd8299dec718aa67002bd4cad943c0f4d1119d8a javac-oo -c7c45568259fff73358178400a9e1b3311d8d4c8 lombok-oo diff --git a/README.md b/README.md deleted file mode 100644 index fbfea7d..0000000 --- a/README.md +++ /dev/null @@ -1,246 +0,0 @@ -# Java Operator Overloading # - -Java-OO is a modular extension (plugin) to Java compilers and IDEs -for ([Scala-like]) [Operator Overloading] support. -Works with standard JavaC compiler, [Netbeans IDE], [Eclipse IDE], [IntelliJ IDEA] IDE and any build tools. - -Example (see other examples at [examples/](https://github.com/amelentev/java-oo/tree/master/javac-oo-mvndemo/src/) dir): - -```java -import java.math.*; -import java.util.*; -public class Test { - public static void main(String[] args) { - BigInteger a = BigInteger.valueOf(1), // without OO - b = 2, // with OO - - c1 = a.negate().add(b.multiply(b)).add(b.divide(a)), // without OO - c2 = -a + b*b + b/a; // with OO - - if (c1.compareTo(c2)<0 || c1.compareTo(c2)>0) // without OO - System.out.println("impossible"); - if (c1c2) // with OO - System.out.println("impossible"); - - HashMap map = new HashMap<>(); - if (!map.containsKey("qwe")) map.put("qwe", map.get("asd")); // without OO - if (map["qwe"]==null) map["qwe"] = map["asd"]; // with OO - } -} -``` - -# Versions # - - JavaC/Netbeans: 0.5 - JavaC8: 0.5 - Eclipse: 0.5 - IntelliJ IDEA: 0.7 - -Note plugin versions are independent. If version for X > version for Y then it doesn't mean Y is behind feature wise. - -# News # -16 Nov 2019. [IntelliJ IDEA](#IDEA) plugin v0.7 released with support of IDEA 2019.2+. - -20 May 2017. [IntelliJ IDEA](#IDEA) plugin v0.6 released with support of IDEA 2017. - -14 July 2016. As a workaround [Eclipse plugin](#Eclipse) works fine on Eclipse 4.4+ if you install [Scala IDE] plugin first. - -2 Feb 2016. [IntelliJ IDEA](#IDEA) plugin v0.5 released with support of IDEA 15. Requires Java8 to run the plugin. - -10 April 2015. [IntelliJ IDEA](#IDEA) plugin v0.4.1 released with support of IDEA 14.1. - -27 January 2015. Eclipse-oo-plugin version 0.5 released with support of [reverse binary operator overload][operatorRev]. - -2 December 2014. New feature: [Reverse binary operator overload via `operatorRev` methods][operatorRev].
-Plugin versions updated:
-[JavaC7 & JavaC8](#javac): 0.5
-[IntelliJ IDEA](#IDEA): 0.4. Support of IDEA 14 - -31 May 2014. Javac8 plugin version 0.1.1 released. Removed runtime depencendy on nbjavac. - -24 May 2014. [IntelliJ IDEA](#IDEA) plugin v0.3.1 released. Bugfixes for IDEA 13 Ultimate and for type resolution for binary expressions with primitives. - -30 April 2014. [IJPLA] published a [paper] about Java-OO. - -3 Feb 2014. New JavaC8 plugin version 0.1 for JDK8 was released. -It has the same features as JavaC plugin for JDK7 but doesn't work in Netbeans yet. - -12 Jan 2014. JavaC plugin version 0.4 and Eclipse plugin version 0.4 released. -Now operator overloading perform autoboxing/autounboxing primitive to/from wrapper types where appropriate. -Fixed [javac plugin bug with index-set OO](https://github.com/amelentev/java-oo/issues/13). - -3 Jan 2014. JavaC plugin version 0.3 released. -Fixed [#10 javac: binary operator adds erroneous cast on 1st operand](https://github.com/amelentev/java-oo/issues/10). - -8 Sep 2013. Eclipse plugin version 0.3 released. -Removed copypasta from Eclipse Compiler. Plugin should be more steady agains compiler changes. - -14 May 2013. [IntelliJ IDEA](#IDEA) IDE plugin v0.2.1 with IDEA Ultimate Edition support. - -17 Apr 2013. [IntelliJ IDEA](#IDEA) IDE plugin v0.2. - -26 Nov 2012. [Version 0.2] released. New feature: [Assignment operator overloading](https://github.com/amelentev/java-oo/issues/4) via static _#valueOf_ method. - -# Installation # - - - -## javac, ant, etc ## -Just add to classpath: [javac8-oo-plugin.jar] for JDK8 or [javac-oo-plugin.jar] for JDK7. - -``` -javac -cp javac8-oo-plugin.jar -``` - -Demo at [examples/compile.sh](https://github.com/amelentev/java-oo/blob/master/javac-oo-mvndemo/src/compile.sh) - - - -## [Eclipse IDE] update site ## -Click in menu: `Help - Install New Software`. Enter in `Work with` field: - - http://amelentev.github.io/eclipse.jdt-oo-site/ - -Tested on Eclipse Standard 4.3.2. Should work with older versions too.
-To work on 4.4+ you need to install [Scala IDE] plugin (or similar plugin with Equanox weaving). You can find it in `Help -> Eclipse Marketplace`. This is workaround until normal solution will be found. Tested on 4.4 and 4.6. - -## [Netbeans IDE] ## -1. Add [javac-oo-plugin.jar] as compile or processor library to Netbeans. -2. Enable "Annotation Processing in Editor": `Project Properties -> Build -> Compiling`. - -Tested on 7.2.1 - -
- -## [IntelliJ IDEA] IDE ## -1. Install [Java Operator Overloading support](https://plugins.jetbrains.com/idea/plugin/7224-java-operator-overloading-support) plugin: `File -> Settings -> Plugins -> Browse repositories`. Mirror: [idea-oo-plugin.jar])
-For [Maven projects](#maven) installation is done. IDEA should setup everything according to pom.xml.
-For other project types:
-2. Add [javac8-oo-plugin.jar] as compile or processor library. -3. Enable Annotation Processing: -`Menu File -> Settings -> Compiler -> Annotation Processing -> Enable annotation processing` -4. Make sure you use `javac` compiler in `Settings -> Java Compiler -> Use compiler`.
-Tested on IDEA 2019.2.4 Ultimate & Community editions. You can use earlier plugin versions for older IDEA releases. - -### Android project in IDEA 12 ### -Add [javac-oo-plugin.jar] to `File - Settings - Compiler - Annotation Processors - Processor path` - -### Android Studio (IDEA 13) / Gradle ### -add to `build.gradle`: - -``` -repositories { - maven { url 'http://amelentev.github.io/mvnrepo/' } -} -dependencies { - compile 'java-oo:javac-oo-plugin:0.5' -} -``` - -
- -## Maven ## -Look at [javac-oo-mvndemo/pom.xml](https://github.com/amelentev/java-oo/blob/master/javac-oo-mvndemo/pom.xml) - -# Details # - -Read the [paper] to learn more. -Supported operators (operator to method name map): - -binary: - - | OPERATOR | METHOD NAME| - ------------------------- - | + | add | - | - | subtract | - | * | multiply | - | / | divide | - | % | remainder | - | & | and | - | | | or | - | ^ | xor | - | << | shiftLeft | - | >> | shiftRight | - -If left operand has no such method then the plugin will try to use ['reverse' method `Rev`][operatorRev] on right operand. -So `2*a` will be transformed to `a.multiplyRev(2)` if `a` has such method. - -unary: - - | - | negate | - | ~ | not | - -comparison: - - | <, <=, >, >= | compareTo | example: `a < b` <=> `a.compareTo(b)<0` - `==` and `!=` are not overloadable because it will break things - -index: - - | [] | get | `v = lst[i]` <=> `v = lst.get(i)` - | []= | set, put | `map[s] = v` <=> `map.put(s,v)`, `lst[i] = v` <=> `lst.set(i,v)` - -assignment: - - | var = expr | var = VarClass.valueOf(expr) | - -if `expr` is not assignable to `var` and `var` is an instance of `VarClass` and `expr` has type `ExprType` and there are static method `VarClass#valueOf(ExprType)`
-then `var = expr` is transformed to `var = VarClass.valueOf(expr)`. -example:
-`BigInteger a = 1` is transformed to `BigInteger a = BigInteger.valueOf(1)` - -These methods exists in many java classes (example: BigInteger, BigDecimal) so you can -use operators on them "out of the box". Or you can add these methods to your classes to use OO (see [examples/Vector.java](https://github.com/amelentev/java-oo/blob/master/javac-oo-mvndemo/src//Vector.java)). - - -## Subprojects / Implementation details - -- javac-oo-plugin - - Plugin to JavaC 1.7 and [Netbeans IDE] for operator overloading. Based on [javac-oo]. - - Building via [maven] at top level: `cd java-oo; mvn clean install`. Or import maven settings in your IDE. - -- eclipse-oo-plugin - - [Eclipse IDE](JDT) plugin for OO support. - - Patching Eclipse Java Compiler to allow OO. - - Build in Eclipse with [PDE], [AJDT and Equanox Weaving] plugins. Run as Eclipse application with [equinox weaving enabled][equinox-weaving-launcher]. - -- idea-oo-plugin - - [IntelliJ IDEA] IDE plugin for OO support. - - Modify Java frontend in IDEA to allow OO. Need javac-oo-plugin to actually compile. - - Build in IDEA. Run as IDEA plugin. - -- by-products: - - [javac-oo] - - Patched version of JavaC 1.7 for Operator Overloading support. If you need standalone javac compiler with OO. - - Build via ant or netbeans: http://openjdk.java.net/groups/compiler/README.html#build - - [eclipse-oo] - - Eclipse [Java Developer Tools] fork for Operator Overloading. - - Use it if you need native [Eclipse IDE] support, or Eclipse Java Compiler support. - - Build in Eclipse with [PDE]. Run as Eclipse application. - -## Publications -["Java Modular Extension for Operator Overloading", IJPLA, April 2014.](https://github.com/amelentev/java-oo/raw/master/doc/ijpla.pdf) - -[Scala-like]: http://www.slideshare.net/joeygibson/operator-overloading-in-scala-2923973 -[javac-oo]: https://bitbucket.org/amelentev/javac-oo -[lombok]: http://projectlombok.org/ -[lombok-oo]: https://github.com/amelentev/lombok-oo -[Eclipse IDE]: http://eclipse.org/ -[Netbeans IDE]: http://www.netbeans.org/ -[IntelliJ IDEA]: http://www.jetbrains.com/idea/ -[Java Developer Tools]: http://eclipse.org/jdt/ -[eclipse-oo]: https://github.com/amelentev/eclipse.jdt-oo -[Operator Overloading]: http://en.wikipedia.org/wiki/Operator_overloading -[AJDT and Equanox Weaving]: http://wiki.eclipse.org/Equinox_Weaving_QuickStart -[PDE]: http://www.eclipse.org/pde/ -[maven]: https://maven.apache.org/ - -[javac-oo-plugin.jar]: http://amelentev.github.io/mvnrepo/java-oo/javac-oo-plugin/0.5/javac-oo-plugin-0.5.jar -[javac8-oo-plugin.jar]: http://amelentev.github.io/mvnrepo/java-oo/javac8-oo-plugin/0.5/javac8-oo-plugin-0.5.jar -[idea-oo-plugin.jar]: http://amelentev.github.io/mvnrepo/java-oo/idea-oo-plugin/idea-oo-plugin-0.7.jar -[IJPLA]: http://airccse.org/journal/ijpla/current2014.html#apr -[paper]: https://github.com/amelentev/java-oo/raw/master/doc/ijpla.pdf -[operatorRev]: https://github.com/amelentev/java-oo/issues/25 -[equinox-weaving-launcher]: https://github.com/milessabin/equinox-weaving-launcher -[Scala IDE]: http://scala-ide.org/download/current.html -[Version 0.2]: https://github.com/amelentev/java-oo/issues?milestone=1&state=closed diff --git a/doc/.gitignore b/doc/.gitignore deleted file mode 100644 index ab13dea..0000000 --- a/doc/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -*.blg -*.aux -*.bbl -*.log -*.pdf -*.out -*.fdb_latexmk -*.synctex.gz -*.fls diff --git a/doc/aircc.cls b/doc/aircc.cls deleted file mode 100644 index 4275cff..0000000 --- a/doc/aircc.cls +++ /dev/null @@ -1,346 +0,0 @@ -% ============================================================================ -%% aircc.cls V 1.1, 2012/09/13, (c) 2012 Thomas Zink -%% minor modifications by Artem Melentyev, 2014. -%% -%% This is an unofficial Latex class for Authors of AIRCC Papers. -%% It tries to follow the formating guidelines set in the official -%% template "aircc_template.doc" as close as possible. -%% Unfortunately, some are not easily applicable in Latex. Examples include -%% text style combinations like \bf\sc\it which simply is generally not -%% supported. Some font sizes are also not directly supported. -%% -%% *************************************************************************** -%% Legal Notice: -%% This code is offered as-is without any warranty either expressed or -%% implied; without even the implied warranty of MERCHANTABILITY or -%% FITNESS FOR A PARTICULAR PURPOSE! -%% -%% This work is distributed under the LaTeX Project Public License (LPPL) -%% ( http://www.latex-project.org/ ) version 1.3, and may be freely used, -%% distributed and modified. A copy of the LPPL, version 1.3, is included -%% in the base LaTeX documentation of all distributions of LaTeX released -%% 2003/12/01 or later. -%% Retain all contribution notices and credits. -%% ** Modified files should be clearly indicated as such, including ** -%% ** renaming them and changing author support contact information. ** -%% -% ============================================================================ -\ProvidesClass{aircc}[2012/06/14 V1.0 by Thomas Zink] -\typeout{-- Class for AIRCC Journal submissions --} -\NeedsTeXFormat{LaTeX2e} - -\usepackage{rcs} -\RCS $Date: 2012/06/12 $ -\RCS $Author: thomas zink (tzn) $ -\RCS $file: aircc.cls $ - -\typeout{-- \RCSfile, Copyright (c) \RCSDate, by \RCSAuthor --} - -% we can either use 'bold-extra': \bf\sc -% or 'slantsc' and 'lmodern': \sl\sc -% unfortunately, not both at the same time and no \bf\sl\sc -% we use bold-extra and find a workaround for Abstract and Keywords below -\usepackage{bold-extra} % allow \bf\sc - -% ============================================================================ -% 2.1. General Format, Page Layout and Margins -% ============================================================================ - -% Standard A4 (210mm x 297mm) -% left, right, top and bottom margins should be 30mm -%\usepackage[paper=a4paper,top=30mm,bottom=30mm,left=30mm,right=30mm]{geometry} -\usepackage[paper=a4paper,top=30mm,bottom=30mm,left=30mm,right=30mm, headsep=8pt, headheight=8pt, ignoreheadfoot]{geometry} - -% no rule on header -\usepackage{fancyhdr} -\renewcommand{\headrulewidth}{0pt} - -% Do not use any headers, footers or footnotes. No page numbers. Single column. All main text paragraphs, including the abstract, must be fully (left and right) justified. All text, including title, authors, headings, captions and body, will be Times New Roman font. -\pagestyle{empty} -\def\thepage{\arabic{page}} - -\def\xsmall{\@setfontsize{\xsmall}{9}{10pt}} -\def\small{\@setfontsize{\small}{10}{12pt}} -\def\normalsize{\@setfontsize{\normalsize}{11}{13.3846pt}}% -\def\large{\@setfontsize{\large}{12}{14pt}} -\def\xlarge{\@setfontsize{\xlarge}{13}{14pt}} -\def\Large{\@setfontsize{\Large}{14}{17pt}} -\def\XLarge{\@setfontsize{\XLarge}{20}{22pt}} -\normalsize - -% Do not indent paragraphs. -\setlength\parindent{0pt} -\setlength\parskip{6pt} -%\parfillskip=6pt - -% ============================================================================ -% 2.2. Title & 2.3 Authors -% ============================================================================ -% The title is to be written in 20 pt. Garamond font, centred and using the bold and “Small Caps” formats. There should be 24 pt. (paragraph) spacing after the last line. - -% Author names are to be written in 13 pt. Times New Roman format, centred and followed by a 12pt. paragraph spacing. If necessary, use superscripts to link individual authors with institutions as shown above. Author affiliations are to be written in 12 pt. Times New Roman, centred, with email addresses, in 10 pt. Courier New, on the line following. The last email address will have an 18 pt. (paragraph) spacing following. - -\newcommand{\@affiliation}{} -\def\affiliation#1{% - \renewcommand{\@affiliation}{#1}% -} - -\newcommand{\email}[1]{{\small #1}} - -\def\maketitle{% - \begin{center} - {\XLarge\textbf{\textsc{\@title}}\\} - \vspace{24pt} - {\xlarge\@author\\} - \vspace{12pt} - {\large\@affiliation\\} - \vspace{12pt} % 18 - parskip - \end{center} -} - -% ============================================================================ -% 2.4. Abstract -% ============================================================================ -% The Abstract section begins with the word, “Abstract” in 13 pt. Times New Roman, bold italics, -% “Small Caps” font with a 6pt. spacing following. The abstract must not exceed 150 words in length in 10 pt. -% Times New Roman italics. The text must be fully justified, with a 12 pt. paragraph spacing following the last line. - -\newenvironment{abstract} - %{\par\fontsize{13}{14}\textbf{\textit{\textsc{Abstract}}}\begin{itshape}\par\normalsize} - {\par\fontsize{13}{14}\textbf{\textit{A}}\fontsize{10}{10}\textbf{\textit{BSTRACT}}\begin{itshape}\par\small} - {\end{itshape}\vspace{6pt}} - -% ============================================================================ -% 2.5. Keywords -% ============================================================================ -% The Keywords section begins with the word, “Keywords” in 13 pt. Times New Roman, bold italics, -% “Small Caps” font with a 6pt. spacing following. There may be up to five keywords (or short phrases) separated by commas and six spaces, -% in 10 pt. Times New Roman italics. An 18 pt. line spacing follows. - -\newenvironment{keywords} - %{\par\fontsize{13}{14}\textbf{\textsl{\textsc{Keywords}}}\begin{itshape}\par\small} - {\par\fontsize{13}{14}\textbf{\textit{K}}\fontsize{10}{10}\textbf{\textit{EYWORDS}}\begin{itshape}\par\small} - {\end{itshape}\vspace{12pt}} - -% ============================================================================ -%% 2.6. Section and sub-section headings -% ============================================================================ -\newcounter{section}\setcounter{section}{0} -\newcounter{subsection}[section] -\newcounter{subsubsection}[subsection] -\newcounter{paragraph}[subsubsection] - -\def\thesection{\arabic{section}} -\def\thesubsection{\arabic{section}.\arabic{subsection}} -\def\thesubsubsection{\arabic{section}.\arabic{subsection}.\arabic{subsubsection}} - -%% Section headings are numbered 1. Xxx, 2. Yyy, etc. in 14 pt. bold “Small Caps” Times New Roman font with a 6 pt. line spacing following. - -% \@startsection {NAME}{LEVEL}{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE} -% optional * [ALTHEADING]{HEADING} -\def\section{ - \@startsection{section}{1}{0pt}% - {-12pt minus -\parskip} - {.1\parskip minus \parskip} % .1 larger than 6 pt, closest we can get - {\Large\bfseries\scshape\refstepcounter{section}\thesection. }% -}% - -%% Subsection headings are numbered 1.1. Aaa, 1.2. Bbb, etc. in 12 pt. bold Times New Roman font with a 6pt line spacing following. -\def\subsection{ - \@startsection{subsection}{2}{0pt}% - {-12pt minus -\parskip} - {.1\parskip minus \parskip} % .1 larger than 6 pt, closest we can get - {\large\bfseries\refstepcounter{subsection}\thesubsection. }% -}% - -\def\subsubsection{ - \@startsection{subsection}{2}{0pt}% - {-12pt minus -\parskip} - {.1\parskip minus \parskip} % .1 larger than 6 pt, closest we can get - {\large\bfseries\refstepcounter{subsubsection}\thesubsubsection. }% -}% - -% ============================================================================ -% 2.7 Text -% ============================================================================ -% Main-body text is to written in fully (left and right) justified 11 pt. Times New Roman font with a 6pt. (paragraph) line spacing following the last line of each paragraph, but a 12pt. (paragraph) line spacing following the last paragraph. - -% this is already standard, paragraph spacing set above - -% ============================================================================ -% Appendix -% ============================================================================ -\def\appendix{ - \@startsection{appendix}{2}{0pt}% - {-12pt minus -\parskip} - {.1\parskip minus \parskip} - {\large\scshape A. }% -}% - -% ============================================================================ -% Caption -% ============================================================================ -\newlength\abovecaptionskip -\newlength\belowcaptionskip -\setlength\abovecaptionskip{10\p@} -\setlength\belowcaptionskip{0\p@} - -\long\def\@makecaption#1#2{% - \vskip\abovecaptionskip - \sbox\@tempboxa{#1: #2}% - \ifdim \wd\@tempboxa >\hsize - #1: #2\par - \else - \global \@minipagefalse - \hb@xt@\hsize{\hfil\box\@tempboxa\hfil}% - \fi - \vskip\belowcaptionskip% -} - -% ============================================================================ -% Figures -% ============================================================================ -\newcounter{figure} -\renewcommand\thefigure{\@arabic\c@figure} -\def\fnum@figure{\figurename\nobreakspace\thefigure} -\def\fps@figure{tbp} -\def\ftype@figure{1} -\def\ext@figure{lof} - -\newcommand\figurename{Figure} - -\newenvironment{figure} - {\@float{figure}} - {\end@float} -\newenvironment{figure*} - {\@dblfloat{figure}} - {\end@dblfloat} - -% ============================================================================ -% Footnotes -% ============================================================================ -% Do not use any footnotes! -\def\footnotesize{\small} -% print a rule above footnotes -\renewcommand\footnoterule{% - \kern-3\p@ - \hrule\@width.5\columnwidth - \kern2.6\p@} - -% creates the footnote text, indented with mark -\newcommand\@makefntext[1]{% - \parindent 1em% - \noindent - \hb@xt@1.8em{\hss\@makefnmark}#1} - -% replaces the footnote and prints a warning instead -% comment out to be able to use footnotes -\renewcommand\footnote[1]{ - \@latex@warning{AIRCC: Do not use any footnotes!} -} -% ============================================================================ -% List / Itemize / Enumeration settings -% ============================================================================ -% itemized list label styles -\def\labelitemi{$\scriptstyle\bullet$} -\def\labelitemii{\textbf{--}} -\def\labelitemiii{$\ast$} -\def\labelitemiv{$\cdot$} - -% enum labels -\newcommand\labelenumi{\theenumi.} -\newcommand\labelenumii{(\theenumii)} -\newcommand\labelenumiii{\theenumiii.} -\newcommand\labelenumiv{\theenumiv.} - -% level indents -\setlength\leftmargini {2.5em} -\setlength\leftmarginii {2.2em} -\setlength\leftmarginiii {1.87em} -\setlength\leftmarginiv {1.7em} - -\leftmargin \leftmargini - -% labels general -\setlength\labelsep{.5em} -\setlength\labelwidth{\leftmargini} -\addtolength\labelwidth{-\labelsep} - -%\renewenvironment{enumerate}% -%{% -% \setcounter{enumi}{0}% restart numbering -% \smallskip% skip a line -% \renewcommand{\item}{% new definition of item -% \par% start a new line -% \parindent 1.5em -% \hangindent=1.5em -% \refstepcounter{enumi}% advance counter -% \makebox[2.0em][l]{(\theenumi)}% print counter to width of 3em, aligned to left -% }% end of definition of item -%}{% at end of environment -% \par% start new paragraph -% \smallskip% skip a line -%} - -% ============================================================================ -% Bibliography -% ============================================================================ -\newcommand\refname{References} -\newcommand\newblock{\hskip .11em\@plus.33em\@minus.07em} - -\newdimen\bibindent -\setlength\bibindent{1.0em} - -\newenvironment{thebibliography}[1] - {% - \section*{\refname}% - \list{\@biblabel{\@arabic\c@enumiv}}% - {\settowidth\labelwidth{\@biblabel{#1}}% - \leftmargin\labelwidth - \advance\leftmargin\labelsep - \usecounter{enumiv}% - }% - \sloppy - \clubpenalty4000 - \@clubpenalty \clubpenalty - \widowpenalty4000% - } - {\def\@noitemerr - {\@latex@warning{Empty `thebibliography' environment}}% - \endlist} - -\let\oldbibliography\thebibliography -\renewcommand{\thebibliography}[1]{% add 6pt spacing between bibitems - \oldbibliography{#1}% - \setlength{\itemsep}{5pt}% -} - -% ============================================================================ -% Tables -% ============================================================================ -\newcommand\tablename{Table} - -% array and table seperations -\setlength\arraycolsep{5\p@} -\setlength\arrayrulewidth{.4\p@} -\setlength\tabcolsep{6\p@} -\setlength\doublerulesep{2\p@} -\setlength\tabbingsep{\labelsep} - -% table counters -\newcounter{table} -\renewcommand\thetable{\@arabic\c@table} -\def\fps@table{tbp} -\def\ftype@table{2} -\def\ext@table{lot} -\def\fnum@table{\tablename\nobreakspace\thetable} - -% table environment -\newenvironment{table} - {\@float{table}} - {\end@float} -\newenvironment{table*} - {\@dblfloat{table}} - {\end@dblfloat} - -\endinput diff --git a/doc/ijpla.bib b/doc/ijpla.bib deleted file mode 100644 index ec327b5..0000000 --- a/doc/ijpla.bib +++ /dev/null @@ -1,133 +0,0 @@ -@misc{oo, - title = {{Operator Overloading}}, - howpublished = {\url{http://en.wikipedia.org/wiki/Operator_overloading}}, -} -@book{itc, - author = {Odersky, Martin and Spoon, Lex and Venners, Bill}, - title = {Programming in Scala: A Comprehensive Step-by-Step Guide, 2nd Edition. Chapter 21: Implicit Conversions and Parameters}, - year = {2011}, - isbn = {0981531644, 9780981531649}, - edition = {2nd}, - publisher = {Artima Incorporation}, - address = {USA}, -} -@misc{javac-oo, - title = {{Fork of JDK langtools for operator overloading}}, - howpublished = { \\ \url{http://bitbucket.org/amelentev/javac-oo}}, -} -@misc{eclipse.jdt-oo, - title = {{Fork of Eclipse JDT for operator overloading}}, - howpublished = { \\ \url{http://github.com/amelentev/eclipse.jdt-oo/}}, -} -@misc{jop, - title = {{JOP: The Java Operator Overloading Project}}, - howpublished = { \\ \url{http://motonacciu.50webs.com/projects/jop/index.html}}, -} -@misc{lombok, - title = {{Project Lombok}}, - howpublished = {\url{http://projectlombok.org/}}, -} -@misc{lombok-oo, - title ={{First version of Java Operator Overloading plugin based on Lombok}}, - howpublished = { \\ \url{https://github.com/amelentev/lombok-oo}}, -} -@misc{psi, - title = {{IntelliJ IDEA Program Structure Interfaces}}, - howpublished = {\url{http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview#IntelliJIDEAArchitecturalOverview-PsiElements}}, -} -@article{juast, - author = {A. V. Klepinin and - A. A. Melentyev}, - title = {{Integration of semantic verifiers into Java language compilers}}, - journal = {Automatic Control and Computer Sciences}, - volume = {45}, - number = {7}, - year = {2011}, - pages = {408-412}, - ee = {http://dx.doi.org/10.3103/S014641161107008X}, - bibsource = {DBLP, http://dblp.uni-trier.de}, - url = {http://www.springerlink.com/content/38u5623607v17251/}, -} -@talk{Xplugin, - title = {{Hacking the Java Compiler for Fun and Profit}}, - author = {{Raoul-Gabriel Urma}} -} -@article{HackerGuideJavac, - title = {{The Hacker's Guide to Javac}}, - author = {David Erni and Adrian Kuhn}, - year = {2008} -} -@misc{jsr269, - title = {{JSR 269: Pluggable Annotation Processing API}}, - howpublished = { \\ \url{http://jcp.org/en/jsr/detail?id=269}} -} -@misc{jls, - title = {{Java Language Specification. Java SE 7 Edition. 6.6.1. Determining Accessibility}}, - howpublished = { \\ \url{http://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html#jls-6.6.1}}, -} -@misc{jvmspecPP, - title = {{The Java Virtual Machine Specification. Java SE 7 Edition. 5.3. Creation and Loading and 5.4.4 Access Control}}, - howpublished = {\url{http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-5.html#jvms-5.3}}, -} -@misc{soPackagePrivate, - title = {{Overriding package-private method in different classloader}}, - howpublished = { \\ \url{http://stackoverflow.com/questions/4060842}}, -} -@misc{lombok.patcher, - title = {{Lombok.patcher: A framework for easily patching JVM programs}}, - howpublished = { \\ \url{https://github.com/rzwitserloot/lombok.patcher}}, -} -@misc{AJLTW, - title = {{AspectJ Load Time Weaving}}, - howpublished = { \\ \url{http://www.eclipse.org/aspectj/doc/next/devguide/ltw.html}}, -} -@misc{EquanoxW, - title = {{Equinox Weaving}}, - howpublished = {\url{http://eclipse.org/equinox/weaving/}}, -} -@misc{groovyoo, - title = {{Operator Overloading in Groovy}}, - howpublished = { \\ \url{http://groovy.codehaus.org/Operator+Overloading}}, -} -@misc{kotlinoo, - title = {{Operator Overloading in Kotlin}}, - howpublished = {\url{http://confluence.jetbrains.com/display/Kotlin/Operator+overloading}}, -} -@unpublished{scalaspec, - author = {Odersky, Martin and Others}, - citeulike-article-id = {104333}, - posted-at = {2005-02-26 03:29:52}, - priority = {0}, - title = {{The Scala Language Specification}}, - year = {2011} -} -@misc{smartcasts, - title = {{Smart casts in Kotlin}}, - howpublished = { \\ \url{http://confluence.jetbrains.com/display/Kotlin/Type+casts}}, -} -@misc{safenav, - title = {{Safe Navigation and Elvis Operator in Groovy}}, - howpublished = {\url{http://docs.codehaus.org/display/GROOVY/Operators#Operators-ElvisOperator(?:)}}, -} -@misc{offsiderule, - title = {{Off-side rule syntax}}, - howpublished = {\url{http://en.wikipedia.org/wiki/Off-side_rule}} -} - -@inproceedings{sugarj, - author = {Erdweg, Sebastian and Rendel, Tillmann and K\"{a}stner, Christian and Ostermann, Klaus}, - title = {SugarJ: Library-based Syntactic Language Extensibility}, - booktitle = {Proceedings of the 2011 ACM International Conference on Object Oriented Programming Systems Languages and Applications}, - series = {OOPSLA '11}, - year = {2011}, - isbn = {978-1-4503-0940-0}, - location = {Portland, Oregon, USA}, - pages = {391--406}, - numpages = {16}, - url = {http://doi.acm.org/10.1145/2048066.2048099}, - doi = {10.1145/2048066.2048099}, - acmid = {2048099}, - publisher = {ACM}, - address = {New York, NY, USA}, - keywords = {DSL embedding, SugarJ, language composition, language extensibility, libraries, syntactic sugar}, -} diff --git a/doc/ijpla.pdf b/doc/ijpla.pdf deleted file mode 100644 index 6a1f0cc..0000000 Binary files a/doc/ijpla.pdf and /dev/null differ diff --git a/doc/ijpla.tex b/doc/ijpla.tex deleted file mode 100644 index 1889973..0000000 --- a/doc/ijpla.tex +++ /dev/null @@ -1,444 +0,0 @@ -% use xelatex to build. -\documentclass{aircc} -\usepackage{mathpartir} -\usepackage{hyperref} -\usepackage{listings} -\lstset{language=Java} - -% xelatex: -%\usepackage{fontspec} -%\setmainfont[Ligatures=TeX]{Times New Roman} -%\setsansfont{Garamond} -%\setmonofont{Courier New} - -\begin{document} - -\title{ -%{\sffamily -%J\fontsize{17}{17}\textbf{AVA MODULAR EXTENSION FOR \\ OPERATOR OVERLOADING -Java Modular Extension for \\ -Operator Overloading -%}} -} - -\author{Artem Melentyev} -\affiliation{Ural Federal University \\ \email{\url{http://artem.melentyev.me}}} - -\maketitle - -\begin{abstract} -The paper introduces a modular extension (plugin) for Java language compilers and Integrated Development Environments (IDE) -which adds operator overloading feature to Java language while preserving backward compatibility. - -The extension use the idea of library-based language extensibility similar to SugarJ\cite{sugarj}. -But unlike most language extensions, it works directly inside the compiler and does not have any external preprocessors. -This gives much faster compilation, better language compatibility and -support of native developer tools (IDE, build tools). - -The extension plugs into javac and Eclipse Java compilers -as well as in all tools whose use the compilers such as IDEs (Netbeans, Eclipse, IntelliJ IDEA), build tools (ant, maven, gradle), etc. -No compiler, IDE, build tools modification needed. Just add a jar library to classpath and/or install a plugin to your IDE. - -The paper also discuss on how to build such Java compiler extensions. - -The extension source code is open on -\url{http://amelentev.github.io/java-oo/} -\end{abstract} - -\begin{keywords} -Java compilers, operator overloading, language extension, compiler plugin, Integrated Development Environment -\end{keywords} - -\section{Introduction} -Operators are important part of a programming language. -They greatly improve readability. - -For example the code -$$if~(a { - TA add(TA o); // a + b - TA negate(); // -a - TA multiply(TM o); // a*b -} -\end{lstlisting} -Next, the $comp$ function: -\begin{lstlisting} -> -TA comp(TA a, TA b, TM c) { - return -a + b*c; -} -\end{lstlisting} -First line tells to compiler that generics type \textit{TA} should implement methods from \textit{MyNumbers} interface which contain methods for our operators. And compiler will use these methods instead of operators. -Let's try to use our generalized function with geometric 2d point: -\begin{lstlisting} -class Point implements MyNumber { - double x, y; - public Point(double x, double y) { - this.x = x; this.y = y; - } - public Point add(Point o) { - return new Point(x+o.x, y+o.y); - } - public Point multiply(Double o) { - return new Point(x*o, y*o); - } - public Point negate() { - return new Point(-x, -y); - } - public String toString() { - return "(" + x + "," + y + ")"; - } -} -\end{lstlisting} -And $comp(new~Point(1.0,2.0), new~Point(3.0,4.0), 5.0)$ will return point (14.0, 18.0) as expected. -As you see operator overloading greatly improve code reuse and readability. - -\subsection{Criticisms of operator overloading} -Operator overloading has often been criticized because it allows programmers to give operators completely different semantics depending on the types of their operands. -Java language historically doesn't support operator overloading mostly because of this reason. -The common reply to this criticism is that the same argument applies to function (method) overloading as well. -Furthermore, even without overloading, a programmer can define a method to do something totally different from what would be expected from its name. - -Also some people say that adding operator overloading to Java language will -complicate Java compiler. -The paper presents an implementation of Operator Overloading via small compiler plugin. -The patch for javac compiler has 179 modified lines, for Eclipse Java compiler - 193. - -Because operator overloading allows the original programmer to change the usual semantics of an operator and to catch any subsequent programmers by surprise, it is usually considered good practice to use operator overloading with care (the same for method overloading). - -\subsection{Modularity} -Adding operator overloading directly to Java compiler is only one problem -(See subprojects: forked JDK\cite{javac-oo} and Eclipse JDT\cite{eclipse.jdt-oo}). -The resulting compiler need to be installed as replacement of standard javac/ecj, updated with new versions of JDK/JDT, etc. -This complicates using of the extension, especially in big teams. - -What if adding a language feature can be as easy as adding a library to a project? -The extension uses this idea of library-based language extensions, like in SugarJ\cite{sugarj}. -The Java language \textit{changes} when you compile your project with this library. - -This approach has following advantages: -\begin{enumerate} - \item Easy install and use \\ - No need to install modified compiler. Just add a library to your project. - \item Independent of compiler changes. \\ - You do not need to modify compiler again if new version was released. - If there are no major changes in the compiler then the plugin will work with new version just fine. -\end{enumerate} -Nonetheless, there is one disadvantage. It is harder to write such modular extensions. -There are less ways to affect the compiler from plugin. - -\section{Type system of Operator Overloading \label{typesystem}} - -Our extension is semantic. It changes type system and code generation. -Note it is impossible to implement operator overloading in Java solely on syntax level. -We need to know operands types and it is semantic information. - -Let's look at type system changes. -The extension adds to Java type system the following type inference rules: - -\subsection{Binary operators} -\begin{mathpar} - \inferrule{e1.add(e2):T}{e1 + e2 : T} \and - \inferrule{e1.subtract(e2):T}{e1 - e2 : T} \and - \inferrule{e1.multiply(e2):T}{e1 * e2 : T} \and - \inferrule{e1.divide(e2):T}{e1 / e2 : T} \and - \inferrule{e1.remainder(e2):T}{e1 \% e2 : T} \and - \inferrule{e1.and(e2):T}{e1 \& e2 : T} \and - \inferrule{e1.or(e2):T}{e1 | e2 : T} \and - \inferrule{e1.xor(e2):T}{e1 \wedge e2 : T} \and - \inferrule{e1.shiftLeft(e2):T}{e1 << e2 : T} \and - \inferrule{e1.shiftRight(e2):T}{e1 >> e2 : T} -\end{mathpar} -Here and below $e,e1,e2$ \textemdash~arbitrary expressions in Java language. -$expression : T$ means expression $expression$ has type $T$. -$e1.methodname(e2) : T$ means type (class) of expression $e1$ has a method $methodname$ what can accept $e2$ as argument, -and the method return type is $T$. - -Binary operator overloading allows to write, for example, $a + b$, -where class of $a$, has a method $add$ which can accept $b$ as argument. -Thus, $a$ and $b$ can be of type $BigInteger$ and so expression $a+b$ will be equivalent to $a.add(b)$. - -The extension doesn't change operator precedence. So $a+b*c$ will be transformed to $a.add(b.multiply(c))$ (but not $a.add(b).multiply(c)$) according to Java operator precedence rules. - -\subsection{Unary operators} -\begin{mathpar} - \inferrule{e.negate():T}{-e : T} \and \inferrule{e.not():T}{\sim e : T} -\end{mathpar} -allows to write $-a$ instead of $a.negate()$ and $\sim e$ instead of $e.not()$. - -\subsection{Comparison operators} -\begin{mathpar} - \inferrule{e1.compareTo(e2):int}{e1 < e2 : boolean \\ e1 <= e2: boolean \\ e1 > e2: boolean \\ e1 >= e2: boolean} -\end{mathpar} -allows to write $a$, $>=$. - -\subsection{Index operators} -\begin{mathpar} - \inferrule{e1.get(e2):T}{e1[e2] : T} \and - \inferrule{e1.set(e2, e3):T ~ or ~ e1.put(e2, e3):T}{e1[e2] = e3 : T} -\end{mathpar} -allows to write $list[i]$ instead of $list.get(i)$ -and $list[i] = v$ instead of $list.set(i, v)$. -Thus the syntax of accessing to Java collections ($java.util.Collection, List, Map$,etc) -become the same as the syntax of accessing to arrays. - -\subsection{Assignment operator} -\begin{mathpar} - \inferrule{e1:T1 \and T2.valueOf(T1):T2 \and var:T2}{var = e1 :T2} -\end{mathpar} -allows transforming incompatible types in assignment via static method $valueOf$. -For example $BigInteger~a = 1$ is equivalent to $BigInteger~a = BigInteger.valueOf(1)$. -This is weak version of Scala \textit{implicit conversion}\cite{itc} ($implicit$ keyword) which works only on assignments and variable declarations with initialization. -Because of this restriction assignment operator overloading doesn't cause any ambiguity (unlike in Scala). - -New rules added with lowest priority, so backward compatibility is provided. -Thus any correct Java program remains correct on Java with the extension. -And some incorrect Java programs (with operator overloading) become correct on Java with the extension. - -\section{Code generation} - -New operator expressions are transformed (desugar) to corresponded method calls from section~\ref{typesystem}. -Comparison operator transformed to $compareTo$ method call and compare the result to 0 (e.g. $e1 <= e2$ is transformed to $e1.compareTo(e2)<=0$). Assignment operator wraps right side of the assignment to static $valueOf$ method. -So it can be considered as syntactic sugar. -But strictly speaking, it is not a syntactical extension because it doesn't change the Java syntax. - -\section{Implementation} - -The extension consist of 3 parts: -\begin{enumerate} -\item \textit{javac-oo-plugin} for javac compiler, Netbeans IDE and build tools (ant, maven, gradle, etc) -\item \textit{eclipse-oo-plugin} for Eclipse IDE -\item \textit{idea-oo-plugin} for IntelliJ IDEA IDE -\end{enumerate} - -\subsection{Javac\label{javac}} -Development of javac extension began with experimenting on JDK 7 langtools repository\cite{javac-oo}. -An overview of javac compilation process can be found in \cite{HackerGuideJavac}. -Javac compiler has quite modular architecture and there is a module for every compilation stage in $com.sun.tools.javac.comp$ package. -The stages in order of execution are: \textit{Parse, Enter, Process, Attr, Flow, TransTypes, Lower, Generate}. -All stages except $Parse$ implemented as visitor design patterns, so it is easy to focus on something specific in abstract syntax trees (AST). -Type inference is performed in $Attr$ stage. -We cannot do operator overloading before $Attr$ stage because we need type information. -And we cannot do it after $Attr$ stage because $Attr$ marks all overloaded operators as errors and write error messages to compiler log. -So we need to resolve types of overloaded operators inside $Attr$ stage by modifying it. -Also $Attr$ stage uses $Resolve$ submodule to perform method and operator resolving, so we need to modify it too. -%TODO Resolve encode result in Symbol. -Next we need to desugar our constructs somewhere. -$TransTypes$ and $Lower$ are translator stages. This means they can rewrite AST. -$TransTypes$ stage translates Generic Java to conventional Java (without Generics). -$Lower$ stage desugar some high level Java constructs to low level constructs. -We need to desugar overloaded operators as soon as possible (otherwise we can miss some compiler stages), -so we modified $TransTypes$ stage for this. -For full list of changes see difference between ``default'' and ``oo'' branches of javac-oo repository\cite{javac-oo}. - -When desired functionality was achieved we began to prepare a plugin for javac while looking at difference between javac and extended javac. -Instead of modifying compiler stages we extend them by creating subclasses and override specific methods. -But original compiler stages need to be replaced by extended ones somehow. - -JSR269: Pluggable annotation processing API\cite{jsr269} allows creating compiler plugins for custom annotation processing. -We do not have any annotations but we use JSR269 mechanisms to gain control during annotation processing stage \textemdash~$Process$. -Once we are in control we use $TaskListener$ of the compiler to wait until $Attr$ stage begins. -And when $Attr$ begins, we replace $Attr$, $Resolve$ and $TransTypes$ modules to our extended versions. -Not all operations described here are public, so we have to use reflection to access private members. - -However, there is one interesting problem\cite{soPackagePrivate} here. -The extension needs to override a package-private method in the compiler. -Java Language Specification\cite{jls} allows access to package private fields and methods only within the same java package. -But a little known fact it also should be within the same \textit{classloader} by Java Virtual Machine specification\cite{jvmspecPP}. -Clearly the \texttt{javac-oo-plugin.jar} (the extension) and \texttt{tools.jar} (javac compiler) have different classloaders. -As a way around this problem, the extension just injects a part of self into the compiler's classloader at run time\cite{soPackagePrivate}. - -As a result we got a plain jar library, \texttt{javac-oo-plugin.jar}. -The library uses JSR269 to gain control from the compiler and then replaces some compiler modules to extended ones. -To use the javac extension just add it to classpath (\texttt{javac -cp javac-oo-plugin.jar *.java}) and enable annotation processing (on by default). - -Due to changes in JDK8, there is separate fork (\texttt{javac8-oo} repository) and separate plugin for JDK8 (\texttt{javac8-oo-plugin}). - -%Size of current version \texttt{javac-oo-plugin-0.4.jar} library = 19 Kilobytes. - -\subsection{Netbeans IDE} - -Netbeans IDE uses slightly modified javac compiler, -so we performed some minor modification to support both Netbeans and javac in one \texttt{javac-oo-plugin.jar} library. -%After these modification the extension works fine in Netbeans. %java editor and project building. -To use the extension in Netbeans IDE you just need to activate ``Annotation processing in Editor'' in project settings. - -\subsection{Eclipse Java Compiler, Eclipse Java IDE} - -Eclipse Java Compiler (ecj) is completely different Java compiler. -It used by Eclipse Java IDE (Eclipse Java Developer Tools) in Java editor and project compiling. -One notable difference is that the Eclipse compiler lets you run code that didn't actually properly compile. -If the block of code with the error is never ran, your program will run fine. -Otherwise, it will throw an exception indicating that you tried to run code that doesn't compile. -Another difference is that the Eclipse compiler allows for incremental builds, that is, only changed and affected files compiles. - -The extension development began the same way as in javac case \textemdash~by forking Eclipse JDT\cite{eclipse.jdt-oo}. -Architecture of ecj is very different from javac. Ecj is not modular. -Implementation of most ecj compilation stages is contained inside classes of abstract syntax tree (AST). -Type resolving performed in $ASTClass\#resolveType(..)$ methods. -Code generation in $ASTClass\#generateCode(..)$. -We are interested in $ArrayReference$, $Assignment$, $BinaryExpression$, $UnaryExpression$ AST classes. - -There is no visitor design pattern and there are no translators (AST rewriters). -This complicates extension much. -We can't just replace overloaded operators with method calls because of no translators. -We need to save desugared expressions and proxy many calls from nodes to these expressions. - -Another problem is we can't call $\#resolveType$ twice on the same AST node. -The algorithm of ecj type resolution assumes every node is resolved only once. -Because of that there is no cache in $\#resolveType$ method. -And if we call $resolveType$ again we will get strange name resolution error from $Scope$ due to name duplications. -Because of this problem we can't just check overloaded operators at top of $resolveType$ method -and if it is not our case then just continue below, like in javac extension. -We need to do it just before error printing. - -More problems arise when we are trying to create a plugin from the extension. -We can't extend AST classes because they are hardcoded and there are no AST factory. -We need to modify AST classes directly. To do it more powerful tools can be used. - -Previous version of the extension\cite{lombok-oo} uses lombok.patcher\cite{lombok.patcher} library. -It allows modifying ecj classes at runtime and reloading it. - -Current version uses AspectJ load-time weaving\cite{AJLTW}. -The patch defined as AspectJ aspects loaded at start of Eclipse IDE via Equanox weaving\cite{EquanoxW}. -AspectJ is an Aspect Oriented language based on Java. -It has much more features than specialized lombok.patcher library. -Aspect Oriented Programming fit nicely for creating plugins in non-modular environment. -It can inject code into quite specific points, like ``for all subclasses of some class, inside specific method, just before call to another specific method, do something''. - -As a result we got the plugin for Eclipse IDE which uses Equanox Weaving and AspectJ for ecj compiler modification. -You just need to install the eclipse plugin to use Operator Overloading in Eclipse IDE. - -\subsection{IntelliJ IDEA IDE \label{idea}} - -IntelliJ IDEA uses javac or ecj for compilation. The extension support only javac for now. -Thus you need to use javac plugin (see subsection \ref{javac}) for real compilation. - -But IDEA also use own complex java frontend (parser and analyzer) for Java editor. -The problem is to relax this frontend to allow operator overloading. So we need to extend type resolution only. - -Like in ecj, type resolution in IDEA performed in AST nodes. -But unlike ecj, IDEA has some private AST factory $JavaElementType$. -The extension replace in the factory some AST classes to extended ones with extra type inference. - -Also IDEA has error highlighting module $HighlightVisitor$ where similar type resolution performed again. -So the extension replaces it to extended module to ignore places with correct operator overloading. - -The IntelliJ IDEA extension ``Java Operator Overloading support'' is located in official IDEA repository. - -% TODO: doesn't have easily method resolution functionality. - -%Size: 18Kb. - -\section{Related works} - -Most attempts of language extending use preprocessor from extended to plain language. -But this extension works directly in the compiler, -allowing much faster compilation, better language compatibility, -support of native developer tools (IDE, build tools, etc). - -\begin{itemize} -\item jop\cite{jop} -is a preprocessor for a small subset of Java (Featherweight Java) language with operator overloading to plain Java. \\ -Presented extension work for whole Java language and doesn't require preprocessing. -Also no IDE, no build tools support. -\item SugarJ\cite{sugarj} -is a Java 1.5 extension for library-based language extensibility. -It allows changing language syntax at compile time by union syntax extensions into one grammar. -New constructs should be (finally) desugared to plain java. -Note it is impossible to implement operator overloading as SugarJ extension because it doesn't provide Java type system information. -SugarJ is built on top of Spoofax Language Workbench (SDF, Stratego, Eclipse IDE). -It uses SDF parser which is powerful but quite slow ($O(n^3)$). -It uses Eclipse Java compiler for actual compiling to bytecode. So it is a preprocessor to Java. -Works only in Eclipse based IDE (limited support, no debugging). -\item projectlombok.org uses similar ideas of compiler plugin for different needs. -Mainly to remove Java verbosity: -generate getters, setters, toString, equals, hashCode automatically on compile time, -type inference (val a = 1), and others. -First version of this operator overloading plugin was lombok based\cite{lombok-oo}. -\item juast\cite{juast} uses similar compiler plugin to do extra verification/bug finding. -\item javac in JDK8 has some compiler plugin support via $-Xplugin$ option\cite{Xplugin}. -Presented extension doesn't use it. It works on both JDK7 and JDK8 via JSR269. -\end{itemize} - -\section{Conclusion} -The paper presented a Java modular extension (plugin) for -Operator Overloading support. -The extension is useful for - defining and using own operators on user defined classes - as well as using various libraries (algebra, physics, geometry, date/time, finance) - with convenient mathematical syntax - (e.g. ``$a + b$'' instead of ``$a.add(b)$'' for $java.math.BigInteger$ and $BigDecimal$). -The extension improve readability by allowing to write formulas in convenient mathematical syntax -instead of method calls and improve code reuse by reducing difference between primitive and reference types. - -The extension works with: -\begin{itemize} -\item javac 7 and 8 compiler, Netbeans IDE and build tools (ant, maven, gradle, etc.) -\item Eclipse Java IDE -\item Intellij IDEA IDE -\end{itemize} -The extension source code is open and located on \\ -\url{http://amelentev.github.io/java-oo/} - -\section{Future works} -Using such ideas of compiler plugins we can add to Java language some major features like: -\begin{itemize} -\item \textit{Static extension methods} like in C\#. -\item \textit{Smart casts} like in Kotlin\cite{smartcasts} -\item \textit{Safe navigation}(?.) and \textit{elvis}(?:) operators like in Groovy\cite{safenav} -\item \textit{Off-side rule}\cite{offsiderule} syntax like in Python -\item And many more -\end{itemize} - -\bibliographystyle{ieeetr} -\bibliography{ijpla} - -\end{document} diff --git a/doc/mathpartir.sty b/doc/mathpartir.sty deleted file mode 100644 index a3ac05c..0000000 --- a/doc/mathpartir.sty +++ /dev/null @@ -1,456 +0,0 @@ -% Mathpartir --- Math Paragraph for Typesetting Inference Rules -% -% Copyright (C) 2001, 2002, 2003, 2004, 2005 Didier Rmy -% -% Author : Didier Remy -% Version : 1.2.1 -% Bug Reports : to author -% Web Site : http://pauillac.inria.fr/~remy/latex/ -% -% Mathpartir is free software; you can redistribute it and/or modify -% it under the terms of the GNU General Public License as published by -% the Free Software Foundation; either version 2, or (at your option) -% any later version. -% -% Mathpartir is distributed in the hope that it will be useful, -% but WITHOUT ANY WARRANTY; without even the implied warranty of -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -% GNU General Public License for more details -% (http://pauillac.inria.fr/~remy/license/GPL). -% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% File mathpartir.sty (LaTeX macros) -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{mathpartir} - [2005/12/20 version 1.2.0 Math Paragraph for Typesetting Inference Rules] - -%% - -%% Identification -%% Preliminary declarations - -\RequirePackage {keyval} - -%% Options -%% More declarations - -%% PART I: Typesetting maths in paragraphe mode - -%% \newdimen \mpr@tmpdim -%% Dimens are a precious ressource. Uses seems to be local. -\let \mpr@tmpdim \@tempdima - -% To ensure hevea \hva compatibility, \hva should expands to nothing -% in mathpar or in inferrule -\let \mpr@hva \empty - -%% normal paragraph parametters, should rather be taken dynamically -\def \mpr@savepar {% - \edef \MathparNormalpar - {\noexpand \lineskiplimit \the\lineskiplimit - \noexpand \lineskip \the\lineskip}% - } - -\def \mpr@rulelineskip {\lineskiplimit=0.3em\lineskip=0.2em plus 0.1em} -\def \mpr@lesslineskip {\lineskiplimit=0.6em\lineskip=0.5em plus 0.2em} -\def \mpr@lineskip {\lineskiplimit=1.2em\lineskip=1.2em plus 0.2em} -\let \MathparLineskip \mpr@lineskip -\def \mpr@paroptions {\MathparLineskip} -\let \mpr@prebindings \relax - -\newskip \mpr@andskip \mpr@andskip 2em plus 0.5fil minus 0.5em - -\def \mpr@goodbreakand - {\hskip -\mpr@andskip \penalty -1000\hskip \mpr@andskip} -\def \mpr@and {\hskip \mpr@andskip} -\def \mpr@andcr {\penalty 50\mpr@and} -\def \mpr@cr {\penalty -10000\mpr@and} -\def \mpr@eqno #1{\mpr@andcr #1\hskip 0em plus -1fil \penalty 10} - -\def \mpr@bindings {% - \let \and \mpr@andcr - \let \par \mpr@andcr - \let \\\mpr@cr - \let \eqno \mpr@eqno - \let \hva \mpr@hva - } -\let \MathparBindings \mpr@bindings - -% \@ifundefined {ignorespacesafterend} -% {\def \ignorespacesafterend {\aftergroup \ignorespaces} - -\newenvironment{mathpar}[1][] - {$$\mpr@savepar \parskip 0em \hsize \linewidth \centering - \vbox \bgroup \mpr@prebindings \mpr@paroptions #1\ifmmode $\else - \noindent $\displaystyle\fi - \MathparBindings} - {\unskip \ifmmode $\fi\egroup $$\ignorespacesafterend} - -\newenvironment{mathparpagebreakable}[1][] - {\begingroup - \par - \mpr@savepar \parskip 0em \hsize \linewidth \centering - \mpr@prebindings \mpr@paroptions #1% - \vskip \abovedisplayskip \vskip -\lineskip% - \ifmmode \else $\displaystyle\fi - \MathparBindings - } - {\unskip - \ifmmode $\fi \par\endgroup - \vskip \belowdisplayskip - \noindent - \ignorespacesafterend} - -% \def \math@mathpar #1{\setbox0 \hbox {$\displaystyle #1$}\ifnum -% \wd0 < \hsize $$\box0$$\else \bmathpar #1\emathpar \fi} - -%%% HOV BOXES - -\def \mathvbox@ #1{\hbox \bgroup \mpr@normallineskip - \vbox \bgroup \tabskip 0em \let \\ \cr - \halign \bgroup \hfil $##$\hfil\cr #1\crcr \egroup \egroup - \egroup} - -\def \mathhvbox@ #1{\setbox0 \hbox {\let \\\qquad $#1$}\ifnum \wd0 < \hsize - \box0\else \mathvbox {#1}\fi} - - -%% Part II -- operations on lists - -\newtoks \mpr@lista -\newtoks \mpr@listb - -\long \def\mpr@cons #1\mpr@to#2{\mpr@lista {\\{#1}}\mpr@listb \expandafter -{#2}\edef #2{\the \mpr@lista \the \mpr@listb}} - -\long \def\mpr@snoc #1\mpr@to#2{\mpr@lista {\\{#1}}\mpr@listb \expandafter -{#2}\edef #2{\the \mpr@listb\the\mpr@lista}} - -\long \def \mpr@concat#1=#2\mpr@to#3{\mpr@lista \expandafter {#2}\mpr@listb -\expandafter {#3}\edef #1{\the \mpr@listb\the\mpr@lista}} - -\def \mpr@head #1\mpr@to #2{\expandafter \mpr@head@ #1\mpr@head@ #1#2} -\long \def \mpr@head@ #1#2\mpr@head@ #3#4{\def #4{#1}\def#3{#2}} - -\def \mpr@flatten #1\mpr@to #2{\expandafter \mpr@flatten@ #1\mpr@flatten@ #1#2} -\long \def \mpr@flatten@ \\#1\\#2\mpr@flatten@ #3#4{\def #4{#1}\def #3{\\#2}} - -\def \mpr@makelist #1\mpr@to #2{\def \mpr@all {#1}% - \mpr@lista {\\}\mpr@listb \expandafter {\mpr@all}\edef \mpr@all {\the - \mpr@lista \the \mpr@listb \the \mpr@lista}\let #2\empty - \def \mpr@stripof ##1##2\mpr@stripend{\def \mpr@stripped{##2}}\loop - \mpr@flatten \mpr@all \mpr@to \mpr@one - \expandafter \mpr@snoc \mpr@one \mpr@to #2\expandafter \mpr@stripof - \mpr@all \mpr@stripend - \ifx \mpr@stripped \empty \let \mpr@isempty 0\else \let \mpr@isempty 1\fi - \ifx 1\mpr@isempty - \repeat -} - -\def \mpr@rev #1\mpr@to #2{\let \mpr@tmp \empty - \def \\##1{\mpr@cons ##1\mpr@to \mpr@tmp}#1\let #2\mpr@tmp} - -%% Part III -- Type inference rules - -\newif \if@premisse -\newbox \mpr@hlist -\newbox \mpr@vlist -\newif \ifmpr@center \mpr@centertrue -\def \mpr@htovlist {% - \setbox \mpr@hlist - \hbox {\strut - \ifmpr@center \hskip -0.5\wd\mpr@hlist\fi - \unhbox \mpr@hlist}% - \setbox \mpr@vlist - \vbox {\if@premisse \box \mpr@hlist \unvbox \mpr@vlist - \else \unvbox \mpr@vlist \box \mpr@hlist - \fi}% -} -% OLD version -% \def \mpr@htovlist {% -% \setbox \mpr@hlist -% \hbox {\strut \hskip -0.5\wd\mpr@hlist \unhbox \mpr@hlist}% -% \setbox \mpr@vlist -% \vbox {\if@premisse \box \mpr@hlist \unvbox \mpr@vlist -% \else \unvbox \mpr@vlist \box \mpr@hlist -% \fi}% -% } - -\def \mpr@item #1{$\displaystyle #1$} -\def \mpr@sep{2em} -\def \mpr@blank { } -\def \mpr@hovbox #1#2{\hbox - \bgroup - \ifx #1T\@premissetrue - \else \ifx #1B\@premissefalse - \else - \PackageError{mathpartir} - {Premisse orientation should either be T or B} - {Fatal error in Package}% - \fi \fi - \def \@test {#2}\ifx \@test \mpr@blank\else - \setbox \mpr@hlist \hbox {}% - \setbox \mpr@vlist \vbox {}% - \if@premisse \let \snoc \mpr@cons \else \let \snoc \mpr@snoc \fi - \let \@hvlist \empty \let \@rev \empty - \mpr@tmpdim 0em - \expandafter \mpr@makelist #2\mpr@to \mpr@flat - \if@premisse \mpr@rev \mpr@flat \mpr@to \@rev \else \let \@rev \mpr@flat \fi - \def \\##1{% - \def \@test {##1}\ifx \@test \empty - \mpr@htovlist - \mpr@tmpdim 0em %%% last bug fix not extensively checked - \else - \setbox0 \hbox{\mpr@item {##1}}\relax - \advance \mpr@tmpdim by \wd0 - %\mpr@tmpdim 1.02\mpr@tmpdim - \ifnum \mpr@tmpdim < \hsize - \ifnum \wd\mpr@hlist > 0 - \if@premisse - \setbox \mpr@hlist - \hbox {\unhbox0 \hskip \mpr@sep \unhbox \mpr@hlist}% - \else - \setbox \mpr@hlist - \hbox {\unhbox \mpr@hlist \hskip \mpr@sep \unhbox0}% - \fi - \else - \setbox \mpr@hlist \hbox {\unhbox0}% - \fi - \else - \ifnum \wd \mpr@hlist > 0 - \mpr@htovlist - \mpr@tmpdim \wd0 - \fi - \setbox \mpr@hlist \hbox {\unhbox0}% - \fi - \advance \mpr@tmpdim by \mpr@sep - \fi - }% - \@rev - \mpr@htovlist - \ifmpr@center \hskip \wd\mpr@vlist\fi \box \mpr@vlist - \fi - \egroup -} - -%%% INFERENCE RULES - -\@ifundefined{@@over}{% - \let\@@over\over % fallback if amsmath is not loaded - \let\@@overwithdelims\overwithdelims - \let\@@atop\atop \let\@@atopwithdelims\atopwithdelims - \let\@@above\above \let\@@abovewithdelims\abovewithdelims - }{} - -%% The default - -\def \mpr@@fraction #1#2{\hbox {\advance \hsize by -0.5em - $\displaystyle {#1\mpr@over #2}$}} -\def \mpr@@nofraction #1#2{\hbox {\advance \hsize by -0.5em - $\displaystyle {#1\@@atop #2}$}} - -\let \mpr@fraction \mpr@@fraction - -%% A generic solution to arrow - -\def \mpr@@fractionaboveskip {0ex} -\def \mpr@@fractionbelowskip {0.22ex} - -\def \mpr@make@fraction #1#2#3#4#5{\hbox {% - \def \mpr@tail{#1}% - \def \mpr@body{#2}% - \def \mpr@head{#3}% - \setbox1=\hbox{$#4$}\setbox2=\hbox{$#5$}% - \setbox3=\hbox{$\mkern -3mu\mpr@body\mkern -3mu$}% - \dimen0\ht3\advance\dimen0 by \dp3\relax - \dimen0 0.5\dimen0\relax - \advance \dimen0 by \mpr@@fractionaboveskip - \setbox1=\hbox {\raise \dimen0 \box1}\relax - \dimen0 -\dimen0\advance \dimen0 \mpr@@fractionaboveskip\dimen0 -\dimen0 - \advance \dimen0 by \mpr@@fractionbelowskip - \setbox2=\hbox {\lower \dimen0 \box2}\relax - \setbox0=\hbox {$\displaystyle {\box1 \atop \box2}$}% - \dimen0=\wd0\box0 - \box0 \hskip -\dimen0\relax - \hbox to \dimen0 {$%\color{blue} - \mathrel{\mpr@tail}\joinrel - \xleaders\hbox{\copy3}\hfil\joinrel\mathrel{\mpr@head}% - $}}} - -%% Old stuff should be removed in next version -\def \mpr@@nothing #1#2 - {$\lower 0.01pt \mpr@@nofraction {#1}{#2}$} -\def \mpr@@reduce #1#2{\hbox - {$\lower 0.01pt \mpr@@fraction {#1}{#2}\mkern -15mu\rightarrow$}} -\def \mpr@@rewrite #1#2#3{\hbox - {$\lower 0.01pt \mpr@@fraction {#2}{#3}\mkern -8mu#1$}} -\def \mpr@infercenter #1{\vcenter {\mpr@hovbox{T}{#1}}} - -\def \mpr@empty {} -\def \mpr@inferrule - {\bgroup - \ifnum \linewidth<\hsize \hsize \linewidth\fi - \mpr@rulelineskip - \let \and \qquad - \let \hva \mpr@hva - \let \@rulename \mpr@empty - \let \@rule@options \mpr@empty - \let \mpr@over \@@over - \mpr@inferrule@} -\newcommand {\mpr@inferrule@}[3][] - {\everymath={\displaystyle}% - \def \@test {#2}\ifx \empty \@test - \setbox0 \hbox {$\vcenter {\mpr@hovbox{B}{#3}}$}% - \else - \def \@test {#3}\ifx \empty \@test - \setbox0 \hbox {$\vcenter {\mpr@hovbox{T}{#2}}$}% - \else - \setbox0 \mpr@fraction {\mpr@hovbox{T}{#2}}{\mpr@hovbox{B}{#3}}% - \fi \fi - \def \@test {#1}\ifx \@test\empty \box0 - \else \vbox -%%% Suggestion de Francois pour les etiquettes longues -%%% {\hbox to \wd0 {\RefTirName {#1}\hfil}\box0}\fi - {\hbox {\RefTirName {#1}}\box0}\fi - \egroup} - -\def \mpr@vdotfil #1{\vbox to #1{\leaders \hbox{$\cdot$} \vfil}} - -% They are two forms -% \inferrule [label]{[premisses}{conclusions} -% or -% \inferrule* [options]{[premisses}{conclusions} -% -% Premisses and conclusions are lists of elements separated by \\ -% Each \\ produces a break, attempting horizontal breaks if possible, -% and vertical breaks if needed. -% -% An empty element obtained by \\\\ produces a vertical break in all cases. -% -% The former rule is aligned on the fraction bar. -% The optional label appears on top of the rule -% The second form to be used in a derivation tree is aligned on the last -% line of its conclusion -% -% The second form can be parameterized, using the key=val interface. The -% folloiwng keys are recognized: -% -% width set the width of the rule to val -% narrower set the width of the rule to val\hsize -% before execute val at the beginning/left -% lab put a label [Val] on top of the rule -% lskip add negative skip on the right -% left put a left label [Val] -% Left put a left label [Val], ignoring its width -% right put a right label [Val] -% Right put a right label [Val], ignoring its width -% leftskip skip negative space on the left-hand side -% rightskip skip negative space on the right-hand side -% vdots lift the rule by val and fill vertical space with dots -% after execute val at the end/right -% -% Note that most options must come in this order to avoid strange -% typesetting (in particular leftskip must preceed left and Left and -% rightskip must follow Right or right; vdots must come last -% or be only followed by rightskip. -% - -%% Keys that make sence in all kinds of rules -\def \mprset #1{\setkeys{mprset}{#1}} -\define@key {mprset}{andskip}[]{\mpr@andskip=#1} -\define@key {mprset}{lineskip}[]{\lineskip=#1} -\define@key {mprset}{lessskip}[]{\lineskip=0.5\lineskip} -\define@key {mprset}{flushleft}[]{\mpr@centerfalse} -\define@key {mprset}{center}[]{\mpr@centertrue} -\define@key {mprset}{rewrite}[]{\let \mpr@fraction \mpr@@rewrite} -\define@key {mprset}{atop}[]{\let \mpr@fraction \mpr@@nofraction} -\define@key {mprset}{myfraction}[]{\let \mpr@fraction #1} -\define@key {mprset}{fraction}[]{\def \mpr@fraction {\mpr@make@fraction #1}} -\define@key {mprset}{sep}{\def\mpr@sep{#1}} -\define@key {mprset}{fractionaboveskip}{\def\mpr@@fractionaboveskip{#1}} -\define@key {mprset}{fractionbelowskip}{\def\mpr@@fractionbelowskip{#1}} - -\newbox \mpr@right -\define@key {mpr}{flushleft}[]{\mpr@centerfalse} -\define@key {mpr}{center}[]{\mpr@centertrue} -\define@key {mpr}{rewrite}[]{\let \mpr@fraction \mpr@@rewrite} -\define@key {mpr}{myfraction}[]{\let \mpr@fraction #1} -\define@key {mpr}{fraction}[]{\def \mpr@fraction {\mpr@make@fraction #1}} -\define@key {mpr}{left}{\setbox0 \hbox {$\TirName {#1}\;$}\relax - \advance \hsize by -\wd0\box0} -\define@key {mpr}{width}{\hsize #1} -\define@key {mpr}{sep}{\def\mpr@sep{#1}} -\define@key {mpr}{before}{#1} -\define@key {mpr}{lab}{\let \RefTirName \TirName \def \mpr@rulename {#1}} -\define@key {mpr}{Lab}{\let \RefTirName \TirName \def \mpr@rulename {#1}} -\define@key {mpr}{narrower}{\hsize #1\hsize} -\define@key {mpr}{leftskip}{\hskip -#1} -\define@key {mpr}{reduce}[]{\let \mpr@fraction \mpr@@reduce} -\define@key {mpr}{rightskip} - {\setbox \mpr@right \hbox {\unhbox \mpr@right \hskip -#1}} -\define@key {mpr}{LEFT}{\setbox0 \hbox {$#1$}\relax - \advance \hsize by -\wd0\box0} -\define@key {mpr}{left}{\setbox0 \hbox {$\TirName {#1}\;$}\relax - \advance \hsize by -\wd0\box0} -\define@key {mpr}{Left}{\llap{$\TirName {#1}\;$}} -\define@key {mpr}{right} - {\setbox0 \hbox {$\;\TirName {#1}$}\relax \advance \hsize by -\wd0 - \setbox \mpr@right \hbox {\unhbox \mpr@right \unhbox0}} -\define@key {mpr}{RIGHT} - {\setbox0 \hbox {$#1$}\relax \advance \hsize by -\wd0 - \setbox \mpr@right \hbox {\unhbox \mpr@right \unhbox0}} -\define@key {mpr}{Right} - {\setbox \mpr@right \hbox {\unhbox \mpr@right \rlap {$\;\TirName {#1}$}}} -\define@key {mpr}{vdots}{\def \mpr@vdots {\@@atop \mpr@vdotfil{#1}}} -\define@key {mpr}{after}{\edef \mpr@after {\mpr@after #1}} - -\newcommand \mpr@inferstar@ [3][]{\setbox0 - \hbox {\let \mpr@rulename \mpr@empty \let \mpr@vdots \relax - \setbox \mpr@right \hbox{}% - $\setkeys{mpr}{#1}% - \ifx \mpr@rulename \mpr@empty \mpr@inferrule {#2}{#3}\else - \mpr@inferrule [{\mpr@rulename}]{#2}{#3}\fi - \box \mpr@right \mpr@vdots$} - \setbox1 \hbox {\strut} - \@tempdima \dp0 \advance \@tempdima by -\dp1 - \raise \@tempdima \box0} - -\def \mpr@infer {\@ifnextchar *{\mpr@inferstar}{\mpr@inferrule}} -\newcommand \mpr@err@skipargs[3][]{} -\def \mpr@inferstar*{\ifmmode - \let \@do \mpr@inferstar@ - \else - \let \@do \mpr@err@skipargs - \PackageError {mathpartir} - {\string\inferrule* can only be used in math mode}{}% - \fi \@do} - - -%%% Exports - -% Envirnonment mathpar - -\let \inferrule \mpr@infer - -% make a short name \infer is not already defined -\@ifundefined {infer}{\let \infer \mpr@infer}{} - -\def \TirNameStyle #1{\small \textsc{#1}} -\def \tir@name #1{\hbox {\small \TirNameStyle{#1}}} -\let \TirName \tir@name -\let \DefTirName \TirName -\let \RefTirName \TirName - -%%% Other Exports - -% \let \listcons \mpr@cons -% \let \listsnoc \mpr@snoc -% \let \listhead \mpr@head -% \let \listmake \mpr@makelist - - - - -\endinput diff --git a/eclipse-oo b/eclipse-oo deleted file mode 160000 index 3e03864..0000000 --- a/eclipse-oo +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3e03864f939d670ac149d5d6ed6ad1fdd0aa248e diff --git a/eclipse-oo-feature/.project b/eclipse-oo-feature/.project deleted file mode 100644 index 09ef8c6..0000000 --- a/eclipse-oo-feature/.project +++ /dev/null @@ -1,17 +0,0 @@ - - - eclipse-oo-feature - - - - - - org.eclipse.pde.FeatureBuilder - - - - - - org.eclipse.pde.FeatureNature - - diff --git a/eclipse-oo-feature/build.properties b/eclipse-oo-feature/build.properties deleted file mode 100644 index 3c54be9..0000000 --- a/eclipse-oo-feature/build.properties +++ /dev/null @@ -1,2 +0,0 @@ -bin.includes = feature.xml,\ - p2.inf diff --git a/eclipse-oo-feature/feature.xml b/eclipse-oo-feature/feature.xml deleted file mode 100644 index b47ee14..0000000 --- a/eclipse-oo-feature/feature.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - - Plugin for Java Operator Overloading support in Eclipse IDE - - - - Copyright (c) 2012 Artem Melentyev <amelentev@gmail.com>. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Eclipse Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/epl-v10.html - -Used some parts of org.eclipse.jdt.core - - - - Copyright (c) 2012 Artem Melentyev <amelentev@gmail.com>. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Eclipse Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/epl-v10.html - - - - - - - - - - - - - - - - - - - - - - - diff --git a/eclipse-oo-feature/p2.inf b/eclipse-oo-feature/p2.inf deleted file mode 100644 index e2ce355..0000000 --- a/eclipse-oo-feature/p2.inf +++ /dev/null @@ -1,28 +0,0 @@ -## this p2 installation script set org.eclipse.equinox.weaving.aspectj bundle to autostart at level 2 - -#create a requirement on the IU fragment we are creating -requires.2.namespace=org.eclipse.equinox.p2.iu -requires.2.name=configure.org.eclipse.equinox.weaving.aspectj -requires.2.range=[$version$,$version$] -requires.2.greedy=true - -#create a IU frament named configure.org.eclipse.equinox.common -units.0.id=configure.org.eclipse.equinox.weaving.aspectj -units.0.version=$version$ -units.0.provides.1.namespace=org.eclipse.equinox.p2.iu -units.0.provides.1.name=configure.org.eclipse.equinox.weaving.aspectj -units.0.provides.1.version=$version$ -units.0.instructions.install=installBundle(bundle:${artifact}); -units.0.instructions.uninstall=uninstallBundle(bundle:${artifact}); -units.0.instructions.unconfigure=setStartLevel(startLevel:-1); markStarted(started:false); -units.0.instructions.configure=setStartLevel(startLevel:2); markStarted(started:true); -units.0.hostRequirements.1.namespace=osgi.bundle -units.0.hostRequirements.1.name=org.eclipse.equinox.weaving.aspectj -units.0.hostRequirements.1.greedy=false -units.0.hostRequirements.2.namespace=org.eclipse.equinox.p2.eclipse.type -units.0.hostRequirements.2.name=bundle -units.0.hostRequirements.2.range=[1.0.0,2.0.0) -units.0.hostRequirements.2.greedy=false -units.0.requires.1.namespace=osgi.bundle -units.0.requires.1.name=org.eclipse.equinox.weaving.aspectj -units.0.requires.1.greedy=false \ No newline at end of file diff --git a/eclipse-oo-plugin/.classpath b/eclipse-oo-plugin/.classpath deleted file mode 100644 index 0013bd9..0000000 --- a/eclipse-oo-plugin/.classpath +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - diff --git a/eclipse-oo-plugin/.project b/eclipse-oo-plugin/.project deleted file mode 100644 index 5e6454c..0000000 --- a/eclipse-oo-plugin/.project +++ /dev/null @@ -1,35 +0,0 @@ - - - eclipse-oo-plugin - - - - - - org.eclipse.ajdt.core.ajbuilder - - - - - org.eclipse.pde.ManifestBuilder - - - - - org.eclipse.pde.SchemaBuilder - - - - - org.eclipse.pde.api.tools.apiAnalysisBuilder - - - - - - org.eclipse.ajdt.ui.ajnature - org.eclipse.pde.PluginNature - org.eclipse.jdt.core.javanature - org.eclipse.pde.api.tools.apiAnalysisNature - - diff --git a/eclipse-oo-plugin/.settings/org.eclipse.ajdt.core.prefs b/eclipse-oo-plugin/.settings/org.eclipse.ajdt.core.prefs deleted file mode 100644 index 099111b..0000000 --- a/eclipse-oo-plugin/.settings/org.eclipse.ajdt.core.prefs +++ /dev/null @@ -1,41 +0,0 @@ -eclipse.preferences.version=1 -org.aspectj.ajdt.core.compiler.BuildOptions.showweavemessages=false -org.aspectj.ajdt.core.compiler.lint.BrokeSerialVersionCompatibility=ignore -org.aspectj.ajdt.core.compiler.lint.CannotImplementLazyTJP=ignore -org.aspectj.ajdt.core.compiler.lint.InvalidAbsoluteTypeName=warning -org.aspectj.ajdt.core.compiler.lint.NeedSerialVersionUIDField=ignore -org.aspectj.ajdt.core.compiler.lint.NoInterfaceCtorJoinpoint=warning -org.aspectj.ajdt.core.compiler.lint.ShadowNotInStructure=ignore -org.aspectj.ajdt.core.compiler.lint.TypeNotExposedToWeaver=warning -org.aspectj.ajdt.core.compiler.lint.UnresolvableMember=warning -org.aspectj.ajdt.core.compiler.lint.WildcardTypeName=ignore -org.aspectj.ajdt.core.compiler.lint.adviceDidNotMatch=warning -org.aspectj.ajdt.core.compiler.lint.annotationAsTargetForDecpIgnored=warning -org.aspectj.ajdt.core.compiler.lint.calculatingSerialVersionUID=ignore -org.aspectj.ajdt.core.compiler.lint.cantFindType=warning -org.aspectj.ajdt.core.compiler.lint.cantFindTypeAffectingJPMatch=warning -org.aspectj.ajdt.core.compiler.lint.cantMatchArrayTypeOnVarargs=ignore -org.aspectj.ajdt.core.compiler.lint.elementAlreadyAnnotated=warning -org.aspectj.ajdt.core.compiler.lint.enumAsTargetForDecpIgnored=warning -org.aspectj.ajdt.core.compiler.lint.invalidTargetForAnnotation=warning -org.aspectj.ajdt.core.compiler.lint.multipleAdviceStoppingLazyTjp=ignore -org.aspectj.ajdt.core.compiler.lint.noExplicitConstructorCall=warning -org.aspectj.ajdt.core.compiler.lint.noGuardForLazyTjp=ignore -org.aspectj.ajdt.core.compiler.lint.noJoinpointsForBridgeMethods=warning -org.aspectj.ajdt.core.compiler.lint.runtimeExceptionNotSoftened=warning -org.aspectj.ajdt.core.compiler.lint.swallowedExceptionInCatchBlock=ignore -org.aspectj.ajdt.core.compiler.lint.uncheckedAdviceConversion=warning -org.aspectj.ajdt.core.compiler.lint.uncheckedArgument=warning -org.aspectj.ajdt.core.compiler.lint.unmatchedTargetKind=warning -org.aspectj.ajdt.core.compiler.lint.unorderedAdviceAtShadow=ignore -org.aspectj.ajdt.core.compiler.list.UnmatchedSuperTypeInCall=warning -org.aspectj.ajdt.core.compiler.weaver.XHasMember=false -org.aspectj.ajdt.core.compiler.weaver.XNoInline=false -org.aspectj.ajdt.core.compiler.weaver.XNotReweavable=false -org.aspectj.ajdt.core.compiler.weaver.XSerializableAspects=false -org.aspectj.ajdt.core.compiler.weaver.timers=false -org.aspectj.ajdt.core.compiler.weaver.verbose=false -org.aspectj.ajdt.core.complier.lint.aspectExcludedByConfiguration=ignore -org.eclipse.ajdt.core.builder.incrementalCompilationOptimizations=true -org.eclipse.ajdt.core.compiler.nonStandardOptions= -org.eclipse.ajdt.core.compiler.useProjectSettings=true diff --git a/eclipse-oo-plugin/.settings/org.eclipse.jdt.core.prefs b/eclipse-oo-plugin/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index d17b672..0000000 --- a/eclipse-oo-plugin/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,12 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.7 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.source=1.7 diff --git a/eclipse-oo-plugin/META-INF/MANIFEST.MF b/eclipse-oo-plugin/META-INF/MANIFEST.MF deleted file mode 100644 index 68fbfc3..0000000 --- a/eclipse-oo-plugin/META-INF/MANIFEST.MF +++ /dev/null @@ -1,12 +0,0 @@ -Manifest-Version: 1.0 -Bundle-ManifestVersion: 2 -Bundle-Name: Java Operator Overloading support for Eclipse -Bundle-SymbolicName: eclipse-oo-plugin;singleton:=true -Bundle-Version: 0.5.0.qualifier -Bundle-RequiredExecutionEnvironment: JavaSE-1.7 -Require-Bundle: org.eclipse.jdt.core, - org.aspectj.weaver, - org.eclipse.equinox.weaving.aspectj, - org.eclipse.equinox.weaving.caching -Export-Package: javaoo.eclipse;aspects="ExpressionAspect,BinaryExpressionAspect,UnaryExpressionAspect,ArrayReferenceAspect,AssignmentAspect,StatementAspect" -Eclipse-SupplementBundle: org.eclipse.jdt.core diff --git a/eclipse-oo-plugin/README.md b/eclipse-oo-plugin/README.md deleted file mode 100644 index a66da59..0000000 --- a/eclipse-oo-plugin/README.md +++ /dev/null @@ -1,35 +0,0 @@ -This eclipse plugin uses AspectJ aspects and Equinox weaving to modify Eclipse Java Compiler for operator overloading support. - -If something doesn't work: - -1. Ensure `org.eclipse.equinox.weaving.aspectj` bundle is auto-started at level 2. Look at `eclipse/configuration/org.eclipse.equinox.simpleconfigurator/bundles.info`: - -``` -org.eclipse.equinox.weaving.aspectj,1.0.300.I20130319-1000,plugins/org.eclipse.equinox.weaving.aspectj_1.0.300.I20130319-1000.jar,2,true -``` - -2. Ensure the following bundles are installed: - -``` -org.aspectj.weaver -org.eclipse.equinox.weaving.aspectj -org.eclipse.equinox.weaving.caching -org.eclipse.equinox.weaving.hook -eclipse-oo-plugin -``` - -3. Check org.eclipse.equinox.weaving.hook is added to osgi extensions (`eclipse/configuration/config.ini`): - -``` -osgi.framework.extensions=reference\:file\:org.eclipse.equinox.weaving.hook_1.0.200.I20130319-1000.jar -``` - -4. Add following to JVM argumets (after `-vmargs` in `eclipse/eclipse.ini`) to enable weaving debug info: - -``` --Daj.weaving.verbose=true --Dorg.aspectj.weaver.showWeaveInfo=true --Dorg.aspectj.osgi.verbose=true -``` - -See also http://wiki.eclipse.org/Equinox_Weaving_QuickStart diff --git a/eclipse-oo-plugin/build.properties b/eclipse-oo-plugin/build.properties deleted file mode 100644 index 8632935..0000000 --- a/eclipse-oo-plugin/build.properties +++ /dev/null @@ -1,7 +0,0 @@ -source.. = src/ -output.. = bin/ -bin.includes = META-INF/,\ - . -compilerAdapter=org.eclipse.ajdt.core.ant.AJDT_AjcCompilerAdapter -sourceFileExtensions=*.java, *.aj -jre.compilation.profile = JavaSE-1.7 diff --git a/eclipse-oo-plugin/src/META-INF/aop-ajc.xml b/eclipse-oo-plugin/src/META-INF/aop-ajc.xml deleted file mode 100644 index f2c5f8a..0000000 --- a/eclipse-oo-plugin/src/META-INF/aop-ajc.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - diff --git a/eclipse-oo-plugin/src/javaoo/eclipse/ArrayReferenceAspect.aj b/eclipse-oo-plugin/src/javaoo/eclipse/ArrayReferenceAspect.aj deleted file mode 100644 index e1a564f..0000000 --- a/eclipse-oo-plugin/src/javaoo/eclipse/ArrayReferenceAspect.aj +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Artem Melentyev - initial API and implementation - * some code from org.eclipse.jdt.code - ******************************************************************************/ -package javaoo.eclipse; - -import org.eclipse.jdt.internal.compiler.ast.ArrayReference; -import org.eclipse.jdt.internal.compiler.ast.Assignment; -import org.eclipse.jdt.internal.compiler.ast.Expression; -import org.eclipse.jdt.internal.compiler.ast.MessageSend; -import org.eclipse.jdt.internal.compiler.codegen.CodeStream; -import org.eclipse.jdt.internal.compiler.lookup.BlockScope; -import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; -import org.eclipse.jdt.internal.compiler.lookup.TypeIds; -import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; - -@SuppressWarnings("restriction") -public aspect ArrayReferenceAspect implements TypeIds { - declare precedence: ExpressionAspect; - - ThreadLocal _scope = new ThreadLocal(); - TypeBinding around(BlockScope scope): - execution(* ArrayReference.resolveType(BlockScope)) && args(scope) - { - try { - _scope.set(scope); - return proceed(scope); - } catch (ReturnException e) { - return (TypeBinding) e.getReturn(); - } - } - - void around(ArrayReference that): - withincode(* ArrayReference.resolveType(BlockScope)) - && call(* ProblemReporter.referenceMustBeArrayTypeAt(TypeBinding, ArrayReference)) && args(*, that) - { - BlockScope scope = _scope.get(); - that.position.resolveType(scope); - MessageSend ms = Utils.findMethod(scope, that.receiver, "get", new Expression[]{that.position}); //$NON-NLS-1$ - if (ms == null) - proceed(that); - else { - ExpressionAspect.setTranslate(that, ms); - that.resolvedType = ms.resolvedType; - throw new ReturnException(that.resolvedType); - } - } - - pointcut generateAssignment(ArrayReference that, BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired): - this(that) && within(org.eclipse.jdt.internal.compiler.ast.ArrayReference) && - execution(* org.eclipse.jdt.internal.compiler.ast.ArrayReference.generateAssignment(BlockScope, CodeStream, Assignment, boolean)) && - args(currentScope, codeStream, assignment, valueRequired); - - void around(ArrayReference that, BlockScope currentScope, CodeStream codeStream, Assignment assignment, boolean valueRequired): - generateAssignment(that, currentScope, codeStream, assignment, valueRequired) { - if (ExpressionAspect.getTranslate(that)==null) { - proceed(that, currentScope, codeStream, assignment, valueRequired); - } else { - ExpressionAspect.removeAndGetTranslate(that).generateCode(currentScope, codeStream, valueRequired); - } - } - - pointcut generateCode(ArrayReference that, BlockScope currentScope, CodeStream codeStream, boolean valueRequired): - this(that) && within(org.eclipse.jdt.internal.compiler.ast.ArrayReference) && - execution(* org.eclipse.jdt.internal.compiler.ast.ArrayReference.generateCode(BlockScope, CodeStream, boolean)) && - args(currentScope, codeStream, valueRequired); - - void around(ArrayReference that, BlockScope currentScope, CodeStream codeStream, boolean valueRequired): - generateCode(that, currentScope, codeStream, valueRequired) { - if (ExpressionAspect.getTranslate(that) == null) { - proceed(that, currentScope, codeStream, valueRequired); - } else { - ExpressionAspect.removeAndGetTranslate(that).generateCode(currentScope, codeStream, valueRequired); - } - } -} diff --git a/eclipse-oo-plugin/src/javaoo/eclipse/AssignmentAspect.aj b/eclipse-oo-plugin/src/javaoo/eclipse/AssignmentAspect.aj deleted file mode 100644 index b949ae3..0000000 --- a/eclipse-oo-plugin/src/javaoo/eclipse/AssignmentAspect.aj +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Artem Melentyev - initial API and implementation - ******************************************************************************/ -package javaoo.eclipse; - -import org.eclipse.jdt.internal.compiler.ast.ArrayReference; -import org.eclipse.jdt.internal.compiler.ast.Assignment; -import org.eclipse.jdt.internal.compiler.ast.Expression; -import org.eclipse.jdt.internal.compiler.ast.MessageSend; -import org.eclipse.jdt.internal.compiler.lookup.BlockScope; -import org.eclipse.jdt.internal.compiler.lookup.Scope; -import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; - -@SuppressWarnings("restriction") -public aspect AssignmentAspect { - ThreadLocal _scope = new ThreadLocal(); - // catch scope param - before(BlockScope scope): - execution(* org.eclipse.jdt.internal.compiler.ast.Assignment.resolveType(BlockScope)) - && args(scope) - { - _scope.set(scope); - } - - before(Assignment that, Expression e): - withincode(* org.eclipse.jdt.internal.compiler.ast.Assignment.resolveType(..)) - && call(* org.eclipse.jdt.internal.compiler.ast.Expression.getDirectBinding(..)) - && this(that) && args(e) - { - if (e!=that.lhs) return; // ignore second call to getDirectBinding - BlockScope scope = _scope.get(); - if (that.lhs instanceof ArrayReference) { - ArrayReference alhs = (ArrayReference) that.lhs; - if (!alhs.receiver.resolvedType.isArrayType()) { - Expression[] args = new Expression[]{alhs.position, that.expression}; - MessageSend ms = Utils.findMethod(scope, alhs.receiver, "set", args); //$NON-NLS-1$ - if (ms==null) - ms = Utils.findMethod(scope, alhs.receiver, "put", args); //$NON-NLS-1$ - if (ms==null) - scope.problemReporter().referenceMustBeArrayTypeAt(alhs.receiver.resolvedType, alhs); - else { - ExpressionAspect.setTranslate(alhs, ms); - that.resolvedType = ms.resolvedType; - } - } - } - } - - void around(Assignment that, Scope scope, TypeBinding runtimeType, TypeBinding compileTimeType): - target(Assignment) - && execution(* org.eclipse.jdt.internal.compiler.ast.Expression.computeConversion(..)) - && this(that) && args(scope, runtimeType, compileTimeType) - { - Expression translate = ExpressionAspect.getTranslate(that.lhs); - if (translate != null) - translate.computeConversion(scope, runtimeType, compileTimeType); - else - proceed(that, scope, runtimeType, compileTimeType); - } -} diff --git a/eclipse-oo-plugin/src/javaoo/eclipse/BinaryExpressionAspect.aj b/eclipse-oo-plugin/src/javaoo/eclipse/BinaryExpressionAspect.aj deleted file mode 100644 index 93a727d..0000000 --- a/eclipse-oo-plugin/src/javaoo/eclipse/BinaryExpressionAspect.aj +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Artem Melentyev - initial API and implementation - * some code from org.eclipse.jdt.code - ******************************************************************************/ -package javaoo.eclipse; - -import org.eclipse.jdt.internal.compiler.ast.ASTNode; -import org.eclipse.jdt.internal.compiler.ast.BinaryExpression; -import org.eclipse.jdt.internal.compiler.ast.Expression; -import org.eclipse.jdt.internal.compiler.ast.IntLiteral; -import org.eclipse.jdt.internal.compiler.ast.MessageSend; -import org.eclipse.jdt.internal.compiler.ast.OperatorExpression; -import org.eclipse.jdt.internal.compiler.impl.Constant; -import org.eclipse.jdt.internal.compiler.lookup.BlockScope; -import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; -import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; - -@SuppressWarnings("restriction") -public aspect BinaryExpressionAspect { - @SuppressWarnings("serial") - public final static java.util.Map binaryOperators = new java.util.HashMap() {{ - put("+", "add"); - put("-", "subtract"); - put("*", "multiply"); - put("/", "divide"); - put("%", "remainder"); - put("&", "and"); - put("|", "or"); - put("^", "xor"); - put("<<", "shiftLeft"); - put(">>", "shiftRight"); - put("<", "compareTo"); - put(">", "compareTo"); - put("<=", "compareTo"); - put(">=", "compareTo"); - }}; - - public static TypeBinding overloadBinaryOperator(BinaryExpression that, BlockScope scope) { - // try operator overloading - String method = (String) binaryOperators.get(that.operatorToString()); - if (method != null) { - // find method - MessageSend ms = Utils.findMethod(scope, that.left, method, new Expression[]{that.right}); - if (ms == null) - ms = Utils.findMethod(scope, that.right, method + "Rev", new Expression[]{that.left}); // try find right.methodRev(left) - if (ms != null) { // found - if ("compareTo".equals(method)) { //$NON-NLS-1$ - // rewrite to `left.compareTo(right) 0` - that.left = ms; - that.right = IntLiteral.buildIntLiteral("0".toCharArray(), that.sourceStart, that.sourceEnd); //$NON-NLS-1$ - that.right.resolve(scope); - int leftTypeID = that.left.resolvedType.id; - int rightTypeID = that.right.resolvedType.id; - if (leftTypeID == rightTypeID) { // if compareTo really returns int - // resolve rest info about `left 0` - int operator = (that.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT; - int operatorSignature = OperatorExpression.OperatorSignatures[operator][(leftTypeID << 4) + rightTypeID]; - that.left.computeConversion(scope, TypeBinding.wellKnownType(scope, (operatorSignature >>> 16) & 0x0000F), that.left.resolvedType); - that.right.computeConversion(scope, TypeBinding.wellKnownType(scope, (operatorSignature >>> 8) & 0x0000F), that.right.resolvedType); - that.bits |= operatorSignature & 0xF; - that.computeConstant(scope, leftTypeID, rightTypeID); - return that.resolvedType = TypeBinding.BOOLEAN; - } - } else { - ExpressionAspect.setTranslate(that, ms); - that.constant = Constant.NotAConstant; - return that.resolvedType = ms.resolvedType; - } - } - } - return null; - } - - pointcut isCompactableOperation(BinaryExpression that): - execution(* org.eclipse.jdt.internal.compiler.ast.BinaryExpression.isCompactableOperation()) && - within(org.eclipse.jdt.internal.compiler.ast.BinaryExpression) && - this(that); - - boolean around(BinaryExpression that): isCompactableOperation(that) { - return ExpressionAspect.getTranslate(that) == null; - } - - pointcut resolveType(BlockScope scope): - execution(* BinaryExpression.resolveType(BlockScope)) && args(scope); - - ThreadLocal _scope = new ThreadLocal(); - TypeBinding around(BlockScope scope): resolveType(scope) { - try { - _scope.set(scope); - return proceed(scope); - } catch (ReturnException e) { - return (TypeBinding) e.getReturn(); - } - } - - void around(BinaryExpression that): - withincode(* BinaryExpression.resolveType(BlockScope)) - && call(* ProblemReporter.invalidOperator(BinaryExpression, TypeBinding, TypeBinding)) && args(that, ..) - { - BlockScope scope = _scope.get(); - TypeBinding res = overloadBinaryOperator(that, scope); - if (res != null) - throw new ReturnException(res); - proceed(that); - } -} diff --git a/eclipse-oo-plugin/src/javaoo/eclipse/Dummy.java b/eclipse-oo-plugin/src/javaoo/eclipse/Dummy.java deleted file mode 100644 index 8181ddf..0000000 --- a/eclipse-oo-plugin/src/javaoo/eclipse/Dummy.java +++ /dev/null @@ -1,4 +0,0 @@ -package javaoo.eclipse; - -/** XXX: Dummy java file to force plugin building via org.eclipse.ajdt.core.ant.AJDT_AjcCompilerAdapter */ -public class Dummy {} diff --git a/eclipse-oo-plugin/src/javaoo/eclipse/ExpressionAspect.aj b/eclipse-oo-plugin/src/javaoo/eclipse/ExpressionAspect.aj deleted file mode 100644 index 5b9531b..0000000 --- a/eclipse-oo-plugin/src/javaoo/eclipse/ExpressionAspect.aj +++ /dev/null @@ -1,56 +0,0 @@ -package javaoo.eclipse; - -import java.util.Arrays; - -import org.eclipse.jdt.internal.compiler.ast.Expression; -import org.eclipse.jdt.internal.compiler.ast.MessageSend; -import org.eclipse.jdt.internal.compiler.codegen.CodeStream; -import org.eclipse.jdt.internal.compiler.lookup.BlockScope; -import org.eclipse.jdt.internal.compiler.lookup.Scope; -import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; - -@SuppressWarnings("restriction") -public aspect ExpressionAspect { - private MessageSend Expression.translate; - - public static MessageSend getTranslate(Expression e) { - return e.translate; - } - public static void setTranslate(Expression e, MessageSend t) { - e.translate = t; - } - public static Expression removeAndGetTranslate(Expression x) { - MessageSend e = getTranslate(x); - setTranslate(x, null); // to prevent loop - if (!Arrays.equals("valueOf".toCharArray(), e.selector)) { - x.implicitConversion = e.implicitConversion = x.implicitConversion | e.implicitConversion; - x.bits = e.bits = x.bits | e.bits; - } - return e; - } - - pointcut generateCode(Expression that, BlockScope currentScope, CodeStream codeStream, boolean valueRequired): - execution(* org.eclipse.jdt.internal.compiler.ast.Expression.generateCode(BlockScope, CodeStream, boolean)) && - this(that) && args(currentScope, codeStream, valueRequired); - - void around(Expression that, BlockScope currentScope, CodeStream codeStream, boolean valueRequired): - generateCode(that, currentScope, codeStream, valueRequired) { - if (getTranslate(that) == null) { - proceed(that, currentScope, codeStream, valueRequired); - } else { - ExpressionAspect.removeAndGetTranslate(that).generateCode(currentScope, codeStream, valueRequired); - } - } - - void around(Expression that, Scope scope, TypeBinding runtimeType, TypeBinding compileTimeType): - execution(* org.eclipse.jdt.internal.compiler.ast.Expression.computeConversion(..)) && - this(that) && args(scope, runtimeType, compileTimeType) - { - MessageSend translate = getTranslate(that); - if (translate != null) { - if (!Arrays.equals("valueOf".toCharArray(), translate.selector)) - translate.computeConversion(scope, runtimeType, compileTimeType); - } else - proceed(that, scope, runtimeType, compileTimeType); - } -} diff --git a/eclipse-oo-plugin/src/javaoo/eclipse/ReturnException.java b/eclipse-oo-plugin/src/javaoo/eclipse/ReturnException.java deleted file mode 100644 index 979e434..0000000 --- a/eclipse-oo-plugin/src/javaoo/eclipse/ReturnException.java +++ /dev/null @@ -1,13 +0,0 @@ -package javaoo.eclipse; - -@SuppressWarnings("serial") -public class ReturnException extends RuntimeException { - private Object ret; - public ReturnException(Object ret) { - super(); - this.ret = ret; - } - public Object getReturn() { - return ret; - } -} \ No newline at end of file diff --git a/eclipse-oo-plugin/src/javaoo/eclipse/StatementAspect.aj b/eclipse-oo-plugin/src/javaoo/eclipse/StatementAspect.aj deleted file mode 100644 index 97d527d..0000000 --- a/eclipse-oo-plugin/src/javaoo/eclipse/StatementAspect.aj +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Artem Melentyev - initial API and implementation - ******************************************************************************/ -package javaoo.eclipse; - -import org.eclipse.jdt.internal.compiler.ast.Expression; -import org.eclipse.jdt.internal.compiler.ast.MessageSend; -import org.eclipse.jdt.internal.compiler.ast.SingleNameReference; -import org.eclipse.jdt.internal.compiler.ast.Statement; -import org.eclipse.jdt.internal.compiler.lookup.BlockScope; -import org.eclipse.jdt.internal.compiler.lookup.Scope; -import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; - -@SuppressWarnings("restriction") -public aspect StatementAspect { - pointcut isBoxingCompatible(Statement that, TypeBinding expressionType, TypeBinding targetType, Expression expression, Scope scope): - this(that) && within(org.eclipse.jdt.internal.compiler.ast.Statement) && - execution(* org.eclipse.jdt.internal.compiler.ast.Statement.isBoxingCompatible(TypeBinding, TypeBinding, Expression, Scope)) && - args(expressionType, targetType, expression, scope); - - boolean around(Statement that, TypeBinding expressionType, TypeBinding targetType, Expression expression, Scope scope): - isBoxingCompatible(that, expressionType, targetType, expression, scope) { - return proceed(that, expressionType, targetType, expression, scope) - || tryBoxingOverload(expressionType, targetType, expression, scope); - } - private static boolean tryBoxingOverload(TypeBinding expressionType, TypeBinding targetType, Expression expression, Scope scope) { - if (!(scope instanceof BlockScope)) return false; - BlockScope bscope = (BlockScope) scope; - Expression receiver = new SingleNameReference(targetType.shortReadableName(), expression.sourceStart); - receiver.resolvedType = targetType; - MessageSend ms = Utils.findMethod(bscope, receiver, "valueOf", new Expression[]{expression}); //$NON-NLS-1$ - if (ms != null && ms.resolvedType == targetType) { - ExpressionAspect.setTranslate(expression, ms); - expression.resolvedType = ms.resolvedType; - return true; - } - return false; - } -} diff --git a/eclipse-oo-plugin/src/javaoo/eclipse/UnaryExpressionAspect.aj b/eclipse-oo-plugin/src/javaoo/eclipse/UnaryExpressionAspect.aj deleted file mode 100644 index 28fd92d..0000000 --- a/eclipse-oo-plugin/src/javaoo/eclipse/UnaryExpressionAspect.aj +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Artem Melentyev - initial API and implementation - ******************************************************************************/ -package javaoo.eclipse; - -import org.eclipse.jdt.internal.compiler.ast.Expression; -import org.eclipse.jdt.internal.compiler.ast.MessageSend; -import org.eclipse.jdt.internal.compiler.ast.UnaryExpression; -import org.eclipse.jdt.internal.compiler.lookup.BlockScope; -import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; -import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; - -@SuppressWarnings("restriction") -public aspect UnaryExpressionAspect { - @SuppressWarnings("serial") - public final static java.util.Map unaryOperators = new java.util.HashMap() {{ - put("-", "negate"); - put("~", "not"); - }}; - - public static TypeBinding overloadUnaryOperator(UnaryExpression that, BlockScope scope) { - // similar to BinaryExpression#overloadBinaryOperator - String method = (String) unaryOperators.get(that.operatorToString()); - if (method != null) { - // find method - MessageSend ms = Utils.findMethod(scope, that.expression, method, new Expression[0]); - if (ms != null) { - ExpressionAspect.setTranslate(that, ms); - return that.resolvedType = ms.resolvedType; - } - } - return null; - } - - ThreadLocal _scope = new ThreadLocal(); - - TypeBinding around(BlockScope scope): - execution(* UnaryExpression.resolveType(BlockScope)) && args(scope) - { - try { - _scope.set(scope); - return proceed(scope); - } catch (ReturnException e) { - return (TypeBinding) e.getReturn(); - } - } - - void around(UnaryExpression that): - withincode(* UnaryExpression.resolveType(BlockScope)) - && call(* ProblemReporter.invalidOperator(UnaryExpression, TypeBinding)) && args(that, ..) - { - TypeBinding res = overloadUnaryOperator(that, _scope.get()); - if (res != null) - throw new ReturnException(res); - proceed(that); - } -} diff --git a/eclipse-oo-plugin/src/javaoo/eclipse/Utils.aj b/eclipse-oo-plugin/src/javaoo/eclipse/Utils.aj deleted file mode 100644 index 98a33e3..0000000 --- a/eclipse-oo-plugin/src/javaoo/eclipse/Utils.aj +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * Artem Melentyev - initial API and implementation - ******************************************************************************/ -package javaoo.eclipse; - -import org.eclipse.jdt.internal.compiler.ast.ASTNode; -import org.eclipse.jdt.internal.compiler.ast.CastExpression; -import org.eclipse.jdt.internal.compiler.ast.Expression; -import org.eclipse.jdt.internal.compiler.ast.MessageSend; -import org.eclipse.jdt.internal.compiler.impl.Constant; -import org.eclipse.jdt.internal.compiler.lookup.BlockScope; -import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; - -@SuppressWarnings("restriction") -public class Utils { - public static MessageSend findMethod(BlockScope scope, Expression receiver, String selector, Expression[] args) { - char[] s = selector.toCharArray(); - MessageSend ms = new MessageSend(); - ms.receiver = receiver; - ms.selector = s; - ms.arguments = args; - ms.actualReceiverType = receiver.resolvedType; - TypeBinding[] targs = new TypeBinding[args.length]; - for (int i = 0; i < args.length; i++) - targs[i] = args[i].resolvedType; - ms.binding = scope.getMethod(ms.actualReceiverType, s, targs, ms); - if (ms.binding != null && ms.binding.isValidBinding()) { - boolean argsContainCast = false; - for (Expression e : args) - argsContainCast |= e instanceof CastExpression; - if (ASTNode.checkInvocationArguments(scope, ms.receiver, ms.actualReceiverType, ms.binding, ms.arguments, targs, argsContainCast, ms)) - ms.bits |= ASTNode.Unchecked; - ms.resolvedType = ms.binding.returnType; - ms.constant = Constant.NotAConstant; - ms.sourceStart = receiver.sourceStart; - ms.sourceEnd = receiver.sourceEnd; - return ms; - } - return null; - } -} diff --git a/eclipse-oo-plugin/test/javaoo/eclipse/AspectTest.java b/eclipse-oo-plugin/test/javaoo/eclipse/AspectTest.java deleted file mode 100644 index e229fde..0000000 --- a/eclipse-oo-plugin/test/javaoo/eclipse/AspectTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package javaoo.eclipse; - -import java.io.PrintWriter; - -import org.eclipse.jdt.core.compiler.batch.BatchCompiler; - -/** Run with AspectJ load-time weaving. LTW aspect path = this project */ -public class AspectTest { - public static void compile(String clas) throws Exception { - compile(clas, "../examples"); - } - static boolean globalres = true; - public static void compile(String clas, String dir) throws Exception { - String file = dir + "/" + clas + ".java"; - System.out.print("Compiling " + file + ": "); - boolean res = BatchCompiler.compile(file + " -source 1.7 -d bin", new PrintWriter(System.out), new PrintWriter(System.err), null); - res &= (Boolean)Class.forName(clas).getDeclaredMethod("test").invoke(null); - System.out.println(res ? "ok" : "fail"); - globalres &= res; - } - public static void main(String[] args) throws Exception { - compile("ValueOf"); - compile("Math"); - compile("Cmp"); - compile("ListIndexGet"); - compile("ListIndexSet"); - compile("MapIndex"); - compile("ValueOf"); - compile("Vector"); - compile("CompAss", "../tests"); - compile("VecMat", "../tests"); - compile("IndexBoxing", "../tests"); - compile("Boxing", "../tests"); - System.out.println(globalres ? "ok" : "fail"); - } -} \ No newline at end of file diff --git a/eclipse-oo-site b/eclipse-oo-site deleted file mode 160000 index f6ec82b..0000000 --- a/eclipse-oo-site +++ /dev/null @@ -1 +0,0 @@ -Subproject commit f6ec82bca284d5c0b37e43a03c25e6c0ad99b405 diff --git a/examples b/examples deleted file mode 120000 index 73d152c..0000000 --- a/examples +++ /dev/null @@ -1 +0,0 @@ -javac-oo-mvndemo/src \ No newline at end of file diff --git a/idea-oo-plugin/.idea/.name b/idea-oo-plugin/.idea/.name deleted file mode 100644 index 3bfa80f..0000000 --- a/idea-oo-plugin/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -idea-oo-plugin \ No newline at end of file diff --git a/idea-oo-plugin/.idea/ant.xml b/idea-oo-plugin/.idea/ant.xml deleted file mode 100644 index f6e673a..0000000 --- a/idea-oo-plugin/.idea/ant.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/idea-oo-plugin/.idea/compiler.xml b/idea-oo-plugin/.idea/compiler.xml deleted file mode 100644 index 217af47..0000000 --- a/idea-oo-plugin/.idea/compiler.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - diff --git a/idea-oo-plugin/.idea/copyright/profiles_settings.xml b/idea-oo-plugin/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/idea-oo-plugin/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/idea-oo-plugin/.idea/encodings.xml b/idea-oo-plugin/.idea/encodings.xml deleted file mode 100644 index f758959..0000000 --- a/idea-oo-plugin/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/idea-oo-plugin/.idea/misc.xml b/idea-oo-plugin/.idea/misc.xml deleted file mode 100644 index 4b76804..0000000 --- a/idea-oo-plugin/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/idea-oo-plugin/.idea/modules.xml b/idea-oo-plugin/.idea/modules.xml deleted file mode 100644 index a05386c..0000000 --- a/idea-oo-plugin/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/idea-oo-plugin/.idea/scopes/scope_settings.xml b/idea-oo-plugin/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b..0000000 --- a/idea-oo-plugin/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/idea-oo-plugin/.idea/uiDesigner.xml b/idea-oo-plugin/.idea/uiDesigner.xml deleted file mode 100644 index 3b00020..0000000 --- a/idea-oo-plugin/.idea/uiDesigner.xml +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/idea-oo-plugin/.idea/vcs.xml b/idea-oo-plugin/.idea/vcs.xml deleted file mode 100644 index 21cbaa6..0000000 --- a/idea-oo-plugin/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/idea-oo-plugin/META-INF/plugin.xml b/idea-oo-plugin/META-INF/plugin.xml deleted file mode 100644 index 4a7d762..0000000 --- a/idea-oo-plugin/META-INF/plugin.xml +++ /dev/null @@ -1,62 +0,0 @@ - - javaoo.idea - Java Operator Overloading support - 0.7 - Artem Melentyev - - - Custom Languages - - - - - - com.intellij.modules.java - - - - javaoo.idea.OOComponent - - - - - - - - -
  • 0.7 -
      Support of IDEA 2019.2+
    -
  • -
  • 0.6 -
      Support of IDEA 2017.1.3. Minimum 2016.2
    -
  • -
  • 0.5 -
      Support of IDEA 15. Java8 is required to run the plugin.
    -
  • -
  • 0.4.1 -
      Support of IDEA 14.1
    -
  • -
  • 0.4 -
      #25: Reverse binary operator overload via 'operatorRev' methods
    -
      Support of IDEA 14
    -
  • -
  • 0.3.1 -
      #18: bugfix in type resolution for binary expressions with primitives
    -
  • -
  • 0.3 -
      #17: Bugfix for IDEA 13 Ultimate Edition
    -
  • -
  • 0.2.1 -
      #7: IntelliJ IDEA Ultimate Edition support
    -
  • -
  • 0.2 -
      Initial release.
    -
  • - ]]> - - \ No newline at end of file diff --git a/idea-oo-plugin/idea-oo-plugin.iml b/idea-oo-plugin/idea-oo-plugin.iml deleted file mode 100644 index 3d46c57..0000000 --- a/idea-oo-plugin/idea-oo-plugin.iml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/idea-oo-plugin/src/javaoo/OOMethods.java b/idea-oo-plugin/src/javaoo/OOMethods.java deleted file mode 120000 index 7c5faf3..0000000 --- a/idea-oo-plugin/src/javaoo/OOMethods.java +++ /dev/null @@ -1 +0,0 @@ -../../../javac-oo-plugin/src/main/java/javaoo/OOMethods.java \ No newline at end of file diff --git a/idea-oo-plugin/src/javaoo/idea/OOComponent.java b/idea-oo-plugin/src/javaoo/idea/OOComponent.java deleted file mode 100644 index e9e02d6..0000000 --- a/idea-oo-plugin/src/javaoo/idea/OOComponent.java +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright 2013 Artem Melentyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javaoo.idea; - -import com.intellij.codeInsight.daemon.impl.HighlightVisitor; -import com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl; -import com.intellij.openapi.components.ProjectComponent; -import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.extensions.ExtensionPoint; -import com.intellij.openapi.extensions.Extensions; -import com.intellij.openapi.extensions.impl.ExtensionComponentAdapter; -import com.intellij.openapi.extensions.impl.ExtensionPointImpl; -import com.intellij.openapi.project.Project; -import com.intellij.psi.impl.source.tree.JavaElementType; -import com.intellij.psi.impl.source.tree.java.PsiArrayAccessExpressionImpl; -import com.intellij.psi.impl.source.tree.java.PsiBinaryExpressionImpl; -import com.intellij.psi.impl.source.tree.java.PsiPolyadicExpressionImpl; -import com.intellij.psi.impl.source.tree.java.PsiPrefixExpressionImpl; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -public class OOComponent implements ProjectComponent { - private static final Logger LOG = Logger.getInstance("#"+OOComponent.class.getName()); - - private final Project project; - - public OOComponent(Project project) { - this.project = project; - } - - @NotNull @Override - public String getComponentName() { - return "Java Operator Overloading plugin"; - } - - @Override - public void initComponent() { - LOG.info("OO init"); - Util.setJavaElementConstructor(JavaElementType.BINARY_EXPRESSION, PsiOOBinaryExpressionImpl::new); - Util.setJavaElementConstructor(JavaElementType.PREFIX_EXPRESSION, PsiOOPrefixExpressionImpl::new); - Util.setJavaElementConstructor(JavaElementType.POLYADIC_EXPRESSION, PsiOOPolyadicExpressionImpl::new); - Util.setJavaElementConstructor(JavaElementType.ARRAY_ACCESS_EXPRESSION, PsiOOArrayAccessExpressionImpl::new); - - // TODO: replace to project.getExtensionArea() after 2019.3 - ExtensionPoint ep = Extensions.getArea(project).getExtensionPoint(HighlightVisitor.EP_HIGHLIGHT_VISITOR); - List hadapters = (List) Util.get(ExtensionPointImpl.class, (ExtensionPointImpl) ep, List.class, "myAdapters"); - for (ExtensionComponentAdapter ca : hadapters) { - if (HighlightVisitorImpl.class.getName().equals(ca.getAssignableToClassName())) { - try { - Util.set(ExtensionComponentAdapter.class, ca, Object.class, OOHighlightVisitorImpl.class, "myImplementationClassOrName"); - } catch (Exception e) { - LOG.error("Can't load transformed OOHighlightVisitorImpl class", e); - } - break; - } - } - } - - @Override - public void disposeComponent() { - LOG.info("OO dispose"); - Util.setJavaElementConstructor(JavaElementType.BINARY_EXPRESSION, PsiBinaryExpressionImpl::new); - Util.setJavaElementConstructor(JavaElementType.PREFIX_EXPRESSION, PsiPrefixExpressionImpl::new); - Util.setJavaElementConstructor(JavaElementType.POLYADIC_EXPRESSION, PsiPolyadicExpressionImpl::new); - Util.setJavaElementConstructor(JavaElementType.ARRAY_ACCESS_EXPRESSION, PsiArrayAccessExpressionImpl::new); - } - - public void projectOpened() {} - public void projectClosed() {} -} diff --git a/idea-oo-plugin/src/javaoo/idea/OOHighlightVisitorImpl.java b/idea-oo-plugin/src/javaoo/idea/OOHighlightVisitorImpl.java deleted file mode 100644 index 5401ca6..0000000 --- a/idea-oo-plugin/src/javaoo/idea/OOHighlightVisitorImpl.java +++ /dev/null @@ -1,145 +0,0 @@ -/* Copyright 2013 Artem Melentyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javaoo.idea; - -import com.intellij.codeInsight.daemon.impl.HighlightInfo; -import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder; -import com.intellij.codeInsight.daemon.impl.analysis.HighlightVisitorImpl; -import com.intellij.lang.annotation.HighlightSeverity; -import com.intellij.openapi.util.TextRange; -import com.intellij.psi.*; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.List; - -import static javaoo.idea.Util.sneakyThrow; - -public class OOHighlightVisitorImpl extends HighlightVisitorImpl { - - private HighlightInfoHolder myHolder; - - @Override - public boolean analyze(@NotNull PsiFile file, boolean updateWholeFile, @NotNull HighlightInfoHolder holder, @NotNull Runnable action) { - myHolder = holder; - try { - return super.analyze(file, updateWholeFile, holder, action); - } finally { - myHolder = null; - } - } - - @Override // Binary OO - public void visitPolyadicExpression(PsiPolyadicExpression expression) { - super.visitPolyadicExpression(expression); - if (isHighlighted(expression)) { - PsiExpression[] operands = expression.getOperands(); - PsiType lType = operands[0].getType(); - for (int i = 1; i < operands.length; i++) { - PsiExpression operand = operands[i]; - PsiType rType = operand.getType(); - // TODO: case A + A + int ? A.add(A) : int - lType = OOResolver.getOOType(lType, rType, expression.getTokenBeforeOperand(operand)); - } - if (lType != OOResolver.NoType) - removeLastHighlight(); - } - } - - @Override // Unary OO - public void visitPrefixExpression(PsiPrefixExpression expression) { - super.visitPrefixExpression(expression); - if (isHighlighted(expression) - && OOResolver.getOOType(expression) != OOResolver.NoType) { - removeLastHighlight(); - } - } - - @Override // Index-Get OO - public void visitExpression(PsiExpression expression) { - super.visitExpression(expression); - if (expression instanceof PsiArrayAccessExpression) { - PsiArrayAccessExpression paa = (PsiArrayAccessExpression) expression; - if (isHighlighted(paa.getArrayExpression()) - && OOResolver.indexGet((PsiArrayAccessExpression) expression) != OOResolver.NoType) - removeLastHighlight(); - } - } - - @Override - public void visitAssignmentExpression(PsiAssignmentExpression ass) { - super.visitAssignmentExpression(ass); - if ("=".equals(ass.getOperationSign().getText())) { - // Index-Set OO - if (ass.getLExpression() instanceof PsiArrayAccessExpression - && isHighlighted(ass.getLExpression())) { - PsiArrayAccessExpression paa = (PsiArrayAccessExpression) ass.getLExpression(); - if (OOResolver.indexSet(paa, ass.getRExpression()) != OOResolver.NoType) - removeLastHighlight(); - } - // Implicit type conversion in assignment - if (isHighlighted(ass) && OOResolver.isTypeConvertible(ass.getLExpression().getType(), ass.getRExpression())) - removeLastHighlight(); - } - } - - @Override // Implicit type conversion in variable declaration - public void visitVariable(PsiVariable var) { - super.visitVariable(var); - if (var.hasInitializer() && isHighlighted(var) && OOResolver.isTypeConvertible(var.getType(), var.getInitializer())) - removeLastHighlight(); - } - - private boolean isHighlighted(@NotNull PsiElement expression) { - if (myHolder.hasErrorResults()) { - HighlightInfo hi = myHolder.get(myHolder.size() - 1); - if (hi.getSeverity() != HighlightSeverity.ERROR) return false; - if (expression instanceof PsiVariable) { // workaround for variable declaration incompatible types highlight - PsiVariable v = (PsiVariable) expression; - PsiTypeElement pte = v.getTypeElement(); - if (pte == null) - return false; - TextRange tetr = pte.getTextRange(); - TextRange tr = v.getTextRange(); - return tr != null && tetr != null - && hi.startOffset == tetr.getStartOffset() - && hi.endOffset == tr.getEndOffset(); - } - TextRange tr = expression.getTextRange(); - return hi.startOffset == tr.getStartOffset() && hi.endOffset == tr.getEndOffset(); - } - return false; - } - - // TODO: what highlightInfo to delete? - private void removeLastHighlight() { - // remove highlight - List myInfos = (List) Util.get(HighlightInfoHolder.class, myHolder, List.class, "myInfos", "f"); - myInfos.remove(myHolder.size() - 1); - // update error count - Field fmyErrorCount = Util.findField(HighlightInfoHolder.class, int.class, "myErrorCount", "b"); - try { - fmyErrorCount.setInt(myHolder, fmyErrorCount.getInt(myHolder) - 1); - } catch (IllegalAccessException e) { - throw sneakyThrow(e); - } - } - - @Override - @NotNull - public OOHighlightVisitorImpl clone() { - return new OOHighlightVisitorImpl(); - } -} diff --git a/idea-oo-plugin/src/javaoo/idea/OOResolver.java b/idea-oo-plugin/src/javaoo/idea/OOResolver.java deleted file mode 100644 index ff30c88..0000000 --- a/idea-oo-plugin/src/javaoo/idea/OOResolver.java +++ /dev/null @@ -1,128 +0,0 @@ -/* Copyright 2013 Artem Melentyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javaoo.idea; - -import com.intellij.lang.java.JavaLanguage; -import com.intellij.openapi.project.Project; -import com.intellij.psi.*; -import com.intellij.psi.impl.light.LightMethodBuilder; -import com.intellij.psi.util.TypeConversionUtil; -import javaoo.OOMethods; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class OOResolver { - public static final PsiType NoType = TypeConversionUtil.NULL_TYPE; - - private OOResolver() {} - - public static @NotNull PsiType getOOType(PsiBinaryExpression e) { - if (e == null || e.getROperand() == null) - return NoType; - return getOOType(e.getLOperand().getType(), e.getROperand().getType(), e.getOperationSign()); - } - - public static @NotNull PsiType getOOType(PsiType left, PsiType right, PsiJavaToken op) { - if (op == null) return NoType; - String methodname = OOMethods.binary.get(op.getText()); - if (methodname != null && right != null) { - PsiType res = resolveMethod(left, methodname, right); - if (res == null) - res = resolveMethod(right, methodname+OOMethods.revSuffix, left); - if (res != null) - if (OOMethods.compareTo.equals(methodname)) return PsiType.BOOLEAN; - else return res; - } - return NoType; - } - - public static @NotNull PsiType getOOType(PsiPrefixExpression e) { - if (e == null || e.getOperand() == null) - return NoType; - String methodname = OOMethods.unary.get(e.getOperationSign().getText()); - if (methodname != null) { - PsiType res = resolveMethod(e.getOperand(), methodname); - if (res != null) - return res; - } - return NoType; - } - - public static @NotNull PsiType indexGet(PsiArrayAccessExpression e) { - if (e==null || e.getIndexExpression() == null) - return NoType; - PsiType res = resolveMethod(e.getArrayExpression(), OOMethods.indexGet, e.getIndexExpression()); - return res!=null ? res : NoType; - } - - public static @NotNull PsiType indexSet(PsiArrayAccessExpression paa, PsiExpression value) { - if (paa == null) return NoType; - for (String method : OOMethods.indexSet) { - PsiType res = resolveMethod(paa.getArrayExpression(), method, paa.getIndexExpression(), value); - if (res != null) return res; - } - return NoType; - } - - public static boolean isTypeConvertible(PsiType to, PsiExpression from) { - if (from != null) - for (String methodName : OOMethods.valueOf) - if (resolveMethod(from.getProject(), from.getContext(), to.getCanonicalText(), methodName, from)!=null) - return true; - return false; - } - public static @Nullable PsiType resolveMethod(PsiExpression receiver, String methodName, @NotNull PsiExpression... args) { - return resolveMethod(receiver.getProject(), receiver.getContext(), receiver.getText(), methodName, args); - } - - public static @Nullable PsiType resolveMethod(Project proj, PsiElement context, String clas, String methodName, @NotNull PsiExpression... args) { - StringBuilder sb = new StringBuilder(); - sb.append(clas).append(".").append(methodName).append("("); - boolean comma = false; - for (PsiExpression arg : args) { - if (comma) - sb.append(","); - sb.append(arg.getText()); - comma = true; - } - sb.append(")"); - PsiExpression exp = JavaPsiFacade.getElementFactory(proj).createExpressionFromText(sb.toString(), context); - return exp.getType(); - /*if (clas == null || methodName == null) return null; - PsiType[] argTypes = new PsiType[args.length]; - for (int i = 0; i < args.length; i++) { - if (args[i] == null) return null; - argTypes[i] = args[i].getType(); - } - return resolveMethod(clas.getType(), methodName, argTypes);*/ - } - - public static @Nullable PsiType resolveMethod(@Nullable PsiType type, String methodName, @NotNull PsiType... argTypes) { - if (!(type instanceof PsiClassType) || methodName==null) return null; - for (PsiType a : argTypes) - if (a == null) - return null; - PsiClassType clas = (PsiClassType) type; - PsiSubstitutor subst = clas.resolveGenerics().getSubstitutor(); - PsiClass psiClass = clas.resolve(); - if (psiClass == null) - return null; - LightMethodBuilder method = new LightMethodBuilder(psiClass.getManager(), JavaLanguage.INSTANCE, methodName); - for (PsiType a : argTypes) - method.addParameter("_", a); - PsiMethod m = psiClass.findMethodBySignature(method, true); - return m==null ? null : subst.substitute(m.getReturnType()); - } -} diff --git a/idea-oo-plugin/src/javaoo/idea/PsiOOArrayAccessExpressionImpl.java b/idea-oo-plugin/src/javaoo/idea/PsiOOArrayAccessExpressionImpl.java deleted file mode 100644 index 82efba0..0000000 --- a/idea-oo-plugin/src/javaoo/idea/PsiOOArrayAccessExpressionImpl.java +++ /dev/null @@ -1,26 +0,0 @@ -/* Copyright 2013 Artem Melentyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javaoo.idea; - -import com.intellij.psi.PsiType; -import com.intellij.psi.impl.source.tree.java.PsiArrayAccessExpressionImpl; - -public class PsiOOArrayAccessExpressionImpl extends PsiArrayAccessExpressionImpl { - @Override - public PsiType getType() { - PsiType res = super.getType(); - return res != null ? res : OOResolver.indexGet(this); - } -} diff --git a/idea-oo-plugin/src/javaoo/idea/PsiOOBinaryExpressionImpl.java b/idea-oo-plugin/src/javaoo/idea/PsiOOBinaryExpressionImpl.java deleted file mode 100644 index 7ec28f5..0000000 --- a/idea-oo-plugin/src/javaoo/idea/PsiOOBinaryExpressionImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright 2013 Artem Melentyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javaoo.idea; - -import com.intellij.psi.PsiBinaryExpression; -import com.intellij.psi.PsiType; -import com.intellij.psi.impl.source.resolve.JavaResolveCache; -import com.intellij.psi.impl.source.tree.java.PsiBinaryExpressionImpl; -import com.intellij.psi.util.TypeConversionUtil; -import com.intellij.util.Function; - -public class PsiOOBinaryExpressionImpl extends PsiBinaryExpressionImpl { - @Override - public PsiType getType() { - return JavaResolveCache.getInstance(getProject()).getType(this, new Function() { - @Override - public PsiType fun(PsiBinaryExpression e) { - if (TypeConversionUtil.isBinaryOperatorApplicable(e.getOperationTokenType(), e.getLOperand(), e.getROperand(), false)) - return PsiOOBinaryExpressionImpl.super.getType(); - return OOResolver.getOOType(PsiOOBinaryExpressionImpl.this); - } - }); - } -} diff --git a/idea-oo-plugin/src/javaoo/idea/PsiOOPolyadicExpressionImpl.java b/idea-oo-plugin/src/javaoo/idea/PsiOOPolyadicExpressionImpl.java deleted file mode 100644 index 2c29f98..0000000 --- a/idea-oo-plugin/src/javaoo/idea/PsiOOPolyadicExpressionImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -/* Copyright 2013 Artem Melentyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javaoo.idea; - -import com.intellij.psi.PsiExpression; -import com.intellij.psi.PsiType; -import com.intellij.psi.impl.source.resolve.JavaResolveCache; -import com.intellij.psi.impl.source.tree.java.PsiPolyadicExpressionImpl; -import com.intellij.psi.tree.IElementType; -import com.intellij.psi.util.TypeConversionUtil; -import com.intellij.util.Function; -import com.intellij.util.NullableFunction; - -public class PsiOOPolyadicExpressionImpl extends PsiPolyadicExpressionImpl { - @Override - public PsiType getType() { - return JavaResolveCache.getInstance(getProject()).getType(this, OO_TYPE_EVALUATOR); - } - private static final Function OO_TYPE_EVALUATOR = new NullableFunction() { - @Override - public PsiType fun(PsiPolyadicExpressionImpl param) { - // copied from com.intellij.psi.impl.source.tree.java.PsiPolyadicExpressionImpl.doGetType - PsiExpression[] operands = param.getOperands(); - PsiType lType = null; - - IElementType sign = param.getOperationTokenType(); - for (int i=1; i - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javaoo.idea; - -import com.intellij.psi.PsiType; -import com.intellij.psi.impl.source.tree.java.PsiPrefixExpressionImpl; - -public class PsiOOPrefixExpressionImpl extends PsiPrefixExpressionImpl { - @Override - public PsiType getType() { - PsiType res = super.getType(); - return res != null ? res : OOResolver.getOOType(this); - } -} diff --git a/idea-oo-plugin/src/javaoo/idea/Util.java b/idea-oo-plugin/src/javaoo/idea/Util.java deleted file mode 100644 index d97ca9b..0000000 --- a/idea-oo-plugin/src/javaoo/idea/Util.java +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright 2013 Artem Melentyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javaoo.idea; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.impl.source.tree.JavaElementType; -import com.intellij.psi.tree.IElementType; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.function.Supplier; - -public class Util { - private Util() {} - - public static @NotNull Field findField(Class clas, Class type, String... fields) { - for (String field : fields) { - try { - Field f = clas.getDeclaredField(field); - if (f.getType() == type) { - f.setAccessible(true); - return f; - } - } catch (NoSuchFieldException e) { - // continue - } - } - Field found = null; - int count = 0; - for (Field f : clas.getDeclaredFields()) { - if (f.getType() == type) { - count++; - found = f; - } - } - if (count != 1) - sneakyThrow(new NoSuchFieldException(String.format("Can't find %s fields in %s class", Arrays.toString(fields), clas.getName()))); - found.setAccessible(true); - return found; - } - - public static Object get(Class clas, T obj, @NotNull Class type, String... fields) { - try { - return findField(clas, type, fields).get(obj); - } catch (IllegalAccessException e) { - throw sneakyThrow(e); - } - } - - public static void set(Class clas, Object obj, Class type, Object val, String... fields) { - try { - findField(clas, type, fields).set(obj, val); - } catch (Exception e) { - throw sneakyThrow(e); - } - } - - public static void setJavaElementConstructor(IElementType et, Supplier constructor) { - set(JavaElementType.JavaCompositeElementType.class, et, Supplier.class, constructor, "myConstructor", "a"); - } - - public static RuntimeException sneakyThrow(Throwable ex) { - return Util.sneakyThrowInner(ex); - } - private static T sneakyThrowInner(Throwable ex) throws T { - throw (T) ex; - } -} \ No newline at end of file diff --git a/idea-oo-plugin/test/ReflectionTest.java b/idea-oo-plugin/test/ReflectionTest.java deleted file mode 100644 index 73b0234..0000000 --- a/idea-oo-plugin/test/ReflectionTest.java +++ /dev/null @@ -1,29 +0,0 @@ -import com.intellij.codeInsight.daemon.impl.analysis.HighlightInfoHolder; -import com.intellij.openapi.extensions.impl.ExtensionComponentAdapter; -import com.intellij.openapi.extensions.impl.ExtensionPointImpl; -import com.intellij.psi.impl.source.tree.JavaElementType; -import com.intellij.psi.impl.source.tree.java.PsiBinaryExpressionImpl; -import javaoo.idea.Util; -import org.junit.Test; - -import java.util.List; -import java.util.function.Supplier; - -import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -// To check on Community AND Ultimate editions -public class ReflectionTest { - @Test public void findField() { - assertTrue(asList("myErrorCount", "b").contains(Util.findField(HighlightInfoHolder.class, int.class).getName())); - assertTrue(asList("myInfos", "f").contains(Util.findField(HighlightInfoHolder.class, List.class).getName())); - assertTrue(asList("myConstructor", "a").contains(Util.findField(JavaElementType.JavaCompositeElementType.class, Supplier.class).getName())); - assertEquals("myAdapters", Util.findField(ExtensionPointImpl.class, List.class, "myAdapters").getName()); - assertEquals("myImplementationClassOrName", Util.findField(ExtensionComponentAdapter.class, Object.class, "myImplementationClassOrName").getName()); - } - - @Test public void setJavaElementConstructor() { - Util.setJavaElementConstructor(JavaElementType.BINARY_EXPRESSION, PsiBinaryExpressionImpl::new); - } -} diff --git a/ideas b/ideas deleted file mode 100644 index 48b5b9b..0000000 --- a/ideas +++ /dev/null @@ -1,32 +0,0 @@ -todo: ! = #not(), ~ = #complement() - -CompoundAssignment overload: - a += b <=> a.mutableAdd(b) or a = a.add(b) - -increment/decrement: - a++ => a.postInc() - --a => a.preDec() - a+=b => a.addAssign(b) or a = a.add(b) - -translate to pure java. like delombok - via pe.getFiler(), after Attr phase - -bug: - lst[0] = lst[1] = 1; - -extension methods - str.iterator() -> static Iterator iterator(String s) - import static StringUtils.iterator; - @Extension public static Iterator iterator(String s); - -Flow dependent typing - final Object a = ...; if (a instanceof BigInteger) c = a.add(b) // without ((BigInteger)a).add(b) - -null operators: - obj?.method() -> obj==null ? null : obj.method() - obj ?: "null" -> obj==null ? "null" : obj - String? s <=> @Nullable String s - String s <=> @NotNull String s - -light syntax: - like python. diff --git a/images/bg_hr.png b/images/bg_hr.png new file mode 100644 index 0000000..514aee5 Binary files /dev/null and b/images/bg_hr.png differ diff --git a/images/blacktocat.png b/images/blacktocat.png new file mode 100644 index 0000000..e160053 Binary files /dev/null and b/images/blacktocat.png differ diff --git a/images/icon_download.png b/images/icon_download.png new file mode 100644 index 0000000..5a793f1 Binary files /dev/null and b/images/icon_download.png differ diff --git a/images/sprite_download.png b/images/sprite_download.png new file mode 100644 index 0000000..f9f8de2 Binary files /dev/null and b/images/sprite_download.png differ diff --git a/index.md b/index.md deleted file mode 120000 index 42061c0..0000000 --- a/index.md +++ /dev/null @@ -1 +0,0 @@ -README.md \ No newline at end of file diff --git a/index.md b/index.md new file mode 100644 index 0000000..6d03092 --- /dev/null +++ b/index.md @@ -0,0 +1,242 @@ +# Java Operator Overloading # + +Java-OO is a modular extension (plugin) to Java compilers and IDEs +for ([Scala-like]) [Operator Overloading] support. +Works with standard JavaC compiler, [Netbeans IDE], [Eclipse IDE], [IntelliJ IDEA] IDE and any build tools. + +Example (see other examples at [examples/](https://github.com/amelentev/java-oo/tree/master/javac-oo-mvndemo/src/) dir): + +```java +import java.math.*; +import java.util.*; +public class Test { + public static void main(String[] args) { + BigInteger a = BigInteger.valueOf(1), // without OO + b = 2, // with OO + + c1 = a.negate().add(b.multiply(b)).add(b.divide(a)), // without OO + c2 = -a + b*b + b/a; // with OO + + if (c1.compareTo(c2)<0 || c1.compareTo(c2)>0) // without OO + System.out.println("impossible"); + if (c1c2) // with OO + System.out.println("impossible"); + + HashMap map = new HashMap<>(); + if (!map.containsKey("qwe")) map.put("qwe", map.get("asd")); // without OO + if (map["qwe"]==null) map["qwe"] = map["asd"]; // with OO + } +} +``` + +# Versions # + + JavaC/Netbeans: 0.5 + JavaC8: 0.5 + Eclipse: 0.5 + IntelliJ IDEA: 0.5 + +Note plugin versions are independent. If version for X > version for Y then it doesn't mean Y is behind feature wise. + +# News # +14 July 2016. As a workaround [Eclipse plugin](#Eclipse) works fine on Eclipse 4.4+ if you install [Scala IDE] plugin first. + +2 Feb 2016. [IntelliJ IDEA](#IDEA) plugin v0.5 released with support of IDEA 15. Requires Java8 to run the plugin. + +10 April 2015. [IntelliJ IDEA](#IDEA) plugin v0.4.1 released with support of IDEA 14.1. + +27 January 2015. Eclipse-oo-plugin version 0.5 released with support of [reverse binary operator overload][operatorRev]. + +2 December 2014. New feature: [Reverse binary operator overload via `operatorRev` methods][operatorRev].
    +Plugin versions updated:
    +[JavaC7 & JavaC8](#javac): 0.5
    +[IntelliJ IDEA](#IDEA): 0.4. Support of IDEA 14 + +31 May 2014. Javac8 plugin version 0.1.1 released. Removed runtime depencendy on nbjavac. + +24 May 2014. [IntelliJ IDEA](#IDEA) plugin v0.3.1 released. Bugfixes for IDEA 13 Ultimate and for type resolution for binary expressions with primitives. + +30 April 2014. [IJPLA] published a [paper] about Java-OO. + +3 Feb 2014. New JavaC8 plugin version 0.1 for JDK8 was released. +It has the same features as JavaC plugin for JDK7 but doesn't work in Netbeans yet. + +12 Jan 2014. JavaC plugin version 0.4 and Eclipse plugin version 0.4 released. +Now operator overloading perform autoboxing/autounboxing primitive to/from wrapper types where appropriate. +Fixed [javac plugin bug with index-set OO](https://github.com/amelentev/java-oo/issues/13). + +3 Jan 2014. JavaC plugin version 0.3 released. +Fixed [#10 javac: binary operator adds erroneous cast on 1st operand](https://github.com/amelentev/java-oo/issues/10). + +8 Sep 2013. Eclipse plugin version 0.3 released. +Removed copypasta from Eclipse Compiler. Plugin should be more steady agains compiler changes. + +14 May 2013. [IntelliJ IDEA](#IDEA) IDE plugin v0.2.1 with IDEA Ultimate Edition support. + +17 Apr 2013. [IntelliJ IDEA](#IDEA) IDE plugin v0.2. + +26 Nov 2012. [Version 0.2] released. New feature: [Assignment operator overloading](https://github.com/amelentev/java-oo/issues/4) via static _#valueOf_ method. + +# Installation # + + + +## javac, ant, etc ## +Just add to classpath: [javac8-oo-plugin.jar] for JDK8 or [javac-oo-plugin.jar] for JDK7. + +``` +javac -cp javac8-oo-plugin.jar +``` + +Demo at [examples/compile.sh](https://github.com/amelentev/java-oo/blob/master/javac-oo-mvndemo/src/compile.sh) + + + +## [Eclipse IDE] update site ## +Click in menu: `Help - Install New Software`. Enter in `Work with` field: + + http://amelentev.github.io/eclipse.jdt-oo-site/ + +Tested on Eclipse Standard 4.3.2. Should work with older versions too.
    +To work on 4.4+ you need to install [Scala IDE] plugin (or similar plugin with Equanox weaving). You can find it in `Help -> Eclipse Marketplace`. This is workaround until normal solution will be found. Tested on 4.4 and 4.6. + +## [Netbeans IDE] ## +1. Add [javac-oo-plugin.jar] as compile or processor library to Netbeans. +2. Enable "Annotation Processing in Editor": `Project Properties -> Build -> Compiling`. + +Tested on 7.2.1 + +
    + +## [IntelliJ IDEA] IDE ## +1. Install [Java Operator Overloading support](https://plugins.jetbrains.com/idea/plugin/7224-java-operator-overloading-support) plugin: `File -> Settings -> Plugins -> Browse repositories`. Mirror: [idea-oo-plugin.jar])
    +For [Maven projects](#maven) installation is done. IDEA should setup everything according to pom.xml.
    +For other project types:
    +2. Add [javac8-oo-plugin.jar] as compile or processor library. +3. Enable Annotation Processing: +`Menu File -> Settings -> Compiler -> Annotation Processing -> Enable annotation processing` +4. Make sure you use `javac` compiler in `Settings -> Java Compiler -> Use compiler`.
    +Tested on IDEA 2016.3.3. + +### Android project in IDEA 12 ### +Add [javac-oo-plugin.jar] to `File - Settings - Compiler - Annotation Processors - Processor path` + +### Android Studio (IDEA 13) / Gradle ### +add to `build.gradle`: + +``` +repositories { + maven { url 'http://amelentev.github.io/mvnrepo/' } +} +dependencies { + compile 'java-oo:javac-oo-plugin:0.5' +} +``` + +
    + +## Maven ## +Look at [javac-oo-mvndemo/pom.xml](https://github.com/amelentev/java-oo/blob/master/javac-oo-mvndemo/pom.xml) + +# Details # + +Read the [paper] to learn more. +Supported operators (operator to method name map): + +binary: + + | OPERATOR | METHOD NAME| + ------------------------- + | + | add | + | - | subtract | + | * | multiply | + | / | divide | + | % | remainder | + | & | and | + | | | or | + | ^ | xor | + | << | shiftLeft | + | >> | shiftRight | + +If left operand has no such method then the plugin will try to use ['reverse' method `Rev`][operatorRev] on right operand. +So `2*a` will be transformed to `a.multiplyRev(2)` if `a` has such method. + +unary: + + | - | negate | + | ~ | not | + +comparison: + + | <, <=, >, >= | compareTo | example: `a < b` <=> `a.compareTo(b)<0` + `==` and `!=` are not overloadable because it will break things + +index: + + | [] | get | `v = lst[i]` <=> `v = lst.get(i)` + | []= | set, put | `map[s] = v` <=> `map.put(s,v)`, `lst[i] = v` <=> `lst.set(i,v)` + +assignment: + + | var = expr | var = VarClass.valueOf(expr) | + +if `expr` is not assignable to `var` and `var` is an instance of `VarClass` and `expr` has type `ExprType` and there are static method `VarClass#valueOf(ExprType)`
    +then `var = expr` is transformed to `var = VarClass.valueOf(expr)`. +example:
    +`BigInteger a = 1` is transformed to `BigInteger a = BigInteger.valueOf(1)` + +These methods exists in many java classes (example: BigInteger, BigDecimal) so you can +use operators on them "out of the box". Or you can add these methods to your classes to use OO (see [examples/Vector.java](https://github.com/amelentev/java-oo/blob/master/javac-oo-mvndemo/src//Vector.java)). + + +## Subprojects / Implementation details + +- javac-oo-plugin + - Plugin to JavaC 1.7 and [Netbeans IDE] for operator overloading. Based on [javac-oo]. + - Building via [maven] at top level: `cd java-oo; mvn clean install`. Or import maven settings in your IDE. + +- eclipse-oo-plugin + - [Eclipse IDE](JDT) plugin for OO support. + - Patching Eclipse Java Compiler to allow OO. + - Build in Eclipse with [PDE], [AJDT and Equanox Weaving] plugins. Run as Eclipse application with [equinox weaving enabled][equinox-weaving-launcher]. + +- idea-oo-plugin + - [IntelliJ IDEA] IDE plugin for OO support. + - Modify Java frontend in IDEA to allow OO. Need javac-oo-plugin to actually compile. + - Build in IDEA. Run as IDEA plugin. + +- by-products: + - [javac-oo] + - Patched version of JavaC 1.7 for Operator Overloading support. If you need standalone javac compiler with OO. + - Build via ant or netbeans: http://openjdk.java.net/groups/compiler/README.html#build + - [eclipse-oo] + - Eclipse [Java Developer Tools] fork for Operator Overloading. + - Use it if you need native [Eclipse IDE] support, or Eclipse Java Compiler support. + - Build in Eclipse with [PDE]. Run as Eclipse application. + +## Publications +["Java Modular Extension for Operator Overloading", IJPLA, April 2014.](https://github.com/amelentev/java-oo/raw/master/doc/ijpla.pdf) + +[Scala-like]: http://www.slideshare.net/joeygibson/operator-overloading-in-scala-2923973 +[javac-oo]: https://bitbucket.org/amelentev/javac-oo +[lombok]: http://projectlombok.org/ +[lombok-oo]: https://github.com/amelentev/lombok-oo +[Eclipse IDE]: http://eclipse.org/ +[Netbeans IDE]: http://www.netbeans.org/ +[IntelliJ IDEA]: http://www.jetbrains.com/idea/ +[Java Developer Tools]: http://eclipse.org/jdt/ +[eclipse-oo]: https://github.com/amelentev/eclipse.jdt-oo +[Operator Overloading]: http://en.wikipedia.org/wiki/Operator_overloading +[AJDT and Equanox Weaving]: http://wiki.eclipse.org/Equinox_Weaving_QuickStart +[PDE]: http://www.eclipse.org/pde/ +[maven]: https://maven.apache.org/ + +[javac-oo-plugin.jar]: http://amelentev.github.io/mvnrepo/java-oo/javac-oo-plugin/0.5/javac-oo-plugin-0.5.jar +[javac8-oo-plugin.jar]: http://amelentev.github.io/mvnrepo/java-oo/javac8-oo-plugin/0.5/javac8-oo-plugin-0.5.jar +[idea-oo-plugin.jar]: http://amelentev.github.io/mvnrepo/java-oo/idea-oo-plugin/idea-oo-plugin-0.5.jar +[IJPLA]: http://airccse.org/journal/ijpla/current2014.html#apr +[paper]: https://github.com/amelentev/java-oo/raw/master/doc/ijpla.pdf +[operatorRev]: https://github.com/amelentev/java-oo/issues/25 +[equinox-weaving-launcher]: https://github.com/milessabin/equinox-weaving-launcher +[Scala IDE]: http://scala-ide.org/download/current.html +[Version 0.2]: https://github.com/amelentev/java-oo/issues?milestone=1&state=closed diff --git a/javac-oo-mvndemo/.classpath b/javac-oo-mvndemo/.classpath deleted file mode 100644 index 5910b55..0000000 --- a/javac-oo-mvndemo/.classpath +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/javac-oo-mvndemo/.idea/.name b/javac-oo-mvndemo/.idea/.name deleted file mode 100644 index f4dfd02..0000000 --- a/javac-oo-mvndemo/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -javac-oo-mvndemo \ No newline at end of file diff --git a/javac-oo-mvndemo/.idea/compiler.xml b/javac-oo-mvndemo/.idea/compiler.xml deleted file mode 100644 index 8ac7584..0000000 --- a/javac-oo-mvndemo/.idea/compiler.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - \ No newline at end of file diff --git a/javac-oo-mvndemo/.idea/copyright/profiles_settings.xml b/javac-oo-mvndemo/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/javac-oo-mvndemo/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/javac-oo-mvndemo/.idea/encodings.xml b/javac-oo-mvndemo/.idea/encodings.xml deleted file mode 100644 index f758959..0000000 --- a/javac-oo-mvndemo/.idea/encodings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/javac-oo-mvndemo/.idea/misc.xml b/javac-oo-mvndemo/.idea/misc.xml deleted file mode 100644 index 65e0ff4..0000000 --- a/javac-oo-mvndemo/.idea/misc.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/javac-oo-mvndemo/.idea/modules.xml b/javac-oo-mvndemo/.idea/modules.xml deleted file mode 100644 index 1bcee00..0000000 --- a/javac-oo-mvndemo/.idea/modules.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/javac-oo-mvndemo/.idea/scopes/scope_settings.xml b/javac-oo-mvndemo/.idea/scopes/scope_settings.xml deleted file mode 100644 index 922003b..0000000 --- a/javac-oo-mvndemo/.idea/scopes/scope_settings.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/javac-oo-mvndemo/.idea/vcs.xml b/javac-oo-mvndemo/.idea/vcs.xml deleted file mode 100644 index 21cbaa6..0000000 --- a/javac-oo-mvndemo/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/javac-oo-mvndemo/.project b/javac-oo-mvndemo/.project deleted file mode 100644 index d73ed2a..0000000 --- a/javac-oo-mvndemo/.project +++ /dev/null @@ -1,23 +0,0 @@ - - - javac-oo-mvndemo - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - - diff --git a/javac-oo-mvndemo/.settings/org.eclipse.jdt.core.prefs b/javac-oo-mvndemo/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index ec4300d..0000000 --- a/javac-oo-mvndemo/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,5 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 diff --git a/javac-oo-mvndemo/.settings/org.eclipse.m2e.core.prefs b/javac-oo-mvndemo/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f..0000000 --- a/javac-oo-mvndemo/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/javac-oo-mvndemo/pom.xml b/javac-oo-mvndemo/pom.xml deleted file mode 100644 index 1792684..0000000 --- a/javac-oo-mvndemo/pom.xml +++ /dev/null @@ -1,47 +0,0 @@ - - 4.0.0 - java-oo - javac-oo-mvndemo - 0.6-SNAPSHOT - - - java-oo - - - javac8-oo-plugin - 0.5 - provided - - - - ${project.basedir}/src - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.8 - 1.8 - - - - - - - - amelentev - http://amelentev.github.io/mvnrepo/ - - - - - - deploy - file:///home/mart/src/my/gitmvnrepo - - - diff --git a/javac-oo-mvndemo/src/Cmp.java b/javac-oo-mvndemo/src/Cmp.java deleted file mode 100644 index 86eb37a..0000000 --- a/javac-oo-mvndemo/src/Cmp.java +++ /dev/null @@ -1,21 +0,0 @@ -import java.math.BigDecimal; - -public class Cmp { - public static boolean test() { - // without OO: - BigDecimal a = BigDecimal.valueOf(0), - // with OO: - b = 1, - c = 2; - // without OO: - boolean r1 = a.compareTo(b)<0 && c.compareTo(a)>0 && (b.add(b)).compareTo(c)>=0 && c.compareTo(b.add(b))>=0; - // with OO: - boolean r2 = a < b && c > a && b+b >= c && c >= b+b; - System.out.printf("(a < b && c > a && b >= c && c >= b) = %b\n", r2); - System.out.printf("Here a,b,c's class is %s, and a=%s, b=%s, c=%s\n", a.getClass().getSimpleName(), a, b, c); - return r1 && r2; - } - public static void main(String[] args) { - System.out.println(Cmp.test()); - } -} diff --git a/javac-oo-mvndemo/src/Demo.java b/javac-oo-mvndemo/src/Demo.java deleted file mode 100644 index cdb50b9..0000000 --- a/javac-oo-mvndemo/src/Demo.java +++ /dev/null @@ -1,19 +0,0 @@ -import java.math.*; -import java.util.*; -public class Demo { - public static void main(String[] args) { - BigInteger a = BigInteger.valueOf(1), // without OO - b = 2, // with OO - - c1 = a.negate().add(b.multiply(b)).add(b.divide(a)), // without OO - c2 = -a + b*b + b/a; // with OO - - if (c1.compareTo(c2)<0 || c1.compareTo(c2)>0) System.out.println("impossible"); // without OO - if (c1c2) System.out.println("impossible"); // with OO - - HashMap map = new HashMap<>(); - if (!map.containsKey("qwe")) map.put("qwe", "asd"); // without OO - if (map["qwe"]==null) map["qwe"] = "asd"; // with OO - } - public static boolean test() { Demo.main(null); return true; } -} diff --git a/javac-oo-mvndemo/src/ListIndexGet.java b/javac-oo-mvndemo/src/ListIndexGet.java deleted file mode 100644 index 4c99d8d..0000000 --- a/javac-oo-mvndemo/src/ListIndexGet.java +++ /dev/null @@ -1,16 +0,0 @@ -import java.util.Arrays; -import java.util.List; - -public class ListIndexGet { - public static boolean test() { - List lst = Arrays.asList(1); - // without OO: - int resl1 = lst.get(0); - // with OO: - int resl2 = lst[0]; - return resl2 == resl1; - } - public static void main(String[] args) { - System.out.println(ListIndexGet.test()); - } -} \ No newline at end of file diff --git a/javac-oo-mvndemo/src/ListIndexSet.java b/javac-oo-mvndemo/src/ListIndexSet.java deleted file mode 100644 index a03b5e0..0000000 --- a/javac-oo-mvndemo/src/ListIndexSet.java +++ /dev/null @@ -1,18 +0,0 @@ -import java.lang.Integer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class ListIndexSet { - public static boolean test() { - List lst = new ArrayList<>(Arrays.asList(1)); - // without OO: - lst.set(0, 1); - // with OO: - lst[0] = 2; - return lst.get(0)==2; - } - public static void main(String[] args) { - System.out.println(ListIndexSet.test()); - } -} diff --git a/javac-oo-mvndemo/src/MapIndex.java b/javac-oo-mvndemo/src/MapIndex.java deleted file mode 100644 index 1bf4c38..0000000 --- a/javac-oo-mvndemo/src/MapIndex.java +++ /dev/null @@ -1,18 +0,0 @@ -import java.util.HashMap; - -public class MapIndex { - public static boolean test() { - HashMap map = new HashMap<>(); - // without OO: - map.put("qwe", "qwe"); - String r1 = map.get("qwe"); - // with OO: - map["qwe"] = "asd"; - String r2 = map["qwe"]; - - return "asd".equals(r2) && "qwe".equals(r1); - } - public static void main(String[] args) { - System.out.println(MapIndex.test()); - } -} diff --git a/javac-oo-mvndemo/src/Math.java b/javac-oo-mvndemo/src/Math.java deleted file mode 100644 index 6354f09..0000000 --- a/javac-oo-mvndemo/src/Math.java +++ /dev/null @@ -1,16 +0,0 @@ -import java.math.BigInteger; - -public class Math { - public static boolean test() { - BigInteger a = BigInteger.ONE, - b = BigInteger.TEN; - // without OO: - BigInteger r1 = a.negate().add(b.multiply(b)).subtract(b.divide(a)); - // with OO: - final BigInteger r2 = -a + b * b - b/a; - return r1.equals(r2); - } - public static void main(String[] args) { - System.out.println(Math.test()); - } -} diff --git a/javac-oo-mvndemo/src/ValueOf.java b/javac-oo-mvndemo/src/ValueOf.java deleted file mode 100644 index 1402ff6..0000000 --- a/javac-oo-mvndemo/src/ValueOf.java +++ /dev/null @@ -1,12 +0,0 @@ -import java.math.*; - -public class ValueOf { - public static boolean test() { - BigInteger a = BigInteger.valueOf(123); - BigInteger b = 123; - return a.equals(b); - } - public static void main(String []args) { - System.out.println(test()); - } -} diff --git a/javac-oo-mvndemo/src/Vector.java b/javac-oo-mvndemo/src/Vector.java deleted file mode 100644 index 8e5c010..0000000 --- a/javac-oo-mvndemo/src/Vector.java +++ /dev/null @@ -1,72 +0,0 @@ -import java.util.Arrays; - -public class Vector { - int[] d; - public Vector(int... d) { - this.d = d; - } - public static Vector valueOf(int[] d) { // for implicit type conversion - return new Vector(d); - } - public Vector add(Vector a) { - assert d.length == a.d.length; - int[] n = d.clone(); - for (int i = 0; i < a.d.length; i++) - n[i] += a.d[i]; - return new Vector(n); - } - public Vector multiply(int a) { - int[] n = d.clone(); - for (int i = 0; i < d.length; i++) - n[i] *= a; - return new Vector(n); - } - public Vector multiplyRev(int a) { - return multiply(a); - } - public int get(int i) { - return d[i]; - } - public String toString() { - return Arrays.toString(d); - } - public boolean equals(Object obj) { - if (obj==null || obj.getClass()!=getClass()) return false; - return Arrays.equals(d, ((Vector)obj).d); - } - - public Vector multiply(Matrix A) { - assert d.length == A.n(); - int res[] = new int[A.m()]; - for (int j = 0; j < A.m(); j++) - for (int i = 0; i < A.n(); i++) - res[j] += d[i] * A[i][j]; - return new Vector(res); - } - - public static class Matrix { - int d[][]; - public Matrix(int d[][]) { - for (int[] a : d) - assert a.length == d[0].length; - this.d = d; - } - public int n() { return d.length; } - public int m() { return d[0].length; } - public Vector get(int i) { return new Vector(d[i]); } - public String toString() { return Arrays.deepToString(d); } - } - - public static boolean test() { - Vector a = new Vector(1,2), - b = new int[]{2,3}, - c = a + 2*b; - if (!"[5, 8]".equals(c.toString())) - return false; - Matrix A = new Matrix(new int[][] {{1,2,3}, {4,5,6}}); - return (a*A).equals(new Vector(9,12,15)); - } - public static void main(String[] args) { - System.out.println(test()); - } -} diff --git a/javac-oo-mvndemo/src/compile.sh b/javac-oo-mvndemo/src/compile.sh deleted file mode 100755 index 4c66c91..0000000 --- a/javac-oo-mvndemo/src/compile.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -javac -cp ../../javac-oo-plugin/target/*jar *.java diff --git a/javac-oo-mvndemo/src/compile8.sh b/javac-oo-mvndemo/src/compile8.sh deleted file mode 100755 index 64d066c..0000000 --- a/javac-oo-mvndemo/src/compile8.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -javac -cp ../../javac8-oo-plugin/target/*jar *.java diff --git a/javac-oo-plugin/LICENSE b/javac-oo-plugin/LICENSE deleted file mode 100644 index b40a0f4..0000000 --- a/javac-oo-plugin/LICENSE +++ /dev/null @@ -1,347 +0,0 @@ -The GNU General Public License (GPL) - -Version 2, June 1991 - -Copyright (C) 1989, 1991 Free Software Foundation, Inc. -59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Everyone is permitted to copy and distribute verbatim copies of this license -document, but changing it is not allowed. - -Preamble - -The licenses for most software are designed to take away your freedom to share -and change it. By contrast, the GNU General Public License is intended to -guarantee your freedom to share and change free software--to make sure the -software is free for all its users. This General Public License applies to -most of the Free Software Foundation's software and to any other program whose -authors commit to using it. (Some other Free Software Foundation software is -covered by the GNU Library General Public License instead.) You can apply it to -your programs, too. - -When we speak of free software, we are referring to freedom, not price. Our -General Public Licenses are designed to make sure that you have the freedom to -distribute copies of free software (and charge for this service if you wish), -that you receive source code or can get it if you want it, that you can change -the software or use pieces of it in new free programs; and that you know you -can do these things. - -To protect your rights, we need to make restrictions that forbid anyone to deny -you these rights or to ask you to surrender the rights. These restrictions -translate to certain responsibilities for you if you distribute copies of the -software, or if you modify it. - -For example, if you distribute copies of such a program, whether gratis or for -a fee, you must give the recipients all the rights that you have. You must -make sure that they, too, receive or can get the source code. And you must -show them these terms so they know their rights. - -We protect your rights with two steps: (1) copyright the software, and (2) -offer you this license which gives you legal permission to copy, distribute -and/or modify the software. - -Also, for each author's protection and ours, we want to make certain that -everyone understands that there is no warranty for this free software. If the -software is modified by someone else and passed on, we want its recipients to -know that what they have is not the original, so that any problems introduced -by others will not reflect on the original authors' reputations. - -Finally, any free program is threatened constantly by software patents. We -wish to avoid the danger that redistributors of a free program will -individually obtain patent licenses, in effect making the program proprietary. -To prevent this, we have made it clear that any patent must be licensed for -everyone's free use or not licensed at all. - -The precise terms and conditions for copying, distribution and modification -follow. - -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - -0. This License applies to any program or other work which contains a notice -placed by the copyright holder saying it may be distributed under the terms of -this General Public License. The "Program", below, refers to any such program -or work, and a "work based on the Program" means either the Program or any -derivative work under copyright law: that is to say, a work containing the -Program or a portion of it, either verbatim or with modifications and/or -translated into another language. (Hereinafter, translation is included -without limitation in the term "modification".) Each licensee is addressed as -"you". - -Activities other than copying, distribution and modification are not covered by -this License; they are outside its scope. The act of running the Program is -not restricted, and the output from the Program is covered only if its contents -constitute a work based on the Program (independent of having been made by -running the Program). Whether that is true depends on what the Program does. - -1. You may copy and distribute verbatim copies of the Program's source code as -you receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice and -disclaimer of warranty; keep intact all the notices that refer to this License -and to the absence of any warranty; and give any other recipients of the -Program a copy of this License along with the Program. - -You may charge a fee for the physical act of transferring a copy, and you may -at your option offer warranty protection in exchange for a fee. - -2. You may modify your copy or copies of the Program or any portion of it, thus -forming a work based on the Program, and copy and distribute such modifications -or work under the terms of Section 1 above, provided that you also meet all of -these conditions: - - a) You must cause the modified files to carry prominent notices stating - that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in whole or - in part contains or is derived from the Program or any part thereof, to be - licensed as a whole at no charge to all third parties under the terms of - this License. - - c) If the modified program normally reads commands interactively when run, - you must cause it, when started running for such interactive use in the - most ordinary way, to print or display an announcement including an - appropriate copyright notice and a notice that there is no warranty (or - else, saying that you provide a warranty) and that users may redistribute - the program under these conditions, and telling the user how to view a copy - of this License. (Exception: if the Program itself is interactive but does - not normally print such an announcement, your work based on the Program is - not required to print an announcement.) - -These requirements apply to the modified work as a whole. If identifiable -sections of that work are not derived from the Program, and can be reasonably -considered independent and separate works in themselves, then this License, and -its terms, do not apply to those sections when you distribute them as separate -works. But when you distribute the same sections as part of a whole which is a -work based on the Program, the distribution of the whole must be on the terms -of this License, whose permissions for other licensees extend to the entire -whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest your -rights to work written entirely by you; rather, the intent is to exercise the -right to control the distribution of derivative or collective works based on -the Program. - -In addition, mere aggregation of another work not based on the Program with the -Program (or with a work based on the Program) on a volume of a storage or -distribution medium does not bring the other work under the scope of this -License. - -3. You may copy and distribute the Program (or a work based on it, under -Section 2) in object code or executable form under the terms of Sections 1 and -2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable source - code, which must be distributed under the terms of Sections 1 and 2 above - on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three years, to - give any third party, for a charge no more than your cost of physically - performing source distribution, a complete machine-readable copy of the - corresponding source code, to be distributed under the terms of Sections 1 - and 2 above on a medium customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer to - distribute corresponding source code. (This alternative is allowed only - for noncommercial distribution and only if you received the program in - object code or executable form with such an offer, in accord with - Subsection b above.) - -The source code for a work means the preferred form of the work for making -modifications to it. For an executable work, complete source code means all -the source code for all modules it contains, plus any associated interface -definition files, plus the scripts used to control compilation and installation -of the executable. However, as a special exception, the source code -distributed need not include anything that is normally distributed (in either -source or binary form) with the major components (compiler, kernel, and so on) -of the operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the source -code from the same place counts as distribution of the source code, even though -third parties are not compelled to copy the source along with the object code. - -4. You may not copy, modify, sublicense, or distribute the Program except as -expressly provided under this License. Any attempt otherwise to copy, modify, -sublicense or distribute the Program is void, and will automatically terminate -your rights under this License. However, parties who have received copies, or -rights, from you under this License will not have their licenses terminated so -long as such parties remain in full compliance. - -5. You are not required to accept this License, since you have not signed it. -However, nothing else grants you permission to modify or distribute the Program -or its derivative works. These actions are prohibited by law if you do not -accept this License. Therefore, by modifying or distributing the Program (or -any work based on the Program), you indicate your acceptance of this License to -do so, and all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - -6. Each time you redistribute the Program (or any work based on the Program), -the recipient automatically receives a license from the original licensor to -copy, distribute or modify the Program subject to these terms and conditions. -You may not impose any further restrictions on the recipients' exercise of the -rights granted herein. You are not responsible for enforcing compliance by -third parties to this License. - -7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), conditions -are imposed on you (whether by court order, agreement or otherwise) that -contradict the conditions of this License, they do not excuse you from the -conditions of this License. If you cannot distribute so as to satisfy -simultaneously your obligations under this License and any other pertinent -obligations, then as a consequence you may not distribute the Program at all. -For example, if a patent license would not permit royalty-free redistribution -of the Program by all those who receive copies directly or indirectly through -you, then the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply and -the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any patents or -other property right claims or to contest validity of any such claims; this -section has the sole purpose of protecting the integrity of the free software -distribution system, which is implemented by public license practices. Many -people have made generous contributions to the wide range of software -distributed through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing to -distribute software through any other system and a licensee cannot impose that -choice. - -This section is intended to make thoroughly clear what is believed to be a -consequence of the rest of this License. - -8. If the distribution and/or use of the Program is restricted in certain -countries either by patents or by copyrighted interfaces, the original -copyright holder who places the Program under this License may add an explicit -geographical distribution limitation excluding those countries, so that -distribution is permitted only in or among countries not thus excluded. In -such case, this License incorporates the limitation as if written in the body -of this License. - -9. The Free Software Foundation may publish revised and/or new versions of the -General Public License from time to time. Such new versions will be similar in -spirit to the present version, but may differ in detail to address new problems -or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any later -version", you have the option of following the terms and conditions either of -that version or of any later version published by the Free Software Foundation. -If the Program does not specify a version number of this License, you may -choose any version ever published by the Free Software Foundation. - -10. If you wish to incorporate parts of the Program into other free programs -whose distribution conditions are different, write to the author to ask for -permission. For software which is copyrighted by the Free Software Foundation, -write to the Free Software Foundation; we sometimes make exceptions for this. -Our decision will be guided by the two goals of preserving the free status of -all derivatives of our free software and of promoting the sharing and reuse of -software generally. - -NO WARRANTY - -11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR -THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE -STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE -PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND -PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, -YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - -12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL -ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE -PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR -INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA -BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER -OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -END OF TERMS AND CONDITIONS - -How to Apply These Terms to Your New Programs - -If you develop a new program, and you want it to be of the greatest possible -use to the public, the best way to achieve this is to make it free software -which everyone can redistribute and change under these terms. - -To do so, attach the following notices to the program. It is safest to attach -them to the start of each source file to most effectively convey the exclusion -of warranty; and each file should have at least the "copyright" line and a -pointer to where the full notice is found. - - One line to give the program's name and a brief idea of what it does. - - Copyright (C) - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., 59 - Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this when it -starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author Gnomovision comes - with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free - software, and you are welcome to redistribute it under certain conditions; - type 'show c' for details. - -The hypothetical commands 'show w' and 'show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may be -called something other than 'show w' and 'show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your school, -if any, to sign a "copyright disclaimer" for the program, if necessary. Here -is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - 'Gnomovision' (which makes passes at compilers) written by James Hacker. - - signature of Ty Coon, 1 April 1989 - - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General Public -License instead of this License. - - -"CLASSPATH" EXCEPTION TO THE GPL - -Certain source files distributed by Oracle America and/or its affiliates are -subject to the following clarification and special exception to the GPL, but -only where Oracle has expressly included in the particular source file's header -the words "Oracle designates this particular file as subject to the "Classpath" -exception as provided by Oracle in the LICENSE file that accompanied this code." - - Linking this library statically or dynamically with other modules is making - a combined work based on this library. Thus, the terms and conditions of - the GNU General Public License cover the whole combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent modules, - and to copy and distribute the resulting executable under terms of your - choice, provided that you also meet, for each linked independent module, - the terms and conditions of the license of that module. An independent - module is a module which is not derived from or based on this library. If - you modify this library, you may extend this exception to your version of - the library, but you are not obligated to do so. If you do not wish to do - so, delete this exception statement from your version. diff --git a/javac-oo-plugin/ideas b/javac-oo-plugin/ideas deleted file mode 100644 index 2ecc47f..0000000 --- a/javac-oo-plugin/ideas +++ /dev/null @@ -1,3 +0,0 @@ -dynamic class transform: - get class binary via classloader, transform, inject into classloader, reconstruct objects. - for Attr, NBAttr, etc diff --git a/javac-oo-plugin/pom.xml b/javac-oo-plugin/pom.xml deleted file mode 100644 index f31d0cd..0000000 --- a/javac-oo-plugin/pom.xml +++ /dev/null @@ -1,42 +0,0 @@ - - 4.0.0 - - java-oo - parent - 0.6-SNAPSHOT - ../pom.xml - - javac-oo-plugin - jar - Java Operator Overloading plugin for javac - http://amelentev.github.io/java-oo/ - - - junit - junit - 4.11 - test - - - com.oracle.java - tools - 1.7 - system - ${java.home}/../lib/tools.jar - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - -proc:none - - - - - diff --git a/javac-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOAttr.java b/javac-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOAttr.java deleted file mode 100644 index 46ec68e..0000000 --- a/javac-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOAttr.java +++ /dev/null @@ -1,152 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the - * GNU Public License v2.0 + OpenJDK assembly exception. - * - * Contributors: - * Artem Melentyev - initial API and implementation - * some code from from OpenJDK langtools (GPL2 + assembly exception) - ******************************************************************************/ -package com.sun.tools.javac.comp; - -import com.sun.source.tree.Tree; -import com.sun.tools.javac.code.Kinds; -import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.List; -import javaoo.OOMethods; - -import java.util.Map; -import java.util.WeakHashMap; - -import static com.sun.tools.javac.code.Kinds.VAL; -import static com.sun.tools.javac.code.Kinds.VAR; -import static com.sun.tools.javac.code.TypeTags.*; - -// XXX: NBAttr? -public class OOAttr extends Attr { - protected OOAttr(Context context) { - super(context); - } - public static OOAttr instance(Context context) { - Attr attr = context.get(attrKey); - if (attr instanceof OOAttr) return (OOAttr) attr; - context.put(attrKey, (Attr)null); - return new OOAttr(context); - } - - /** WeakHashMap to allow GC collect entries. Because we don't need them then they are gone */ - Map translateMap = new WeakHashMap<>(); - - private Symbol findMethods(Type site, List argts, String... methodNames) { - for (String methodName : methodNames) { - Symbol m = rs.findMethod(env, site, names.fromString(methodName), argts, null, false, false, false); // without boxing - if (m.kind == Kinds.MTH) return m; - m = rs.findMethod(env, site, names.fromString(methodName), argts, null, true, false, false); // with boxing - if (m.kind == Kinds.MTH) return m; - } - return null; - } - - @Override - Type check(JCTree tree, Type owntype, int ownkind, int pkind, Type pt) { - if (owntype.tag != ERROR && pt.tag == CLASS && (ownkind & ~pkind) == 0) { - JCTree.JCExpression t = tryImplicitConversion(tree, owntype, pt); - if (t != null) { - translateMap.put(tree, t); - return tree.type = owntype; - } - } - return super.check(tree, owntype, ownkind, pkind, pt); - } - - /** try implicit conversion tree to pt type via #valueOf - * @return static valueOf method call iff successful */ - JCTree.JCMethodInvocation tryImplicitConversion(JCTree tree, Type owntype, Type req) { - if (!isBoxingAllowed(owntype, req)) - return null; - JCTree.JCExpression param = translateMap.get(tree); - // construct ".valueOf(tree)" static method call - tree.type = owntype; - make.pos = tree.pos; - for (String methodName : OOMethods.valueOf) { - JCTree.JCMethodInvocation method = make.Apply(null, - make.Select(make.Ident(pt.tsym), names.fromString(methodName)), - List.of(param == null ? (JCTree.JCExpression) tree : param)); - method.type = attribTree(method, env, pkind, pt); - if (types.isAssignable(method.type, req)) - return method; - } - return null; - } - boolean isBoxingAllowed(Type found, Type req) { - // similar to Check#checkType - if (req.tag == ERROR) - return false; // req - if (found.tag == FORALL) - return false; // chk.instantiatePoly(pos, (ForAll)found, req, convertWarner(pos, found, req)); - if (req.tag == NONE) - return false; //found; - if (types.isAssignable(found, req)) //convertWarner(pos, found, req))) - return false; // found; - if (found.tag <= DOUBLE && req.tag <= DOUBLE) - return false; // typeError(pos, diags.fragment("possible.loss.of.precision"), found, req); - if (found.isSuperBound()) { - //log.error(pos, "assignment.from.super-bound", found); - return false; //types.createErrorType(found); - } - if (req.isExtendsBound()) { - //log.error(pos, "assignment.to.extends-bound", req); - return false; //types.createErrorType(found); - } - return findMethods(req, List.of(found), OOMethods.valueOf) != null; - } - - @Override - public void visitAssign(JCTree.JCAssign tree) { - if (tree.lhs.getKind() == Tree.Kind.ARRAY_ACCESS) { // index-set OO: "a[i] = v" - JCTree.JCArrayAccess aa = (JCTree.JCArrayAccess) tree.lhs; - Type atype = attribExpr(aa.indexed, env); - if (!atype.isErroneous() && !types.isArray(atype)) { - Type itype = attribExpr(aa.index, env); - Type rhstype = attribExpr(tree.rhs, env); - Symbol m = findMethods(atype, List.of(itype, rhstype), OOMethods.indexSet); - if (m != null) { - JCTree.JCMethodInvocation mi = make.Apply(null, make.Select(aa.indexed, m), List.of(aa.index, tree.rhs)); - Type owntype = attribExpr(mi, env); - translateMap.put(tree, mi); - aa.type = rhstype; - check(aa, aa.type, VAR, VAR, Type.noType); - result = check(tree, owntype, VAL, pkind, pt); - return; - } - } - } - super.visitAssign(tree); - } - - @Override - public void visitIndexed(JCTree.JCArrayAccess tree) { - Type owntype = types.createErrorType(tree.type); - Type atype = attribExpr(tree.indexed, env); - if (types.isArray(atype)) { - attribExpr(tree.index, env, syms.intType); - owntype = types.elemtype(atype); - } else if (!atype.isErroneous()) { // index get - attribExpr(tree.index, env); - Symbol m = findMethods(atype, List.of(tree.index.type), OOMethods.indexGet); - if (m != null) { - JCTree.JCMethodInvocation mi = make.Apply(null, make.Select(tree.indexed, m), List.of(tree.index)); - attribExpr(mi, env); - translateMap.put(tree, mi); - owntype = mi.type; - } else - log.error(tree.pos(), "array.req.but.found", atype); - } - if ((pkind & VAR) == 0) owntype = types.capture(owntype); - result = check(tree, owntype, VAR, pkind, pt); - } -} diff --git a/javac-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOResolve.java b/javac-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOResolve.java deleted file mode 100644 index b8a2751..0000000 --- a/javac-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOResolve.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the - * GNU Public License v2.0 + OpenJDK assembly exception. - * - * Contributors: - * Artem Melentyev - initial API and implementation - ******************************************************************************/ -package com.sun.tools.javac.comp; - -import com.sun.tools.javac.code.Kinds; -import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.jvm.ByteCodes; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.List; -import com.sun.tools.javac.util.Name; -import javaoo.OOMethods; - -import static com.sun.tools.javac.code.Kinds.ABSENT_MTH; -import static com.sun.tools.javac.code.Kinds.ERR; - -public class OOResolve extends Resolve { - protected OOResolve(Context context) { - super(context); - } - public static OOResolve instance(Context context) { - Resolve res = context.get(resolveKey); - if (res instanceof OOResolve) return (OOResolve)res; - context.put(resolveKey, (Resolve)null); - return new OOResolve(context); - } - - final Symbol methodNotFound = new SymbolNotFoundError(ABSENT_MTH); - - private Symbol findOperatorMethod(Env env, Name name, List args) { - String methodName = args.tail.isEmpty() ? OOMethods.unary.get(name.toString()) : OOMethods.binary.get(name.toString()); - if (methodName == null) - return methodNotFound; - Symbol res = findMethod(env, args.head, names.fromString(methodName), args.tail, null, true, false, false); - if (res.kind != Kinds.MTH) { - args = args.reverse(); // try reverse with methodRev - res = findMethod(env, args.head, names.fromString(methodName + OOMethods.revSuffix), args.tail, null, true, false, false); - } - return res; - } - - @Override - Symbol findMethod(Env env, - Type site, - Name name, - List argtypes, - List typeargtypes, - boolean allowBoxing, - boolean useVarargs, - boolean operator) { - Symbol bestSoFar = super.findMethod(env, site, name, argtypes, typeargtypes, allowBoxing, useVarargs, operator); - if (bestSoFar.kind >= ERR && operator) { // try operator overloading - Symbol method = findOperatorMethod(env, name, argtypes); - if (method.kind == Kinds.MTH) { - bestSoFar = new Symbol.OperatorSymbol(method.name, method.type, ByteCodes.error+1, method); - if (OOMethods.compareTo.equals(method.name.toString())) { // change result type to boolean if - Type.MethodType oldmt = (Type.MethodType) method.type; - bestSoFar.type = new Type.MethodType(oldmt.argtypes, syms.booleanType, oldmt.thrown, oldmt.tsym); - } - } - } - return bestSoFar; - } -} diff --git a/javac-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOTransTypes.java b/javac-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOTransTypes.java deleted file mode 100644 index f8cf8b1..0000000 --- a/javac-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOTransTypes.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the - * GNU Public License v2.0 + OpenJDK assembly exception. - * - * Contributors: - * Artem Melentyev - initial API and implementation - ******************************************************************************/ -package com.sun.tools.javac.comp; - -import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Symtab; -import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.jvm.ByteCodes; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.tree.TreeMaker; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.List; -import javaoo.OOMethods; - -import java.lang.reflect.Field; - -public class OOTransTypes extends TransTypes { - private final Symtab syms; - private final TreeMaker make; - private final OOResolve rs; - private final OOAttr attr; - - public static OOTransTypes instance(Context context) { - TransTypes res = context.get(transTypesKey); - if (res instanceof OOTransTypes) return (OOTransTypes) res; - context.put(transTypesKey, (TransTypes)null); - return new OOTransTypes(context); - } - protected OOTransTypes(Context context) { - super(context); - syms = Symtab.instance(context); - make = TreeMaker.instance(context); - attr = OOAttr.instance(context); - rs = OOResolve.instance(context); - } - - private Env getEnv() { - try { - Field f = TransTypes.class.getDeclaredField("env"); - f.setAccessible(true); - return (Env) f.get(this); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @Override - public T translate(T tree) { - JCTree.JCExpression t = attr.translateMap.remove(tree); - if (t!=null) - return (T) translate(t); - return super.translate(tree); - } - - @Override - public void visitUnary(JCTree.JCUnary tree) { - if (tree.operator instanceof Symbol.OperatorSymbol) { - // similar to #visitBinary - Symbol.OperatorSymbol os = (Symbol.OperatorSymbol) tree.operator; - if (os.opcode == ByteCodes.error+1) { - Symbol.MethodSymbol ms = (Symbol.MethodSymbol) os.owner; - JCTree.JCFieldAccess meth = make.Select(tree.arg, ms.name); - meth.type = ms.type; - meth.sym = ms; - result = make.Apply(null, meth, List.nil()) - .setType(tree.type); - result = translate(result); - return; - } - } - super.visitUnary(tree); - } - - @Override - public void visitBinary(JCTree.JCBinary tree) { - if (tree.operator instanceof Symbol.OperatorSymbol) { - Symbol.OperatorSymbol os = (Symbol.OperatorSymbol) tree.operator; - if (os.opcode == ByteCodes.error+1) { // if operator overloading? - Symbol.MethodSymbol ms = (Symbol.MethodSymbol) os.owner; - boolean isRev = ms.name.toString().endsWith(OOMethods.revSuffix); // reverse hs if methodRev - JCTree.JCExpression lhs = isRev ? tree.rhs : tree.lhs; - JCTree.JCExpression rhs = isRev ? tree.lhs : tree.rhs; - // construct method invocation ast - JCTree.JCFieldAccess meth = make.Select(lhs, ms.name); - meth.type = ms.type; - meth.sym = ms; - result = make.Apply(null, meth, List.of(rhs)) - .setType( ((Type.MethodType)ms.type).restype ); // tree.type may be != ms.type.restype. see below - if (ms.name.contentEquals(OOMethods.compareTo)) { - // rewrite to `left.compareTo(right) 0` - JCTree.JCLiteral zero = make.Literal(0); - JCTree.JCBinary r = make.Binary(tree.getTag(), (JCTree.JCExpression) result, zero); - r.type = syms.booleanType; - r.operator = rs.resolveBinaryOperator(tree, tree.getTag(), getEnv(), result.type, zero.type); - result = r; - } - result = translate(result); - return; - } - } - super.visitBinary(tree); - } -} diff --git a/javac-oo-plugin/src/main/java/javaoo/OOMethods.java b/javac-oo-plugin/src/main/java/javaoo/OOMethods.java deleted file mode 100644 index cbb66c5..0000000 --- a/javac-oo-plugin/src/main/java/javaoo/OOMethods.java +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright 2013 Artem Melentyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package javaoo; - -import java.util.HashMap; -import java.util.Map; - -/** Caution this file is symlinked in all plugins */ -public interface OOMethods { - Map binary = new HashMap() {{ - put("+", "add"); - put("-", "subtract"); - put("*", "multiply"); - put("/", "divide"); - put("%", "remainder"); - put("&", "and"); - put("|", "or"); - put("^", "xor"); - put("<<", "shiftLeft"); - put(">>", "shiftRight"); - put("<", compareTo); - put(">", compareTo); - put("<=", compareTo); - put(">=", compareTo); - }}; - String revSuffix = "Rev"; - Map unary = new java.util.HashMap() {{ - put("-", "negate"); // jdk7 - put("---", "negate"); // jdk8 - put("~", "not"); - }}; - String compareTo = "compareTo"; - String indexGet = "get"; - String[] indexSet = new String[]{"set", "put"}; - String[] valueOf = new String[]{"valueOf", "of"}; -} diff --git a/javac-oo-plugin/src/main/java/javaoo/javac/OOProcessor.java b/javac-oo-plugin/src/main/java/javaoo/javac/OOProcessor.java deleted file mode 100644 index 3ed84d4..0000000 --- a/javac-oo-plugin/src/main/java/javaoo/javac/OOProcessor.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the - * GNU Public License v2.0 + OpenJDK assembly exception. - * - * Contributors: - * Artem Melentyev - initial API and implementation - ******************************************************************************/ -package javaoo.javac; - -import com.sun.source.util.TaskEvent; -import com.sun.source.util.TaskListener; -import com.sun.tools.javac.comp.Attr; -import com.sun.tools.javac.comp.MemberEnter; -import com.sun.tools.javac.comp.Resolve; -import com.sun.tools.javac.comp.TransTypes; -import com.sun.tools.javac.main.JavaCompiler; -import com.sun.tools.javac.processing.JavacProcessingEnvironment; -import com.sun.tools.javac.util.Context; - -import javax.annotation.processing.*; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.TypeElement; -import javax.tools.Diagnostic; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Set; - -@SupportedAnnotationTypes("*") -@SupportedSourceVersion(SourceVersion.RELEASE_7) -public class OOProcessor extends AbstractProcessor { - @Override - public synchronized void init(ProcessingEnvironment processingEnv) { - super.init(processingEnv); - JavacProcessingEnvironment pe = (JavacProcessingEnvironment) processingEnv; - JavaCompiler compiler = JavaCompiler.instance(pe.getContext()); - try { - ClassLoader pclassloader = (ClassLoader) get(pe, "processorClassLoader"); - if (pclassloader != null && (!pclassloader.getClass().equals(ClassLoader.class))) - set(pe, "processorClassLoader", new ClassLoader(pclassloader) {}); - if (pclassloader == null) { // netbeans - processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Injecting OO to netbeans"); - patch(compiler, OOProcessor.class.getClassLoader()); - return; - } - processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Injecting OO to javac"); - final TaskListener oldTaskListener = (TaskListener) get(compiler, "taskListener"); - if (oldTaskListener instanceof WaitAnalyzeTaskListener) - return; - TaskListener newTaskListener = new WaitAnalyzeTaskListener(oldTaskListener, compiler, pclassloader); - set(compiler, "taskListener", newTaskListener); - pe.getContext().put(TaskListener.class, (TaskListener)null); - pe.getContext().put(TaskListener.class, newTaskListener); - } catch (Exception e) { - if (e instanceof RuntimeException) - throw (RuntimeException)e; - throw new RuntimeException(e); - } - } - - @Override - public boolean process(Set annotations, RoundEnvironment roundEnv) { - return false; - } - - static class WaitAnalyzeTaskListener implements TaskListener { - TaskListener oldTaskListener; - JavaCompiler compiler; - ClassLoader pclassloader; - boolean done = false; - public WaitAnalyzeTaskListener(TaskListener old, JavaCompiler compiler, ClassLoader pclassloader) { - this.oldTaskListener = old; - this.compiler = compiler; - this.pclassloader = pclassloader; - } - @Override - public void started(TaskEvent e) { - if (oldTaskListener != null) - oldTaskListener.started(e); - if (e.getKind() == TaskEvent.Kind.ANALYZE && !done) { - patch(compiler, pclassloader); - done = true; - } - } - @Override - public void finished(TaskEvent e) { - if (oldTaskListener != null) - oldTaskListener.finished(e); - } - } - - static Object get(Object obj, String field) throws ReflectiveOperationException { - Field f = obj.getClass().getDeclaredField(field); - f.setAccessible(true); - return f.get(obj); - } - static void set(Object obj, String field, Object val) throws ReflectiveOperationException { - Field f = obj.getClass().getDeclaredField(field); - f.setAccessible(true); - f.set(obj, val); - } - static Object getInstance(Class clas, Context context) throws ReflectiveOperationException { - return clas.getDeclaredMethod("instance", Context.class).invoke(null, context); - } - - static void patch(JavaCompiler compiler, ClassLoader pcl) { - try { - JavaCompiler delCompiler = (JavaCompiler) get(compiler, "delegateCompiler"); - if (delCompiler != null) - compiler = delCompiler; // javac has delegateCompiler. netbeans hasn't - Context context = (Context) get(compiler, "context"); - - // hack: load classes to the same classloader so they will be able to use and override default accessor members - Class attrClass = reloadClass("com.sun.tools.javac.comp.OOAttr", pcl, Attr.class.getClassLoader()); - Class resolveClass = reloadClass("com.sun.tools.javac.comp.OOResolve", pcl, Resolve.class.getClassLoader()); - Class transTypesClass = reloadClass("com.sun.tools.javac.comp.OOTransTypes", pcl, TransTypes.class.getClassLoader()); - reloadClass("javaoo.OOMethods", pcl, TransTypes.class.getClassLoader()); - reloadClass("javaoo.OOMethods$1", pcl, TransTypes.class.getClassLoader()); - reloadClass("javaoo.OOMethods$2", pcl, TransTypes.class.getClassLoader()); - - getInstance(resolveClass, context); - Object attr = getInstance(attrClass, context); - Object transTypes = getInstance(transTypesClass, context); - - set(compiler, "attr", attr); - set(MemberEnter.instance(context), "attr", attr); - set(compiler, "transTypes", transTypes); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - @SuppressWarnings("unchecked") - /** add class claz to outClassLoader */ - static Class reloadClass(String claz, ClassLoader incl, ClassLoader outcl) throws Exception { - try { // already loaded? - return (Class) outcl.loadClass(claz); - } catch (ClassNotFoundException e) {} - String path = claz.replace('.', '/') + ".class"; - InputStream is = incl.getResourceAsStream(path); - byte[] bytes = new byte[is.available()]; - is.read(bytes); - Method m = ClassLoader.class.getDeclaredMethod("defineClass", new Class[] { - String.class, byte[].class, int.class, int.class }); - m.setAccessible(true); - return (Class) m.invoke(outcl, claz, bytes, 0, bytes.length); - } -} diff --git a/javac-oo-plugin/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/javac-oo-plugin/src/main/resources/META-INF/services/javax.annotation.processing.Processor deleted file mode 100644 index fa75948..0000000 --- a/javac-oo-plugin/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ /dev/null @@ -1 +0,0 @@ -javaoo.javac.OOProcessor \ No newline at end of file diff --git a/javac-oo-plugin/src/test/java/JCPOOTest.java b/javac-oo-plugin/src/test/java/JCPOOTest.java deleted file mode 100644 index 2158b12..0000000 --- a/javac-oo-plugin/src/test/java/JCPOOTest.java +++ /dev/null @@ -1,63 +0,0 @@ -import com.sun.tools.javac.Main; -import org.junit.Test; - -import java.io.File; - -import static org.junit.Assert.assertEquals; - -public class JCPOOTest { - @Test public void testMath() throws Exception { - compile("Math"); - } - @Test public void testCmp() throws Exception { - compile("Cmp"); - } - @Test public void testList() throws Exception { - compile("ListIndexGet"); - compile("ListIndexSet"); - } - @Test public void testMap() throws Exception { - compile("MapIndex"); - } - @Test public void testValueOf() throws Exception { - compile("ValueOf"); - } - @Test public void testDemo() throws Exception { - compile("Demo"); - } - @Test public void testVector() throws Exception { - compile("Vector"); - } - @Test public void testCompAss() throws Exception { - compile("CompAss", "../tests"); - } - @Test public void testVecMat() throws Exception { - compile("VecMat", "../tests"); - } - @Test public void testBoxing() throws Exception { - compile("Boxing", "../tests"); - } - @Test public void testVec() throws Exception { - compile("Vec", "../tests"); - } - @Test public void testAbstract() throws Exception { - compile("Abstract", "../tests"); - } - @Test public void testBinaryRev() throws Exception { - compile("BinaryRev", "../tests"); - } - void compile(String clas) throws Exception { - compile(clas, "../examples/"); - } - void compile(String clas, String path) throws Exception { - String outputDir = "target/test-classes"; - if (!new File(outputDir).isDirectory()) { // workaround for IDEA current dir. - path = path.substring(3); // remove "../" - outputDir = "javac-oo-plugin/" + outputDir; - } - String file = path+"/"+clas+".java"; - String opts = file + " -processor javaoo.javac.OOProcessor -d "+outputDir; - assertEquals("compilation failed", 0, Main.compile(opts.split(" "))); - assertEquals(true, Class.forName(clas).getDeclaredMethod("test").invoke(null)); - } -} diff --git a/javac8-oo-plugin/LICENSE b/javac8-oo-plugin/LICENSE deleted file mode 100644 index b40a0f4..0000000 --- a/javac8-oo-plugin/LICENSE +++ /dev/null @@ -1,347 +0,0 @@ -The GNU General Public License (GPL) - -Version 2, June 1991 - -Copyright (C) 1989, 1991 Free Software Foundation, Inc. -59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Everyone is permitted to copy and distribute verbatim copies of this license -document, but changing it is not allowed. - -Preamble - -The licenses for most software are designed to take away your freedom to share -and change it. By contrast, the GNU General Public License is intended to -guarantee your freedom to share and change free software--to make sure the -software is free for all its users. This General Public License applies to -most of the Free Software Foundation's software and to any other program whose -authors commit to using it. (Some other Free Software Foundation software is -covered by the GNU Library General Public License instead.) You can apply it to -your programs, too. - -When we speak of free software, we are referring to freedom, not price. Our -General Public Licenses are designed to make sure that you have the freedom to -distribute copies of free software (and charge for this service if you wish), -that you receive source code or can get it if you want it, that you can change -the software or use pieces of it in new free programs; and that you know you -can do these things. - -To protect your rights, we need to make restrictions that forbid anyone to deny -you these rights or to ask you to surrender the rights. These restrictions -translate to certain responsibilities for you if you distribute copies of the -software, or if you modify it. - -For example, if you distribute copies of such a program, whether gratis or for -a fee, you must give the recipients all the rights that you have. You must -make sure that they, too, receive or can get the source code. And you must -show them these terms so they know their rights. - -We protect your rights with two steps: (1) copyright the software, and (2) -offer you this license which gives you legal permission to copy, distribute -and/or modify the software. - -Also, for each author's protection and ours, we want to make certain that -everyone understands that there is no warranty for this free software. If the -software is modified by someone else and passed on, we want its recipients to -know that what they have is not the original, so that any problems introduced -by others will not reflect on the original authors' reputations. - -Finally, any free program is threatened constantly by software patents. We -wish to avoid the danger that redistributors of a free program will -individually obtain patent licenses, in effect making the program proprietary. -To prevent this, we have made it clear that any patent must be licensed for -everyone's free use or not licensed at all. - -The precise terms and conditions for copying, distribution and modification -follow. - -TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - -0. This License applies to any program or other work which contains a notice -placed by the copyright holder saying it may be distributed under the terms of -this General Public License. The "Program", below, refers to any such program -or work, and a "work based on the Program" means either the Program or any -derivative work under copyright law: that is to say, a work containing the -Program or a portion of it, either verbatim or with modifications and/or -translated into another language. (Hereinafter, translation is included -without limitation in the term "modification".) Each licensee is addressed as -"you". - -Activities other than copying, distribution and modification are not covered by -this License; they are outside its scope. The act of running the Program is -not restricted, and the output from the Program is covered only if its contents -constitute a work based on the Program (independent of having been made by -running the Program). Whether that is true depends on what the Program does. - -1. You may copy and distribute verbatim copies of the Program's source code as -you receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice and -disclaimer of warranty; keep intact all the notices that refer to this License -and to the absence of any warranty; and give any other recipients of the -Program a copy of this License along with the Program. - -You may charge a fee for the physical act of transferring a copy, and you may -at your option offer warranty protection in exchange for a fee. - -2. You may modify your copy or copies of the Program or any portion of it, thus -forming a work based on the Program, and copy and distribute such modifications -or work under the terms of Section 1 above, provided that you also meet all of -these conditions: - - a) You must cause the modified files to carry prominent notices stating - that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in whole or - in part contains or is derived from the Program or any part thereof, to be - licensed as a whole at no charge to all third parties under the terms of - this License. - - c) If the modified program normally reads commands interactively when run, - you must cause it, when started running for such interactive use in the - most ordinary way, to print or display an announcement including an - appropriate copyright notice and a notice that there is no warranty (or - else, saying that you provide a warranty) and that users may redistribute - the program under these conditions, and telling the user how to view a copy - of this License. (Exception: if the Program itself is interactive but does - not normally print such an announcement, your work based on the Program is - not required to print an announcement.) - -These requirements apply to the modified work as a whole. If identifiable -sections of that work are not derived from the Program, and can be reasonably -considered independent and separate works in themselves, then this License, and -its terms, do not apply to those sections when you distribute them as separate -works. But when you distribute the same sections as part of a whole which is a -work based on the Program, the distribution of the whole must be on the terms -of this License, whose permissions for other licensees extend to the entire -whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest your -rights to work written entirely by you; rather, the intent is to exercise the -right to control the distribution of derivative or collective works based on -the Program. - -In addition, mere aggregation of another work not based on the Program with the -Program (or with a work based on the Program) on a volume of a storage or -distribution medium does not bring the other work under the scope of this -License. - -3. You may copy and distribute the Program (or a work based on it, under -Section 2) in object code or executable form under the terms of Sections 1 and -2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable source - code, which must be distributed under the terms of Sections 1 and 2 above - on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three years, to - give any third party, for a charge no more than your cost of physically - performing source distribution, a complete machine-readable copy of the - corresponding source code, to be distributed under the terms of Sections 1 - and 2 above on a medium customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer to - distribute corresponding source code. (This alternative is allowed only - for noncommercial distribution and only if you received the program in - object code or executable form with such an offer, in accord with - Subsection b above.) - -The source code for a work means the preferred form of the work for making -modifications to it. For an executable work, complete source code means all -the source code for all modules it contains, plus any associated interface -definition files, plus the scripts used to control compilation and installation -of the executable. However, as a special exception, the source code -distributed need not include anything that is normally distributed (in either -source or binary form) with the major components (compiler, kernel, and so on) -of the operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the source -code from the same place counts as distribution of the source code, even though -third parties are not compelled to copy the source along with the object code. - -4. You may not copy, modify, sublicense, or distribute the Program except as -expressly provided under this License. Any attempt otherwise to copy, modify, -sublicense or distribute the Program is void, and will automatically terminate -your rights under this License. However, parties who have received copies, or -rights, from you under this License will not have their licenses terminated so -long as such parties remain in full compliance. - -5. You are not required to accept this License, since you have not signed it. -However, nothing else grants you permission to modify or distribute the Program -or its derivative works. These actions are prohibited by law if you do not -accept this License. Therefore, by modifying or distributing the Program (or -any work based on the Program), you indicate your acceptance of this License to -do so, and all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - -6. Each time you redistribute the Program (or any work based on the Program), -the recipient automatically receives a license from the original licensor to -copy, distribute or modify the Program subject to these terms and conditions. -You may not impose any further restrictions on the recipients' exercise of the -rights granted herein. You are not responsible for enforcing compliance by -third parties to this License. - -7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), conditions -are imposed on you (whether by court order, agreement or otherwise) that -contradict the conditions of this License, they do not excuse you from the -conditions of this License. If you cannot distribute so as to satisfy -simultaneously your obligations under this License and any other pertinent -obligations, then as a consequence you may not distribute the Program at all. -For example, if a patent license would not permit royalty-free redistribution -of the Program by all those who receive copies directly or indirectly through -you, then the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply and -the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any patents or -other property right claims or to contest validity of any such claims; this -section has the sole purpose of protecting the integrity of the free software -distribution system, which is implemented by public license practices. Many -people have made generous contributions to the wide range of software -distributed through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing to -distribute software through any other system and a licensee cannot impose that -choice. - -This section is intended to make thoroughly clear what is believed to be a -consequence of the rest of this License. - -8. If the distribution and/or use of the Program is restricted in certain -countries either by patents or by copyrighted interfaces, the original -copyright holder who places the Program under this License may add an explicit -geographical distribution limitation excluding those countries, so that -distribution is permitted only in or among countries not thus excluded. In -such case, this License incorporates the limitation as if written in the body -of this License. - -9. The Free Software Foundation may publish revised and/or new versions of the -General Public License from time to time. Such new versions will be similar in -spirit to the present version, but may differ in detail to address new problems -or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any later -version", you have the option of following the terms and conditions either of -that version or of any later version published by the Free Software Foundation. -If the Program does not specify a version number of this License, you may -choose any version ever published by the Free Software Foundation. - -10. If you wish to incorporate parts of the Program into other free programs -whose distribution conditions are different, write to the author to ask for -permission. For software which is copyrighted by the Free Software Foundation, -write to the Free Software Foundation; we sometimes make exceptions for this. -Our decision will be guided by the two goals of preserving the free status of -all derivatives of our free software and of promoting the sharing and reuse of -software generally. - -NO WARRANTY - -11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR -THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE -STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE -PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, -INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND -PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, -YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - -12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL -ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE -PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR -INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA -BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER -OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. - -END OF TERMS AND CONDITIONS - -How to Apply These Terms to Your New Programs - -If you develop a new program, and you want it to be of the greatest possible -use to the public, the best way to achieve this is to make it free software -which everyone can redistribute and change under these terms. - -To do so, attach the following notices to the program. It is safest to attach -them to the start of each source file to most effectively convey the exclusion -of warranty; and each file should have at least the "copyright" line and a -pointer to where the full notice is found. - - One line to give the program's name and a brief idea of what it does. - - Copyright (C) - - This program is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation; either version 2 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., 59 - Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this when it -starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author Gnomovision comes - with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free - software, and you are welcome to redistribute it under certain conditions; - type 'show c' for details. - -The hypothetical commands 'show w' and 'show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may be -called something other than 'show w' and 'show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your school, -if any, to sign a "copyright disclaimer" for the program, if necessary. Here -is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - 'Gnomovision' (which makes passes at compilers) written by James Hacker. - - signature of Ty Coon, 1 April 1989 - - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General Public -License instead of this License. - - -"CLASSPATH" EXCEPTION TO THE GPL - -Certain source files distributed by Oracle America and/or its affiliates are -subject to the following clarification and special exception to the GPL, but -only where Oracle has expressly included in the particular source file's header -the words "Oracle designates this particular file as subject to the "Classpath" -exception as provided by Oracle in the LICENSE file that accompanied this code." - - Linking this library statically or dynamically with other modules is making - a combined work based on this library. Thus, the terms and conditions of - the GNU General Public License cover the whole combination. - - As a special exception, the copyright holders of this library give you - permission to link this library with independent modules to produce an - executable, regardless of the license terms of these independent modules, - and to copy and distribute the resulting executable under terms of your - choice, provided that you also meet, for each linked independent module, - the terms and conditions of the license of that module. An independent - module is a module which is not derived from or based on this library. If - you modify this library, you may extend this exception to your version of - the library, but you are not obligated to do so. If you do not wish to do - so, delete this exception statement from your version. diff --git a/javac8-oo-plugin/pom.xml b/javac8-oo-plugin/pom.xml deleted file mode 100644 index cc2b54a..0000000 --- a/javac8-oo-plugin/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ - - 4.0.0 - - java-oo - parent - 0.5 - ../pom.xml - - javac8-oo-plugin - 0.6-SNAPSHOT - jar - Java Operator Overloading plugin for javac v8 - http://amelentev.github.io/java-oo/ - - - org.netbeans.modules - org-netbeans-lib-nbjavac - RELEASE801 - provided - - - junit - junit - 4.11 - test - - - - - netbeans - http://bits.netbeans.org/nexus/content/groups/netbeans/ - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - -proc:none - - - - - diff --git a/javac8-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOAttr.java b/javac8-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOAttr.java deleted file mode 100644 index 1de8155..0000000 --- a/javac8-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOAttr.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the - * GNU Public License v2.0 + OpenJDK assembly exception. - * - * Contributors: - * Artem Melentyev - initial API and implementation - * some code from from OpenJDK langtools (GPL2 + assembly exception) - ******************************************************************************/ -package com.sun.tools.javac.comp; - -import com.sun.source.tree.Tree; -import com.sun.tools.javac.code.Kinds; -import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.List; -import javaoo.OOMethods; - -import java.util.Map; -import java.util.WeakHashMap; - -import static com.sun.tools.javac.code.Kinds.VAL; -import static com.sun.tools.javac.code.Kinds.VAR; -import static com.sun.tools.javac.code.TypeTag.*; - - -public class OOAttr extends Attr { - protected OOAttr(Context context) { - super(context); - } - public static OOAttr instance(Context context) { - Attr attr = context.get(attrKey); - if (attr instanceof OOAttr) return (OOAttr) attr; - context.put(attrKey, (Attr)null); - return new OOAttr(context); - } - - /** WeakHashMap to allow GC collect entries. Because we don't need them then they are gone */ - Map translateMap = new WeakHashMap<>(); - - private Symbol findMethods(Type site, List argts, String... methodNames) { - Resolve.MethodResolutionContext newrc = null; - try { - if (rs.currentResolutionContext == null) { // rc.findMethod requires resolution context - newrc = rs.new MethodResolutionContext(); - newrc.step = Resolve.MethodResolutionPhase.BOX; // allow autoboxing, no varargs - newrc.methodCheck = rs.resolveMethodCheck; - rs.currentResolutionContext = newrc; - } - for (String methodName: methodNames) { - Symbol m = rs.findMethod(env, site, names.fromString(methodName), argts, null, true, false, false); - if (m.kind == Kinds.MTH) return m; - m = rs.findMethod(env, site, names.fromString(methodName), argts, null, true, false, false); // with boxing - if (m.kind == Kinds.MTH) return m; - } - return null; - } finally { - if (rs.currentResolutionContext == newrc) - rs.currentResolutionContext = null; - } - } - - @Override - Type check(final JCTree tree, final Type found, final int ownkind, final ResultInfo resultInfo) { - // mimic super.check - Infer.InferenceContext inferenceContext = resultInfo.checkContext.inferenceContext(); - Type owntype = found; - if (!owntype.hasTag(ERROR) && !resultInfo.pt.hasTag(METHOD) && !resultInfo.pt.hasTag(FORALL)) { - if (allowPoly && inferenceContext.free(found)) {} - else if ((ownkind & ~resultInfo.pkind) == 0) { - JCTree.JCExpression t = tryImplicitConversion(tree, owntype, resultInfo); - if (t != null) { - translateMap.put(tree, t); - return tree.type = owntype; - } - } - } - return super.check(tree, owntype, ownkind, resultInfo); - } - - /** try implicit conversion tree to pt type via #valueOf - * @return static valueOf method call iff successful. null otherwise */ - JCTree.JCMethodInvocation tryImplicitConversion(JCTree tree, Type owntype, ResultInfo resultInfo) { - if (!isImplicitConversionAllowed(owntype, resultInfo.pt)) - return null; - JCTree.JCExpression param = translateMap.get(tree); - // construct ".valueOf(tree)" static method call - tree.type = owntype; - make.pos = tree.pos; - for (String methodName : OOMethods.valueOf) { - JCTree.JCMethodInvocation method = make.Apply(null, - make.Select(make.Ident(resultInfo.pt.tsym), names.fromString(methodName)), - List.of(param == null ? (JCTree.JCExpression) tree : param)); - method.type = attribTree(method, env, resultInfo); - if (types.isAssignable(method.type, resultInfo.pt)) - return method; - } - return null; - } - boolean isImplicitConversionAllowed(Type found, Type req) { - // similar to Check#checkType - if (req.hasTag(ERROR) || req.hasTag(NONE) || types.isAssignable(found, req) || found.isNumeric() && req.isNumeric()) - return false; - return findMethods(req, List.of(found), OOMethods.valueOf) != null; - } - - @Override - public void visitAssign(JCTree.JCAssign tree) { - if (tree.lhs.getKind() == Tree.Kind.ARRAY_ACCESS) { // index-set OO: "a[i] = v" - JCTree.JCArrayAccess aa = (JCTree.JCArrayAccess) tree.lhs; - Type atype = attribExpr(aa.indexed, env); - if (!atype.isErroneous() && !types.isArray(atype)) { - Type itype = attribExpr(aa.index, env); - Type rhstype = attribExpr(tree.rhs, env); - Symbol m = findMethods(atype, List.of(itype, rhstype), OOMethods.indexSet); - if (m != null) { - JCTree.JCMethodInvocation mi = make.Apply(null, make.Select(aa.indexed, m), List.of(aa.index, tree.rhs)); - Type owntype = attribExpr(mi, env); - translateMap.put(tree, mi); - aa.type = rhstype; - check(aa, aa.type, VAR, resultInfo); - result = check(tree, owntype, VAL, resultInfo); - return; - } - } - } - super.visitAssign(tree); - } - - @Override - public void visitIndexed(JCTree.JCArrayAccess tree) { - Type owntype = types.createErrorType(tree.type); - Type atype = attribExpr(tree.indexed, env); - if (types.isArray(atype)) { - attribExpr(tree.index, env, syms.intType); - owntype = types.elemtype(atype); - } else if (!atype.isErroneous()) { - attribExpr(tree.index, env); - Symbol m = findMethods(atype, List.of(tree.index.type), OOMethods.indexGet); - if (m != null) { - JCTree.JCMethodInvocation mi = make.Apply(null, make.Select(tree.indexed, m), List.of(tree.index)); - attribExpr(mi, env); - translateMap.put(tree, mi); - owntype = mi.type; - } else - log.error(tree.pos(), "array.req.but.found", atype); - } - if ((pkind() & VAR) == 0) owntype = types.capture(owntype); - result = check(tree, owntype, VAR, resultInfo); - } -} diff --git a/javac8-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOResolve.java b/javac8-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOResolve.java deleted file mode 100644 index b8a2751..0000000 --- a/javac8-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOResolve.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the - * GNU Public License v2.0 + OpenJDK assembly exception. - * - * Contributors: - * Artem Melentyev - initial API and implementation - ******************************************************************************/ -package com.sun.tools.javac.comp; - -import com.sun.tools.javac.code.Kinds; -import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.jvm.ByteCodes; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.List; -import com.sun.tools.javac.util.Name; -import javaoo.OOMethods; - -import static com.sun.tools.javac.code.Kinds.ABSENT_MTH; -import static com.sun.tools.javac.code.Kinds.ERR; - -public class OOResolve extends Resolve { - protected OOResolve(Context context) { - super(context); - } - public static OOResolve instance(Context context) { - Resolve res = context.get(resolveKey); - if (res instanceof OOResolve) return (OOResolve)res; - context.put(resolveKey, (Resolve)null); - return new OOResolve(context); - } - - final Symbol methodNotFound = new SymbolNotFoundError(ABSENT_MTH); - - private Symbol findOperatorMethod(Env env, Name name, List args) { - String methodName = args.tail.isEmpty() ? OOMethods.unary.get(name.toString()) : OOMethods.binary.get(name.toString()); - if (methodName == null) - return methodNotFound; - Symbol res = findMethod(env, args.head, names.fromString(methodName), args.tail, null, true, false, false); - if (res.kind != Kinds.MTH) { - args = args.reverse(); // try reverse with methodRev - res = findMethod(env, args.head, names.fromString(methodName + OOMethods.revSuffix), args.tail, null, true, false, false); - } - return res; - } - - @Override - Symbol findMethod(Env env, - Type site, - Name name, - List argtypes, - List typeargtypes, - boolean allowBoxing, - boolean useVarargs, - boolean operator) { - Symbol bestSoFar = super.findMethod(env, site, name, argtypes, typeargtypes, allowBoxing, useVarargs, operator); - if (bestSoFar.kind >= ERR && operator) { // try operator overloading - Symbol method = findOperatorMethod(env, name, argtypes); - if (method.kind == Kinds.MTH) { - bestSoFar = new Symbol.OperatorSymbol(method.name, method.type, ByteCodes.error+1, method); - if (OOMethods.compareTo.equals(method.name.toString())) { // change result type to boolean if - Type.MethodType oldmt = (Type.MethodType) method.type; - bestSoFar.type = new Type.MethodType(oldmt.argtypes, syms.booleanType, oldmt.thrown, oldmt.tsym); - } - } - } - return bestSoFar; - } -} diff --git a/javac8-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOTransTypes.java b/javac8-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOTransTypes.java deleted file mode 100644 index 29f0801..0000000 --- a/javac8-oo-plugin/src/main/java/com/sun/tools/javac/comp/OOTransTypes.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the - * GNU Public License v2.0 + OpenJDK assembly exception. - * - * Contributors: - * Artem Melentyev - initial API and implementation - ******************************************************************************/ -package com.sun.tools.javac.comp; - -import com.sun.tools.javac.code.Symbol; -import com.sun.tools.javac.code.Symtab; -import com.sun.tools.javac.code.Type; -import com.sun.tools.javac.jvm.ByteCodes; -import com.sun.tools.javac.tree.JCTree; -import com.sun.tools.javac.tree.TreeMaker; -import com.sun.tools.javac.util.Context; -import com.sun.tools.javac.util.List; -import javaoo.OOMethods; - -import java.lang.reflect.Field; - -public class OOTransTypes extends TransTypes { - private final Symtab syms; - private final TreeMaker make; - private final OOResolve rs; - private final OOAttr attr; - - public static OOTransTypes instance(Context context) { - TransTypes res = context.get(transTypesKey); - if (res instanceof OOTransTypes) return (OOTransTypes) res; - context.put(transTypesKey, (TransTypes)null); - return new OOTransTypes(context); - } - protected OOTransTypes(Context context) { - super(context); - syms = Symtab.instance(context); - make = TreeMaker.instance(context); - attr = OOAttr.instance(context); - rs = OOResolve.instance(context); - } - - private Env getEnv() { - try { - Field f = TransTypes.class.getDeclaredField("env"); - f.setAccessible(true); - return (Env) f.get(this); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); - } - } - - @Override - public T translate(T tree) { - JCTree.JCExpression t = attr.translateMap.remove(tree); - if (t!=null) - return (T) translate(t); - return super.translate(tree); - } - - @Override - public void visitUnary(JCTree.JCUnary tree) { - if (tree.operator instanceof Symbol.OperatorSymbol) { - // similar to #visitBinary - Symbol.OperatorSymbol os = (Symbol.OperatorSymbol) tree.operator; - if (os.opcode == ByteCodes.error+1) { - Symbol.MethodSymbol ms = (Symbol.MethodSymbol) os.owner; - JCTree.JCFieldAccess meth = make.Select(tree.arg, ms.name); - meth.type = ms.type; - meth.sym = ms; - result = make.Apply(null, meth, List.nil()) - .setType(tree.type); - result = translate(result); - return; - } - } - super.visitUnary(tree); - } - - @Override - public void visitBinary(JCTree.JCBinary tree) { - if (tree.operator instanceof Symbol.OperatorSymbol) { - Symbol.OperatorSymbol os = (Symbol.OperatorSymbol) tree.operator; - if (os.opcode == ByteCodes.error+1) { // if operator overloading? - Symbol.MethodSymbol ms = (Symbol.MethodSymbol) os.owner; - boolean isRev = ms.name.toString().endsWith(OOMethods.revSuffix); // reverse hs if methodRev - JCTree.JCExpression lhs = isRev ? tree.rhs : tree.lhs; - JCTree.JCExpression rhs = isRev ? tree.lhs : tree.rhs; - // construct method invocation ast - JCTree.JCFieldAccess meth = make.Select(lhs, ms.name); - meth.type = ms.type; - meth.sym = ms; - result = make.Apply(null, meth, List.of(rhs)) - .setType( ((Type.MethodType)ms.type).restype ); // tree.type may be != ms.type.restype. see below - if (ms.name.contentEquals(OOMethods.compareTo)) { - // rewrite to `left.compareTo(right) 0` - JCTree.JCLiteral zero = make.Literal(0); - JCTree.JCBinary r = make.Binary(tree.getTag(), (JCTree.JCExpression) result, zero); - r.type = syms.booleanType; - r.operator = rs.resolveBinaryOperator(tree, tree.getTag(), getEnv(), result.type, zero.type); - result = r; - } - result = translate(result); - return; - } - } - super.visitBinary(tree); - } -} diff --git a/javac8-oo-plugin/src/main/java/javaoo/OOMethods.java b/javac8-oo-plugin/src/main/java/javaoo/OOMethods.java deleted file mode 120000 index 3e5caf2..0000000 --- a/javac8-oo-plugin/src/main/java/javaoo/OOMethods.java +++ /dev/null @@ -1 +0,0 @@ -../../../../../javac-oo-plugin/src/main/java/javaoo/OOMethods.java \ No newline at end of file diff --git a/javac8-oo-plugin/src/main/java/javaoo/javac8/OOProcessor.java b/javac8-oo-plugin/src/main/java/javaoo/javac8/OOProcessor.java deleted file mode 100644 index a6d17ec..0000000 --- a/javac8-oo-plugin/src/main/java/javaoo/javac8/OOProcessor.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2012 Artem Melentyev . - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the - * GNU Public License v2.0 + OpenJDK assembly exception. - * - * Contributors: - * Artem Melentyev - initial API and implementation - ******************************************************************************/ -package javaoo.javac8; - -import com.sun.source.util.TaskEvent; -import com.sun.source.util.TaskListener; -import com.sun.tools.javac.api.MultiTaskListener; -import com.sun.tools.javac.comp.*; -import com.sun.tools.javac.main.JavaCompiler; -import com.sun.tools.javac.processing.JavacProcessingEnvironment; -import com.sun.tools.javac.util.Context; - -import javax.annotation.processing.*; -import javax.lang.model.SourceVersion; -import javax.lang.model.element.TypeElement; -import javax.tools.Diagnostic; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Set; - -@SupportedAnnotationTypes("*") -@SupportedSourceVersion(SourceVersion.RELEASE_8) -public class OOProcessor extends AbstractProcessor { - @Override - public synchronized void init(ProcessingEnvironment processingEnv) { - super.init(processingEnv); - JavacProcessingEnvironment pe = (JavacProcessingEnvironment) processingEnv; - JavaCompiler compiler = JavaCompiler.instance(pe.getContext()); - try { - ClassLoader pclassloader = (ClassLoader) get(pe, "processorClassLoader"); - if (pclassloader != null && (!pclassloader.getClass().equals(ClassLoader.class))) - // do not let compiler to close our classloader. we need it later. - set(pe, JavacProcessingEnvironment.class, "processorClassLoader", new ClassLoader(pclassloader) {}); - if (pclassloader == null) { // netbeans - processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Injecting OO to netbeans"); - patch(compiler, OOProcessor.class.getClassLoader()); - return; - } - processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "Injecting OO to javac8"); - final MultiTaskListener taskListener = (MultiTaskListener) get(compiler, "taskListener"); - taskListener.add(new WaitAnalyzeTaskListener(compiler, pclassloader)); - } catch (Exception e) { - sneakyThrow(e); - } - } - - @Override - public boolean process(Set annotations, RoundEnvironment roundEnv) { - return false; - } - - static class WaitAnalyzeTaskListener implements TaskListener { - JavaCompiler compiler; - ClassLoader pclassloader; - boolean done = false; - public WaitAnalyzeTaskListener(JavaCompiler compiler, ClassLoader pclassloader) { - this.compiler = compiler; - this.pclassloader = pclassloader; - } - @Override - public void started(TaskEvent e) { - if (!done && e.getKind() == TaskEvent.Kind.ANALYZE) { - patch(compiler, pclassloader); - done = true; - } - } - @Override - public void finished(TaskEvent e) {} - } - - static void patch(JavaCompiler compiler, ClassLoader pcl) { - try { - JavaCompiler delCompiler = (JavaCompiler) get(compiler, "delegateCompiler"); - if (delCompiler != null) - compiler = delCompiler; // javac has delegateCompiler. netbeans hasn't - Context context = (Context) get(compiler, "context"); - Attr attr = Attr.instance(context); - if (attr instanceof OOAttr) - return; - ClassLoader destcl = attr.getClass().getClassLoader(); - - // hack: load classes to the same classloader so they will be able to use and override default accessor members - Class attrClass = reloadClass("com.sun.tools.javac.comp.OOAttr", pcl, destcl); - Class resolveClass = reloadClass("com.sun.tools.javac.comp.OOResolve", pcl, destcl); - Class transTypesClass = reloadClass("com.sun.tools.javac.comp.OOTransTypes", pcl, destcl); - reloadClass("javaoo.OOMethods", pcl, destcl); - reloadClass("javaoo.OOMethods$1", pcl, destcl); - reloadClass("javaoo.OOMethods$2", pcl, destcl); - - getInstance(resolveClass, context); - attr = (Attr) getInstance(attrClass, context); - Object transTypes = getInstance(transTypesClass, context); - - set(compiler, JavaCompiler.class, "attr", attr); - set(compiler, JavaCompiler.class, "transTypes", transTypes); - set(MemberEnter.instance(context), MemberEnter.class, "attr", attr); - } catch (Exception e) { - sneakyThrow(e); - } - } - @SuppressWarnings("unchecked") - /** add class claz to outClassLoader */ - static Class reloadClass(final String claz, ClassLoader incl, ClassLoader outcl) throws Exception { - try { // already loaded? - return (Class) outcl.loadClass(claz); - } catch (ClassNotFoundException e) {} - String path = claz.replace('.', '/') + ".class"; - InputStream is = incl.getResourceAsStream(path); - byte[] bytes = new byte[is.available()]; - is.read(bytes); - Method m = ClassLoader.class.getDeclaredMethod("defineClass", new Class[] { - String.class, byte[].class, int.class, int.class }); - m.setAccessible(true); - return (Class) m.invoke(outcl, claz, bytes, 0, bytes.length); - } - - // reflection stuff - static Object getInstance(Class clas, Context context) throws ReflectiveOperationException { - return clas.getDeclaredMethod("instance", Context.class).invoke(null, context); - } - static Object get(Object obj, String field) throws ReflectiveOperationException { - Field f = obj.getClass().getDeclaredField(field); - f.setAccessible(true); - return f.get(obj); - } - static void set(Object obj, Class clas, String field, Object val) throws ReflectiveOperationException { - Field f = clas.getDeclaredField(field); - f.setAccessible(true); - f.set(obj, val); - } - public static void sneakyThrow(Throwable ex) { - OOProcessor.sneakyThrowInner(ex); - } - private static T sneakyThrowInner(Throwable ex) throws T { - throw (T) ex; - } -} diff --git a/javac8-oo-plugin/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/javac8-oo-plugin/src/main/resources/META-INF/services/javax.annotation.processing.Processor deleted file mode 100644 index 0280f4a..0000000 --- a/javac8-oo-plugin/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ /dev/null @@ -1 +0,0 @@ -javaoo.javac8.OOProcessor \ No newline at end of file diff --git a/javac8-oo-plugin/src/test/java/JCPOOTest.java b/javac8-oo-plugin/src/test/java/JCPOOTest.java deleted file mode 100644 index 09f6383..0000000 --- a/javac8-oo-plugin/src/test/java/JCPOOTest.java +++ /dev/null @@ -1,63 +0,0 @@ -import com.sun.tools.javac.Main; -import org.junit.Test; - -import java.io.File; - -import static org.junit.Assert.assertEquals; - -public class JCPOOTest { - @Test public void testMath() throws Exception { - compile("Math"); - } - @Test public void testCmp() throws Exception { - compile("Cmp"); - } - @Test public void testList() throws Exception { - compile("ListIndexGet"); - compile("ListIndexSet"); - } - @Test public void testMap() throws Exception { - compile("MapIndex"); - } - @Test public void testValueOf() throws Exception { - compile("ValueOf"); - } - @Test public void testDemo() throws Exception { - compile("Demo"); - } - @Test public void testVector() throws Exception { - compile("Vector"); - } - @Test public void testCompAss() throws Exception { - compile("CompAss", "../tests"); - } - @Test public void testVecMat() throws Exception { - compile("VecMat", "../tests"); - } - @Test public void testBoxing() throws Exception { - compile("Boxing", "../tests"); - } - @Test public void testVec() throws Exception { - compile("Vec", "../tests"); - } - @Test public void testAbstract() throws Exception { - compile("Abstract", "../tests"); - } - @Test public void testBinaryRev() throws Exception { - compile("BinaryRev", "../tests"); - } - void compile(String clas) throws Exception { - compile(clas, "../examples/"); - } - void compile(String clas, String path) throws Exception { - String outputDir = "target/test-classes"; - if (!new File(outputDir).isDirectory()) { // workaround for IDEA current dir. - path = path.substring(3); // remove "../" - outputDir = "javac8-oo-plugin/" + outputDir; - } - String file = path+"/"+clas+".java"; - String opts = file + " -processor javaoo.javac8.OOProcessor -d "+outputDir; - assertEquals("compilation failed", 0, Main.compile(opts.split(" "))); - assertEquals(true, Class.forName(clas).getDeclaredMethod("test").invoke(null)); - } -} diff --git a/javascripts/main.js b/javascripts/main.js new file mode 100644 index 0000000..d8135d3 --- /dev/null +++ b/javascripts/main.js @@ -0,0 +1 @@ +console.log('This would be the main JS file.'); diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 0fc57a1..0000000 --- a/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ - - 4.0.0 - - java-oo - parent - 0.6-SNAPSHOT - pom - http://amelentev.github.io/java-oo/ - - - javac-oo-plugin - javac-oo-mvndemo - - - - - amelentev - http://amelentev.github.io/mvnrepo/ - - - - UTF-8 - - - - - - deploy - file:///home/mart/src/my/gitmvnrepo - - - - scm:git:git@github.com:amelentev/java-oo.git - HEAD - - - - - org.apache.maven.plugins - maven-release-plugin - 2.5.1 - - @{project.version} - false - true - - - - - diff --git a/stylesheets/github-light.css b/stylesheets/github-light.css new file mode 100644 index 0000000..0c6b24d --- /dev/null +++ b/stylesheets/github-light.css @@ -0,0 +1,124 @@ +/* +The MIT License (MIT) + +Copyright (c) 2016 GitHub, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +*/ + +.pl-c /* comment */ { + color: #969896; +} + +.pl-c1 /* constant, variable.other.constant, support, meta.property-name, support.constant, support.variable, meta.module-reference, markup.raw, meta.diff.header */, +.pl-s .pl-v /* string variable */ { + color: #0086b3; +} + +.pl-e /* entity */, +.pl-en /* entity.name */ { + color: #795da3; +} + +.pl-smi /* variable.parameter.function, storage.modifier.package, storage.modifier.import, storage.type.java, variable.other */, +.pl-s .pl-s1 /* string source */ { + color: #333; +} + +.pl-ent /* entity.name.tag */ { + color: #63a35c; +} + +.pl-k /* keyword, storage, storage.type */ { + color: #a71d5d; +} + +.pl-s /* string */, +.pl-pds /* punctuation.definition.string, string.regexp.character-class */, +.pl-s .pl-pse .pl-s1 /* string punctuation.section.embedded source */, +.pl-sr /* string.regexp */, +.pl-sr .pl-cce /* string.regexp constant.character.escape */, +.pl-sr .pl-sre /* string.regexp source.ruby.embedded */, +.pl-sr .pl-sra /* string.regexp string.regexp.arbitrary-repitition */ { + color: #183691; +} + +.pl-v /* variable */ { + color: #ed6a43; +} + +.pl-id /* invalid.deprecated */ { + color: #b52a1d; +} + +.pl-ii /* invalid.illegal */ { + color: #f8f8f8; + background-color: #b52a1d; +} + +.pl-sr .pl-cce /* string.regexp constant.character.escape */ { + font-weight: bold; + color: #63a35c; +} + +.pl-ml /* markup.list */ { + color: #693a17; +} + +.pl-mh /* markup.heading */, +.pl-mh .pl-en /* markup.heading entity.name */, +.pl-ms /* meta.separator */ { + font-weight: bold; + color: #1d3e81; +} + +.pl-mq /* markup.quote */ { + color: #008080; +} + +.pl-mi /* markup.italic */ { + font-style: italic; + color: #333; +} + +.pl-mb /* markup.bold */ { + font-weight: bold; + color: #333; +} + +.pl-md /* markup.deleted, meta.diff.header.from-file */ { + color: #bd2c00; + background-color: #ffecec; +} + +.pl-mi1 /* markup.inserted, meta.diff.header.to-file */ { + color: #55a532; + background-color: #eaffea; +} + +.pl-mdr /* meta.diff.range */ { + font-weight: bold; + color: #795da3; +} + +.pl-mo /* meta.output */ { + color: #1d3e81; +} + diff --git a/stylesheets/normalize.css b/stylesheets/normalize.css new file mode 100644 index 0000000..30366a6 --- /dev/null +++ b/stylesheets/normalize.css @@ -0,0 +1,424 @@ +/*! normalize.css v3.0.2 | MIT License | git.io/normalize */ + +/** + * 1. Set default font family to sans-serif. + * 2. Prevent iOS text size adjust after orientation change, without disabling + * user zoom. + */ + +html { + font-family: sans-serif; /* 1 */ + -ms-text-size-adjust: 100%; /* 2 */ + -webkit-text-size-adjust: 100%; /* 2 */ +} + +/** + * Remove default margin. + */ + +body { + margin: 0; +} + +/* HTML5 display definitions + ========================================================================== */ + +/** + * Correct `block` display not defined for any HTML5 element in IE 8/9. + * Correct `block` display not defined for `details` or `summary` in IE 10/11 + * and Firefox. + * Correct `block` display not defined for `main` in IE 11. + */ + +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +main, +menu, +nav, +section, +summary { + display: block; +} + +/** + * 1. Correct `inline-block` display not defined in IE 8/9. + * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. + */ + +audio, +canvas, +progress, +video { + display: inline-block; /* 1 */ + vertical-align: baseline; /* 2 */ +} + +/** + * Prevent modern browsers from displaying `audio` without controls. + * Remove excess height in iOS 5 devices. + */ + +audio:not([controls]) { + display: none; + height: 0; +} + +/** + * Address `[hidden]` styling not present in IE 8/9/10. + * Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22. + */ + +[hidden], +template { + display: none; +} + +/* Links + ========================================================================== */ + +/** + * Remove the gray background color from active links in IE 10. + */ + +a { + background-color: transparent; +} + +/** + * Improve readability when focused and also mouse hovered in all browsers. + */ + +a:active, +a:hover { + outline: 0; +} + +/* Text-level semantics + ========================================================================== */ + +/** + * Address styling not present in IE 8/9/10/11, Safari, and Chrome. + */ + +abbr[title] { + border-bottom: 1px dotted; +} + +/** + * Address style set to `bolder` in Firefox 4+, Safari, and Chrome. + */ + +b, +strong { + font-weight: bold; +} + +/** + * Address styling not present in Safari and Chrome. + */ + +dfn { + font-style: italic; +} + +/** + * Address variable `h1` font-size and margin within `section` and `article` + * contexts in Firefox 4+, Safari, and Chrome. + */ + +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +/** + * Address styling not present in IE 8/9. + */ + +mark { + background: #ff0; + color: #000; +} + +/** + * Address inconsistent and variable font size in all browsers. + */ + +small { + font-size: 80%; +} + +/** + * Prevent `sub` and `sup` affecting `line-height` in all browsers. + */ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sup { + top: -0.5em; +} + +sub { + bottom: -0.25em; +} + +/* Embedded content + ========================================================================== */ + +/** + * Remove border when inside `a` element in IE 8/9/10. + */ + +img { + border: 0; +} + +/** + * Correct overflow not hidden in IE 9/10/11. + */ + +svg:not(:root) { + overflow: hidden; +} + +/* Grouping content + ========================================================================== */ + +/** + * Address margin not present in IE 8/9 and Safari. + */ + +figure { + margin: 1em 40px; +} + +/** + * Address differences between Firefox and other browsers. + */ + +hr { + box-sizing: content-box; + height: 0; +} + +/** + * Contain overflow in all browsers. + */ + +pre { + overflow: auto; +} + +/** + * Address odd `em`-unit font size rendering in all browsers. + */ + +code, +kbd, +pre, +samp { + font-family: monospace, monospace; + font-size: 1em; +} + +/* Forms + ========================================================================== */ + +/** + * Known limitation: by default, Chrome and Safari on OS X allow very limited + * styling of `select`, unless a `border` property is set. + */ + +/** + * 1. Correct color not being inherited. + * Known issue: affects color of disabled elements. + * 2. Correct font properties not being inherited. + * 3. Address margins set differently in Firefox 4+, Safari, and Chrome. + */ + +button, +input, +optgroup, +select, +textarea { + color: inherit; /* 1 */ + font: inherit; /* 2 */ + margin: 0; /* 3 */ +} + +/** + * Address `overflow` set to `hidden` in IE 8/9/10/11. + */ + +button { + overflow: visible; +} + +/** + * Address inconsistent `text-transform` inheritance for `button` and `select`. + * All other form control elements do not inherit `text-transform` values. + * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera. + * Correct `select` style inheritance in Firefox. + */ + +button, +select { + text-transform: none; +} + +/** + * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` + * and `video` controls. + * 2. Correct inability to style clickable `input` types in iOS. + * 3. Improve usability and consistency of cursor style between image-type + * `input` and others. + */ + +button, +html input[type="button"], /* 1 */ +input[type="reset"], +input[type="submit"] { + -webkit-appearance: button; /* 2 */ + cursor: pointer; /* 3 */ +} + +/** + * Re-set default cursor for disabled elements. + */ + +button[disabled], +html input[disabled] { + cursor: default; +} + +/** + * Remove inner padding and border in Firefox 4+. + */ + +button::-moz-focus-inner, +input::-moz-focus-inner { + border: 0; + padding: 0; +} + +/** + * Address Firefox 4+ setting `line-height` on `input` using `!important` in + * the UA stylesheet. + */ + +input { + line-height: normal; +} + +/** + * It's recommended that you don't attempt to style these elements. + * Firefox's implementation doesn't respect box-sizing, padding, or width. + * + * 1. Address box sizing set to `content-box` in IE 8/9/10. + * 2. Remove excess padding in IE 8/9/10. + */ + +input[type="checkbox"], +input[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Fix the cursor style for Chrome's increment/decrement buttons. For certain + * `font-size` values of the `input`, it causes the cursor style of the + * decrement button to change from `default` to `text`. + */ + +input[type="number"]::-webkit-inner-spin-button, +input[type="number"]::-webkit-outer-spin-button { + height: auto; +} + +/** + * 1. Address `appearance` set to `searchfield` in Safari and Chrome. + * 2. Address `box-sizing` set to `border-box` in Safari and Chrome + * (include `-moz` to future-proof). + */ + +input[type="search"] { + -webkit-appearance: textfield; /* 1 */ /* 2 */ + box-sizing: content-box; +} + +/** + * Remove inner padding and search cancel button in Safari and Chrome on OS X. + * Safari (but not Chrome) clips the cancel button when the search input has + * padding (and `textfield` appearance). + */ + +input[type="search"]::-webkit-search-cancel-button, +input[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** + * Define consistent border, margin, and padding. + */ + +fieldset { + border: 1px solid #c0c0c0; + margin: 0 2px; + padding: 0.35em 0.625em 0.75em; +} + +/** + * 1. Correct `color` not being inherited in IE 8/9/10/11. + * 2. Remove padding so people aren't caught out if they zero out fieldsets. + */ + +legend { + border: 0; /* 1 */ + padding: 0; /* 2 */ +} + +/** + * Remove default vertical scrollbar in IE 8/9/10/11. + */ + +textarea { + overflow: auto; +} + +/** + * Don't inherit the `font-weight` (applied by a rule above). + * NOTE: the default cannot safely be changed in Chrome and Safari on OS X. + */ + +optgroup { + font-weight: bold; +} + +/* Tables + ========================================================================== */ + +/** + * Remove most spacing between table cells. + */ + +table { + border-collapse: collapse; + border-spacing: 0; +} + +td, +th { + padding: 0; +} diff --git a/stylesheets/pygment_trac.css b/stylesheets/pygment_trac.css new file mode 100644 index 0000000..e65cedf --- /dev/null +++ b/stylesheets/pygment_trac.css @@ -0,0 +1,70 @@ +.highlight .hll { background-color: #ffffcc } +.highlight { background: #f0f3f3; } +.highlight .c { color: #0099FF; font-style: italic } /* Comment */ +.highlight .err { color: #AA0000; background-color: #FFAAAA } /* Error */ +.highlight .k { color: #006699; font-weight: bold } /* Keyword */ +.highlight .o { color: #555555 } /* Operator */ +.highlight .cm { color: #0099FF; font-style: italic } /* Comment.Multiline */ +.highlight .cp { color: #009999 } /* Comment.Preproc */ +.highlight .c1 { color: #0099FF; font-style: italic } /* Comment.Single */ +.highlight .cs { color: #0099FF; font-weight: bold; font-style: italic } /* Comment.Special */ +.highlight .gd { background-color: #FFCCCC; border: 1px solid #CC0000 } /* Generic.Deleted */ +.highlight .ge { font-style: italic } /* Generic.Emph */ +.highlight .gr { color: #FF0000 } /* Generic.Error */ +.highlight .gh { color: #003300; font-weight: bold } /* Generic.Heading */ +.highlight .gi { background-color: #CCFFCC; border: 1px solid #00CC00 } /* Generic.Inserted */ +.highlight .go { color: #AAAAAA } /* Generic.Output */ +.highlight .gp { color: #000099; font-weight: bold } /* Generic.Prompt */ +.highlight .gs { font-weight: bold } /* Generic.Strong */ +.highlight .gu { color: #003300; font-weight: bold } /* Generic.Subheading */ +.highlight .gt { color: #99CC66 } /* Generic.Traceback */ +.highlight .kc { color: #006699; font-weight: bold } /* Keyword.Constant */ +.highlight .kd { color: #006699; font-weight: bold } /* Keyword.Declaration */ +.highlight .kn { color: #006699; font-weight: bold } /* Keyword.Namespace */ +.highlight .kp { color: #006699 } /* Keyword.Pseudo */ +.highlight .kr { color: #006699; font-weight: bold } /* Keyword.Reserved */ +.highlight .kt { color: #007788; font-weight: bold } /* Keyword.Type */ +.highlight .m { color: #FF6600 } /* Literal.Number */ +.highlight .s { color: #CC3300 } /* Literal.String */ +.highlight .na { color: #330099 } /* Name.Attribute */ +.highlight .nb { color: #336666 } /* Name.Builtin */ +.highlight .nc { color: #00AA88; font-weight: bold } /* Name.Class */ +.highlight .no { color: #336600 } /* Name.Constant */ +.highlight .nd { color: #9999FF } /* Name.Decorator */ +.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */ +.highlight .ne { color: #CC0000; font-weight: bold } /* Name.Exception */ +.highlight .nf { color: #CC00FF } /* Name.Function */ +.highlight .nl { color: #9999FF } /* Name.Label */ +.highlight .nn { color: #00CCFF; font-weight: bold } /* Name.Namespace */ +.highlight .nt { color: #330099; font-weight: bold } /* Name.Tag */ +.highlight .nv { color: #003333 } /* Name.Variable */ +.highlight .ow { color: #000000; font-weight: bold } /* Operator.Word */ +.highlight .w { color: #bbbbbb } /* Text.Whitespace */ +.highlight .mf { color: #FF6600 } /* Literal.Number.Float */ +.highlight .mh { color: #FF6600 } /* Literal.Number.Hex */ +.highlight .mi { color: #FF6600 } /* Literal.Number.Integer */ +.highlight .mo { color: #FF6600 } /* Literal.Number.Oct */ +.highlight .sb { color: #CC3300 } /* Literal.String.Backtick */ +.highlight .sc { color: #CC3300 } /* Literal.String.Char */ +.highlight .sd { color: #CC3300; font-style: italic } /* Literal.String.Doc */ +.highlight .s2 { color: #CC3300 } /* Literal.String.Double */ +.highlight .se { color: #CC3300; font-weight: bold } /* Literal.String.Escape */ +.highlight .sh { color: #CC3300 } /* Literal.String.Heredoc */ +.highlight .si { color: #AA0000 } /* Literal.String.Interpol */ +.highlight .sx { color: #CC3300 } /* Literal.String.Other */ +.highlight .sr { color: #33AAAA } /* Literal.String.Regex */ +.highlight .s1 { color: #CC3300 } /* Literal.String.Single */ +.highlight .ss { color: #FFCC33 } /* Literal.String.Symbol */ +.highlight .bp { color: #336666 } /* Name.Builtin.Pseudo */ +.highlight .vc { color: #003333 } /* Name.Variable.Class */ +.highlight .vg { color: #003333 } /* Name.Variable.Global */ +.highlight .vi { color: #003333 } /* Name.Variable.Instance */ +.highlight .il { color: #FF6600 } /* Literal.Number.Integer.Long */ + +.type-csharp .highlight .k { color: #0000FF } +.type-csharp .highlight .kt { color: #0000FF } +.type-csharp .highlight .nf { color: #000000; font-weight: normal } +.type-csharp .highlight .nc { color: #2B91AF } +.type-csharp .highlight .nn { color: #000000 } +.type-csharp .highlight .s { color: #A31515 } +.type-csharp .highlight .sc { color: #A31515 } diff --git a/stylesheets/stylesheet.css b/stylesheets/stylesheet.css new file mode 100644 index 0000000..b5f20c2 --- /dev/null +++ b/stylesheets/stylesheet.css @@ -0,0 +1,245 @@ +* { + box-sizing: border-box; } + +body { + padding: 0; + margin: 0; + font-family: "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + font-size: 16px; + line-height: 1.5; + color: #606c71; } + +a { + color: #1e6bb8; + text-decoration: none; } + a:hover { + text-decoration: underline; } + +.btn { + display: inline-block; + margin-bottom: 1rem; + color: rgba(255, 255, 255, 0.7); + background-color: rgba(255, 255, 255, 0.08); + border-color: rgba(255, 255, 255, 0.2); + border-style: solid; + border-width: 1px; + border-radius: 0.3rem; + transition: color 0.2s, background-color 0.2s, border-color 0.2s; } + .btn + .btn { + margin-left: 1rem; } + +.btn:hover { + color: rgba(255, 255, 255, 0.8); + text-decoration: none; + background-color: rgba(255, 255, 255, 0.2); + border-color: rgba(255, 255, 255, 0.3); } + +@media screen and (min-width: 64em) { + .btn { + padding: 0.75rem 1rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .btn { + padding: 0.6rem 0.9rem; + font-size: 0.9rem; } } + +@media screen and (max-width: 42em) { + .btn { + display: block; + width: 100%; + padding: 0.75rem; + font-size: 0.9rem; } + .btn + .btn { + margin-top: 1rem; + margin-left: 0; } } + +.page-header { + color: #fff; + text-align: center; + background-color: #159957; + background-image: linear-gradient(120deg, #155799, #159957); } + +@media screen and (min-width: 64em) { + .page-header { + padding: 5rem 6rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .page-header { + padding: 3rem 4rem; } } + +@media screen and (max-width: 42em) { + .page-header { + padding: 2rem 1rem; } } + +.project-name { + margin-top: 0; + margin-bottom: 0.1rem; } + +@media screen and (min-width: 64em) { + .project-name { + font-size: 3.25rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .project-name { + font-size: 2.25rem; } } + +@media screen and (max-width: 42em) { + .project-name { + font-size: 1.75rem; } } + +.project-tagline { + margin-bottom: 2rem; + font-weight: normal; + opacity: 0.7; } + +@media screen and (min-width: 64em) { + .project-tagline { + font-size: 1.25rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .project-tagline { + font-size: 1.15rem; } } + +@media screen and (max-width: 42em) { + .project-tagline { + font-size: 1rem; } } + +.main-content :first-child { + margin-top: 0; } +.main-content img { + max-width: 100%; } +.main-content h1, .main-content h2, .main-content h3, .main-content h4, .main-content h5, .main-content h6 { + margin-top: 2rem; + margin-bottom: 1rem; + font-weight: normal; + color: #159957; } +.main-content p { + margin-bottom: 1em; } +.main-content code { + padding: 2px 4px; + font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; + font-size: 0.9rem; + color: #383e41; + background-color: #f3f6fa; + border-radius: 0.3rem; } +.main-content pre { + padding: 0.8rem; + margin-top: 0; + margin-bottom: 1rem; + font: 1rem Consolas, "Liberation Mono", Menlo, Courier, monospace; + color: #567482; + word-wrap: normal; + background-color: #f3f6fa; + border: solid 1px #dce6f0; + border-radius: 0.3rem; } + .main-content pre > code { + padding: 0; + margin: 0; + font-size: 0.9rem; + color: #567482; + word-break: normal; + white-space: pre; + background: transparent; + border: 0; } +.main-content .highlight { + margin-bottom: 1rem; } + .main-content .highlight pre { + margin-bottom: 0; + word-break: normal; } +.main-content .highlight pre, .main-content pre { + padding: 0.8rem; + overflow: auto; + font-size: 0.9rem; + line-height: 1.45; + border-radius: 0.3rem; } +.main-content pre code, .main-content pre tt { + display: inline; + max-width: initial; + padding: 0; + margin: 0; + overflow: initial; + line-height: inherit; + word-wrap: normal; + background-color: transparent; + border: 0; } + .main-content pre code:before, .main-content pre code:after, .main-content pre tt:before, .main-content pre tt:after { + content: normal; } +.main-content ul, .main-content ol { + margin-top: 0; } +.main-content blockquote { + padding: 0 1rem; + margin-left: 0; + color: #819198; + border-left: 0.3rem solid #dce6f0; } + .main-content blockquote > :first-child { + margin-top: 0; } + .main-content blockquote > :last-child { + margin-bottom: 0; } +.main-content table { + display: block; + width: 100%; + overflow: auto; + word-break: normal; + word-break: keep-all; } + .main-content table th { + font-weight: bold; } + .main-content table th, .main-content table td { + padding: 0.5rem 1rem; + border: 1px solid #e9ebec; } +.main-content dl { + padding: 0; } + .main-content dl dt { + padding: 0; + margin-top: 1rem; + font-size: 1rem; + font-weight: bold; } + .main-content dl dd { + padding: 0; + margin-bottom: 1rem; } +.main-content hr { + height: 2px; + padding: 0; + margin: 1rem 0; + background-color: #eff0f1; + border: 0; } + +@media screen and (min-width: 64em) { + .main-content { + max-width: 64rem; + padding: 2rem 6rem; + margin: 0 auto; + font-size: 1.1rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .main-content { + padding: 2rem 4rem; + font-size: 1.1rem; } } + +@media screen and (max-width: 42em) { + .main-content { + padding: 2rem 1rem; + font-size: 1rem; } } + +.site-footer { + padding-top: 2rem; + margin-top: 2rem; + border-top: solid 1px #eff0f1; } + +.site-footer-owner { + display: block; + font-weight: bold; } + +.site-footer-credits { + color: #819198; } + +@media screen and (min-width: 64em) { + .site-footer { + font-size: 1rem; } } + +@media screen and (min-width: 42em) and (max-width: 64em) { + .site-footer { + font-size: 1rem; } } + +@media screen and (max-width: 42em) { + .site-footer { + font-size: 0.9rem; } } diff --git a/tests/Abstract.java b/tests/Abstract.java deleted file mode 100644 index 5bf8ecd..0000000 --- a/tests/Abstract.java +++ /dev/null @@ -1,19 +0,0 @@ -public abstract class Abstract { - public abstract Interface add(Interface a); - - interface Interface { - Interface add(Interface a); - } - - static class Concrete extends Abstract implements Interface { - public Interface add(Interface a) { - return this; - } - } - - public static boolean test() { - Abstract a1 = new Concrete(); - Interface a2 = new Concrete(); - return a1 == (a1 + a2); - } -} diff --git a/tests/BinaryRev.java b/tests/BinaryRev.java deleted file mode 100644 index 94efad4..0000000 --- a/tests/BinaryRev.java +++ /dev/null @@ -1,18 +0,0 @@ -import java.math.BigInteger; - -public class BinaryRev { - static class MyInt { - public int v; - public MyInt(int v) { this.v = v; } - public MyInt multiply(int a) { return new MyInt(v*a); } - public MyInt multiplyRev(int a) { return multiply(a); } - public boolean equals(Object o) { - return (o instanceof MyInt) && ((MyInt)o).v == v; - } - } - - public static boolean test() { - MyInt a = new MyInt(1); - return (a*2).equals(2*a); - } -} diff --git a/tests/Boxing.java b/tests/Boxing.java deleted file mode 100644 index b8e338e..0000000 --- a/tests/Boxing.java +++ /dev/null @@ -1,28 +0,0 @@ -public class Boxing { - static class Vec { - double d[]; - Vec(double... d) { this.d = d; } - double get(int i) { return d[i]; } - double set(int i, double a) { return d[i] = a; } - double add(double a) { return a; } - } - static class WVec { - Double d[]; - WVec(Double... a) { d = a; } - Double get(Integer i) { return d[i]; } - Double set(Integer i, Double a) { return d[i] = a; } - Double add(Double a) { return a; } - } - public static boolean test() { - Vec v = new Vec(1.,2.,3.); - Double d = (v[new Integer(2)] = new Double(4.)); - return d==4. && new Double(4.).equals(v[2]) - && (new Double(1.).equals(v + new Double(1.))) - && wtest(); - } - public static boolean wtest() { - WVec v = new WVec(1.,2.,3.); - double d = (v[2] = 4.0); - return d == 4. && 4 == v[2] && (v+1.)==1.; - } -} diff --git a/tests/CompAss.java b/tests/CompAss.java deleted file mode 100644 index 90466b8..0000000 --- a/tests/CompAss.java +++ /dev/null @@ -1,23 +0,0 @@ -import java.math.BigInteger; - -public class CompAss { - public static boolean test1() { - boolean res = true; - res |= false; - return res; - } - public static boolean test2() { - BigInteger x = BigInteger.ONE; - x = x + BigInteger.TEN; - return x.equals(BigInteger.valueOf(11)); - } - public static boolean test3(boolean a) { - if (a) - a = a || Boolean.TRUE.booleanValue(); - return a; - } - public static boolean test() { return test1() && test2() && test3(true) && !test3(false); } - public static void main(String[] args) throws Exception { - System.out.println(test()); - } -} diff --git a/tests/IndexBoxing.java b/tests/IndexBoxing.java deleted file mode 100644 index 16f97bb..0000000 --- a/tests/IndexBoxing.java +++ /dev/null @@ -1,9 +0,0 @@ -public class IndexBoxing { - int get(int a) { return a; } - public static boolean test() { - IndexBoxing a = new IndexBoxing(); - Integer i = new Integer(1); - a.get(i); - return a[i] == 1; - } -} diff --git a/tests/Vec.java b/tests/Vec.java deleted file mode 100644 index 4d26159..0000000 --- a/tests/Vec.java +++ /dev/null @@ -1,28 +0,0 @@ -public class Vec { - private double x; - private double y; - - public static boolean test() { - Vec[] test = new Vec[] { new Vec(), new Vec() }; - test[1][0] = new Double(1.0); - test[1][1] = 2.f; - (test[0][0] = test[1][0])[1] = 3.; - return test[0][0] == 1.0 && 2.f == test[1][1] && test[0][1] == 3.; - } - - public double get(int i) { - return (i == 0 ? x : y); - } - - public Vec set(int i, double v) { - switch (i) { - case 0: - x = v; - break; - case 1: - y = v; - break; - } - return this; - } -} diff --git a/tests/VecMat.java b/tests/VecMat.java deleted file mode 100644 index e90f321..0000000 --- a/tests/VecMat.java +++ /dev/null @@ -1,11 +0,0 @@ -public class VecMat { - static class Vec { - Vec multiply(Mat A) { return this; } - } - static class Mat {} - public static boolean test() { - Vec a = new Vec(); - Mat A = new Mat(); - return a*A == a; - } -}