1 /*
2 * Copyright 2020-2022 Foreseeti AB <https://foreseeti.com>
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.mal_lang.langspec.builders.step;
18
19 import java.util.List;
20 import java.util.Map;
21 import org.mal_lang.langspec.Asset;
22 import org.mal_lang.langspec.builders.AssetBuilder;
23
24 /**
25 * A builder for creating {@link org.mal_lang.langspec.step.StepField} objects.
26 *
27 * @since 1.0.0
28 */
29 public final class StepFieldBuilder extends StepReferenceBuilder {
30 /**
31 * Constructs a new {@code StepFieldBuilder} object.
32 *
33 * @param name the name of the field
34 * @throws java.lang.NullPointerException if {@code name} is {@code null}
35 * @throws java.lang.IllegalArgumentException if {@code name} is not a valid identifier
36 * @since 1.0.0
37 */
38 public StepFieldBuilder(String name) {
39 super(name);
40 }
41
42 @Override
43 public Asset getTarget(
44 Asset sourceAsset, Map<String, Asset> assets, List<AssetBuilder> assetBuilders) {
45 if (!sourceAsset.hasField(this.getName())) {
46 throw new IllegalArgumentException(
47 String.format("Field %s.%s not found", sourceAsset.getName(), this.getName()));
48 }
49 return sourceAsset.getField(this.getName()).getTarget().getAsset();
50 }
51 }