-
Notifications
You must be signed in to change notification settings - Fork 0
/
ReferencedTargetHelper.xtend
95 lines (86 loc) · 3.14 KB
/
ReferencedTargetHelper.xtend
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
/*******************************************************************************
* Copyright (c) 2020 German Aerospace Center (DLR), Simulation and Software Technology, Germany.
*
* 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 de.dlr.sc.overtarget.language.generator.util
import de.dlr.sc.overtarget.language.targetmodel.TargetModel
import de.dlr.sc.overtarget.language.targetmodel.TargetFile
import de.dlr.sc.overtarget.language.targetmodel.RepositoryLocation
import org.eclipse.emf.ecore.util.EcoreUtil
import java.util.ArrayList
import org.eclipse.core.resources.IFile
import de.dlr.sc.overtarget.language.generator.OvertargetGenerator
import de.dlr.sc.overtarget.language.util.TargetFileHandler
/**
* This class processes the model data for generation
*/
class ReferencedTargetHelper {
public static val TARGET_FOR_REFERENCES_NAME = "targetForReferences"
/**
* This method copies the original tmodel and
* looks for all repositoryLocations without a referenced target
*
* @param model original tmodel with unresolved references
* @return tmodelWithReference tmodel with repositoryLocations containing the keyword referencedTarget
*/
def getReferencedModelToGenerate(TargetModel model) {
val tmodelWithReference = EcoreUtil.copy(model)
val list = newArrayList
for (RepositoryLocation repos : tmodelWithReference.repositoryLocations) {
if (repos.referencedTarget == false) {
list.addAll(repos)
}
}
deleteRepositoryLocation(list)
renameTmodel(tmodelWithReference)
return tmodelWithReference
}
def deleteRepositoryLocation(ArrayList<RepositoryLocation> list) {
for (RepositoryLocation reposLoc : list) {
EcoreUtil.delete(reposLoc)
}
return list
}
def renameTmodel(TargetModel model) {
val renamedTmodel = TARGET_FOR_REFERENCES_NAME
model.name = renamedTmodel
return model.name
}
def hasUnresolvedReferences(TargetModel model) {
importedModelIsProxy(model) == true || parentIsProxy(model) == true
}
def importedModelIsProxy(TargetModel model) {
for (TargetFile file : model.importedModels) {
if (file.eIsProxy == true) {
return file.eIsProxy
}
}
return false
}
def parentIsProxy(TargetModel model) {
val parentTarget = model.super
if (parentTarget !== null) {
return parentTarget.eIsProxy
} else {
return false
}
}
/**
* In the project the targetForReferences file is searched with the outputPath.
* Checks if the file is located directly in the project folder or in an extra folder.
*
* @param file targetFile with unresolved references
* @param outputDirectory output directory of generated targetFile
* @return targetForReferences
*/
def findTargetForReferencesFile(IFile file, String outputDirectory) {
val fileName = TARGET_FOR_REFERENCES_NAME + OvertargetGenerator.TARGET_FILE_EXTENSION
val targetFileHandler = new TargetFileHandler
return targetFileHandler.findTargetFile(file, outputDirectory, fileName)
}
}