-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add exclude/include tranforms using selectors
- Loading branch information
Showing
7 changed files
with
909 additions
and
0 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
76 changes: 76 additions & 0 deletions
76
...-build/src/main/java/software/amazon/smithy/build/transforms/ExcludeShapesBySelector.java
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,76 @@ | ||
/* | ||
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.smithy.build.transforms; | ||
|
||
import java.util.Set; | ||
import software.amazon.smithy.build.TransformContext; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.selector.Selector; | ||
import software.amazon.smithy.model.shapes.Shape; | ||
import software.amazon.smithy.model.transform.ModelTransformer; | ||
import software.amazon.smithy.utils.FunctionalUtils; | ||
|
||
/** | ||
* {@code excludeShapesBySelector} excludes the shapes matching the given selector. | ||
* | ||
* <p>Prelude shapes are not removed by this transformer. | ||
*/ | ||
public final class ExcludeShapesBySelector extends ConfigurableProjectionTransformer<ExcludeShapesBySelector.Config> { | ||
|
||
/** | ||
* {@code excludeShapesBySelector} configuration. | ||
*/ | ||
public static final class Config { | ||
private Selector selector = null; | ||
|
||
/** | ||
* Gets the selector used to filter the shapes. | ||
* | ||
* @return The selector used to filter the shapes. | ||
*/ | ||
public Selector getSelector() { | ||
return selector; | ||
} | ||
|
||
/** | ||
* Sets the selector used to filter the shapes. | ||
* | ||
* @param selector The selector used to filter the shapes. | ||
*/ | ||
public void setSelector(Selector selector) { | ||
this.selector = selector; | ||
} | ||
} | ||
|
||
@Override | ||
public Class<Config> getConfigType() { | ||
return Config.class; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "excludeShapesBySelector"; | ||
} | ||
|
||
@Override | ||
protected Model transformWithConfig(TransformContext context, Config config) { | ||
Selector selector = config.getSelector(); | ||
ModelTransformer transformer = context.getTransformer(); | ||
Model model = context.getModel(); | ||
Set<Shape> selected = selector.select(model); | ||
return transformer.filterShapes(model, FunctionalUtils.not(selected::contains)); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...-build/src/main/java/software/amazon/smithy/build/transforms/IncludeShapesBySelector.java
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,76 @@ | ||
/* | ||
* Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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 software.amazon.smithy.build.transforms; | ||
|
||
import java.util.Set; | ||
import software.amazon.smithy.build.TransformContext; | ||
import software.amazon.smithy.model.Model; | ||
import software.amazon.smithy.model.selector.Selector; | ||
import software.amazon.smithy.model.shapes.Shape; | ||
import software.amazon.smithy.model.transform.ModelTransformer; | ||
|
||
/** | ||
* {@code includeShapesBySelector} includes the shapes matching the given selector. | ||
* | ||
* <p>Prelude shapes are not removed by this transformer. | ||
*/ | ||
public final class IncludeShapesBySelector extends ConfigurableProjectionTransformer<IncludeShapesBySelector.Config> { | ||
|
||
/** | ||
* {@code includeShapesBySelector} configuration. | ||
*/ | ||
public static final class Config { | ||
private Selector selector = null; | ||
|
||
/** | ||
* Gets the selector used to filter the shapes. | ||
* | ||
* @return The selector used to filter the shapes. | ||
*/ | ||
public Selector getSelector() { | ||
return selector; | ||
} | ||
|
||
/** | ||
* Sets the selector used to filter the shapes. | ||
* | ||
* @param selector The selector used to filter the shapes. | ||
*/ | ||
public void setSelector(Selector selector) { | ||
this.selector = selector; | ||
} | ||
} | ||
|
||
@Override | ||
public Class<Config> getConfigType() { | ||
return Config.class; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "includeShapesBySelector"; | ||
} | ||
|
||
|
||
@Override | ||
protected Model transformWithConfig(TransformContext context, Config config) { | ||
Selector selector = config.getSelector(); | ||
ModelTransformer transformer = context.getTransformer(); | ||
Model model = context.getModel(); | ||
Set<Shape> selected = selector.select(model); | ||
return transformer.filterShapes(model, selected::contains); | ||
} | ||
} |
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.