本文整理汇总了Java中net.ssehub.easy.varModel.model.Project.getImport方法的典型用法代码示例。如果您正苦于以下问题:Java Project.getImport方法的具体用法?Java Project.getImport怎么用?Java Project.getImport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.ssehub.easy.varModel.model.Project
的用法示例。
在下文中一共展示了Project.getImport方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: put
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Puts the variables of project into <code>data</code> if they comply with <code>selector</code>.
*
* @param project the project to be iterated over
* @param data the data to be modified as a side effect (fqn-instance mapping)
* @param cfg the underlying IVML configuration
* @param selector the selector instance
*/
private void put(Project project, Map<String, IDecisionVariable> data,
net.ssehub.easy.varModel.confModel.Configuration cfg, IVariableSelector selector) {
for (int i = 0; i < project.getImportsCount(); i++) {
ProjectImport imp = project.getImport(i);
if (null != imp.getResolved()) {
put(imp.getResolved(), data, cfg, selector);
}
}
for (int e = 0; e < project.getElementCount(); e++) {
ContainableModelElement elt = project.getElement(e);
if (elt instanceof AbstractVariable) {
IDecisionVariable var = cfg.getDecision((AbstractVariable) elt);
if (null != var && AssignmentState.FROZEN == var.getState() && selector.select(var)) {
data.put(var.getDeclaration().getQualifiedName(), var);
}
}
}
}
示例2: visitProject
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
@Override
public void visitProject(Project project) {
if (!done.contains(project)) {
done.add(project);
// local variables take precedence over imports
for (int e = 0; e < project.getElementCount(); e++) {
project.getElement(e).accept(this);
}
for (int i = 0; i < project.getImportsCount(); i++) {
ProjectImport imp = project.getImport(i);
String name = imp.getName();
if (null != imp.getInterfaceName()) {
name = name + IvmlKeyWords.NAMESPACE_SEPARATOR + imp.getInterfaceName();
}
imports.put(name, i);
if (null != imp.getResolved()) {
imp.getResolved().accept(this);
}
}
}
}
示例3: assertImported
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Recursively asserts the resolved instances of model imports.
* @param project the project to visit
* @param imported the already imported (and visited) projects
*/
private static void assertImported(Project project, Map<ModelInfo<Project>, Project> imported) {
for (int i = 0; i < project.getImportsCount(); i++) {
ProjectImport imp = project.getImport(i);
Project resolved = imp.getResolved();
Assert.assertNotNull("import '" + imp.getName() + "' in '" + project.getName() + "' is not resolved",
resolved);
ModelInfo<Project> info = VarModel.INSTANCE.availableModels().getModelInfo(resolved);
Assert.assertNotNull("no model info for '" + imp.getName() + "'", info);
if (imported.containsKey(info)) {
Assert.assertTrue("only one instance of '" + imp.getName() + "' shall be used in the model references",
resolved == imported.get(info));
// already visited, no recursion
} else {
imported.put(info, imp.getResolved());
assertImported(imp.getResolved(), imported);
}
}
}
示例4: assertProjectImport
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Helpermethod: Tests whether the copied project contains the same imports than the original.
* @param originalProject The original project for comparison
* @param copy The copied project for testing
* @return The first import (must exist).
*/
private Project assertProjectImport(Project originalProject, Project copy) {
Assert.assertEquals(originalProject.getName(), copy.getName());
ProjectTestUtilities.validateProject(copy);
Assert.assertEquals("Error: Copyied project does not contain the expected numbers of project imports.",
originalProject.getImportsCount(), copy.getImportsCount());
ProjectImport copiedImport = copy.getImport(0);
Assert.assertNotNull("Error: Copyied project does not contain the original import.", copiedImport);
Project importedCopy = copiedImport.getResolved();
Assert.assertNotNull("Error: Copyied project does not contain the original import.", importedCopy);
return importedCopy;
}
示例5: assertProject
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests the copies projects (and its imports).
* @param original The original for comparison.
* @param copy The copied project to test.
* @param done Already checked copied projects (to avoid cycles).
*/
private void assertProject(Project original, Project copy, java.util.Set<Project> done) {
Assert.assertNotNull("Copy is null", copy);
if (!done.contains(copy)) {
done.add(copy);
// Test project
Assert.assertEquals("Copied project does not have the same name", original.getName(), copy.getName());
Assert.assertNotSame("Projects \"" + original.getName() + "\"are same, i.e., no copy was created",
original, copy);
Assert.assertTrue("Copied project has not the same Version",
Version.equals(original.getVersion(), copy.getVersion()));
Assert.assertEquals("Copied project does not have the same amount of imports", original.getImportsCount(),
copy.getImportsCount());
Assert.assertEquals("Copied project has not the same amount of elements", original.getElementCount(),
copy.getElementCount());
// Test imports
Assert.assertEquals("Copy has different amount of imports", original.getImportsCount(),
copy.getImportsCount());
for (int i = 0; i < original.getImportsCount(); i++) {
ProjectImport orgImport = original.getImport(i);
ProjectImport copyImport = copy.getImport(i);
Assert.assertNotSame("Original import[" + i + "] was used instead of copy for import of \""
+ copyImport.getName() + "\"", orgImport, copyImport);
Assert.assertEquals("Import[" + i + "] name is wrong", orgImport.getName(), copyImport.getName());
// TODO SE: Version restriction
Assert.assertEquals("Interface[" + i + "] name is wrong", orgImport.getInterfaceName(),
copyImport.getInterfaceName());
assertProject(orgImport.getResolved(), copyImport.getResolved(), done);
}
// Test annotations
assertAnnotateableElement(original, copy, copy);
}
}
示例6: preprocessProjectElements
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Method to process declarations.
* This is where the required optimization takes place.
* The aim is to use the declarations that have constraints.
* The rest are ignored as they speed up the reasoning process.
* @param project Project.
*/
private void preprocessProjectElements(Project project) {
DroolsVariablesPreProcessor processor = new DroolsVariablesPreProcessor();
for (int i = 0; i < project.getImportsCount(); i++) {
ProjectImport tempProjectImport = project.getImport(i);
preprocessProjectElements(tempProjectImport.getResolved());
}
for (int i = 0; i < project.getElementCount(); i++) {
if (project.getElement(i) instanceof Constraint) {
Constraint cons = (Constraint) project.getElement(i);
cons.getConsSyntax().accept(processor);
}
if (project.getElement(i) instanceof DecisionVariableDeclaration) {
DecisionVariableDeclaration decl = (DecisionVariableDeclaration) project.getElement(i);
if (decl.getDefaultValue() != null) {
ConstraintSyntaxTree call = (ConstraintSyntaxTree) decl.getDefaultValue();
Variable var = new Variable(decl);
OCLFeatureCall valueCall = new OCLFeatureCall(var, OclKeyWords.EQUALS, call);
valueCall.accept(processor);
}
}
if (project.getElement(i) instanceof AttributeAssignment) {
processor.visitAttributeAssignment((AttributeAssignment) project.getElement(i));
}
}
if (optimizationType.equals(OptimizationType.INTERMEDIATE)) {
for (int i = 0; i < project.getInternalConstraintCount(); i++) {
project.getInternalConstraint(i).getConsSyntax().accept(processor);
}
}
}
示例7: visitInnerImports
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Method to recursively visit the inner project imports.
* @param project Resolved project.
*/
private void visitInnerImports(Project project) {
for (int i = 0; i < project.getImportsCount(); i++) {
ProjectImport tempProjectImport = project.getImport(i);
if (tempProjectImport.getResolved().getImportsCount() != 0) {
visitInnerImports(tempProjectImport.getResolved());
}
tempProjectImport.accept((IModelVisitor) droolsVisitor);
this.key = droolsVisitor.getRuleCount();
}
}
示例8: handleConfigFile
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Copies the IVML model. Configs will be cleaned.
* @param relativeFileName The path inside {@link #sourceFolder}.
* @param destFolder The destination folder where to save the copy.
* @throws ModelManagementException If IVML files could not be parsed
* @throws IOException If files could not be copied.
*/
private void handleConfigFile(String relativeFileName, File destFolder) throws ModelManagementException,
IOException {
if (!relativeFileName.toLowerCase().matches(REMOVEABLE_CONFIG_EXTENSION)) {
int lastDot = relativeFileName.lastIndexOf('.');
int lastSeparator = relativeFileName.lastIndexOf('/');
if (-1 == lastSeparator) {
lastSeparator = relativeFileName.lastIndexOf('\\');
}
String projectName = relativeFileName.substring(lastSeparator + 1, lastDot);
Project p = ProjectUtilities.loadProject(projectName);
debugMessage("Filter: " + projectName);
if (BASICS_CONFIG.equals(p.getName())) {
// Clear Basics Config
clearRewriter(p, FilterType.NO_IMPORTS);
rewriter.addModelCopyModifier(new DeclarationNameFilter(new String[] {"IntegerType", "LongType",
"StringType", "BooleanType", "FloatType", "DoubleType", "RealType", "ObjectType"}));
p.accept(rewriter);
} else if (PIPELINES_CONFIG.equals(p.getName())) {
// Clear Pipelines Config
clearRewriter(p, FilterType.NO_IMPORTS);
rewriter.addImportModifier(new ImportNameFilter(new String[] {"Basics", "Pipelines", "FamiliesCfg",
"DataManagementCfg"}));
p.accept(rewriter);
} else if (ALGORITHMS_CONFIG.equals(p.getName())) {
p = processDefaultConfig(p);
} else if (DATAMGT_CONFIG.equals(p.getName())) {
p = processDefaultConfig(p);
} else if (FAMILIES_CONFIG.equals(p.getName())) {
p = processDefaultConfig(p);
} else if (HARDWARE_CONFIG.equals(p.getName())) {
p = processDefaultConfig(p);
} else if (RECONFIGURABLE_HW_CONFIG.equals(p.getName())) {
p = processDefaultConfig(p);
// } else if (INFRASTRUCTURE_CONFIG.equals(p.getName())) {
// p = processDefaultConfig(p);
//
// FIXME SE: Do not remove to much inside InfrastructureCfg
} else {
// Clear all other configs
List<ProjectImport> imports = new ArrayList<ProjectImport>();
for (int i = 0; i < p.getImportsCount(); i++) {
ProjectImport projectImport = p.getImport(i);
String importName = projectImport.getName().toLowerCase();
if (!(importName + ".ivml").matches(REMOVEABLE_CONFIG_EXTENSION)) {
imports.add(projectImport);
}
}
p.clear();
for (int i = 0; i < imports.size(); i++) {
p.addImport(imports.get(i));
}
}
ProjectUtilities.saveProject(destFolder, p);
} else {
debugMessage("Ommiting: " + relativeFileName);
}
}
示例9: visitProject
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
@Override
public void visitProject(Project project) {
checkNameIdentifier(project.getName(), project);
location.push("project " + project.getName());
int count;
//Projects imports
count = project.getImportsCount();
for (int p = 0; p < count; p++) {
ProjectImport imp = project.getImport(p);
if (null == imp) {
addElementIsNullError("import", p, project);
} else {
// imp has no parent!
imp.accept(this);
}
}
/*
* Collect all custom datatypes.
* Sascha El-Sharkawy: This will only be a heuristic, but reduces the run time.
* I think this will be sufficient for most cases.
*/
if (1 == location.size()) {
DatatypeFinder finder = new DatatypeFinder(project, FilterType.ALL, null);
customTypes = new HashSet<IDatatype>(finder.getFoundDatatypes());
}
//Elements on top layer inside the project
count = project.getElementCount();
for (int c = 0; c < count; c++) {
ContainableModelElement elt = project.getElement(c);
if (null == elt) {
addElementIsNullError("element ", c, project);
} else {
checkParent(elt, project);
elt.accept(this);
}
}
//super.visitProject(project);
location.pop();
}
示例10: visitProject
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* {@inheritDoc} <br/>
* <b><font color="red">Attention:</font></b> This method will modify the visited project as a side effect.
* If the original project should not be modified, it is necessary to create a copy first via the
* {@link ProjectCopyVisitor}.
*/
@Override
public void visitProject(Project project) {
if (!done.contains(project)) {
context.addUsedProject(project);
done.add(project);
boolean isImportedProject = originProject != project;
boolean anyProject = FilterType.ALL == filterType;
boolean onlyImports = FilterType.ONLY_IMPORTS == filterType && isImportedProject;
boolean noImports = FilterType.NO_IMPORTS == filterType && !isImportedProject;
if (anyProject || onlyImports || noImports) {
// Remove all elements from project
ProjectImport[] pImports = new ProjectImport[project.getImportsCount()];
for (int i = 0; i < pImports.length; i++) {
pImports[i] = project.getImport(i);
}
ContainableModelElement[] unfilteredElements = new ContainableModelElement[project.getElementCount()];
for (int i = 0; i < unfilteredElements.length; i++) {
unfilteredElements[i] = project.getElement(i);
}
project.clear();
// visit all elements to check which shall be kept and add them again
for (int i = 0; i < pImports.length; i++) {
ProjectImport unfilteredImport = pImports[i];
for (int j = 0, n = importModifiers.size(); j < n && null != pImports[i]; j++) {
IProjectImportFilter currentModifier = importModifiers.get(j);
pImports[i] = currentModifier.handleImport(pImports[i], context);
}
if (null != pImports[i]) {
project.addImport(pImports[i]);
Project importedProject = pImports[i].getResolved();
if (null != importedProject) {
visitProject(importedProject);
}
} else {
Project removedProject = unfilteredImport.getResolved();
if (null != removedProject) {
DeletedElementsCollector collector = new DeletedElementsCollector(removedProject,
FilterType.ALL, context);
removedProject.accept(collector);
}
}
}
currentProject = project;
for (int i = 0; i < unfilteredElements.length; i++) {
unfilteredElements[i].accept(this);
}
// Project modifier
for (int i = 0, end = projectModifiers.size(); i < end; i++) {
IProjectModifier modifier = projectModifiers.get(i);
if (null != modifier) {
modifier.modifyProject(project, context);
}
}
}
if (project == this.originProject) {
context.removeElementsOfRemovedImports();
if (context.elementesWereRemoved()) {
/*
* Elements where removed start filtering again, maybe there exist some elements pointing
* to the removed elements.
*/
revisit(project);
}
}
}
}
示例11: storeComments
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Stores the comments stored in the resolved project of <code>info</code> and optionally
* for all imported projects. Existing data will be overwritten. Currently, this method
* considers only containable model elements.
*
* @param info the project information the comments shall be stored for
* @param considerImports consider also (resolved) imported projects
* @return <code>true</code> if the comments have been stored, <code>false</code> if
* no exception occurred but also the data was not stored, e.g. because <code>info</code>
* is not resolved or {@link ModelInfo#getCommentsResource()} is invalid
* @throws IOException in case that writing of the comments resource caused an error
*/
public synchronized boolean storeComments(ModelInfo<Project> info, boolean considerImports) throws IOException {
boolean done = false;
Project project = info.getResolved();
if (null != project) {
URI resourceUri = info.getCommentsResource();
if (null != resourceUri) {
File resourceFile = new File(resourceUri);
CommentResource props = new CommentResource();
int size = project.getElementCount();
for (int c = 0; c < size; c++) {
ContainableModelElement element = project.getElement(c);
String qName = element.getQualifiedName();
if (null != qName) {
props.put(qName, element.getComment());
}
}
FileWriter fw = new FileWriter(resourceFile);
try {
props.store(fw);
} catch (IOException e) {
try {
fw.close();
} catch (IOException e1) {
}
throw e;
}
fw.close();
size = project.getImportsCount();
for (int i = 0; i < size; i++) {
ProjectImport imp = project.getImport(i);
if (!imp.isConflict()) {
// do not just use getProjectInfo as this may taint unrelated projects
storeComments(repository.getResolvedModelInfo(imp.getResolved()));
}
}
done = true;
}
}
return done;
}
示例12: evaluate
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* This method evaluates a project, configuration with a set of constraints.
*
* @param project
* Project.
* @param cfg
* Configuration.
* @param constraints
* list of constraints to be evaluated.
* @param reasonerConfig
* reasoner configuration.
* @param observer
* Progress Observer.
* @return Result of the reasoning process.
*/
public EvaluationResult evaluate(Project project, Configuration cfg, List<Constraint> constraints,
ReasonerConfiguration reasonerConfig, ProgressObserver observer) {
DroolsVisitor.setOptimize(false);
DroolsOperations.loadOperators();
DroolsOperations.createDroolsOperators();
EvaluationResult result = new EvaluationResult();
logger.info("Checking ... ");
droolsVisitor = new DroolsVisitor();
droolsVisitor.setEvaluationChecking(true);
project.accept(droolsVisitor);
for (int i = 0; i < project.getImportsCount(); i++) {
ProjectImport tempProjectImport = project.getImport(i);
tempProjectImport.accept((IModelVisitor) droolsVisitor);
this.key = droolsVisitor.getRuleCount();
}
java.util.Set<Map.Entry<Integer, ModelElement>> set = droolsVisitor.getRuleMapper().entrySet();
for (Map.Entry<Integer, ModelElement> itr : set) {
this.ruleMapper.put(itr.getKey(), itr.getValue());
}
for (int i = 0; i < project.getElementCount(); i++) {
droolsVisitor.setRuleCount(key);
this.ruleMapper.put(new Integer(key), project.getElement(i));
key++;
if (project.getElement(i) instanceof Constraint) {
Constraint cons = (Constraint) project.getElement(i);
cons.getConsSyntax().accept(this);
if (acceptConstraint) {
project.getElement(i).accept((IModelVisitor) droolsVisitor);
acceptConstraint = false;
}
} else {
project.getElement(i).accept((IModelVisitor) droolsVisitor);
}
}
for (int j = 0; j < project.getInternalConstraintCount(); j++) {
droolsVisitor.setRuleCount(key);
this.ruleMapper.put(new Integer(key), project.getElement(j));
key++;
project.getInternalConstraint(j).accept((IModelVisitor) droolsVisitor);
}
evaluationStartIndex = key;
droolsVisitor.setEvaluationCalls(true);
if (null != constraints) {
logger.info("evaluation constraints are " + constraints.size());
for (int j = 0; j < constraints.size(); j++) {
droolsVisitor.setRuleCount(key);
this.ruleMapper.put(new Integer(key), constraints.get(j));
key++;
constraints.get(j).accept((IModelVisitor) droolsVisitor);
}
}
cfg.accept(droolsVisitor);
instantiateKnowledgeBase(project, result);
return result;
}
示例13: testMultipleProjectsInIVMLFile
import net.ssehub.easy.varModel.model.Project; //导入方法依赖的package包/类
/**
* Tests whether a IVML file with multiple projects is saved correctly by EASy.
* It would be nice if the projects would not be reordered, but this cannot be guaranteed at this moment.
* However, this test tests whether the ordering will be kept.
* @throws PersistenceException Must not occur, otherwise the config files inside the toplevel location are corrupt.
* @throws ValueDoesNotMatchTypeException If configuration is not supported (Error in VarModel).
* @throws ConfigurationException If configuration is not supported (Error in VarModel).
* @throws IOException If the generated file could not read from the file system
*/
@Test
public void testMultipleProjectsInIVMLFile() throws PersistenceException,
ValueDoesNotMatchTypeException, ConfigurationException, IOException {
// Load project
PLPInfo plp = loadPLPInfo(TEST_MULTIPLE_PROJECTS_IN_IVML_FILE);
// Test precondition: PLP should have IVML-Project with 2 imports and no errors
Assert.assertTrue("Error: IVML file with multiple projects could not be parsed.",
plp.getParsingExceptions().isEmpty());
Project mainProject = plp.getProject();
Assert.assertEquals("Error: Not expected number of imports found.", 2, mainProject.getImportsCount());
ProjectImport pImport1 = mainProject.getImport(0);
ProjectImport pImport2 = mainProject.getImport(1);
Assert.assertNotNull("Error: Imported IVML projects could not be resolved.", pImport1.getResolved());
Assert.assertNotNull("Error: Imported IVML projects could not be resolved.", pImport2.getResolved());
// Action: Configure one value and save (All variables are Integers).
Configuration config = plp.getConfiguration();
Iterator<IDecisionVariable> configIterator = config.iterator();
boolean found = false;
// An arbitrary variable could be used, but one specific should be chosen to simplify testing
while (configIterator.hasNext() && !found) {
IDecisionVariable var = configIterator.next();
if (var.getDeclaration().getName().equals("internalProjectVar")) {
Value value = ValueFactory.createValue(var.getDeclaration().getType(), "1");
var.setValue(value, AssignmentState.ASSIGNED);
found = true;
}
}
Assert.assertTrue("Error: No variable found in config.", found);
plp.save();
/*
* Test postcondition: Compare original IVML file and saved IVML file
* 1.) The new file should contain a new line: internalProjectVar = 1;
* 2.) The new file should contain the projects in the same order, but this cannot be guaranteed
*/
String configFolder = plp.getConfigLocation().getName();
String fileName = "MultipleProjectsInIVMLFile_0.ivml";
File originalIVMLFile = new File(AllTests.TESTDATA_DIR_ORIGINS, PROJECT_NAME_MULTIPLE_PROJECTS_IN_IVML_FILE);
originalIVMLFile = new File(new File(originalIVMLFile, configFolder), fileName);
File savedIVMLFile = new File(new File(TEST_MULTIPLE_PROJECTS_IN_IVML_FILE, configFolder), fileName);
String originalContent = FileUtils.readFileToString(originalIVMLFile).replaceAll("\r", "");
String savedContent = FileUtils.readFileToString(savedIVMLFile).replaceAll("\r", "");
// Test whether originalContent + value assignment = savedContent
String assignment = " internalProjectVar = 1;\n";
int index = savedContent.indexOf(assignment);
savedContent = savedContent.replaceAll(assignment, "");
System.out.println(savedContent);
Assert.assertTrue("Error: Assignment was not saved.", index > 0);
Assert.assertEquals("Error: Saved file has not the expected structure. Maybe only the odering of "
+ "projects have been changed (this would be ok).", originalContent, savedContent);
}