Skip to content

Commit

Permalink
Fix another crash when DCL file is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Aug 6, 2024
1 parent 89e2efe commit 4a251cd
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import org.gradle.internal.declarativedsl.dom.DeclarativeDocument
import org.gradle.internal.declarativedsl.dom.DeclarativeDocument.DocumentNode.ElementNode
import org.gradle.internal.declarativedsl.dom.DeclarativeDocument.DocumentNode.PropertyNode

val DeclarativeDocument.singleSoftwareTypeNode: ElementNode
get() = content.filterIsInstance<ElementNode>().single()
val DeclarativeDocument.singleSoftwareTypeNode: ElementNode?
get() = content.filterIsInstance<ElementNode>().singleOrNull()

fun ElementNode.childElementNode(
name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.gradle.client.ui.composables.*
import org.gradle.client.ui.connected.TwoPanes
import org.gradle.client.ui.theme.spacing
import org.gradle.client.ui.theme.transparency
import org.gradle.declarative.dsl.evaluation.EvaluationSchema
import org.gradle.declarative.dsl.schema.DataClass
import org.gradle.declarative.dsl.schema.DataProperty
import org.gradle.declarative.dsl.schema.SchemaMemberFunction
Expand Down Expand Up @@ -149,47 +150,27 @@ class GetDeclarativeDocuments : GetModelAction.GetCompositeModelAction<ResolvedD
)

val softwareTypeNode = domWithDefaults.document.singleSoftwareTypeNode
val softwareTypeSchema = projectAnalysisSchema.softwareTypeNamed(softwareTypeNode.name)
if (softwareTypeSchema == null) {
Text("No software type named '${softwareTypeNode.name}'")
if (softwareTypeNode == null) {
Text("No software type")
} else {

val softwareTypeType =
projectAnalysisSchema.configuredTypeOf(softwareTypeSchema.softwareTypeSemantics)

Column {
with(
ModelTreeRendering(
domWithDefaults.overlayResolutionContainer,
highlightingContext,
mutationApplicability,
onRunMutation = { mutationDefinition, mutationArgumentsContainer ->
MutationUtils.runMutation(
selectedBuildFile.value,
domWithDefaults.inputOverlay,
projectEvaluationSchema,
mutationDefinition,
mutationArgumentsContainer
)
// Trigger recomposition:
updateFileContents()
}
)
) {
WithDecoration(softwareTypeNode) {
TitleMedium(
text = "Software Type: ${softwareTypeNode.name}",
modifier = Modifier
.pointerHoverIcon(
PointerIcon(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR))
)
.withClickTextRangeSelection(softwareTypeNode, highlightingContext)
)
}
MaterialTheme.spacing.VerticalLevel4()

ElementInfoOrNothingDeclared(softwareTypeType, softwareTypeNode, 0)
}
val softwareTypeSchema = projectAnalysisSchema.softwareTypeNamed(softwareTypeNode.name)
if (softwareTypeSchema == null) {
Text("No software type named '${softwareTypeNode.name}'")
} else {

val softwareTypeType =
projectAnalysisSchema.configuredTypeOf(softwareTypeSchema.softwareTypeSemantics)

ModelView(
selectedBuildFile,
highlightingContext,
projectEvaluationSchema,
domWithDefaults,
softwareTypeNode,
softwareTypeType,
mutationApplicability,
::updateFileContents,
)
}
}
}
Expand All @@ -206,6 +187,54 @@ class GetDeclarativeDocuments : GetModelAction.GetCompositeModelAction<ResolvedD
)
}

@Composable
@Suppress("LongParameterList")
private fun ModelView(
selectedBuildFile: MutableState<File>,
highlightingContext: HighlightingContext,
projectEvaluationSchema: EvaluationSchema,
domWithDefaults: DocumentOverlayResult,
softwareTypeNode: DeclarativeDocument.DocumentNode.ElementNode,
softwareTypeType: DataClass,
mutationApplicability: NodeData<List<ApplicableMutation>>,
updateFileContents: () -> Unit
) {
Column {
with(
ModelTreeRendering(
domWithDefaults.overlayResolutionContainer,
highlightingContext,
mutationApplicability,
onRunMutation = { mutationDefinition, mutationArgumentsContainer ->
MutationUtils.runMutation(
selectedBuildFile.value,
domWithDefaults.inputOverlay,
projectEvaluationSchema,
mutationDefinition,
mutationArgumentsContainer
)
// Trigger recomposition:
updateFileContents()
}
)
) {
WithDecoration(softwareTypeNode) {
TitleMedium(
text = "Software Type: ${softwareTypeNode.name}",
modifier = Modifier
.pointerHoverIcon(
PointerIcon(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR))
)
.withClickTextRangeSelection(softwareTypeNode, highlightingContext)
)
}
MaterialTheme.spacing.VerticalLevel4()

ElementInfoOrNothingDeclared(softwareTypeType, softwareTypeNode, 0)
}
}
}

@Composable
private fun SourcesView(
domWithDefaults: DocumentOverlayResult,
Expand Down

0 comments on commit 4a251cd

Please sign in to comment.