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

Fix interface member detection to support inner records #492

Merged
merged 3 commits into from
Jul 19, 2021
Merged
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
3 changes: 2 additions & 1 deletion packages/java-parser/src/productions/interfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ function defineRules($, t) {
nextTokenType = this.LA(1).tokenType;
if (
tokenMatcher(nextTokenType, t.Class) ||
tokenMatcher(nextTokenType, t.Enum)
tokenMatcher(nextTokenType, t.Enum) ||
tokenMatcher(nextTokenType, t.Record)
) {
return InterfaceBodyTypes.classDeclaration;
}
Expand Down
33 changes: 33 additions & 0 deletions packages/java-parser/test/records/records-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,37 @@ describe("Records", () => {
`;
expect(() => javaParser.parse(input, "compilationUnit")).to.not.throw();
});

it("should handle Java records inside an interface definition", () => {
const input = `
public interface SomeInterface {
record SomeRecord(
String param
) { }
}
`;
expect(() => javaParser.parse(input, "compilationUnit")).to.not.throw();
});

it("should handle Java records implementing an interface inside an interface definition", () => {
const input = `
public interface SomeInterface {
record SomeRecord(
String param
) implements AnyInterface { }
}
`;
expect(() => javaParser.parse(input, "compilationUnit")).to.not.throw();
});

it("should handle Java records implementing an interface inside a class definition", () => {
const input = `
public class SomeClass {
record SomeRecord(
String param
) implements AnyInterface { }
}
`;
expect(() => javaParser.parse(input, "compilationUnit")).to.not.throw();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,10 @@ public record MyRecord(
}
}
}

public interface MyInterface {
record MyRecord(
String param) implements MyInterface {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,7 @@ public record MyRecord(String name, int age) {
}
}
}

public interface MyInterface {
record MyRecord(String param) implements MyInterface {}
}