From d385cd01552385def345eb8df2e38ef04fd8c507 Mon Sep 17 00:00:00 2001 From: Andrey Ponomarev Date: Wed, 23 Jan 2013 22:47:39 +0100 Subject: [PATCH] KT-3250 Copyright plugin does not work on Kotlin sources --- .idea/libraries/copyright_plugin.xml | 11 ++++ idea/idea.iml | 1 + idea/src/META-INF/kotlin-copyright.xml | 5 ++ idea/src/META-INF/plugin.xml | 5 ++ .../copyright/UpdateKotlinCopyright.java | 53 +++++++++++++++++++ .../UpdateKotlinCopyrightsProvider.java | 32 +++++++++++ 6 files changed, 107 insertions(+) create mode 100644 .idea/libraries/copyright_plugin.xml create mode 100644 idea/src/META-INF/kotlin-copyright.xml create mode 100644 idea/src/org/jetbrains/jet/plugin/copyright/UpdateKotlinCopyright.java create mode 100644 idea/src/org/jetbrains/jet/plugin/copyright/UpdateKotlinCopyrightsProvider.java diff --git a/.idea/libraries/copyright_plugin.xml b/.idea/libraries/copyright_plugin.xml new file mode 100644 index 00000000000..6c782f6edbe --- /dev/null +++ b/.idea/libraries/copyright_plugin.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/idea/idea.iml b/idea/idea.iml index 267ce11864d..827ac8384c5 100644 --- a/idea/idea.iml +++ b/idea/idea.iml @@ -26,6 +26,7 @@ + diff --git a/idea/src/META-INF/kotlin-copyright.xml b/idea/src/META-INF/kotlin-copyright.xml new file mode 100644 index 00000000000..9c48036cf54 --- /dev/null +++ b/idea/src/META-INF/kotlin-copyright.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index af1b038ae84..ba195144123 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -9,6 +9,7 @@ JUnit + com.intellij.copyright @@ -254,4 +255,8 @@ + + + + diff --git a/idea/src/org/jetbrains/jet/plugin/copyright/UpdateKotlinCopyright.java b/idea/src/org/jetbrains/jet/plugin/copyright/UpdateKotlinCopyright.java new file mode 100644 index 00000000000..16435ec7ad2 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/copyright/UpdateKotlinCopyright.java @@ -0,0 +1,53 @@ +/* + * Copyright 2010-2013 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.jet.plugin.copyright; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.psi.PsiComment; +import com.intellij.psi.PsiElement; +import com.intellij.psi.PsiWhiteSpace; +import com.maddyhome.idea.copyright.CopyrightProfile; +import com.maddyhome.idea.copyright.psi.UpdatePsiFileCopyright; + +class UpdateKotlinCopyright extends UpdatePsiFileCopyright { + + UpdateKotlinCopyright(Project project, Module module, VirtualFile root, CopyrightProfile copyrightProfile) { + super(project, module, root, copyrightProfile); + } + + @Override + protected void scanFile() { + PsiElement first = getFile().getFirstChild(); + PsiElement last = first; + PsiElement next = first; + while (next != null) { + if (next instanceof PsiComment || next instanceof PsiWhiteSpace) { + next = getNextSibling(next); + } + else { + break; + } + last = next; + } + + if (first != null) { + checkComments(first, last, true); + } + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/copyright/UpdateKotlinCopyrightsProvider.java b/idea/src/org/jetbrains/jet/plugin/copyright/UpdateKotlinCopyrightsProvider.java new file mode 100644 index 00000000000..b26996f810e --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/copyright/UpdateKotlinCopyrightsProvider.java @@ -0,0 +1,32 @@ +/* + * Copyright 2010-2013 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.jet.plugin.copyright; + +import com.intellij.openapi.fileTypes.FileType; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vfs.VirtualFile; +import com.maddyhome.idea.copyright.CopyrightProfile; +import com.maddyhome.idea.copyright.psi.UpdateCopyright; +import com.maddyhome.idea.copyright.psi.UpdateCopyrightsProvider; + +public class UpdateKotlinCopyrightsProvider extends UpdateCopyrightsProvider { + @Override + public UpdateCopyright createInstance(Project project, Module module, VirtualFile file, FileType base, CopyrightProfile options) { + return new UpdateKotlinCopyright(project, module, file, options); + } +}