mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-84675 Intention to change access modifiers (private/protected/public) - Groovy
This commit is contained in:
+3
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
<spot>private</spot> def foo() {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
<spot>protected</spot> def foo() {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
Makes selected element <b>private</b>.
|
||||
</body>
|
||||
</html>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
<spot>protected</spot> def foo() {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
<spot>private</spot> def foo() {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
Makes selected element <b>protected</b>.
|
||||
</body>
|
||||
</html>
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
<spot>public</spot> def foo() {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
class Foo {
|
||||
<spot>protected</spot> def foo() {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
Makes selected element <b>public</b>.
|
||||
</body>
|
||||
</html>
|
||||
@@ -1246,6 +1246,21 @@
|
||||
<categoryKey>intention.category.groovy/intention.category.groovy.declaration</categoryKey>
|
||||
<className>org.jetbrains.plugins.groovy.intentions.declaration.GrSetStrongTypeIntention</className>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
<bundleName>org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle</bundleName>
|
||||
<categoryKey>intention.category.groovy/intention.category.groovy.declaration</categoryKey>
|
||||
<className>org.jetbrains.plugins.groovy.intentions.declaration.GrMakeMemberPublicIntention</className>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
<bundleName>org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle</bundleName>
|
||||
<categoryKey>intention.category.groovy/intention.category.groovy.declaration</categoryKey>
|
||||
<className>org.jetbrains.plugins.groovy.intentions.declaration.GrMakeMemberProtectedIntention</className>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
<bundleName>org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle</bundleName>
|
||||
<categoryKey>intention.category.groovy/intention.category.groovy.declaration</categoryKey>
|
||||
<className>org.jetbrains.plugins.groovy.intentions.declaration.GrMakeMemberPrivateIntention</className>
|
||||
</intentionAction>
|
||||
|
||||
<!--other-->
|
||||
<intentionAction>
|
||||
|
||||
@@ -329,3 +329,5 @@ abstract.method.cannot.be.final=Abstract method cannot be final
|
||||
abstract.methods.must.not.have.body=Abstract methods must not have body
|
||||
method.has.incorrect.modifier.volatile=Method has incorrect modifier 'volatile'
|
||||
native.methods.cannot.have.body=Native methods cannot have body
|
||||
top.level.class.maynot.have.private.modifier=Top level class may not have 'private' modifier
|
||||
top.level.class.maynot.have.protected.modifier=Top level class may not have 'protected' modifier
|
||||
|
||||
+7
-1
@@ -183,4 +183,10 @@ remove.unnecessary.return.intention.family.name=Remove unnecessary 'return' keyw
|
||||
gr.alias.import.intention.name=Alias import
|
||||
gr.alias.import.intention.family.name=Alias import statically imported member
|
||||
gr.copy.string.concatenation.content.intention.name=Copy string concatenation text to clipboard
|
||||
gr.copy.string.concatenation.content.intention.family.name=Copy string concatenation text to clipboard
|
||||
gr.copy.string.concatenation.content.intention.family.name=Copy string concatenation text to clipboard
|
||||
gr.make.member.private.intention.name=Make 'private'
|
||||
gr.make.member.private.intention.family.name=Make 'private'
|
||||
gr.make.member.public.intention.name=Make 'public'
|
||||
gr.make.member.public.intention.family.name=Make 'public'
|
||||
gr.make.member.protected.intention.name=Make 'protected'
|
||||
gr.make.member.protected.intention.family.name=Make 'protected'
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.intentions.declaration;
|
||||
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.Intention;
|
||||
import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GrNamedElement;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMember;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public abstract class GrChangeMemberVisibilityModifierBase extends Intention {
|
||||
private final String myModifier;
|
||||
|
||||
public GrChangeMemberVisibilityModifierBase(String modifier) {
|
||||
myModifier = modifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException {
|
||||
final PsiElement parent = element.getParent();
|
||||
if (!(parent instanceof GrMember)) return;
|
||||
|
||||
((GrMember)parent).getModifierList().setModifierProperty(myModifier, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected PsiElementPredicate getElementPredicate() {
|
||||
return new PsiElementPredicate() {
|
||||
@Override
|
||||
public boolean satisfiedBy(PsiElement element) {
|
||||
final PsiElement parent = element.getParent();
|
||||
return parent instanceof GrMember &&
|
||||
parent instanceof GrNamedElement &&
|
||||
(((GrNamedElement)parent).getNameIdentifierGroovy() == element || ((GrNamedElement)parent).getModifierList() == element) &&
|
||||
!((GrMember)parent).getModifierList().hasExplicitModifier(myModifier);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.intentions.declaration;
|
||||
|
||||
import com.intellij.psi.PsiModifier;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GrMakeMemberPrivateIntention extends GrChangeMemberVisibilityModifierBase {
|
||||
public GrMakeMemberPrivateIntention() {
|
||||
super(PsiModifier.PRIVATE);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.intentions.declaration;
|
||||
|
||||
import com.intellij.psi.PsiModifier;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GrMakeMemberProtectedIntention extends GrChangeMemberVisibilityModifierBase {
|
||||
public GrMakeMemberProtectedIntention() {
|
||||
super(PsiModifier.PROTECTED);
|
||||
}
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.intentions.declaration;
|
||||
|
||||
import com.intellij.psi.PsiModifier;
|
||||
|
||||
/**
|
||||
* @author Max Medvedev
|
||||
*/
|
||||
public class GrMakeMemberPublicIntention extends GrChangeMemberVisibilityModifierBase {
|
||||
public GrMakeMemberPublicIntention() {
|
||||
super(PsiModifier.PUBLIC);
|
||||
}
|
||||
}
|
||||
-8
@@ -45,8 +45,6 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.GrStubElementBase;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.stubs.GrModifierListStub;
|
||||
import org.jetbrains.plugins.groovy.lang.resolve.noncode.ConstructorAnnotationsProcessor;
|
||||
|
||||
import static org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier.*;
|
||||
|
||||
/**
|
||||
* @autor: Dmitry.Krasilschikov
|
||||
* @date: 18.03.2007
|
||||
@@ -172,12 +170,6 @@ public class GrModifierListImpl extends GrStubElementBase<GrModifierListStub> im
|
||||
}
|
||||
}
|
||||
|
||||
//top level classes cannot have private and protected modifiers
|
||||
if (owner instanceof GrTypeDefinition && ((GrTypeDefinition)owner).getContainingClass() == null) {
|
||||
if (modifier.equals(PROTECTED) || modifier.equals(PRIVATE)) return false;
|
||||
if (modifier.equals(PACKAGE_LOCAL)) return modifierList.hasExplicitModifier(PRIVATE) || modifierList.hasExplicitModifier(PROTECTED);
|
||||
}
|
||||
|
||||
if (modifierList.hasExplicitModifier(modifier)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -600,13 +600,14 @@ class A {
|
||||
void testPrivateTopLevelClassInJava() {
|
||||
myFixture.addFileToProject('pack/Foo.groovy', 'package pack; private class Foo{}')
|
||||
myFixture.configureByText('Abc.java', '''\
|
||||
import pack.<error descr="'pack.Foo' is not public in 'pack'. Cannot be accessed from outside package">Foo</error>;
|
||||
import pack.Foo;
|
||||
|
||||
class Abc {
|
||||
void foo() {
|
||||
System.out.print(new <error descr="'pack.Foo' is not public in 'pack'. Cannot be accessed from outside package">Foo</error>());
|
||||
System.out.print(new <error descr="'pack.Foo' has private access in 'pack'">Foo</error>());
|
||||
}
|
||||
}''')
|
||||
}
|
||||
''')
|
||||
|
||||
myFixture.testHighlighting(false, false, false)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user