Skip to content

Commit

Permalink
Created expression member objects
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Sep 22, 2024
1 parent 31e9390 commit ba313bd
Show file tree
Hide file tree
Showing 9 changed files with 415 additions and 24 deletions.
7 changes: 4 additions & 3 deletions ph-css/src/main/java/com/helger/css/decl/CSSSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.helger.commons.string.ToStringGenerator;
import com.helger.css.CSSSourceLocation;
import com.helger.css.ICSSSourceLocationAware;
import com.helger.css.ICSSWriteable;
import com.helger.css.ICSSWriterSettings;

/**
Expand All @@ -43,7 +42,7 @@
* @author Philip Helger
*/
@NotThreadSafe
public class CSSSelector implements ICSSWriteable, ICSSSourceLocationAware
public class CSSSelector implements ICSSSelectorMember, ICSSSourceLocationAware
{
private final ICommonsList <ICSSSelectorMember> m_aMembers = new CommonsArrayList <> ();
private CSSSourceLocation m_aSourceLocation;
Expand Down Expand Up @@ -158,6 +157,8 @@ public int hashCode ()
@Override
public String toString ()
{
return new ToStringGenerator (this).append ("members", m_aMembers).appendIfNotNull ("SourceLocation", m_aSourceLocation).getToString ();
return new ToStringGenerator (this).append ("members", m_aMembers)
.appendIfNotNull ("SourceLocation", m_aSourceLocation)
.getToString ();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (C) 2014-2024 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.css.decl;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import com.helger.commons.ValueEnforcer;
import com.helger.commons.annotation.Nonempty;
import com.helger.commons.hashcode.HashCodeGenerator;
import com.helger.commons.string.ToStringGenerator;
import com.helger.css.CSSSourceLocation;
import com.helger.css.ECSSVersion;
import com.helger.css.ICSSSourceLocationAware;
import com.helger.css.ICSSVersionAware;
import com.helger.css.ICSSWriterSettings;

/**
* Represents a single, simple CSS selector as used for the ":has()" CSS pseudo
* element.<br>
*
* @author Philip Helger
* @since 7.0.3
*/
@NotThreadSafe
public class CSSSelectorMemberPseudoHas implements ICSSSelectorMember, ICSSVersionAware, ICSSSourceLocationAware
{
private final CSSSelector m_aSelector;
private CSSSourceLocation m_aSourceLocation;

public CSSSelectorMemberPseudoHas (@Nonnull final CSSSelector aSelector)
{
ValueEnforcer.notNull (aSelector, "Selector");
m_aSelector = aSelector;
}

@Nonnull
public final CSSSelector getSelector ()
{
return m_aSelector;
}

@Nonnull
@Nonempty
public String getAsCSSString (@Nonnull final ICSSWriterSettings aSettings, @Nonnegative final int nIndentLevel)
{
aSettings.checkVersionRequirements (this);

final StringBuilder aSB = new StringBuilder (":has(");
aSB.append (m_aSelector.getAsCSSString (aSettings, 0));
return aSB.append (')').toString ();
}

@Nonnull
public ECSSVersion getMinimumCSSVersion ()
{
return ECSSVersion.CSS30;
}

@Nullable
public final CSSSourceLocation getSourceLocation ()
{
return m_aSourceLocation;
}

public final void setSourceLocation (@Nullable final CSSSourceLocation aSourceLocation)
{
m_aSourceLocation = aSourceLocation;
}

@Override
public boolean equals (final Object o)
{
if (o == this)
return true;
if (o == null || !getClass ().equals (o.getClass ()))
return false;
final CSSSelectorMemberPseudoHas rhs = (CSSSelectorMemberPseudoHas) o;
return m_aSelector.equals (rhs.m_aSelector);
}

@Override
public int hashCode ()
{
return new HashCodeGenerator (this).append (m_aSelector).getHashCode ();
}

@Override
public String toString ()
{
return new ToStringGenerator (null).append ("Selector", m_aSelector)
.appendIfNotNull ("SourceLocation", m_aSourceLocation)
.getToString ();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (C) 2014-2024 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.css.decl;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import com.helger.commons.ValueEnforcer;
import com.helger.commons.annotation.Nonempty;
import com.helger.commons.hashcode.HashCodeGenerator;
import com.helger.commons.string.ToStringGenerator;
import com.helger.css.CSSSourceLocation;
import com.helger.css.ECSSVersion;
import com.helger.css.ICSSSourceLocationAware;
import com.helger.css.ICSSVersionAware;
import com.helger.css.ICSSWriterSettings;

/**
* Represents a single, simple CSS selector as used for the ":is()" CSS pseudo
* element.<br>
*
* @author Philip Helger
* @since 7.0.3
*/
@NotThreadSafe
public class CSSSelectorMemberPseudoIs implements ICSSSelectorMember, ICSSVersionAware, ICSSSourceLocationAware
{
private final CSSSelector m_aSelector;
private CSSSourceLocation m_aSourceLocation;

public CSSSelectorMemberPseudoIs (@Nonnull final CSSSelector aSelector)
{
ValueEnforcer.notNull (aSelector, "Selector");
m_aSelector = aSelector;
}

@Nonnull
public final CSSSelector getSelector ()
{
return m_aSelector;
}

@Nonnull
@Nonempty
public String getAsCSSString (@Nonnull final ICSSWriterSettings aSettings, @Nonnegative final int nIndentLevel)
{
aSettings.checkVersionRequirements (this);

final StringBuilder aSB = new StringBuilder (":is(");
aSB.append (m_aSelector.getAsCSSString (aSettings, 0));
return aSB.append (')').toString ();
}

@Nonnull
public ECSSVersion getMinimumCSSVersion ()
{
return ECSSVersion.CSS30;
}

@Nullable
public final CSSSourceLocation getSourceLocation ()
{
return m_aSourceLocation;
}

public final void setSourceLocation (@Nullable final CSSSourceLocation aSourceLocation)
{
m_aSourceLocation = aSourceLocation;
}

@Override
public boolean equals (final Object o)
{
if (o == this)
return true;
if (o == null || !getClass ().equals (o.getClass ()))
return false;
final CSSSelectorMemberPseudoIs rhs = (CSSSelectorMemberPseudoIs) o;
return m_aSelector.equals (rhs.m_aSelector);
}

@Override
public int hashCode ()
{
return new HashCodeGenerator (this).append (m_aSelector).getHashCode ();
}

@Override
public String toString ()
{
return new ToStringGenerator (null).append ("Selector", m_aSelector)
.appendIfNotNull ("SourceLocation", m_aSourceLocation)
.getToString ();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright (C) 2014-2024 Philip Helger (www.helger.com)
* philip[at]helger[dot]com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.helger.css.decl;

import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import com.helger.commons.ValueEnforcer;
import com.helger.commons.annotation.Nonempty;
import com.helger.commons.hashcode.HashCodeGenerator;
import com.helger.commons.string.ToStringGenerator;
import com.helger.css.CSSSourceLocation;
import com.helger.css.ECSSVersion;
import com.helger.css.ICSSSourceLocationAware;
import com.helger.css.ICSSVersionAware;
import com.helger.css.ICSSWriterSettings;

/**
* Represents a single, simple CSS selector as used for the ":has()" CSS pseudo
* element.<br>
*
* @author Philip Helger
* @since 7.0.3
*/
@NotThreadSafe
public class CSSSelectorMemberPseudoWhere implements ICSSSelectorMember, ICSSVersionAware, ICSSSourceLocationAware
{
private final CSSSelector m_aSelector;
private CSSSourceLocation m_aSourceLocation;

public CSSSelectorMemberPseudoWhere (@Nonnull final CSSSelector aSelector)
{
ValueEnforcer.notNull (aSelector, "Selector");
m_aSelector = aSelector;
}

@Nonnull
public final CSSSelector getSelector ()
{
return m_aSelector;
}

@Nonnull
@Nonempty
public String getAsCSSString (@Nonnull final ICSSWriterSettings aSettings, @Nonnegative final int nIndentLevel)
{
aSettings.checkVersionRequirements (this);

final StringBuilder aSB = new StringBuilder (":where(");
aSB.append (m_aSelector.getAsCSSString (aSettings, 0));
return aSB.append (')').toString ();
}

@Nonnull
public ECSSVersion getMinimumCSSVersion ()
{
return ECSSVersion.CSS30;
}

@Nullable
public final CSSSourceLocation getSourceLocation ()
{
return m_aSourceLocation;
}

public final void setSourceLocation (@Nullable final CSSSourceLocation aSourceLocation)
{
m_aSourceLocation = aSourceLocation;
}

@Override
public boolean equals (final Object o)
{
if (o == this)
return true;
if (o == null || !getClass ().equals (o.getClass ()))
return false;
final CSSSelectorMemberPseudoWhere rhs = (CSSSelectorMemberPseudoWhere) o;
return m_aSelector.equals (rhs.m_aSelector);
}

@Override
public int hashCode ()
{
return new HashCodeGenerator (this).append (m_aSelector).getHashCode ();
}

@Override
public String toString ()
{
return new ToStringGenerator (null).append ("Selector", m_aSelector)
.appendIfNotNull ("SourceLocation", m_aSourceLocation)
.getToString ();
}
}
Loading

0 comments on commit ba313bd

Please sign in to comment.