mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inline parameter: check visibility access (IDEA-52169)
This commit is contained in:
+3
-2
@@ -181,6 +181,8 @@ public class InlineParameterExpressionProcessor extends BaseRefactoringProcessor
|
||||
if (element instanceof PsiMethod || element instanceof PsiField) {
|
||||
if (!mySameClass && !((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC)) {
|
||||
conflicts.putValue(expression, "Parameter initializer depend on non static member from some other class");
|
||||
} else if (!PsiUtil.isAccessible((PsiMember)element, myMethod, null)) {
|
||||
conflicts.putValue(expression, "Parameter initializer depends on value which is not available inside method");
|
||||
}
|
||||
} else if (element instanceof PsiParameter) {
|
||||
conflicts.putValue(expression, "Parameter initializer depends on callers parameter");
|
||||
@@ -203,8 +205,7 @@ public class InlineParameterExpressionProcessor extends BaseRefactoringProcessor
|
||||
if (!PsiTreeUtil.isAncestor(containingClass, methodContainingClass, false)) {
|
||||
conflicts.putValue(thisExpression,
|
||||
"Parameter initializer depends on this which is not available inside the method and cannot be inlined");
|
||||
}
|
||||
if (myMethod.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
} else if (myMethod.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
conflicts.putValue(thisExpression, "Parameter initializer depends on this which is not available inside the static method");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
public class VisibilityPinline {
|
||||
private static DifferentScope cashedObject = new DifferentScope();
|
||||
|
||||
private static DifferentScope provideObject() {
|
||||
return new DifferentScope();
|
||||
}
|
||||
|
||||
public void context() {
|
||||
DifferentScope vB = new DifferentScope();
|
||||
vB.inlineB(provideObject());
|
||||
}
|
||||
}
|
||||
|
||||
class DifferentScope {
|
||||
private int value = 1;
|
||||
|
||||
public void mutate() {
|
||||
value++;
|
||||
}
|
||||
|
||||
public void inlineB(DifferentScope <caret>subj) {
|
||||
subj.mutate();
|
||||
}
|
||||
}
|
||||
@@ -219,6 +219,15 @@ public class InlineParameterTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testVisibility() throws Exception {
|
||||
try {
|
||||
doTest(false);
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
assertEquals("Parameter initializer depends on value which is not available inside method", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void doTest(final boolean createLocal) throws Exception {
|
||||
getProject().putUserData(InlineParameterExpressionProcessor.CREATE_LOCAL_FOR_TESTS,createLocal);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user