Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 XPATH-QS
* Copyright (c) 2026 XPATH-QS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -22,7 +22,6 @@

package org.xpathqs.core.reflection

import org.xpathqs.core.exception.ReflectionException
import org.xpathqs.core.selector.args.SelectorArgs
import org.xpathqs.core.selector.base.BaseSelector
import org.xpathqs.core.selector.base.BaseSelectorProps
Expand Down
54 changes: 42 additions & 12 deletions src/main/kotlin/org/xpathqs/core/selector/base/BaseSelector.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 XPATH-QS
* Copyright (c) 2026 XPATH-QS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -26,7 +26,7 @@ import org.xpathqs.core.selector.NullSelector
import kotlin.reflect.KProperty

/**
* Base class for the Selectors
* Base interface for the Selectors
* @param state of the Selector
* @param base link to the root element
* @param name name of the selector (used for logging purposes)
Expand All @@ -35,25 +35,55 @@ import kotlin.reflect.KProperty
* @param property associated field of the root object.
* It may be NULL, when there is no root object
*/
abstract class BaseSelector(
internal val state: SelectorState = SelectorState.INIT,
interface BaseSelector: ISelector {

val base: ISelector = NullSelector(),
val state: SelectorState

val base: ISelector
override val name: String
override val fullName: String

val props: BaseSelectorProps
val annotations: Collection<Annotation>

val property: KProperty<*>?
val noBase: Boolean

/**
* Get selector's tag or an empty string
* if tag is not applicable to the Selector's type
*/
val tag: String

/**
* A holder collection for some custom properties
* which may be used for the extending the functionality via extension-functions
*
* Require #1 - map should not be cloned. It purposes only for holding some configuration constants
* @sample org.xpathqs.core.selector.base.BaseSelectorCustomPropsMapTest.r1
*/
val customPropsMap: HashMap<String, Any?>
}

abstract class BaseSelectorImpl(
override val state: SelectorState = SelectorState.INIT,

override val base: ISelector = NullSelector(),
override val name: String = "",
override val fullName: String = "",

internal open val props: BaseSelectorProps = BaseSelectorProps(),
val annotations: Collection<Annotation> = emptyList(),
override val props: BaseSelectorProps = BaseSelectorProps(),
override val annotations: Collection<Annotation> = emptyList(),

val property: KProperty<*>? = null,
val noBase: Boolean = false,
) : ISelector {
override val property: KProperty<*>? = null,
override val noBase: Boolean = false,
) : BaseSelector {

/**
* Get selector's tag or an empty string
* if tag is not applicable to the Selector's type
*/
abstract val tag: String
override val tag: String = ""

/**
* Build selector's xpath
Expand Down Expand Up @@ -87,7 +117,7 @@ abstract class BaseSelector(
* Require #1 - map should not be cloned. It purposes only for holding some configuration constants
* @sample org.xpathqs.core.selector.base.BaseSelectorCustomPropsMapTest.r1
*/
val customPropsMap = HashMap<String, Any?>()
override val customPropsMap = HashMap<String, Any?>()

companion object {
fun mergeXpath(xp1: String, xp2: String): String {
Expand Down
15 changes: 4 additions & 11 deletions src/main/kotlin/org/xpathqs/core/selector/block/Block.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 XPATH-QS
* Copyright (c) 2026 XPATH-QS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -139,6 +139,7 @@ open class Block(
is Selector -> copyFrom(sel)
is XpathSelector -> copyFrom(sel)
is GroupSelector -> copyFrom(sel)
is ResultSelector -> copyFrom(sel)
}
}

Expand Down Expand Up @@ -175,9 +176,9 @@ open class Block(
}

/**
* Will copy properties from the GroupSelector
* Will copy properties from the ResultSelector
*
* Require - GroupSelector's properties should be copied
* Require - ResultSelector's properties should be copied
* @sample [org.xpathqs.core.selector.block.CopyFromTest.copyFromGroupSelector]
*/
protected fun copyFrom(sel: ResultSelector) {
Expand Down Expand Up @@ -247,14 +248,6 @@ open class Block(
(property?.call(base) as? Block)?.setProps(originFieldProps)
}

fun copyProps(other: Block?) {
if (other == null) {
return
}
selectorsChain = other.selectorsChain
setProps(other.props)
}

/**
* Callback invoked during [org.xpathqs.core.reflection.SelectorParser.parse] method
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 XPATH-QS
* Copyright (c) 2026 XPATH-QS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,7 +23,7 @@
package org.xpathqs.core.selector.compose

import org.xpathqs.core.selector.NullSelector
import org.xpathqs.core.selector.base.BaseSelector
import org.xpathqs.core.selector.base.BaseSelectorImpl
import org.xpathqs.core.selector.base.ISelector
import org.xpathqs.core.selector.base.SelectorState

Expand All @@ -39,7 +39,7 @@ class ComposeSelector(
fullName: String = "",

override val props: ComposeSelectorProps = ComposeSelectorProps()
) : BaseSelector(
) : BaseSelectorImpl(
state = state,
base = base,
name = name,
Expand Down
Loading
Loading