diff options
Diffstat (limited to 'plugins/copyright/src/com')
6 files changed, 129 insertions, 22 deletions
diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/CopyrightVariablesProvider.java b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/CopyrightVariablesProvider.java new file mode 100644 index 000000000000..623e71eec613 --- /dev/null +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/CopyrightVariablesProvider.java @@ -0,0 +1,27 @@ +/* + * Copyright 2000-2014 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 com.maddyhome.idea.copyright.pattern; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public abstract class CopyrightVariablesProvider { + public abstract void collectVariables(@NotNull Map<String, Object> context, Project project, Module module, @NotNull PsiFile file); +} diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/CopyrightVariablesProviders.java b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/CopyrightVariablesProviders.java new file mode 100644 index 000000000000..939601c2baea --- /dev/null +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/CopyrightVariablesProviders.java @@ -0,0 +1,26 @@ +/* + * Copyright 2000-2014 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 com.maddyhome.idea.copyright.pattern; + +import com.intellij.openapi.fileTypes.FileTypeExtension; + +public class CopyrightVariablesProviders extends FileTypeExtension<CopyrightVariablesProvider> { + public static CopyrightVariablesProviders INSTANCE = new CopyrightVariablesProviders(); + + private CopyrightVariablesProviders() { + super("com.intellij.copyright.variablesProvider"); + } +} diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/FileInfo.java b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/FileInfo.java index f5cf378955ef..33b523e7dc5e 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/FileInfo.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/FileInfo.java @@ -18,7 +18,6 @@ package com.maddyhome.idea.copyright.pattern; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; -import com.intellij.psi.PsiJavaFile; public class FileInfo { @@ -39,26 +38,12 @@ public class FileInfo public String getClassName() { - if (file instanceof PsiJavaFile) - { - return ((PsiJavaFile)file).getClasses()[0].getName(); - } - else - { - return getFileName(); - } + return getFileName(); } public String getQualifiedClassName() { - if (file instanceof PsiJavaFile) - { - return ((PsiJavaFile)file).getClasses()[0].getQualifiedName(); - } - else - { - return getPathName(); - } + return getPathName(); } public DateInfo getLastModified() diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/JavaCopyrightVariablesProvider.java b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/JavaCopyrightVariablesProvider.java new file mode 100644 index 000000000000..3d76074a3935 --- /dev/null +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/JavaCopyrightVariablesProvider.java @@ -0,0 +1,54 @@ +/* + * Copyright 2000-2014 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 com.maddyhome.idea.copyright.pattern; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiClassOwner; +import com.intellij.psi.PsiFile; +import com.intellij.psi.PsiJavaFile; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class JavaCopyrightVariablesProvider extends CopyrightVariablesProvider { + @Override + public void collectVariables(@NotNull Map<String, Object> context, Project project, Module module, @NotNull final PsiFile file) { + if (file instanceof PsiClassOwner) { + final FileInfo info = new FileInfo(file) { + @Override + public String getClassName() { + if (file instanceof PsiJavaFile) { + return ((PsiJavaFile)file).getClasses()[0].getName(); + } + else { + return super.getClassName(); + } + } + + @Override + public String getQualifiedClassName() { + if (file instanceof PsiJavaFile) { + return ((PsiJavaFile)file).getClasses()[0].getQualifiedName(); + } else { + return super.getQualifiedClassName(); + } + } + }; + context.put("file", info); + } + } +} diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java index 2ecc629eb135..7284d0d989f3 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/pattern/VelocityHelper.java @@ -20,7 +20,9 @@ import com.intellij.openapi.application.PathManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; +import com.intellij.psi.util.PsiUtilCore; import com.maddyhome.idea.copyright.CopyrightManager; import org.apache.commons.collections.ExtendedProperties; import org.apache.velocity.VelocityContext; @@ -29,6 +31,8 @@ import org.apache.velocity.runtime.RuntimeConstants; import org.apache.velocity.runtime.log.SimpleLog4JLogSystem; import java.io.StringWriter; +import java.util.HashMap; +import java.util.Map; public class VelocityHelper { @@ -43,7 +47,22 @@ public class VelocityHelper if (module != null) vc.put("module", new ModuleInfo(module)); vc.put("username", System.getProperty("user.name")); - try + if (file != null) { + final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file); + if (virtualFile != null) { + final CopyrightVariablesProvider variablesProvider = CopyrightVariablesProviders.INSTANCE.forFileType(virtualFile.getFileType()); + if (variablesProvider != null) { + final Map<String, Object> context = new HashMap<String, Object>(); + variablesProvider.collectVariables(context, project, module, file); + for (Map.Entry<String, Object> entry : context.entrySet()) { + vc.put(entry.getKey(), entry.getValue()); + } + } + } + } + + + try { StringWriter sw = new StringWriter(); boolean stripLineBreak = false; diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProjectConfigurable.java b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProjectConfigurable.java index e3af27e387fa..4bf8d7b5f235 100644 --- a/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProjectConfigurable.java +++ b/plugins/copyright/src/com/maddyhome/idea/copyright/ui/CopyrightProjectConfigurable.java @@ -81,10 +81,6 @@ public class CopyrightProjectConfigurable extends SearchableConfigurable.Parent. return true; } - public boolean isVisible() { - return true; - } - @NotNull public String getId() { return "copyright"; |