-
Notifications
You must be signed in to change notification settings - Fork 316
/
FileProjectConfig.java
112 lines (88 loc) · 2.76 KB
/
FileProjectConfig.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* Copyright (c) 2015, 2017 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.xtext.workspace;
import static org.eclipse.xtext.xbase.lib.IterableExtensions.*;
import java.io.File;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtext.util.UriUtil;
public class FileProjectConfig implements IProjectConfig {
private final URI path;
private final String name;
private final Set<FileSourceFolder> sourceFolders = new HashSet<>();
private final IWorkspaceConfig workspaceConfig;
public FileProjectConfig(URI path) {
this(path, (IWorkspaceConfig) null);
}
public FileProjectConfig(URI path, String name) {
this(path, name, (IWorkspaceConfig) null);
}
public FileProjectConfig(File root, String name) {
this(root, name, (IWorkspaceConfig) null);
}
public FileProjectConfig(File root) {
this(root, (IWorkspaceConfig) null);
}
public FileProjectConfig(URI path, IWorkspaceConfig workspaceConfig) {
this(path, path.lastSegment(), workspaceConfig);
}
public FileProjectConfig(URI path, String name, IWorkspaceConfig workspaceConfig) {
this.path = UriUtil.toFolderURI(path);
this.name = name;
this.workspaceConfig = (workspaceConfig != null) ? workspaceConfig : new WorkspaceConfig(this);
}
public FileProjectConfig(File root, String name, IWorkspaceConfig workspaceConfig) {
this(UriUtil.createFolderURI(root), name, workspaceConfig);
}
public FileProjectConfig(File root, IWorkspaceConfig workspaceConfig) {
this(UriUtil.createFolderURI(root), root.getName(), workspaceConfig);
}
public FileSourceFolder addSourceFolder(String relativePath) {
FileSourceFolder sourceFolder = new FileSourceFolder(this, relativePath);
sourceFolders.add(sourceFolder);
return sourceFolder;
}
@Override
public FileSourceFolder findSourceFolderContaining(URI member) {
return findFirst(sourceFolders, f -> f.contains(member));
}
@Override
public boolean equals(Object obj) {
if (obj instanceof FileProjectConfig) {
return Objects.equals(path, ((FileProjectConfig) obj).path);
}
return false;
}
@Override
public int hashCode() {
return path.hashCode();
}
@Override
public String toString() {
return "Project " + name + " (" + path + ")";
}
@Override
public URI getPath() {
return path;
}
@Override
public String getName() {
return name;
}
@Override
public Set<FileSourceFolder> getSourceFolders() {
return sourceFolders;
}
@Override
public IWorkspaceConfig getWorkspaceConfig() {
return workspaceConfig;
}
}