-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARIAC-1631 Bicep parser should parse array types (#1550)
- Loading branch information
Showing
14 changed files
with
445 additions
and
43 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
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
33 changes: 33 additions & 0 deletions
33
iac-extensions/arm/src/main/java/org/sonar/iac/arm/tree/api/bicep/ArrayTypeReference.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,33 @@ | ||
/* | ||
* SonarQube IaC Plugin | ||
* Copyright (C) 2021-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.iac.arm.tree.api.bicep; | ||
|
||
import javax.annotation.CheckForNull; | ||
import org.sonar.iac.arm.tree.api.NumericLiteral; | ||
|
||
/** | ||
* Marker interface for array types (e.g. {@code string[]}) | ||
*/ | ||
public interface ArrayTypeReference extends TypeExpressionAble { | ||
TypeExpressionAble getType(); | ||
|
||
@CheckForNull | ||
NumericLiteral getLength(); | ||
} |
26 changes: 26 additions & 0 deletions
26
iac-extensions/arm/src/main/java/org/sonar/iac/arm/tree/api/bicep/ArrayTypeSuffix.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,26 @@ | ||
/* | ||
* SonarQube IaC Plugin | ||
* Copyright (C) 2021-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.iac.arm.tree.api.bicep; | ||
|
||
/** | ||
* Interface for array type suffix that build into {@link ArrayTypeReference}. | ||
*/ | ||
public interface ArrayTypeSuffix extends TypeReferenceSuffix { | ||
} |
34 changes: 34 additions & 0 deletions
34
iac-extensions/arm/src/main/java/org/sonar/iac/arm/tree/api/bicep/TypeReferenceSuffix.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 IaC Plugin | ||
* Copyright (C) 2021-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.iac.arm.tree.api.bicep; | ||
|
||
/** | ||
* Interface for type suffix that get applied to {@link TypeExpressionAble} types. | ||
*/ | ||
public interface TypeReferenceSuffix { | ||
|
||
/** | ||
* Apply the suffix to another type. | ||
* | ||
* @param baseType the base type to which the suffix will be applied | ||
* @return the base type with the suffix | ||
*/ | ||
TypeExpressionAble applyTo(TypeExpressionAble baseType); | ||
} |
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
84 changes: 84 additions & 0 deletions
84
...xtensions/arm/src/main/java/org/sonar/iac/arm/tree/impl/bicep/ArrayTypeReferenceImpl.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,84 @@ | ||
/* | ||
* SonarQube IaC Plugin | ||
* Copyright (C) 2021-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.iac.arm.tree.impl.bicep; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nullable; | ||
import org.sonar.iac.arm.tree.api.NumericLiteral; | ||
import org.sonar.iac.arm.tree.api.bicep.ArrayTypeReference; | ||
import org.sonar.iac.arm.tree.api.bicep.SyntaxToken; | ||
import org.sonar.iac.arm.tree.api.bicep.TypeExpressionAble; | ||
import org.sonar.iac.arm.tree.impl.AbstractArmTreeImpl; | ||
import org.sonar.iac.common.api.tree.Tree; | ||
|
||
public class ArrayTypeReferenceImpl extends AbstractArmTreeImpl implements ArrayTypeReference { | ||
private final TypeExpressionAble type; | ||
private final SyntaxToken lBracket; | ||
@CheckForNull | ||
private final NumericLiteral length; | ||
private final SyntaxToken rBracket; | ||
|
||
public ArrayTypeReferenceImpl(TypeExpressionAble type, SyntaxToken lBracket, @Nullable NumericLiteral length, SyntaxToken rBracket) { | ||
this.type = type; | ||
this.lBracket = lBracket; | ||
this.length = length; | ||
this.rBracket = rBracket; | ||
} | ||
|
||
@Override | ||
public TypeExpressionAble getType() { | ||
return type; | ||
} | ||
|
||
@CheckForNull | ||
@Override | ||
public NumericLiteral getLength() { | ||
return length; | ||
} | ||
|
||
@Override | ||
public List<Tree> children() { | ||
List<Tree> children = new ArrayList<>(type.children()); | ||
children.add(lBracket); | ||
if (length != null) { | ||
children.add(length); | ||
} | ||
children.add(rBracket); | ||
return children; | ||
} | ||
|
||
@Override | ||
public Kind getKind() { | ||
return Kind.ARRAY_TYPE_REFERENCE; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
var result = type.toString(); | ||
result += lBracket.toString(); | ||
if (length != null) { | ||
result += length.toString(); | ||
} | ||
result += rBracket.toString(); | ||
return result; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
iac-extensions/arm/src/main/java/org/sonar/iac/arm/tree/impl/bicep/ArrayTypeSuffixImpl.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,45 @@ | ||
/* | ||
* SonarQube IaC Plugin | ||
* Copyright (C) 2021-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.iac.arm.tree.impl.bicep; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nullable; | ||
import org.sonar.iac.arm.tree.api.NumericLiteral; | ||
import org.sonar.iac.arm.tree.api.bicep.ArrayTypeSuffix; | ||
import org.sonar.iac.arm.tree.api.bicep.SyntaxToken; | ||
import org.sonar.iac.arm.tree.api.bicep.TypeExpressionAble; | ||
|
||
public class ArrayTypeSuffixImpl implements ArrayTypeSuffix { | ||
private final SyntaxToken lBracket; | ||
@CheckForNull | ||
private final NumericLiteral length; | ||
private final SyntaxToken rBracket; | ||
|
||
public ArrayTypeSuffixImpl(SyntaxToken lBracket, @Nullable NumericLiteral length, SyntaxToken rBracket) { | ||
this.lBracket = lBracket; | ||
this.length = length; | ||
this.rBracket = rBracket; | ||
} | ||
|
||
@Override | ||
public TypeExpressionAble applyTo(TypeExpressionAble baseType) { | ||
return new ArrayTypeReferenceImpl(baseType, lBracket, length, rBracket); | ||
} | ||
} |
Oops, something went wrong.