-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unique names withing declarations (#575)
Closes partially #543 ### Summary of Changes Ensure that names are unique within declarations. I'll port the checks for uniqueness on the file level in a future PR. --------- Co-authored-by: megalinter-bot <[email protected]>
- Loading branch information
1 parent
4ba7873
commit 47ce782
Showing
19 changed files
with
670 additions
and
54 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { SdsImport } from '../generated/ast.js'; | ||
|
||
export const isWildcardImport = function (node: SdsImport): boolean { | ||
const importedNamespace = node.importedNamespace ?? ''; | ||
return importedNamespace.endsWith('*'); | ||
}; |
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,96 @@ | ||
import { | ||
isSdsAssignment, | ||
isSdsBlockLambdaResult, | ||
isSdsDeclaration, | ||
isSdsPlaceholder, | ||
SdsAnnotatedObject, | ||
SdsAnnotationCall, | ||
SdsAssignee, | ||
SdsAssignment, | ||
SdsBlock, | ||
SdsBlockLambda, | ||
SdsBlockLambdaResult, | ||
SdsClass, | ||
SdsClassMember, | ||
SdsEnum, | ||
SdsEnumVariant, | ||
SdsLiteral, | ||
SdsLiteralType, | ||
SdsParameter, | ||
SdsParameterList, | ||
SdsPlaceholder, | ||
SdsResult, | ||
SdsResultList, | ||
SdsStatement, | ||
SdsTypeArgument, | ||
SdsTypeArgumentList, | ||
SdsTypeParameter, | ||
SdsTypeParameterList, | ||
} from '../generated/ast.js'; | ||
import { stream } from 'langium'; | ||
|
||
export const annotationCallsOrEmpty = function (node: SdsAnnotatedObject | undefined): SdsAnnotationCall[] { | ||
if (!node) { | ||
/* c8 ignore next 2 */ | ||
return []; | ||
} | ||
|
||
if (isSdsDeclaration(node)) { | ||
return node?.annotationCallList?.annotationCalls ?? node?.annotationCalls ?? []; | ||
} else { | ||
/* c8 ignore next 2 */ | ||
return node?.annotationCalls ?? []; | ||
} | ||
}; | ||
|
||
export const assigneesOrEmpty = function (node: SdsAssignment | undefined): SdsAssignee[] { | ||
return node?.assigneeList?.assignees ?? []; | ||
}; | ||
|
||
export const blockLambdaResultsOrEmpty = function (node: SdsBlockLambda | undefined): SdsBlockLambdaResult[] { | ||
return stream(statementsOrEmpty(node?.body)) | ||
.filter(isSdsAssignment) | ||
.flatMap(assigneesOrEmpty) | ||
.filter(isSdsBlockLambdaResult) | ||
.toArray(); | ||
}; | ||
|
||
export const literalsOrEmpty = function (node: SdsLiteralType | undefined): SdsLiteral[] { | ||
return node?.literalList?.literals ?? []; | ||
}; | ||
|
||
export const classMembersOrEmpty = function (node: SdsClass | undefined): SdsClassMember[] { | ||
return node?.body?.members ?? []; | ||
}; | ||
|
||
export const parametersOrEmpty = function (node: SdsParameterList | undefined): SdsParameter[] { | ||
return node?.parameters ?? []; | ||
}; | ||
|
||
export const placeholdersOrEmpty = function (node: SdsBlock | undefined): SdsPlaceholder[] { | ||
return stream(statementsOrEmpty(node)) | ||
.filter(isSdsAssignment) | ||
.flatMap(assigneesOrEmpty) | ||
.filter(isSdsPlaceholder) | ||
.toArray(); | ||
}; | ||
|
||
export const resultsOrEmpty = function (node: SdsResultList | undefined): SdsResult[] { | ||
return node?.results ?? []; | ||
}; | ||
|
||
export const statementsOrEmpty = function (node: SdsBlock | undefined): SdsStatement[] { | ||
return node?.statements ?? []; | ||
}; | ||
|
||
export const typeArgumentsOrEmpty = function (node: SdsTypeArgumentList | undefined): SdsTypeArgument[] { | ||
return node?.typeArguments ?? []; | ||
}; | ||
|
||
export const typeParametersOrEmpty = function (node: SdsTypeParameterList | undefined): SdsTypeParameter[] { | ||
return node?.typeParameters ?? []; | ||
}; | ||
|
||
export const variantsOrEmpty = function (node: SdsEnum | undefined): SdsEnumVariant[] { | ||
return node?.body?.variants ?? []; | ||
}; |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.