-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARPHP-1533 Support Disjunctive Normal Form Types (PHP 8.2 feature) (…
- Loading branch information
1 parent
93dc62d
commit 717d0fc
Showing
19 changed files
with
545 additions
and
23 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
80 changes: 80 additions & 0 deletions
80
...ontend/src/main/java/org/sonar/php/tree/impl/declaration/DnfIntersectionTypeTreeImpl.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,80 @@ | ||
/* | ||
* SonarQube PHP Plugin | ||
* Copyright (C) 2010-2024 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.php.tree.impl.declaration; | ||
|
||
import java.util.Iterator; | ||
import org.sonar.php.tree.impl.PHPTree; | ||
import org.sonar.php.utils.collections.IteratorUtils; | ||
import org.sonar.plugins.php.api.tree.SeparatedList; | ||
import org.sonar.plugins.php.api.tree.Tree; | ||
import org.sonar.plugins.php.api.tree.declaration.DnfIntersectionTypeTree; | ||
import org.sonar.plugins.php.api.tree.declaration.TypeTree; | ||
import org.sonar.plugins.php.api.tree.lexical.SyntaxToken; | ||
import org.sonar.plugins.php.api.visitors.VisitorCheck; | ||
|
||
public class DnfIntersectionTypeTreeImpl extends PHPTree implements DnfIntersectionTypeTree { | ||
private final SyntaxToken openParenthesisToken; | ||
private final SeparatedList<TypeTree> types; | ||
private final SyntaxToken closedParenthesisToken; | ||
|
||
public DnfIntersectionTypeTreeImpl(SyntaxToken openParenthesisToken, SeparatedList<TypeTree> types, SyntaxToken closedParenthesisToken) { | ||
this.openParenthesisToken = openParenthesisToken; | ||
this.types = types; | ||
this.closedParenthesisToken = closedParenthesisToken; | ||
} | ||
|
||
@Override | ||
public Iterator<Tree> childrenIterator() { | ||
return IteratorUtils.concat( | ||
IteratorUtils.iteratorOf(openParenthesisToken), | ||
types.elementsAndSeparators(), | ||
IteratorUtils.iteratorOf(closedParenthesisToken)); | ||
} | ||
|
||
@Override | ||
public SyntaxToken openParenthesisToken() { | ||
return openParenthesisToken; | ||
} | ||
|
||
@Override | ||
public SeparatedList<TypeTree> types() { | ||
return types; | ||
} | ||
|
||
@Override | ||
public SyntaxToken closedParenthesisToken() { | ||
return closedParenthesisToken; | ||
} | ||
|
||
@Override | ||
public boolean isSimple() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void accept(VisitorCheck visitor) { | ||
visitor.visitDnfIntersectionType(this); | ||
} | ||
|
||
@Override | ||
public Kind getKind() { | ||
return Kind.DNF_INTERSECTION_TYPE; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
php-frontend/src/main/java/org/sonar/php/tree/impl/declaration/DnfTypeTreeImpl.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,62 @@ | ||
/* | ||
* SonarQube PHP Plugin | ||
* Copyright (C) 2010-2024 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.php.tree.impl.declaration; | ||
|
||
import java.util.Iterator; | ||
import org.sonar.php.tree.impl.PHPTree; | ||
import org.sonar.plugins.php.api.tree.SeparatedList; | ||
import org.sonar.plugins.php.api.tree.Tree; | ||
import org.sonar.plugins.php.api.tree.declaration.DeclaredTypeTree; | ||
import org.sonar.plugins.php.api.tree.declaration.DnfTypeTree; | ||
import org.sonar.plugins.php.api.visitors.VisitorCheck; | ||
|
||
public class DnfTypeTreeImpl extends PHPTree implements DnfTypeTree { | ||
|
||
private final SeparatedList<DeclaredTypeTree> types; | ||
|
||
public DnfTypeTreeImpl(SeparatedList<DeclaredTypeTree> types) { | ||
this.types = types; | ||
} | ||
|
||
@Override | ||
public Iterator<Tree> childrenIterator() { | ||
return types.elementsAndSeparators(); | ||
} | ||
|
||
@Override | ||
public boolean isSimple() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public void accept(VisitorCheck visitor) { | ||
visitor.visitDnfType(this); | ||
} | ||
|
||
@Override | ||
public Kind getKind() { | ||
return Kind.DNF_TYPE; | ||
} | ||
|
||
@Override | ||
public SeparatedList<DeclaredTypeTree> types() { | ||
return types; | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
...end/src/main/java/org/sonar/plugins/php/api/tree/declaration/DnfIntersectionTypeTree.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,52 @@ | ||
/* | ||
* SonarQube PHP Plugin | ||
* Copyright (C) 2010-2024 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.php.api.tree.declaration; | ||
|
||
import org.sonar.plugins.php.api.tree.SeparatedList; | ||
import org.sonar.plugins.php.api.tree.lexical.SyntaxToken; | ||
|
||
/** | ||
* Represent intersection in Disjunctive Normal Form (DNF) of types. | ||
* <pre> | ||
* {@link DnfTypeTree} | ||
* </pre> | ||
* | ||
* @since 3.39 | ||
*/ | ||
public interface DnfIntersectionTypeTree extends DeclaredTypeTree { | ||
|
||
/** | ||
* The open parenthesis token, e.g., <code>(</code> in <code>(int|string)</code>. | ||
* @return the open parenthesis token | ||
*/ | ||
SyntaxToken openParenthesisToken(); | ||
|
||
/** | ||
* The list of elements and separators, e.g., <code>int</code>, <code>|</code> and <code>string</code> in <code>(int|string)</code>. | ||
* @return the list of elements and separators | ||
*/ | ||
SeparatedList<TypeTree> types(); | ||
|
||
/** | ||
* The closed parenthesis token, e.g., <code>)</code> in <code>(int|string)</code>. | ||
* @return the closed parenthesis token | ||
*/ | ||
SyntaxToken closedParenthesisToken(); | ||
} |
36 changes: 36 additions & 0 deletions
36
php-frontend/src/main/java/org/sonar/plugins/php/api/tree/declaration/DnfTypeTree.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,36 @@ | ||
/* | ||
* SonarQube PHP Plugin | ||
* Copyright (C) 2010-2024 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.php.api.tree.declaration; | ||
|
||
import org.sonar.plugins.php.api.tree.SeparatedList; | ||
|
||
/** | ||
* <a href="https://wiki.php.net/rfc/dnf_types">DNF Types</a> | ||
* | ||
* @since 3.39 | ||
*/ | ||
public interface DnfTypeTree extends DeclaredTypeTree { | ||
|
||
/** | ||
* The list of elements and separators, e.g., <code>int</code>, <code>|</code> and <code>(A&B)</code> in <code>int|(A&B)</code>. | ||
* @return the list of elements and separators | ||
*/ | ||
SeparatedList<DeclaredTypeTree> types(); | ||
} |
Oops, something went wrong.