[groovy] logback congifuration DSL support (IDEA-128421)
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 24 Oct 2016 13:30:59 +0000 (16:30 +0300)
committerDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 24 Oct 2016 13:30:59 +0000 (16:30 +0300)
- lowercase aliased imported Level constanstans

plugins/groovy/src/META-INF/groovy-logback-support.xml
plugins/groovy/src/org/jetbrains/plugins/groovy/ext/logback/LogbackAliasedImportedMemberContributor.kt [new file with mode: 0644]
plugins/groovy/test/org/jetbrains/plugins/groovy/ext/logback/LogbackTest.groovy

index 945474f5946ee03ff01b8f9bf8b455efbdd73018..ded087cd5a1483f0b11becc52041f28ae8097957 100644 (file)
@@ -3,6 +3,7 @@
     <importContributor implementation="org.jetbrains.plugins.groovy.ext.logback.LogbackImportContributor"/>
     <membersContributor implementation="org.jetbrains.plugins.groovy.ext.logback.LogbackTopLevelMemberContributor"/>
     <membersContributor implementation="org.jetbrains.plugins.groovy.ext.logback.LogbackDelegateMemberContributor"/>
+    <membersContributor implementation="org.jetbrains.plugins.groovy.ext.logback.LogbackAliasedImportedMemberContributor"/>
     <delegatesToProvider implementation="org.jetbrains.plugins.groovy.ext.logback.LogbackDelegatesToProvider"/>
   </extensions>
 
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/ext/logback/LogbackAliasedImportedMemberContributor.kt b/plugins/groovy/src/org/jetbrains/plugins/groovy/ext/logback/LogbackAliasedImportedMemberContributor.kt
new file mode 100644 (file)
index 0000000..eb46af7
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.ext.logback
+
+import com.intellij.psi.*
+import com.intellij.psi.impl.light.LightVariableBuilder
+import com.intellij.psi.scope.ElementClassHint
+import com.intellij.psi.scope.NameHint
+import com.intellij.psi.scope.PsiScopeProcessor
+import org.jetbrains.plugins.groovy.lang.resolve.NonCodeMembersContributor
+import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil
+
+class LogbackAliasedImportedMemberContributor : NonCodeMembersContributor() {
+
+  private companion object {
+    val importedConstants = listOf("off", "error", "warn", "info", "debug", "trace", "all")
+    val levelFqn = "ch.qos.logback.classic.Level"
+  }
+
+  override fun getParentClassName() = "logback"
+
+  override fun processDynamicElements(qualifierType: PsiType,
+                                      aClass: PsiClass?,
+                                      processor: PsiScopeProcessor,
+                                      place: PsiElement,
+                                      state: ResolveState) {
+    if (!aClass.isLogbackConfig()) return
+    if (!ResolveUtil.shouldProcessProperties(processor.getHint(ElementClassHint.KEY))) return
+
+    val levelClass = JavaPsiFacade.getInstance(place.project).findClass(levelFqn, place.resolveScope) ?: return
+
+    fun process(constantName: String): Boolean {
+      val field = levelClass.findFieldByName(constantName.toUpperCase(), false) ?: return true
+      val variable = LightVariableBuilder<LightVariableBuilder<*>>(constantName, field.type, field)
+      return processor.execute(variable, state)
+    }
+
+    val name = processor.getHint(NameHint.KEY)?.getName(state)
+
+    if (name != null) {
+      if (name in importedConstants) {
+        process(name)
+      }
+    }
+    else {
+      for (constantName in importedConstants) {
+        if (!process(constantName)) return
+      }
+    }
+  }
+}
\ No newline at end of file
index 0eadf69fd097da5336207bde2a5ae68cf5c426fb..666b553886b6218d73b656640bbfd63d8805fa40 100644 (file)
@@ -119,6 +119,7 @@ appender("FULL_STACKTRACE", FileAppender) {
 }
 
 logger("StackTrace", ERROR, ['FULL_STACKTRACE'], false)
+root(warn, [''])
 '''
       enableInspections(GrUnresolvedAccessInspection)
       checkHighlighting()