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
2 changes: 1 addition & 1 deletion ph-css/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.helger</groupId>
<groupId>unblu.patched.com.helger</groupId>
<artifactId>ph-css-parent-pom</artifactId>
<version>7.0.5-SNAPSHOT</version>
</parent>
Expand Down
156 changes: 156 additions & 0 deletions ph-css/src/main/java/com/helger/css/decl/CSSLayerRule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*
* Copyright (C) 2014-2025 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.collection.impl.CommonsArrayList;
import com.helger.commons.collection.impl.ICommonsList;
import com.helger.commons.hashcode.HashCodeGenerator;
import com.helger.commons.string.StringHelper;
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;

@NotThreadSafe
public class CSSLayerRule extends AbstractHasTopLevelRules implements ICSSTopLevelRule, ICSSVersionAware, ICSSSourceLocationAware
{
private final ICommonsList <String> m_aSelectors;
private CSSSourceLocation m_aSourceLocation;

public CSSLayerRule (@Nullable final String sLayerSelector)
{
m_aSelectors = StringHelper.hasText (sLayerSelector) ? new CommonsArrayList <> (sLayerSelector) : new CommonsArrayList <> ();
}

public CSSLayerRule (@Nonnull final Iterable <String> aSelectors)
{
ValueEnforcer.notNullNoNullValue (aSelectors, "Selectors");
m_aSelectors = new CommonsArrayList <> (aSelectors);
}

@Nonnull
public ICommonsList <String> getAllSelectors ()
{
return m_aSelectors.getClone ();
}

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

final boolean bOptimizedOutput = aSettings.isOptimizedOutput ();

final StringBuilder aSB = new StringBuilder ("@layer ");
boolean bFirst = true;
if (m_aSelectors.isNotEmpty ())
{
for (final String sSelector : m_aSelectors)
{
if (bFirst)
bFirst = false;
else
aSB.append (bOptimizedOutput ? "," : ", ");
aSB.append (sSelector);
}
}

final int nRuleCount = m_aRules.size ();
if (nRuleCount == 0)
{
aSB.append(";");
}
else
{
// At least one rule present
aSB.append (bOptimizedOutput ? "{" : " {" + aSettings.getNewLineString ());
bFirst = true;
for (final ICSSTopLevelRule aRule : m_aRules)
{
final String sRuleCSS = aRule.getAsCSSString (aSettings, nIndentLevel + 1);
if (StringHelper.hasText (sRuleCSS))
{
if (bFirst)
bFirst = false;
else
if (!bOptimizedOutput)
aSB.append (aSettings.getNewLineString ());

if (!bOptimizedOutput)
aSB.append (aSettings.getIndent (nIndentLevel + 1));
aSB.append (sRuleCSS);
}
}
if (!bOptimizedOutput)
aSB.append (aSettings.getIndent (nIndentLevel));
aSB.append ('}');
}

if (!bOptimizedOutput)
aSB.append (aSettings.getNewLineString ());

return aSB.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;
return true;
}

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

@Override
public String toString ()
{
return new ToStringGenerator (this).appendIfNotNull ("SourceLocation", m_aSourceLocation)
.getToString ();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.helger.commons.annotation.ReturnsMutableCopy;
import com.helger.commons.collection.impl.CommonsArrayList;
import com.helger.commons.collection.impl.ICommonsList;
import com.helger.commons.equals.EqualsHelper;
import com.helger.commons.hashcode.HashCodeGenerator;
import com.helger.commons.state.EChange;
import com.helger.commons.string.ToStringGenerator;
Expand All @@ -46,40 +45,27 @@
@NotThreadSafe
public class CSSSelectorMemberPseudoHas implements ICSSSelectorMember, ICSSVersionAware, ICSSSourceLocationAware
{
private final ECSSSelectorCombinator m_eCombinator;
private final ICommonsList <CSSSelector> m_aNestedSelectors;
private CSSSourceLocation m_aSourceLocation;

public CSSSelectorMemberPseudoHas (@Nullable final ECSSSelectorCombinator eCombinator,
@Nonnull final CSSSelector aNestedSelector)
public CSSSelectorMemberPseudoHas (@Nonnull final CSSSelector aNestedSelector)
{
ValueEnforcer.notNull (aNestedSelector, "NestedSelector");
m_eCombinator = eCombinator;
m_aNestedSelectors = new CommonsArrayList <> (aNestedSelector);
}

public CSSSelectorMemberPseudoHas (@Nullable final ECSSSelectorCombinator eCombinator,
@Nonnull final CSSSelector... aNestedSelectors)
public CSSSelectorMemberPseudoHas (@Nonnull final CSSSelector... aNestedSelectors)
{
ValueEnforcer.notNull (aNestedSelectors, "NestedSelectors");
m_eCombinator = eCombinator;
m_aNestedSelectors = new CommonsArrayList <> (aNestedSelectors);
}

public CSSSelectorMemberPseudoHas (@Nullable final ECSSSelectorCombinator eCombinator,
@Nonnull final Iterable <CSSSelector> aNestedSelectors)
public CSSSelectorMemberPseudoHas (@Nonnull final Iterable <CSSSelector> aNestedSelectors)
{
ValueEnforcer.notNull (aNestedSelectors, "NestedSelectors");
m_eCombinator = eCombinator;
m_aNestedSelectors = new CommonsArrayList <> (aNestedSelectors);
}

@Nullable
public ECSSSelectorCombinator getCombinator ()
{
return m_eCombinator;
}

public boolean hasSelectors ()
{
return m_aNestedSelectors.isNotEmpty ();
Expand Down Expand Up @@ -177,10 +163,6 @@ public String getAsCSSString (@Nonnull final ICSSWriterSettings aSettings, @Nonn

final boolean bOptimizedOutput = aSettings.isOptimizedOutput ();
final StringBuilder aSB = new StringBuilder (":has(");

if (m_eCombinator != null)
aSB.append (m_eCombinator.getAsCSSString (aSettings));

boolean bFirst = true;
for (final CSSSelector aNestedSelector : m_aNestedSelectors)
{
Expand Down Expand Up @@ -218,20 +200,19 @@ public boolean equals (final Object o)
if (o == null || !getClass ().equals (o.getClass ()))
return false;
final CSSSelectorMemberPseudoHas rhs = (CSSSelectorMemberPseudoHas) o;
return EqualsHelper.equals (m_eCombinator, rhs.m_eCombinator) && m_aNestedSelectors.equals (rhs.m_aNestedSelectors);
return m_aNestedSelectors.equals (rhs.m_aNestedSelectors);
}

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

@Override
public String toString ()
{
return new ToStringGenerator (null).append ("Combinator", m_eCombinator)
.append ("NestedSelectors", m_aNestedSelectors)
return new ToStringGenerator (null).append ("NestedSelectors", m_aNestedSelectors)
.appendIfNotNull ("SourceLocation", m_aSourceLocation)
.getToString ();
}
Expand Down
Loading