|
| 1 | +/* |
| 2 | + * Copyright 2014-2021 TNG Technology Consulting GmbH |
| 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 | +package com.tngtech.archunit.core.domain; |
| 17 | + |
| 18 | +import com.tngtech.archunit.PublicAPI; |
| 19 | +import com.tngtech.archunit.base.ChainableFunction; |
| 20 | +import com.tngtech.archunit.core.domain.properties.HasOwner; |
| 21 | +import com.tngtech.archunit.core.domain.properties.HasSourceCodeLocation; |
| 22 | +import com.tngtech.archunit.core.domain.properties.HasType; |
| 23 | + |
| 24 | +import static com.google.common.base.MoreObjects.toStringHelper; |
| 25 | +import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | +import static com.tngtech.archunit.PublicAPI.Usage.ACCESS; |
| 27 | + |
| 28 | +@PublicAPI(usage = ACCESS) |
| 29 | +public final class ReferencedClassObject implements HasType, HasOwner<JavaCodeUnit>, HasSourceCodeLocation { |
| 30 | + private final JavaCodeUnit owner; |
| 31 | + private final JavaClass value; |
| 32 | + private final int lineNumber; |
| 33 | + private final SourceCodeLocation sourceCodeLocation; |
| 34 | + |
| 35 | + private ReferencedClassObject(JavaCodeUnit owner, JavaClass value, int lineNumber) { |
| 36 | + this.owner = checkNotNull(owner); |
| 37 | + this.value = checkNotNull(value); |
| 38 | + this.lineNumber = lineNumber; |
| 39 | + sourceCodeLocation = SourceCodeLocation.of(owner.getOwner(), lineNumber); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + @PublicAPI(usage = ACCESS) |
| 44 | + public JavaType getType() { |
| 45 | + return getRawType(); |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + @PublicAPI(usage = ACCESS) |
| 50 | + public JavaClass getRawType() { |
| 51 | + return value; |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + @PublicAPI(usage = ACCESS) |
| 56 | + public JavaCodeUnit getOwner() { |
| 57 | + return owner; |
| 58 | + } |
| 59 | + |
| 60 | + @PublicAPI(usage = ACCESS) |
| 61 | + public JavaClass getValue() { |
| 62 | + return value; |
| 63 | + } |
| 64 | + |
| 65 | + @PublicAPI(usage = ACCESS) |
| 66 | + public int getLineNumber() { |
| 67 | + return lineNumber; |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + @PublicAPI(usage = ACCESS) |
| 72 | + public SourceCodeLocation getSourceCodeLocation() { |
| 73 | + return sourceCodeLocation; |
| 74 | + } |
| 75 | + |
| 76 | + @Override |
| 77 | + public String toString() { |
| 78 | + return toStringHelper(this) |
| 79 | + .add("owner", owner) |
| 80 | + .add("value", value) |
| 81 | + .add("sourceCodeLocation", sourceCodeLocation) |
| 82 | + .toString(); |
| 83 | + } |
| 84 | + |
| 85 | + static ReferencedClassObject from(JavaCodeUnit owner, JavaClass javaClass, int lineNumber) { |
| 86 | + return new ReferencedClassObject(owner, javaClass, lineNumber); |
| 87 | + } |
| 88 | + |
| 89 | + @PublicAPI(usage = ACCESS) |
| 90 | + public static final class Functions { |
| 91 | + private Functions() { |
| 92 | + } |
| 93 | + |
| 94 | + @PublicAPI(usage = ACCESS) |
| 95 | + public static final ChainableFunction<ReferencedClassObject, JavaClass> GET_VALUE = new ChainableFunction<ReferencedClassObject, JavaClass>() { |
| 96 | + @Override |
| 97 | + public JavaClass apply(ReferencedClassObject input) { |
| 98 | + return input.getValue(); |
| 99 | + } |
| 100 | + }; |
| 101 | + } |
| 102 | +} |
0 commit comments