Debian Codegraph @

src/com/google/javascript/jscomp/deps/SimpleDependencyInfo.java

raw symbols SCIP
1 /*
2 * Copyright 2009 The Closure Compiler Authors.
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 com.google.javascript.jscomp.deps;
18
19 import com.google.common.base.Objects;
20
21 import java.util.Collection;
22 import java.util.Collections;
23 import java.util.List;
24
25 /**
26 * A class to hold JS dependency information for a single .js file.
27 *
28 * @author [email protected] (Andrew Grieve)
29 */
30 public class SimpleDependencyInfo implements DependencyInfo {
31
32 /** A list of provided symbols. */
33 private final List<String> provides;
34
35 /** A list of required symbols. */
36 private final List<String> requires;
37
38 /** The path of the file relative to closure. */
39 private final String srcPathRelativeToClosure;
40
41 /** The path to the file from which we extracted the dependency information.*/
42 private final String pathOfDefiningFile;
43
44 /**
45 * Constructs a DependencyInfo object with the given list of provides &
46 * requires. This does *not* copy the given lists, but uses them directly.
47 *
48 * @param srcPathRelativeToClosure The closure-relative path of the file
49 * associated with this DependencyInfo.
50 * @param pathOfDefiningFile The path to the file from which this dependency
51 * information was extracted.
52 * @param provides List of provided symbols.
53 * @param requires List of required symbols.
54 */
55 public SimpleDependencyInfo(
56 String srcPathRelativeToClosure, String pathOfDefiningFile,
57 List<String> provides, List<String> requires) {
58 this.srcPathRelativeToClosure = srcPathRelativeToClosure;
59 this.pathOfDefiningFile = pathOfDefiningFile;
60 this.provides = provides;
61 this.requires = requires;
62 }
63
64 @Override
65 public String getName() {
66 return pathOfDefiningFile;
67 }
68
69 @Override
70 public String getPathRelativeToClosureBase() {
71 return srcPathRelativeToClosure;
72 }
73
74 @Override
75 public Collection<String> getProvides() {
76 return Collections.<String>unmodifiableList(provides);
77 }
78
79 @Override
80 public Collection<String> getRequires() {
81 return Collections.<String>unmodifiableList(requires);
82 }
83
84 @Override
85 public boolean equals(Object obj) {
86 if (!(obj instanceof SimpleDependencyInfo)) {
87 return false;
88 }
89 SimpleDependencyInfo other = (SimpleDependencyInfo)obj;
90 return Objects.equal(other.srcPathRelativeToClosure,
91 srcPathRelativeToClosure) &&
92 Objects.equal(other.pathOfDefiningFile, pathOfDefiningFile) &&
93 Objects.equal(other.requires, this.requires) &&
94 Objects.equal(other.provides, this.provides);
95 }
96
97 @Override
98 public String toString() {
99 return String.format("DependencyInfo(relativePath='%1$s', path='%2$s', "
100 + "provides=%3$s, requires=%4$s)", srcPathRelativeToClosure,
101 pathOfDefiningFile, provides, requires);
102 }
103 }