Added rename refactoring.

This commit is contained in:
Rik 2014-07-30 12:43:06 +02:00
parent 2f3fc95085
commit d5a83df8d1
4 changed files with 94 additions and 0 deletions

View File

@ -55,6 +55,10 @@
<fileBasedIndex implementation="com.powertuple.intellij.haskell.util.HaskellFileIndex"/>
<lang.findUsagesProvider language="Haskell" implementationClass="com.powertuple.intellij.haskell.HaskellFindUsagesProvider"/>
<lang.namesValidator language="Haskell" implementationClass="com.powertuple.intellij.haskell.HaskellNamesValidator"/>
<lang.refactoringSupport language="Haskell" implementationClass="com.powertuple.intellij.haskell.HaskellRefactoringSupportProvider"/>
<renamePsiElementProcessor implementation="com.powertuple.intellij.haskell.HaskellRenameVariableProcessor"/>
</extensions>
<application-components>

View File

@ -0,0 +1,35 @@
/*
* Copyright 2014 Rik van der Kleij
* 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.powertuple.intellij.haskell
import com.intellij.lang.refactoring.NamesValidator
import com.intellij.openapi.project.Project
class HaskellNamesValidator extends NamesValidator {
override def isKeyword(name: String, project: Project): Boolean = {
val lexer = new HaskellLexer
lexer.start(name.toCharArray)
HaskellParserDefinition.RESERVED_IDS.contains(lexer.getTokenType)
}
override def isIdentifier(name: String, project: Project): Boolean = {
// TODO: Except reservedop and dashes
!isKeyword(name, project)
}
}

View File

@ -0,0 +1,28 @@
/*
* Copyright 2014 Rik van der Kleij
* 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.powertuple.intellij.haskell
import com.intellij.lang.refactoring.RefactoringSupportProvider
import com.intellij.psi.PsiElement
import com.powertuple.intellij.haskell.psi.HaskellVar
class HaskellRefactoringSupportProvider extends RefactoringSupportProvider {
override def isMemberInplaceRenameAvailable(element: PsiElement, context: PsiElement): Boolean = {
element.isInstanceOf[HaskellVar]
}
}

View File

@ -0,0 +1,27 @@
/*
* Copyright 2014 Rik van der Kleij
* 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.powertuple.intellij.haskell
import com.intellij.psi.PsiElement
import com.intellij.refactoring.rename.RenamePsiElementProcessor
import com.powertuple.intellij.haskell.psi.HaskellVar
class HaskellRenameVariableProcessor extends RenamePsiElementProcessor{
override def canProcessElement(element: PsiElement): Boolean = element.isInstanceOf[HaskellVar]
override def forcesShowPreview(): Boolean = true
}