You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
add InspectionCopilot to inspect provided code (#1313)
* add `InspectionCopilot` to inspect provided code: provide prompts, process input code and extract output inspections from comments.
* use `sendInfo` to attach properties to current telemetry event.
* chore: fix miscellaneous issues
You are expert at Java and code refactoring. Please identify code blocks that can be rewritten with
10
+
Java latest features/syntaxes/grammar sugars to make them more **readable**, **efficient** and **concise** for given code.
11
+
I prefer \`Stream\` to loop, \`Optional\` to null, \`record\` to POJO, \`switch\` to if-else, etc.
12
+
Please comment on the rewritable code directly in the original source code in the following format:
13
+
\`\`\`
14
+
other code...
15
+
// @PROBLEM: problem of the code in less than 10 words, should be as short as possible, starts with a gerund/noun word, e.g., "Using".
16
+
// @SOLUTION: solution to fix the problem in less than 10 words, should be as short as possible, starts with a verb.
17
+
// @SYMBOL: symbol of the problematic code block, must be a single word contained by the problematic code. it's usually a Java keyword, a method/field/variable name, or a value(e.g. magic number)... but NOT multiple, '<null>' if cannot be identified
18
+
// @SEVERITY: severity of the problem, must be one of **[HIGH, MIDDLE, LOW]**, *HIGH* for Probable bugs, Security risks, Exception handling or Resource management(e.g. memory leaks); *MIDDLE* for Error handling, Performance, Reflective accesses issues and Verbose or redundant code; *LOW* for others
19
+
the original problematic code...
20
+
\`\`\`
21
+
The comment must be placed directly above the problematic code, and the problematic code must be kept unchanged.
22
+
Your reply must be the complete original code sent to you plus your comments, without any other modifications.
23
+
Never comment on undertermined problems.
24
+
Never comment on code that is well-written or simple enough.
25
+
Don't add any explanation, don't format logger. Don't output markdown.
26
+
You must end your response with "//${Copilot.DEFAULT_END_MARK}".
27
+
`;
28
+
publicstaticreadonlyEXAMPLE_USER_MESSAGE=`
29
+
@Entity
30
+
public class EmployeePojo implements Employee {
31
+
public final String name;
32
+
public EmployeePojo(String name) {
33
+
this.name = name;
34
+
}
35
+
public String getRole() {
36
+
String result = '';
37
+
if (this.name.equals("Miller")) {
38
+
result = "Senior";
39
+
} else if (this.name.equals("Mike")) {
40
+
result = "HR";
41
+
} else {
42
+
result = "FTE";
43
+
}
44
+
return result;
45
+
}
46
+
public void test(String[] arr) {
47
+
try {
48
+
Integer.parseInt(arr[0]);
49
+
} catch (Exception e) {
50
+
e.printStackTrace();
51
+
}
52
+
}
53
+
}
54
+
`;
55
+
publicstaticreadonlyEXAMPLE_ASSISTANT_MESSAGE=`
56
+
@Entity
57
+
// @PROBLEM: Using a traditional POJO
58
+
// @SOLUTION: transform into a record
59
+
// @SYMBOL: EmployeePojo
60
+
// @SEVERITY: MIDDLE
61
+
public class EmployeePojo implements Employee {
62
+
public final String name;
63
+
public EmployeePojo(String name) {
64
+
this.name = name;
65
+
}
66
+
public String getRole() {
67
+
String result = '';
68
+
// @PROBLEM: Using if-else statements to check the type of animal
69
+
// @SOLUTION: Use switch expression
70
+
// @SYMBOL: if
71
+
// @SEVERITY: MIDDLE
72
+
if (this.name.equals("Miller")) {
73
+
result = "Senior";
74
+
} else if (this.name.equals("Mike")) {
75
+
result = "HR";
76
+
} else {
77
+
result = "FTE";
78
+
}
79
+
return result;
80
+
}
81
+
public void test(String[] arr) {
82
+
try {
83
+
Integer.parseInt(arr[0]);
84
+
} catch (Exception e) {
85
+
// @PROBLEM: Print stack trace in case of an exception
0 commit comments