-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARPY-1485 Support type parameter syntax for functions (#1602)
- Loading branch information
1 parent
50bbd04
commit df874bb
Showing
14 changed files
with
409 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
python-frontend/src/main/java/org/sonar/plugins/python/api/tree/TypeParam.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* SonarQube Python Plugin | ||
* Copyright (C) 2011-2023 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.plugins.python.api.tree; | ||
|
||
import javax.annotation.CheckForNull; | ||
|
||
public interface TypeParam extends Tree { | ||
|
||
@CheckForNull | ||
Token starToken(); | ||
|
||
Name name(); | ||
|
||
@CheckForNull | ||
TypeAnnotation typeAnnotation(); | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
python-frontend/src/main/java/org/sonar/plugins/python/api/tree/TypeParams.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* SonarQube Python Plugin | ||
* Copyright (C) 2011-2023 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.plugins.python.api.tree; | ||
|
||
import java.util.List; | ||
|
||
public interface TypeParams extends Tree { | ||
Token leftBracket(); | ||
List<TypeParam> typeParamsList(); | ||
Token rightBracket(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
python-frontend/src/main/java/org/sonar/python/tree/TypeParamImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* SonarQube Python Plugin | ||
* Copyright (C) 2011-2023 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
package org.sonar.python.tree; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nullable; | ||
import org.sonar.plugins.python.api.tree.Name; | ||
import org.sonar.plugins.python.api.tree.Token; | ||
import org.sonar.plugins.python.api.tree.Tree; | ||
import org.sonar.plugins.python.api.tree.TreeVisitor; | ||
import org.sonar.plugins.python.api.tree.TypeAnnotation; | ||
import org.sonar.plugins.python.api.tree.TypeParam; | ||
|
||
public class TypeParamImpl extends PyTree implements TypeParam { | ||
|
||
private final Token starToken; | ||
private final Name name; | ||
private final TypeAnnotation annotation; | ||
|
||
public TypeParamImpl(@Nullable Token starToken, Name name, @Nullable TypeAnnotation annotation) { | ||
this.starToken = starToken; | ||
this.name = name; | ||
this.annotation = annotation; | ||
} | ||
|
||
@Override | ||
public void accept(TreeVisitor visitor) { | ||
visitor.visitTypeParam(this); | ||
} | ||
|
||
@Override | ||
public Kind getKind() { | ||
return Kind.TYPE_PARAM; | ||
} | ||
|
||
@CheckForNull | ||
@Override | ||
public Token starToken() { | ||
return starToken; | ||
} | ||
|
||
@Override | ||
public Name name() { | ||
return name; | ||
} | ||
|
||
@CheckForNull | ||
@Override | ||
public TypeAnnotation typeAnnotation() { | ||
return annotation; | ||
} | ||
|
||
@Override | ||
List<Tree> computeChildren() { | ||
return Stream.of(starToken, name, annotation).filter(Objects::nonNull).collect(Collectors.toList()); | ||
} | ||
} |
Oops, something went wrong.