From: Hannu Niemistö Date: Tue, 10 Oct 2017 15:40:00 +0000 (+0300) Subject: (refs #7541) Added support for module deprecation X-Git-Tag: v1.31.0~129^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=4e753de3df98d5411f8329205c0e03f2e13e3c1d;p=simantics%2Fplatform.git (refs #7541) Added support for module deprecation Change-Id: I61eac59be8891aabc00e0142f6ef812c6ddba922 --- diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java index 50296a3a1..f7f745841 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/compilation/Elaboration.java @@ -169,12 +169,17 @@ public class Elaboration { module = new ConcreteModule(moduleName); compilationContext.module = module; - if(moduleHeader != null && moduleHeader.defaultLocalName != null) - module.setDefaultLocalName(moduleHeader.defaultLocalName); + if(moduleHeader != null) { + if(moduleHeader.defaultLocalName != null) + module.setDefaultLocalName(moduleHeader.defaultLocalName); + if(moduleHeader.deprecated != null) + module.setDeprecation(moduleHeader.deprecated); + } try { if(timer != null) timer.suspendTimer(); importedEnvironment = localEnvironmentFactory.createEnvironment( + compilationContext, importsAst.toArray(new ImportDeclaration[importsAst.size()])); if(timer != null) timer.continueTimer(); diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/EnvironmentFactory.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/EnvironmentFactory.java index f5799ba67..1faa8f645 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/EnvironmentFactory.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/EnvironmentFactory.java @@ -1,12 +1,13 @@ package org.simantics.scl.compiler.environment; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.module.ConcreteModule; import org.simantics.scl.compiler.module.ImportDeclaration; import org.simantics.scl.compiler.module.repository.ImportFailureException; public interface EnvironmentFactory { - Environment createEnvironment(ImportDeclaration[] array) throws ImportFailureException; + Environment createEnvironment(CompilationContext context, ImportDeclaration[] array) throws ImportFailureException; void addBuiltinDependencies(ConcreteModule module); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/EnvironmentFactoryImpl.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/EnvironmentFactoryImpl.java index 790093748..1a7fb3c6d 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/EnvironmentFactoryImpl.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/EnvironmentFactoryImpl.java @@ -3,6 +3,7 @@ package org.simantics.scl.compiler.environment; import java.util.ArrayList; import java.util.Arrays; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.module.ConcreteModule; import org.simantics.scl.compiler.module.ImportDeclaration; import org.simantics.scl.compiler.module.repository.ImportFailureException; @@ -23,7 +24,7 @@ public class EnvironmentFactoryImpl implements EnvironmentFactory { } @Override - public Environment createEnvironment(ImportDeclaration[] imports) throws ImportFailureException { + public Environment createEnvironment(CompilationContext context, ImportDeclaration[] imports) throws ImportFailureException { ArrayList acceptedBuiltinImports = new ArrayList(builtinImports.length); loop: for(ImportDeclaration builtinImport : builtinImports) { @@ -37,7 +38,7 @@ public class EnvironmentFactoryImpl implements EnvironmentFactory { acceptedBuiltinImports.toArray(new ImportDeclaration[acceptedBuiltinImports.size()]), acceptedBuiltinImports.size() + imports.length); System.arraycopy(imports, 0, is, acceptedBuiltinImports.size(), imports.length); - return environment.createEnvironment(is, listener); + return environment.createEnvironment(context, is, listener); } @Override diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java index 73311e99a..b92f3dff6 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/ConcreteModule.java @@ -33,6 +33,7 @@ import gnu.trove.procedure.TObjectProcedure; public class ConcreteModule implements Module { String moduleName; String defaultLocalName; + String deprecation; THashMap typeDescriptors = new THashMap(); THashMap effectConstructors = new THashMap(); THashMap typeClasses = new THashMap(); @@ -326,4 +327,13 @@ public class ConcreteModule implements Module { public void addRuleset(String name, CHRRuleset ruleset) { rulesets.put(name, ruleset); } + + @Override + public String getDeprecation() { + return deprecation; + } + + public void setDeprecation(String deprecation) { + this.deprecation = deprecation; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java index 61d2c2928..6daef2b17 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/LazyModule.java @@ -152,4 +152,9 @@ public abstract class LazyModule implements Module { public CHRRuleset getRuleset(String name) { return null; } + + @Override + public String getDeprecation() { + return null; + } } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java index ee90b5e1a..6e6690fef 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/Module.java @@ -60,4 +60,5 @@ public interface Module { CompilationError[] getWarnings(); ClassLoader getParentClassLoader(); + String getDeprecation(); } diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java index 40c69f434..089f2c26c 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/module/repository/ModuleRepository.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.simantics.scl.compiler.common.exceptions.InternalCompilerError; +import org.simantics.scl.compiler.compilation.CompilationContext; import org.simantics.scl.compiler.elaboration.modules.SCLValue; import org.simantics.scl.compiler.environment.ConcreteEnvironment; import org.simantics.scl.compiler.environment.Environment; @@ -159,7 +160,7 @@ public class ModuleRepository { Collection dependencies = module.getDependencies(); THashMap moduleEntries; try { - moduleEntries = getModuleEntries(dependencies.toArray(new ImportDeclaration[dependencies.size()]), null); + moduleEntries = getModuleEntries(null, dependencies.toArray(new ImportDeclaration[dependencies.size()]), null); } catch (ImportFailureException e) { throw new InternalCompilerError(e); } @@ -254,6 +255,7 @@ public class ModuleRepository { } private THashMap getModuleEntries( + CompilationContext compilationContext, ImportDeclaration[] imports, UpdateListener listener) throws ImportFailureException { THashMap result = new THashMap(); @@ -268,11 +270,17 @@ public class ModuleRepository { while(!stack.isEmpty()) { ImportDeclaration import_ = stack.remove(stack.size()-1); if(!result.containsKey(import_.moduleName)) { - ModuleEntry entry = getModuleEntry(import_.moduleName, originalImports.contains(import_.moduleName) ? listener : null); + boolean originalImport = originalImports.contains(import_.moduleName); + ModuleEntry entry = getModuleEntry(import_.moduleName, originalImport ? listener : null); Failable compilationResult = entry.compilationResult; if(compilationResult.didSucceed()) { result.put(import_.moduleName, entry); stack.addAll(compilationResult.getResult().getDependencies()); + if(originalImport) { + String deprecation = compilationResult.getResult().getDeprecation(); + if(deprecation != null && compilationContext != null) + compilationContext.errorLog.logWarning(import_.location, "Deprecated module " + import_.moduleName + (deprecation.isEmpty() ? "." : ": " + deprecation)); + } } else { if(failures == null) @@ -318,7 +326,14 @@ public class ModuleRepository { public Environment createEnvironment( ImportDeclaration[] imports, UpdateListener listener) throws ImportFailureException { - THashMap entries = getModuleEntries(imports, listener); + return createEnvironment(null, imports, listener); + } + + public Environment createEnvironment( + CompilationContext compilationContext, + ImportDeclaration[] imports, + UpdateListener listener) throws ImportFailureException { + THashMap entries = getModuleEntries(compilationContext, imports, listener); THashMap moduleMap = mapEntriesToModules(entries); return createEnvironment(moduleMap, imports); } @@ -348,14 +363,15 @@ public class ModuleRepository { ImportDeclaration[] imports, ClassLoader parentClassLoader, UpdateListener listener) throws ImportFailureException { - THashMap entries = getModuleEntries(imports, listener); + THashMap entries = getModuleEntries(null, imports, listener); THashMap moduleMap = mapEntriesToModules(entries); Environment environment = createEnvironment(moduleMap, imports); THashMap runtimeModuleMap = mapEntriesToRuntimeModules(entries); return new RuntimeEnvironmentImpl(environment, parentClassLoader, runtimeModuleMap); } - private static Environment createEnvironment(THashMap moduleMap, + private static Environment createEnvironment( + THashMap moduleMap, ImportDeclaration[] imports) { NamespaceSpec spec = new NamespaceSpec(); for(ImportDeclaration import_ : imports)