-
Notifications
You must be signed in to change notification settings - Fork 316
/
FileLocationsImpl.java
127 lines (112 loc) · 4.57 KB
/
FileLocationsImpl.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* Copyright (c) 2013, 2016 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.xtend.core.macro;
import com.google.inject.Inject;
import java.util.Objects;
import java.util.Set;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtend.lib.annotations.Accessors;
import org.eclipse.xtend.lib.macro.file.FileLocations;
import org.eclipse.xtend.lib.macro.file.Path;
import org.eclipse.xtext.generator.IContextualOutputConfigurationProvider;
import org.eclipse.xtext.generator.OutputConfiguration;
import org.eclipse.xtext.workspace.IProjectConfig;
import org.eclipse.xtext.workspace.IProjectConfigProvider;
import org.eclipse.xtext.workspace.ISourceFolder;
import org.eclipse.xtext.xbase.lib.Functions.Function1;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Pure;
/**
* @author Sven Efftinge - Initial contribution and API
*/
@SuppressWarnings("all")
public class FileLocationsImpl implements FileLocations {
@Inject
@Accessors
private IProjectConfigProvider projectInformationProvider;
@Inject
@Accessors
private IContextualOutputConfigurationProvider outputConfigurationProvider;
@Accessors
private Resource context;
protected IProjectConfig getProjectConfig(final Path path) {
final String firstSegment = path.getSegments().get(0);
final IProjectConfig projectConfig = this.projectInformationProvider.getProjectConfig(this.context.getResourceSet());
if (((projectConfig == null) || (!Objects.equals(projectConfig.getName(), firstSegment)))) {
throw new IllegalArgumentException((("The project \'" + firstSegment) + "\' has not been configured."));
}
return projectConfig;
}
@Override
public Path getSourceFolder(final Path path) {
final Function1<Path, Boolean> _function = (Path sourceFolder) -> {
return Boolean.valueOf(path.startsWith(sourceFolder));
};
return IterableExtensions.<Path>findFirst(this.getProjectSourceFolders(path), _function);
}
@Override
public Path getTargetFolder(final Path path) {
Path _xblockexpression = null;
{
final Path projectFolder = this.getProjectFolder(path);
if ((projectFolder == null)) {
return null;
}
final OutputConfiguration outputConfiguration = IterableExtensions.<OutputConfiguration>head(this.outputConfigurationProvider.getOutputConfigurations(this.context));
final Path sourceFolder = this.getSourceFolder(path);
String _xifexpression = null;
if ((sourceFolder == null)) {
_xifexpression = outputConfiguration.getOutputDirectory();
} else {
String _xblockexpression_1 = null;
{
final String projectRelativeSourceFolder = IterableExtensions.join(IterableExtensions.<String>tail(sourceFolder.getSegments()), "/");
_xblockexpression_1 = outputConfiguration.getOutputDirectory(projectRelativeSourceFolder);
}
_xifexpression = _xblockexpression_1;
}
final String outputFolder = _xifexpression;
_xblockexpression = projectFolder.append(outputFolder);
}
return _xblockexpression;
}
@Override
public Path getProjectFolder(final Path path) {
final IProjectConfig config = this.getProjectConfig(path);
return Path.ROOT.append(config.getName());
}
@Override
public Set<Path> getProjectSourceFolders(final Path path) {
final Function1<ISourceFolder, Path> _function = (ISourceFolder it) -> {
return this.getProjectFolder(path).append(it.getName());
};
return IterableExtensions.<Path>toSet(IterableExtensions.map(this.getProjectConfig(path).getSourceFolders(), _function));
}
@Pure
public IProjectConfigProvider getProjectInformationProvider() {
return this.projectInformationProvider;
}
public void setProjectInformationProvider(final IProjectConfigProvider projectInformationProvider) {
this.projectInformationProvider = projectInformationProvider;
}
@Pure
public IContextualOutputConfigurationProvider getOutputConfigurationProvider() {
return this.outputConfigurationProvider;
}
public void setOutputConfigurationProvider(final IContextualOutputConfigurationProvider outputConfigurationProvider) {
this.outputConfigurationProvider = outputConfigurationProvider;
}
@Pure
public Resource getContext() {
return this.context;
}
public void setContext(final Resource context) {
this.context = context;
}
}