]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/java/LoggingModule.java
(refs #7613) Removed some module sources as declarative services
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / elaboration / java / LoggingModule.java
index dadc13aa7ee3e926a894d7cfbbe846c69d82c7b9..8ce399148b0cb9292ae25bf33156dab6b2d35872 100644 (file)
@@ -4,6 +4,7 @@ import org.cojen.classfile.TypeDesc;
 import org.osgi.service.component.annotations.Component;
 import org.simantics.scl.compiler.commands.CommandSession;
 import org.simantics.scl.compiler.common.names.Name;
+import org.simantics.scl.compiler.compilation.CompilationContext;
 import org.simantics.scl.compiler.constants.JavaMethod;
 import org.simantics.scl.compiler.elaboration.contexts.SimplificationContext;
 import org.simantics.scl.compiler.elaboration.expressions.EApply;
@@ -22,7 +23,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Marker;
 
-@Component
 public class LoggingModule extends ConcreteModule {
 
     private static final String[] LOGGING_METHODS = new String[] {
@@ -63,12 +63,7 @@ public class LoggingModule extends ConcreteModule {
                 value.setMacroRule(new MacroRule() {
                     @Override
                     public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
-                        ConcreteModule module = context.getCompilationContext().module;
-                        String identifier;
-                        if (module != null)
-                            identifier = module.getName().replaceAll("/", ".");
-                        else
-                            identifier = CommandSession.class.getName();
+                        String identifier = resolveModuleIdentifier(context.getCompilationContext());
                         apply.set(new ELiteral(javaMethod), new Expression[] {
                                 new EExternalConstant(LoggerFactory.getLogger(identifier), Logger)
                         });
@@ -84,12 +79,7 @@ public class LoggingModule extends ConcreteModule {
                 value.setMacroRule(new MacroRule() {
                     @Override
                     public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
-                        ConcreteModule module = context.getCompilationContext().module;
-                        String identifier;
-                        if (module != null)
-                            identifier = module.getName().replaceAll("/", ".");
-                        else
-                            identifier = CommandSession.class.getName();
+                        String identifier = resolveModuleIdentifier(context.getCompilationContext());
                         apply.set(new ELiteral(javaMethod), new Expression[] {
                                 new EExternalConstant(LoggerFactory.getLogger(identifier), Logger),
                                 apply.parameters[0]
@@ -106,12 +96,7 @@ public class LoggingModule extends ConcreteModule {
                 value.setMacroRule(new MacroRule() {
                     @Override
                     public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
-                        ConcreteModule module = context.getCompilationContext().module;
-                        String identifier;
-                        if (module != null)
-                            identifier = module.getName().replaceAll("/", ".");
-                        else
-                            identifier = CommandSession.class.getName();
+                        String identifier = resolveModuleIdentifier(context.getCompilationContext());
                         apply.set(new ELiteral(javaMethod), new Expression[] {
                                 new EExternalConstant(LoggerFactory.getLogger(identifier), Logger),
                                 apply.parameters[0],
@@ -129,12 +114,7 @@ public class LoggingModule extends ConcreteModule {
                 value.setMacroRule(new MacroRule() {
                     @Override
                     public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
-                        ConcreteModule module = context.getCompilationContext().module;
-                        String identifier;
-                        if (module != null)
-                            identifier = module.getName().replaceAll("/", ".");
-                        else
-                            identifier = CommandSession.class.getName();
+                        String identifier = resolveModuleIdentifier(context.getCompilationContext());
                         apply.set(new ELiteral(javaMethod), new Expression[] {
                                 new EExternalConstant(LoggerFactory.getLogger(identifier), Logger),
                                 apply.parameters[0],
@@ -152,12 +132,7 @@ public class LoggingModule extends ConcreteModule {
                 value.setMacroRule(new MacroRule() {
                     @Override
                     public Expression apply(SimplificationContext context, Type[] typeParameters, EApply apply) {
-                        ConcreteModule module = context.getCompilationContext().module;
-                        String identifier;
-                        if (module != null)
-                            identifier = module.getName().replaceAll("/", ".");
-                        else
-                            identifier = CommandSession.class.getName();
+                        String identifier = resolveModuleIdentifier(context.getCompilationContext());
                         apply.set(new ELiteral(javaMethod), new Expression[] {
                                 new EExternalConstant(LoggerFactory.getLogger(identifier), Logger),
                                 apply.parameters[0],
@@ -181,4 +156,19 @@ public class LoggingModule extends ConcreteModule {
     private static String capitalizeFirstCharacter(String input) {
         return input.substring(0, 1).toUpperCase() + input.substring(1);
     }
+    
+    private static String resolveModuleIdentifier(CompilationContext context) {
+        ConcreteModule module = context.module;
+        String identifier;
+        if (module != null) {
+            String moduleName = module.getName();
+            if (moduleName.startsWith("http://")) {
+                moduleName = moduleName.substring("http://".length());
+            }
+            identifier = moduleName.replaceAll("/", ".");
+        } else {
+            identifier = CommandSession.class.getName();
+        }
+        return identifier;
+    }
 }