java: helper method for Kotlin

This commit is contained in:
Roman Shevchenko
2014-06-05 15:28:10 +04:00
parent 5c41c762da
commit f5f8124350
2 changed files with 26 additions and 14 deletions
@@ -66,30 +66,39 @@ public class ClsParameterImpl extends ClsRepositoryPsiElement<PsiParameterStub>
String name = myName;
if (name == null) {
if (DumbService.getInstance(getProject()).isDumb()) {
return null;
}
ClsMethodImpl method = (ClsMethodImpl)getDeclarationScope();
PsiMethod sourceMethod = method.getSourceMirrorMethod();
if (sourceMethod != null) {
assert sourceMethod != method : method;
name = sourceMethod.getParameterList().getParameters()[getIndex()].getName();
PsiParameterStubImpl parameterStub = (PsiParameterStubImpl)getStub();
if (!parameterStub.isAutoGeneratedName()) {
name = parameterStub.getName();
}
if (name == null) {
PsiParameterStubImpl parameterStub = (PsiParameterStubImpl)getStub();
name = !parameterStub.isAutoGeneratedName() ? parameterStub.getName() : getMirrorName();
if (DumbService.getInstance(getProject()).isDumb()) {
return null;
}
ClsMethodImpl method = (ClsMethodImpl)getDeclarationScope();
PsiMethod sourceMethod = method.getSourceMirrorMethod();
if (sourceMethod != null) {
assert sourceMethod != method : method;
name = sourceMethod.getParameterList().getParameters()[getIndex()].getName();
}
else {
name = getMirrorName();
}
}
if (name != null) {
myName = name;
}
myName = name;
}
return name;
}
public boolean isAutoGeneratedName() {
return ((PsiParameterStubImpl)getStub()).isAutoGeneratedName() &&
!DumbService.getInstance(getProject()).isDumb() &&
((ClsMethodImpl)getDeclarationScope()).getSourceMirrorMethod() == null;
}
@Override
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE);
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileFilter;
import com.intellij.psi.impl.compiled.ClsParameterImpl;
import com.intellij.psi.impl.java.stubs.PsiMethodStub;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiUtil;
@@ -504,6 +505,8 @@ public class ClsRepositoryUseTest extends PsiTestCase {
assertNotNull(parameters[0].getModifierList());
assertNotNull(parameters[1].getModifierList());
assertTrue(((ClsParameterImpl)parameters[0]).isAutoGeneratedName());
assertTrue(((ClsParameterImpl)parameters[1]).isAutoGeneratedName());
assertEquals("ints", parameters[0].getName());
assertEquals("o", parameters[1].getName());
}