Skip to content

Commit e30a38f

Browse files
authored
Merge pull request #20 from desmorto/diamond-operator-update
Versão estável do refatoramento do operador diamante
2 parents b249147 + 8cec484 commit e30a38f

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

src/lang/java/refactoring/Diamond.rsc

+38-33
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,45 @@ public tuple[int, CompilationUnit] refactorDiamond(CompilationUnit unit) {
1313
int numberOfOccurences = 0;
1414
CompilationUnit cu = visit(unit)
1515
{
16-
case (FieldDeclaration)`<FieldModifier* fm><Identifier idt><TypeArguments tas><VariableDeclaratorList vdl>;` : {
17-
VariableDeclaratorList v2 = visit(vdl){ //case lvalue is a generic type
18-
//Case where generics isn't especified
19-
case (ClassOrInterfaceTypeToInstantiate)`<{AnnotatedType "."}* aType>//Diammond` : {
20-
numberOfOccurences += 1;
21-
insert (ClassOrInterfaceTypeToInstantiate)`<{AnnotatedType "."}* aType>\<\>`;
22-
}
23-
//Case where generics may be simplified to <>
24-
case (ClassOrInterfaceTypeToInstantiate)`<{AnnotatedType "."}* aType> <TypeArguments args>` : {
25-
numberOfOccurences += 1;
26-
if (/`\<\>`/ !:= toString(args)){
27-
insert (ClassOrInterfaceTypeToInstantiate)`<{AnnotatedType "."}* aType>\<\>`;
28-
}
29-
}
30-
};
31-
insert((FieldDeclaration)`<FieldModifier* fm> <Identifier idt><TypeArguments tas> <VariableDeclaratorList v2>;`);
16+
//case (FieldDeclaration)`<FieldModifier fm> <Identifier idt><TypeArguments tas><VariableDeclaratorId vdId>= new <{AnnotatedType "."}* aType>(<ArgumentList? al>);` : {
17+
// numberOfOccurences += 1;
18+
// insert((FieldDeclaration)`<FieldModifier fm> <Identifier idt><TypeArguments tas> <VariableDeclaratorId vdId>= new <{AnnotatedType "."}* aType>\<\>(<ArgumentList? al>);`);
19+
//}
20+
//case (FieldDeclaration)`<Identifier idt><TypeArguments tas><VariableDeclaratorId vdId>= new <{AnnotatedType "."}* aType>(<ArgumentList? al>);` : {
21+
// numberOfOccurences += 1;
22+
// insert((FieldDeclaration)`<Identifier idt><TypeArguments tas> <VariableDeclaratorId vdId>= new <{AnnotatedType "."}* aType>\<\>(<ArgumentList? al>);`);
23+
//}
24+
case (FieldDeclaration)`<FieldModifier fm> <Identifier idt><TypeArguments tas><VariableDeclaratorId vdId> = new <{AnnotatedType "."}* aType><TypeArguments args>(<ArgumentList? al>);` : {
25+
if(args !:= (TypeArguments)`\<\>`){
26+
numberOfOccurences += 1;
27+
insert((FieldDeclaration)`<FieldModifier fm> <Identifier idt><TypeArguments tas> <VariableDeclaratorId vdId>= new <{AnnotatedType "."}* aType>\<\>(<ArgumentList? al>);`);
28+
}
3229
}
33-
34-
case (LocalVariableDeclaration)`<Identifier idt> <TypeArguments tas> <VariableDeclaratorList vdl>` : {
35-
VariableDeclaratorList v2 = visit(vdl){ //case lvalue is a generic type
36-
//Case where generics isn't especified
37-
case (ClassOrInterfaceTypeToInstantiate)`<{AnnotatedType "."}* aType>` : {
38-
numberOfOccurences += 1;
39-
insert (ClassOrInterfaceTypeToInstantiate)`<{AnnotatedType "."}* aType>\<\>`;
40-
}
41-
//Case where generics may be simplified to <>
42-
case (ClassOrInterfaceTypeToInstantiate)`<{AnnotatedType "."}* aType> <TypeArguments args>` : {
43-
numberOfOccurences += 1;
44-
if (/`\<\>`/ !:= toString(args)){
45-
insert (ClassOrInterfaceTypeToInstantiate)`<{AnnotatedType "."}* aType>\<\>`;
46-
}
47-
}
48-
};
49-
insert((LocalVariableDeclaration)`<Identifier idt><TypeArguments tas> <VariableDeclaratorList v2>`);
30+
case (FieldDeclaration)`<Identifier idt><TypeArguments tas><VariableDeclaratorId vdId> = new <{AnnotatedType "."}* aType><TypeArguments args>(<ArgumentList? al>);` : {
31+
if(args !:= (TypeArguments)`\<\>`){
32+
numberOfOccurences += 1;
33+
insert((FieldDeclaration)`<Identifier idt><TypeArguments tas> <VariableDeclaratorId vdId>= new <{AnnotatedType "."}* aType>\<\>(<ArgumentList? al>);`);
34+
}
35+
}
36+
//case (LocalVariableDeclaration)`<VariableModifier vm> <Identifier idt><TypeArguments tas><VariableDeclaratorId vdId> = new <{AnnotatedType "."}* aType>(<ArgumentList? al>)` : {
37+
// numberOfOccurences += 1;
38+
// insert((LocalVariableDeclaration)`<VariableModifier vm> <Identifier idt><TypeArguments tas> <VariableDeclaratorId vdId>= new <{AnnotatedType "."}* aType>\<\>(<ArgumentList? al>)`);
39+
//}
40+
//case (LocalVariableDeclaration)`<Identifier idt><TypeArguments tas><VariableDeclaratorId vdId> = new <{AnnotatedType "."}* aType>(<ArgumentList? al>)` : {
41+
// numberOfOccurences += 1;
42+
// insert((LocalVariableDeclaration)`<Identifier idt><TypeArguments tas> <VariableDeclaratorId vdId>= new <{AnnotatedType "."}* aType>\<\>(<ArgumentList? al>)`);
43+
//}
44+
case (LocalVariableDeclaration) `<VariableModifier vm> <Identifier idt><TypeArguments tas><VariableDeclaratorId vdId> = new <{AnnotatedType "."}* aType><TypeArguments args>(<ArgumentList? al>)` : {
45+
if(args !:= (TypeArguments)`\<\>`){
46+
numberOfOccurences += 1;
47+
insert((LocalVariableDeclaration)`<VariableModifier vm> <Identifier idt><TypeArguments tas> <VariableDeclaratorId vdId>= new <{AnnotatedType "."}* aType>\<\>(<ArgumentList? al>)`);
48+
}
49+
}
50+
case (LocalVariableDeclaration)`<Identifier idt><TypeArguments tas><VariableDeclaratorId vdId> = new <{AnnotatedType "."}* aType><TypeArguments args>(<ArgumentList? al>)` : {
51+
if(args !:= (TypeArguments)`\<\>`){
52+
numberOfOccurences += 1;
53+
insert((LocalVariableDeclaration)`<Identifier idt><TypeArguments tas> <VariableDeclaratorId vdId>= new <{AnnotatedType "."}* aType>\<\>(<ArgumentList? al>)`);
54+
}
5055
}
5156
};
5257
return <numberOfOccurences, cu>;

0 commit comments

Comments
 (0)