Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java Records support #121

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions fixtures/VariableDeclaration/OneRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package VariableDeclaration;

public record OneRecord(String aString, Integer anInteger, Long aLong) {

void y() {

}
}
27 changes: 27 additions & 0 deletions fixtures/assignments/RecordAssignments.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package assignments;

record RecordAssignments() {

public void m1() {
int a = 10;
int b = 20;

b = b + 10;
a = a + 10;

int c;
c = 60;
}

public void m2() {
int a = 20;
int b = a;

int c;
c = a + b;
}

public void m3() {

}
}
16 changes: 16 additions & 0 deletions fixtures/cbo/RecordCoupling.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cbo;

record RecordCoupling(){

private B b;

public D m1() {
A a = new A();
C[] x = new C[10];

CouplingHelper h = new CouplingHelper();
C2 c2 = h.m1();

return d;
}
}
4 changes: 4 additions & 0 deletions fixtures/class-types/ARecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package classtypes;

record ARecord(String aString, Integer anInteger, Long aLong) {
}
32 changes: 32 additions & 0 deletions fixtures/comparison/RecordComparison.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package comparison;

record RecordComparison() {

public void m1() {
int a = 1, b = 2;

if(a == 1 || b == 2) {
System.out.println("Yay!");
}
}

public void m2() {
int a = 1, b = 2;

if(a == 1) {
System.out.println("Yay!");
}
}

public void m3() {
int a = 1;
}

public void m4() {
int a = 1;

if(a != 1) {
System.out.println("Yay!");
}
}
}
22 changes: 22 additions & 0 deletions fixtures/dit/RecordR.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dit;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

record RecordR() implements ActionListener, UmaInterface {

@Override
public void actionPerformed(ActionEvent e) {
String x = e.getActionCommand();
if(x.isEmpty()){
x = "teste";
}
else{
x = x;
}
}

public int a(){
return 0;
}
}
6 changes: 6 additions & 0 deletions fixtures/dit/UmaInterface.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dit;

public interface UmaInterface {

public int a();
}
6 changes: 6 additions & 0 deletions fixtures/fields/RecordFields.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package fields;

public record RecordFields(int a, String b, char c) {

private final static int x = 0;
}
87 changes: 87 additions & 0 deletions fixtures/innerclasses/MessyRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package innerclasses;

record MessyRecord {

private int a;
private int b;

class InnerClass1 {
public void m1() {
int x = 0;
int y = 0;
if(x > 10) {
if(y < 20) {
// ...
} else {
// ...
}
}
}

public void m2() {}
}

static class InnerClass2 {
public void m1() {
int a = a + 10;
}

public void m2() {}

public void m3() {}
}

public void m1() {
this.a = 10;

for(int i = 0; i < 10; i++) {
// ...
}
System.out.println(a);
}

public void m2() {
this.b = 10;
System.out.println(b);

}

public void m3() {
Thread t = new Thread()
{
public void run()
{
System.out.println("Child Thread 1");
}
};
}

public void m4() {
Arrays.asList("a1", "a2", "a3")
.stream()
.findFirst()
.ifPresent(x -> System.out.println(x));
}


public void m5() {
Thread t = new Thread()
{
public void run()
{
System.out.println("Child Thread 2");
}

public void x() { }
};
}

public void m6() {
class InnerClass3 {
public void m1();
};

int a = 1;
}

}
17 changes: 17 additions & 0 deletions fixtures/innerclasses/RecordSC2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package innerclasses;

class RecordSC2 {
public void m1() {
System.out.println(new Object() {
@Override public String toString() {

class X {
public void m1() {
int a = 1;
}
}
return "Hello world!";
}
});
}
}
28 changes: 28 additions & 0 deletions fixtures/methods/OneRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package methods;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public record OneRecord(String aString, Integer anInteger, Long aLong) implements ActionListener {

public OneRecord(String aString, Long aLong) {
this(aString, 0, aLong);
}

public int simpleSum(int parcela) {
return anInteger + parcela;
}

@Override
public void actionPerformed(ActionEvent e) {}

private static void privateStaticMethod(){}

void defaultMethod() {}

protected void protectedMethod() {}

public synchronized void syncMethod(){}

public final void finalMethod() {}
}
14 changes: 14 additions & 0 deletions fixtures/parameters/OneRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public record OneRecord(String aString, Integer anInteger, Long aLong) implements ActionListener {

public int simpleSum(int parcela){
return anInteger + parcela;
}

@Override
public void actionPerformed(ActionEvent e) {

}
}
14 changes: 14 additions & 0 deletions fixtures/records/OneRecord.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public record OneRecord(String aString, Integer anInteger, Long aLong) implements ActionListener {

public int simpleSum(int parcela){
return anInteger + parcela;
}

@Override
public void actionPerformed(ActionEvent e) {

}
}
28 changes: 28 additions & 0 deletions fixtures/returns/RecordReturns.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package returns;

record RecordReturns() {

public void m1() {
boolean a = true;
boolean b = false;

if(a) return;
if(b) return;
return;
}

public int m2() {
boolean a = true;

if(a) return 10;
return 20;
}

public void m3() {
return;
}

public void m4() {

}
}
24 changes: 24 additions & 0 deletions fixtures/variables/RecordVariables.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package variables;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public record RecordVariables(String aString, Integer anInteger, Long aLong) implements ActionListener {

public int simpleSum(int parcela) {
return anInteger + parcela;
}

@Override
public void actionPerformed(ActionEvent e) {
int x = 4;
int y = 5;
}

private static void privateStaticMethod(){
int x = 5;
long z = 80;
}

void defaultMethod() {}
}
18 changes: 18 additions & 0 deletions fixtures/wmc/RecordWMC.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package wmc;

record RecordWMC(){

public void m1(boolean x) {
int a = 0;

if(x) a++;
else a--;
}

public void m2(boolean x) {
int a = 0;

if(x == true) a++;
else a--;
}
}
Loading