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

Migrate java scopes #2038

Merged
merged 22 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from 21 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
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,6 @@ const textFragmentExtractors: Record<
"html",
htmlStringTextFragmentExtractor,
),
java: constructDefaultTextFragmentExtractor(
"java",
constructHackedStringTextFragmentExtractor("java"),
),
javascript: constructDefaultTextFragmentExtractor(
"javascript",
typescriptStringTextFragmentExtractor,
Expand Down
114 changes: 2 additions & 112 deletions packages/cursorless-engine/src/languages/java.ts
Original file line number Diff line number Diff line change
@@ -1,122 +1,12 @@
import {
createPatternMatchers,
argumentMatcher,
leadingMatcher,
conditionMatcher,
trailingMatcher,
matcher,
cascadingMatcher,
} from "../util/nodeMatchers";
import { childRangeSelector } from "../util/nodeSelectors";
import { patternFinder } from "../util/nodeFinders";
import { argumentMatcher, createPatternMatchers } from "../util/nodeMatchers";

import { NodeMatcherAlternative } from "../typings/Types";
import { SimpleScopeTypeType } from "@cursorless/common";

// Generated by the following command:
// > curl https://raw.githubusercontent.com/tree-sitter/tree-sitter-java/master/src/node-types.json | jq '[.[] | select(.type == "statement" or .type == "declaration") | .subtypes[].type]'
const STATEMENT_TYPES = [
"annotation_type_declaration",
"class_declaration",
"enum_declaration",
"import_declaration",
"interface_declaration",
"module_declaration",
"package_declaration",
"assert_statement",
"break_statement",
"continue_statement",
"declaration",
"do_statement",
"enhanced_for_statement",
"expression_statement",
"for_statement",
"if_statement",
"labeled_statement",
"local_variable_declaration",
"return_statement",
"switch_expression",
"synchronized_statement",
"throw_statement",
"try_statement",
"try_with_resources_statement",
"while_statement",
"yield_statement",

// exceptions
// ";",
// "block",
"switch_statement",
"method_declaration",
"constructor_declaration",
"field_declaration",
];
import { NodeMatcherAlternative } from "../typings/Types";

const nodeMatchers: Partial<
Record<SimpleScopeTypeType, NodeMatcherAlternative>
> = {
statement: STATEMENT_TYPES,
class: "class_declaration",
className: "class_declaration[name]",
ifStatement: "if_statement",
string: "string_literal",
comment: ["line_comment", "block_comment", "comment"],
anonymousFunction: "lambda_expression",
list: "array_initializer",
functionCall: [
"method_invocation",
"object_creation_expression",
"explicit_constructor_invocation",
],
functionCallee: cascadingMatcher(
matcher(
patternFinder("method_invocation"),
childRangeSelector(["argument_list"], []),
),
matcher(
patternFinder("object_creation_expression"),
childRangeSelector(["argument_list"], []),
),
matcher(
patternFinder("explicit_constructor_invocation"),
childRangeSelector(["argument_list", ";"], []),
),
),
map: "block",
name: [
"*[declarator][name]",
"assignment_expression[left]",
"*[name]",
"formal_parameter.identifier!",
],
namedFunction: ["method_declaration", "constructor_declaration"],
type: trailingMatcher([
"generic_type.type_arguments.type_identifier",
"generic_type.type_identifier",
"generic_type.scoped_type_identifier.type_identifier",
"type_identifier",
"local_variable_declaration[type]",
"array_creation_expression[type]",
"formal_parameter[type]",
"method_declaration[type]",
]),
functionName: [
"method_declaration.identifier!",
"constructor_declaration.identifier!",
],
value: leadingMatcher(
[
"*[declarator][value]",
"assignment_expression[right]",
"return_statement[0]",
"*[value]",
],
["=", "+=", "-=", "*=", "/=", "%=", "&=", "|=", "^=", "<<=", ">>="],
),
condition: conditionMatcher("*[condition]"),
argumentOrParameter: argumentMatcher("formal_parameters", "argument_list"),
branch: ["switch_block_statement_group", "switch_rule"],
switchStatementSubject: "switch_expression[condition][0]",
};

export default createPatternMatchers(nodeMatchers);
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
languageId: java
command:
version: 6
spokenForm: change branch
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: branch}
usePrePhraseSnapshot: true
initialState:
documentContents: |
public class MyClass {
public void myFunk() {
if (true) {
}
else if (false) {
}
else {
}
}
}
selections:
- anchor: {line: 2, character: 4}
active: {line: 2, character: 4}
marks: {}
finalState:
documentContents: |
public class MyClass {
public void myFunk() {

else if (false) {
}
else {
}
}
}
selections:
- anchor: {line: 2, character: 4}
active: {line: 2, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
languageId: java
command:
version: 6
spokenForm: change branch
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: branch}
usePrePhraseSnapshot: true
initialState:
documentContents: |
public class MyClass {
public void myFunk() {
if (true) {
}
else if (false) {
}
else {
}
}
}
selections:
- anchor: {line: 4, character: 4}
active: {line: 4, character: 4}
marks: {}
finalState:
documentContents: |
public class MyClass {
public void myFunk() {
if (true) {
}

else {
}
}
}
selections:
- anchor: {line: 4, character: 4}
active: {line: 4, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
languageId: java
command:
version: 6
spokenForm: change branch
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: branch}
usePrePhraseSnapshot: true
initialState:
documentContents: |
public class MyClass {
public void myFunk() {
if (true) {
}
else if (false) {
}
else {
}
}
}
selections:
- anchor: {line: 6, character: 4}
active: {line: 6, character: 4}
marks: {}
finalState:
documentContents: |
public class MyClass {
public void myFunk() {
if (true) {
}
else if (false) {
}

}
}
selections:
- anchor: {line: 6, character: 4}
active: {line: 6, character: 4}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
languageId: java
command:
version: 6
spokenForm: change branch
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: branch}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
public class MyClass {
public void myFunk() {
true ? 1 : 2
}
}
selections:
- anchor: {line: 2, character: 15}
active: {line: 2, character: 15}
marks: {}
finalState:
documentContents: |-
public class MyClass {
public void myFunk() {
true ? : 2
}
}
selections:
- anchor: {line: 2, character: 15}
active: {line: 2, character: 15}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
languageId: java
command:
version: 6
spokenForm: change branch
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: branch}
usePrePhraseSnapshot: true
initialState:
documentContents: |-
public class MyClass {
public void myFunk() {
true ? 1 : 2
}
}
selections:
- anchor: {line: 2, character: 19}
active: {line: 2, character: 19}
marks: {}
finalState:
documentContents: |-
public class MyClass {
public void myFunk() {
true ? 1 :
}
}
selections:
- anchor: {line: 2, character: 19}
active: {line: 2, character: 19}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ initialState:
active: {line: 0, character: 9}
marks: {}
finalState:
documentContents: new ().bar();
documentContents: ().bar();
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ initialState:
active: {line: 0, character: 12}
marks: {}
finalState:
documentContents: new ();
documentContents: ();
selections:
- anchor: {line: 0, character: 4}
active: {line: 0, character: 4}
- anchor: {line: 0, character: 0}
active: {line: 0, character: 0}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
languageId: java
command:
version: 6
spokenForm: change condition
action:
name: clearAndSetSelection
target:
type: primitive
modifiers:
- type: containingScope
scopeType: {type: condition}
usePrePhraseSnapshot: true
initialState:
documentContents: |
public class MyClass {
public void myFunk() {
if (true) {
}
else if (false) {
}
else {
}
}
}
selections:
- anchor: {line: 2, character: 4}
active: {line: 2, character: 4}
marks: {}
finalState:
documentContents: |
public class MyClass {
public void myFunk() {
if () {
}
else if (false) {
}
else {
}
}
}
selections:
- anchor: {line: 2, character: 8}
active: {line: 2, character: 8}
Loading