mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge branch 'master' of git.labs.intellij.net:idea/community
This commit is contained in:
@@ -30,6 +30,7 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.ui.ScreenUtil;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -37,10 +38,8 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Eugene Zhuravlev
|
||||
@@ -48,8 +47,16 @@ import java.util.Comparator;
|
||||
*/
|
||||
public class JdkComboBox extends ComboBoxWithWidePopup {
|
||||
|
||||
@Nullable
|
||||
private Condition<Sdk> myFilter;
|
||||
|
||||
public JdkComboBox(@NotNull final ProjectSdksModel jdkModel) {
|
||||
super(new JdkComboBoxModel(jdkModel));
|
||||
this(jdkModel, null);
|
||||
}
|
||||
|
||||
public JdkComboBox(@NotNull final ProjectSdksModel jdkModel, @Nullable Condition<Sdk> filter) {
|
||||
super(new JdkComboBoxModel(jdkModel, filter));
|
||||
myFilter = filter;
|
||||
setRenderer(new ProjectJdkListRenderer(getRenderer()) {
|
||||
@Override
|
||||
public void doCustomize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
|
||||
@@ -221,7 +228,10 @@ public class JdkComboBox extends ComboBoxWithWidePopup {
|
||||
model.removeAllElements();
|
||||
model.addElement(firstItem);
|
||||
final ProjectSdksModel projectJdksModel = ProjectStructureConfigurable.getInstance(project).getProjectJdksModel();
|
||||
final ArrayList<Sdk> projectJdks = new ArrayList<Sdk>(projectJdksModel.getProjectSdks().values());
|
||||
List<Sdk> projectJdks = new ArrayList<Sdk>(projectJdksModel.getProjectSdks().values());
|
||||
if (myFilter != null) {
|
||||
projectJdks = ContainerUtil.filter(projectJdks, myFilter);
|
||||
}
|
||||
Collections.sort(projectJdks, new Comparator<Sdk>() {
|
||||
public int compare(final Sdk o1, final Sdk o2) {
|
||||
return o1.getName().compareToIgnoreCase(o2.getName());
|
||||
@@ -233,9 +243,12 @@ public class JdkComboBox extends ComboBoxWithWidePopup {
|
||||
}
|
||||
|
||||
private static class JdkComboBoxModel extends DefaultComboBoxModel {
|
||||
public JdkComboBoxModel(final ProjectSdksModel jdksModel) {
|
||||
super();
|
||||
final Sdk[] jdks = jdksModel.getSdks();
|
||||
public JdkComboBoxModel(final ProjectSdksModel jdksModel, final @Nullable Condition<Sdk> filter) {
|
||||
Sdk[] jdks = jdksModel.getSdks();
|
||||
if (filter != null) {
|
||||
final List<Sdk> filtered = ContainerUtil.filter(jdks, filter);
|
||||
jdks = filtered.toArray(new Sdk[filtered.size()]);
|
||||
}
|
||||
Arrays.sort(jdks, new Comparator<Sdk>() {
|
||||
public int compare(final Sdk s1, final Sdk s2) {
|
||||
return s1.getName().compareToIgnoreCase(s2.getName());
|
||||
|
||||
+3
-3
@@ -78,12 +78,12 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
|
||||
PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting(context.getFile().getViewProvider());
|
||||
}
|
||||
|
||||
insertParentheses(context, delegate, psiClass, !inAnonymous && isAbstract);
|
||||
|
||||
if (item.getDelegate() instanceof JavaPsiClassReferenceElement) {
|
||||
DefaultInsertHandler.addImportForItem(context, delegate);
|
||||
PsiTypeLookupItem.addImportForItem(context, psiClass);
|
||||
}
|
||||
|
||||
insertParentheses(context, delegate, psiClass, !inAnonymous && isAbstract);
|
||||
|
||||
if (inAnonymous) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -22,18 +22,16 @@ import com.intellij.codeInsight.TailTypes;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupItem;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DefaultInsertHandler extends TemplateInsertHandler implements Cloneable {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.DefaultInsertHandler");
|
||||
|
||||
public static final DefaultInsertHandler NO_TAIL_HANDLER = new DefaultInsertHandler(){
|
||||
@Override
|
||||
@@ -54,8 +52,6 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
|
||||
final Document document = editor.getDocument();
|
||||
PsiDocumentManager.getInstance(project).commitDocument(document);
|
||||
|
||||
final PsiFile file = context.getFile();
|
||||
|
||||
TailType tailType = getTailType(completionChar, item);
|
||||
|
||||
InsertHandlerState state = new InsertHandlerState(context.getSelectionEndOffset(), context.getSelectionEndOffset());
|
||||
@@ -73,8 +69,6 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
|
||||
state.caretOffset = processTail(tailType, state.caretOffset, state.tailOffset, editor);
|
||||
editor.getSelectionModel().removeSelection();
|
||||
|
||||
addImportForItem(context, item);
|
||||
|
||||
if (tailType == TailType.DOT || context.getCompletionChar() == '.') {
|
||||
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, null);
|
||||
}
|
||||
@@ -181,49 +175,6 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
|
||||
JavaCompletionUtil.initOffsets(file, file.getProject(), offsetMap);
|
||||
}
|
||||
|
||||
public static void addImportForItem(InsertionContext context, LookupElement item) throws IncorrectOperationException {
|
||||
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
|
||||
|
||||
int startOffset = context.getStartOffset();
|
||||
PsiFile file = context.getFile();
|
||||
Object o = item.getObject();
|
||||
if (o instanceof PsiClass){
|
||||
PsiClass aClass = (PsiClass)o;
|
||||
if (aClass.getQualifiedName() == null) return;
|
||||
final String lookupString = item.getLookupString();
|
||||
int length = lookupString.length();
|
||||
final int i = lookupString.indexOf('<');
|
||||
if (i >= 0) length = i;
|
||||
final int newOffset = addImportForClass(file, startOffset, startOffset + length, aClass);
|
||||
JavaCompletionUtil.shortenReference(file, newOffset);
|
||||
}
|
||||
else if (o instanceof PsiType){
|
||||
PsiType type = ((PsiType)o).getDeepComponentType();
|
||||
if (type instanceof PsiClassType) {
|
||||
PsiClass refClass = ((PsiClassType) type).resolve();
|
||||
if (refClass != null){
|
||||
int length = refClass.getName().length();
|
||||
addImportForClass(file, startOffset, startOffset + length, refClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (o instanceof PsiMethod){
|
||||
PsiMethod method = (PsiMethod)o;
|
||||
if (method.isConstructor()){
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
if (aClass != null){
|
||||
int length = method.getName().length();
|
||||
addImportForClass(file, startOffset, startOffset + length, aClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int addImportForClass(PsiFile file, int startOffset, int endOffset, PsiClass aClass) throws IncorrectOperationException {
|
||||
return JavaCompletionUtil.insertClassReference(aClass, file, startOffset, endOffset);
|
||||
}
|
||||
|
||||
|
||||
public static class InsertHandlerState{
|
||||
int tailOffset;
|
||||
int caretOffset;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Java15CompletionData extends JavaCompletionData {
|
||||
//static keyword in static import
|
||||
{
|
||||
final CompletionVariant variant = new CompletionVariant(PsiImportList.class, new LeftNeighbour(new TextFilter (PsiKeyword.IMPORT)));
|
||||
variant.addCompletion(PsiKeyword.STATIC, TailType.HUMBLE_SPACE);
|
||||
variant.addCompletion(PsiKeyword.STATIC, TailType.HUMBLE_SPACE_BEFORE_WORD);
|
||||
|
||||
registerVariant(variant);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public class Java15CompletionData extends JavaCompletionData {
|
||||
final CompletionVariant variant = new CompletionVariant(PsiJavaFile.class, position);
|
||||
variant.includeScopeClass(PsiClass.class);
|
||||
|
||||
variant.addCompletion(PsiKeyword.INTERFACE, TailType.HUMBLE_SPACE);
|
||||
variant.addCompletion(PsiKeyword.INTERFACE, TailType.HUMBLE_SPACE_BEFORE_WORD);
|
||||
|
||||
registerVariant(variant);
|
||||
}
|
||||
@@ -55,7 +55,7 @@ public class Java15CompletionData extends JavaCompletionData {
|
||||
final CompletionVariant variant = new CompletionVariant(PsiJavaFile.class, CLASS_START);
|
||||
variant.includeScopeClass(PsiClass.class);
|
||||
|
||||
variant.addCompletion(PsiKeyword.ENUM, TailType.HUMBLE_SPACE);
|
||||
variant.addCompletion(PsiKeyword.ENUM, TailType.HUMBLE_SPACE_BEFORE_WORD);
|
||||
registerVariant(variant);
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ public class Java15CompletionData extends JavaCompletionData {
|
||||
final CompletionVariant variant = new CompletionVariant(JavaMemberNameCompletionContributor.INSIDE_TYPE_PARAMS_PATTERN);
|
||||
variant.includeScopeClass(PsiVariable.class, true);
|
||||
variant.includeScopeClass(PsiExpressionStatement.class, true);
|
||||
variant.addCompletion(PsiKeyword.SUPER, TailType.HUMBLE_SPACE);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS, TailType.HUMBLE_SPACE);
|
||||
variant.addCompletion(PsiKeyword.SUPER, TailType.HUMBLE_SPACE_BEFORE_WORD);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS, TailType.HUMBLE_SPACE_BEFORE_WORD);
|
||||
registerVariant(variant);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-13
@@ -19,8 +19,7 @@ import com.intellij.codeInsight.AutoPopupController;
|
||||
import com.intellij.codeInsight.ExpectedTypeInfo;
|
||||
import com.intellij.codeInsight.ExpectedTypesProvider;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.diagnostic.LogMessageEx;
|
||||
import com.intellij.diagnostic.errordialog.Attachment;
|
||||
import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
@@ -90,8 +89,10 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
if (fillTypeArgs) {
|
||||
context.setAddCompletionChar(false);
|
||||
}
|
||||
|
||||
if (shouldInsertParentheses(psiClass, position)) {
|
||||
|
||||
PsiTypeLookupItem.addImportForItem(context, psiClass);
|
||||
|
||||
if (shouldInsertParentheses(psiClass, file.findElementAt(context.getTailOffset() - 1))) {
|
||||
if (ConstructorInsertHandler.insertParentheses(context, item, psiClass, false)) {
|
||||
fillTypeArgs |= psiClass.hasTypeParameters() && PsiUtil.getLanguageLevel(file).isAtLeast(LanguageLevel.JDK_1_5);
|
||||
}
|
||||
@@ -101,15 +102,6 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
|
||||
AutoPopupController.getInstance(project).autoPopupParameterInfo(editor, null);
|
||||
}
|
||||
|
||||
LOG.assertTrue(context.getTailOffset() >= 0);
|
||||
String docText = context.getDocument().getText();
|
||||
DefaultInsertHandler.addImportForItem(context, item);
|
||||
if (context.getTailOffset() < 0) {
|
||||
LOG.error(LogMessageEx.createEvent("Tail offset degraded after insertion", "start=" + context.getStartOffset(),
|
||||
new Attachment(context.getFile().getViewProvider().getVirtualFile().getPath(), docText)));
|
||||
}
|
||||
|
||||
|
||||
if (annotation) {
|
||||
// Check if someone inserts annotation class that require @
|
||||
PsiElement elementAt = file.findElementAt(context.getStartOffset());
|
||||
|
||||
@@ -273,7 +273,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
// completion
|
||||
final CompletionVariant variant = new CompletionVariant(position);
|
||||
variant.includeScopeClass(PsiClass.class, true);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS, TailType.HUMBLE_SPACE);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS, TailType.HUMBLE_SPACE_BEFORE_WORD);
|
||||
variant.excludeScopeClass(PsiAnonymousClass.class);
|
||||
variant.excludeScopeClass(PsiTypeParameter.class);
|
||||
|
||||
@@ -294,7 +294,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
// completion
|
||||
final CompletionVariant variant = new CompletionVariant(position);
|
||||
variant.includeScopeClass(PsiClass.class, true);
|
||||
variant.addCompletion(PsiKeyword.IMPLEMENTS, TailType.HUMBLE_SPACE);
|
||||
variant.addCompletion(PsiKeyword.IMPLEMENTS, TailType.HUMBLE_SPACE_BEFORE_WORD);
|
||||
variant.excludeScopeClass(PsiAnonymousClass.class);
|
||||
|
||||
registerVariant(variant);
|
||||
@@ -306,7 +306,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
psiElement(PsiIdentifier.class).afterLeaf(
|
||||
psiElement().withText(string().oneOf(",", "<")).withParent(PsiTypeParameterList.class))));
|
||||
//variant.includeScopeClass(PsiClass.class, true);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS, TailType.HUMBLE_SPACE);
|
||||
variant.addCompletion(PsiKeyword.EXTENDS, TailType.HUMBLE_SPACE_BEFORE_WORD);
|
||||
registerVariant(variant);
|
||||
}
|
||||
}
|
||||
@@ -414,7 +414,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
return TailType.SEMICOLON;
|
||||
}
|
||||
|
||||
return TailType.HUMBLE_SPACE;
|
||||
return TailType.HUMBLE_SPACE_BEFORE_WORD;
|
||||
}
|
||||
scope = scope.getParent();
|
||||
}
|
||||
@@ -456,7 +456,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
}
|
||||
if (statement != null && statement.getTextRange().getStartOffset() == position.getTextRange().getStartOffset()) {
|
||||
if (!psiElement().withSuperParent(2, PsiSwitchStatement.class).accepts(statement)) {
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE));
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -508,13 +508,13 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
}
|
||||
|
||||
if (INSIDE_PARAMETER_LIST.accepts(position) && !psiElement().afterLeaf(PsiKeyword.FINAL).accepts(position) && !AFTER_DOT.accepts(position)) {
|
||||
result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE));
|
||||
result.addElement(TailTypeDecorator.withTail(createKeyword(position, PsiKeyword.FINAL), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
|
||||
if (CLASS_START.isAcceptable(position, position) &&
|
||||
PsiTreeUtil.getNonStrictParentOfType(position, PsiLiteralExpression.class, PsiComment.class) == null) {
|
||||
for (String s : ModifierChooser.getKeywords(position)) {
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, s), TailType.HUMBLE_SPACE));
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, s), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,11 +589,11 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
isStatementPosition(position)) {
|
||||
for (String primitiveType : PRIMITIVE_TYPES) {
|
||||
LookupElement keyword = createKeyword(position, primitiveType);
|
||||
result.addElement(inCast ? keyword : new OverrideableSpace(keyword, TailType.HUMBLE_SPACE));
|
||||
result.addElement(inCast ? keyword : new OverrideableSpace(keyword, TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
if (declaration) {
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.VOID), TailType.HUMBLE_SPACE));
|
||||
result.addElement(new OverrideableSpace(createKeyword(position, PsiKeyword.VOID), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -606,7 +606,7 @@ public class JavaCompletionData extends JavaAwareCompletionData{
|
||||
if (psiElement().insideSequence(true, psiElement(PsiLabeledStatement.class),
|
||||
or(psiElement(PsiFile.class), psiElement(PsiMethod.class),
|
||||
psiElement(PsiClassInitializer.class))).accepts(position)) {
|
||||
tailType = TailType.HUMBLE_SPACE;
|
||||
tailType = TailType.HUMBLE_SPACE_BEFORE_WORD;
|
||||
}
|
||||
else {
|
||||
tailType = TailType.SEMICOLON;
|
||||
|
||||
@@ -429,7 +429,7 @@ public class JavaCompletionUtil {
|
||||
|
||||
PsiMethodCallExpression call = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
|
||||
boolean checkInitialized = parameters.getInvocationCount() <= 1 && call != null && PsiKeyword.SUPER.equals(call.getMethodExpression().getText());
|
||||
|
||||
|
||||
final JavaCompletionProcessor processor = new JavaCompletionProcessor(element, elementFilter, checkAccess, checkInitialized, filterStaticAfterInstance, nameCondition);
|
||||
javaReference.processVariants(processor);
|
||||
final Collection<CompletionElement> plainResults = processor.getResults();
|
||||
@@ -690,8 +690,8 @@ public class JavaCompletionUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int insertClassReference(@NotNull PsiClass psiClass, @NotNull PsiFile file, int offset) {
|
||||
return insertClassReference(psiClass, file, offset, offset);
|
||||
public static void insertClassReference(@NotNull PsiClass psiClass, @NotNull PsiFile file, int offset) {
|
||||
insertClassReference(psiClass, file, offset, offset);
|
||||
}
|
||||
|
||||
public static int insertClassReference(PsiClass psiClass, PsiFile file, int startOffset, int endOffset) {
|
||||
@@ -707,14 +707,14 @@ public class JavaCompletionUtil {
|
||||
final PsiElement resolved = reference.resolve();
|
||||
if (resolved instanceof PsiClass) {
|
||||
if (((PsiClass)resolved).getQualifiedName() == null || manager.areElementsEquivalent(psiClass, resolved)) {
|
||||
return startOffset;
|
||||
return endOffset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String name = psiClass.getName();
|
||||
if (name == null) {
|
||||
return startOffset;
|
||||
return endOffset;
|
||||
}
|
||||
|
||||
assert document != null;
|
||||
@@ -724,7 +724,7 @@ public class JavaCompletionUtil {
|
||||
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
|
||||
int newStartOffset = startOffset;
|
||||
int newEndOffset = endOffset;
|
||||
PsiElement element = file.findElementAt(startOffset);
|
||||
if (element instanceof PsiIdentifier) {
|
||||
PsiElement parent = element.getParent();
|
||||
@@ -739,7 +739,13 @@ public class JavaCompletionUtil {
|
||||
|
||||
newElement = CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(newElement);
|
||||
if (newElement != null) {
|
||||
newStartOffset = newElement.getTextRange().getStartOffset();
|
||||
newEndOffset = newElement.getTextRange().getEndOffset();
|
||||
if (newElement instanceof PsiJavaCodeReferenceElement) {
|
||||
PsiReferenceParameterList parameterList = ((PsiJavaCodeReferenceElement)newElement).getParameterList();
|
||||
if (parameterList != null) {
|
||||
newEndOffset = parameterList.getTextRange().getStartOffset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!staticImport &&
|
||||
@@ -747,7 +753,7 @@ public class JavaCompletionUtil {
|
||||
!psiClass.getManager().areElementsEquivalent(psiClass, resolveReference((PsiReference)newElement))) {
|
||||
final String qName = psiClass.getQualifiedName();
|
||||
if (qName != null) {
|
||||
document.replaceString(newStartOffset, newElement.getTextRange().getEndOffset(), qName);
|
||||
document.replaceString(newElement.getTextRange().getStartOffset(), newEndOffset, qName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -758,7 +764,7 @@ public class JavaCompletionUtil {
|
||||
document.deleteString(toDelete.getStartOffset(), toDelete.getEndOffset());
|
||||
}
|
||||
|
||||
return newStartOffset;
|
||||
return newEndOffset;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -856,9 +862,7 @@ public class JavaCompletionUtil {
|
||||
//need to shorten references in type argument list
|
||||
public static void shortenReference(final PsiFile file, final int offset) throws IncorrectOperationException {
|
||||
final PsiDocumentManager manager = PsiDocumentManager.getInstance(file.getProject());
|
||||
final Document document = manager.getDocument(file);
|
||||
assert document != null;
|
||||
manager.commitDocument(document);
|
||||
manager.commitDocument(manager.getDocument(file));
|
||||
final PsiReference ref = file.findReferenceAt(offset);
|
||||
if (ref instanceof PsiJavaCodeReferenceElement) {
|
||||
JavaCodeStyleManager.getInstance(file.getProject()).shortenClassReferences((PsiJavaCodeReferenceElement)ref);
|
||||
|
||||
+2
-2
@@ -264,7 +264,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
for (PsiClassType ref : method.getThrowsList().getReferencedTypes()) {
|
||||
final PsiClass exception = ref.resolve();
|
||||
if (exception != null && throwsSet.add(exception)) {
|
||||
result.addElement(TailTypeDecorator.withTail(new JavaPsiClassReferenceElement(exception), TailType.HUMBLE_SPACE));
|
||||
result.addElement(TailTypeDecorator.withTail(new JavaPsiClassReferenceElement(exception), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -282,7 +282,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
|
||||
if (tryBlock == null) return;
|
||||
|
||||
for (final PsiClassType type : ExceptionUtil.getThrownExceptions(tryBlock.getStatements())) {
|
||||
result.addElement(TailTypeDecorator.withTail(PsiTypeLookupItem.createLookupItem(type, tryBlock).setInsertHandler(new DefaultInsertHandler()), TailType.HUMBLE_SPACE));
|
||||
result.addElement(TailTypeDecorator.withTail(PsiTypeLookupItem.createLookupItem(type, tryBlock).setInsertHandler(new DefaultInsertHandler()), TailType.HUMBLE_SPACE_BEFORE_WORD));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -73,14 +73,13 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
public void handleInsert(InsertionContext context) {
|
||||
PsiElement position = context.getFile().findElementAt(context.getStartOffset());
|
||||
assert position != null;
|
||||
if (getObject() instanceof PsiClass) {
|
||||
addImportForItem(context, (PsiClass)getObject());
|
||||
}
|
||||
context.getDocument().insertString(context.getTailOffset(), calcGenerics(position));
|
||||
DefaultInsertHandler.addImportForItem(context, this);
|
||||
PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting();
|
||||
JavaCompletionUtil.shortenReference(context.getFile(), context.getStartOffset());
|
||||
|
||||
int tail = context.getTailOffset();
|
||||
if (tail <= 0) {
|
||||
return;
|
||||
}
|
||||
String braces = StringUtil.repeat("[]", getBracketsCount());
|
||||
Editor editor = context.getEditor();
|
||||
if (!braces.isEmpty()) {
|
||||
@@ -227,4 +226,13 @@ public class PsiTypeLookupItem extends LookupItem {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addImportForItem(InsertionContext context, PsiClass aClass) {
|
||||
if (aClass.getQualifiedName() == null) return;
|
||||
PsiFile file = context.getFile();
|
||||
int newTail = JavaCompletionUtil.insertClassReference(aClass, file, context.getStartOffset(), context.getTailOffset());
|
||||
context.setTailOffset(newTail);
|
||||
PostprocessReformattingAspect.getInstance(context.getProject()).doPostponedFormatting();
|
||||
JavaCompletionUtil.shortenReference(file, context.getStartOffset());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class AAA{}
|
||||
|
||||
class BBB extends AAA implements<caret> {
|
||||
class BBB extends AAA implements <caret> {
|
||||
}
|
||||
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
class Foo {
|
||||
int ELEMENT_A = 1;
|
||||
int ELEMENT_B = 1;
|
||||
int ELEMENT_C = 1;
|
||||
int ELEMENT_D = 1;
|
||||
int ELEMENT_E = 1;
|
||||
int ELEMENT_F = 1;
|
||||
int ELEMENT_G = 1;
|
||||
int ELEMENT_H = 1;
|
||||
int ELEMENT_I = 1;
|
||||
|
||||
|
||||
{
|
||||
El<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -74,7 +74,7 @@ public class JavadocCompletionTest extends LightFixtureCompletionTestCase {
|
||||
|
||||
public void testSee0() throws Exception {
|
||||
configureByFile("See0.java");
|
||||
assertStringItems("foo", "clone", "equals", "finalize", "getClass", "hashCode", "notify", "notifyAll", "Object", "registerNatives", "toString", "wait", "wait", "wait");
|
||||
assertStringItems("foo", "clone", "equals", "getClass", "hashCode", "notify", "notifyAll", "Object", "toString", "wait", "wait", "wait", "finalize", "registerNatives");
|
||||
}
|
||||
|
||||
public void testSee1() throws Exception {
|
||||
|
||||
-10
@@ -233,16 +233,6 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
checkPreferredItems(0, "FooOCSomething", "FooObjectCollector");
|
||||
}
|
||||
|
||||
public void testPreselectMostRelevantInTheMiddle() {
|
||||
myFixture.addClass("package foo; public class Elaaaaaaaaaaaaaaaaaaaa {}");
|
||||
invokeCompletion(getTestName(false) + ".java");
|
||||
myFixture.completeBasic();
|
||||
LookupImpl lookup = getLookup();
|
||||
assertPreferredItems(lookup.getList().getSelectedIndex());
|
||||
assertEquals("Elaaaaaaaaaaaaaaaaaaaa", lookup.getItems().get(0).getLookupString());
|
||||
assertEquals("ELEMENT_A", lookup.getCurrentItem().getLookupString());
|
||||
}
|
||||
|
||||
public void testPreferSamePackageOverImported() {
|
||||
myFixture.addClass("package bar; public class Bar1 {}");
|
||||
myFixture.addClass("package bar; public class Bar2 {}");
|
||||
|
||||
+1
-1
@@ -474,7 +474,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
|
||||
|
||||
public void testVoidExpectedType() throws Throwable {
|
||||
configureByTestName();
|
||||
assertStringItems("notify", "notifyAll", "wait", "wait", "wait", "equals", "getClass", "hashCode", "toString");
|
||||
assertStringItems("notify", "notifyAll", "wait", "wait", "wait", "getClass", "equals", "hashCode", "toString");
|
||||
type('e');
|
||||
assertEquals("equals", assertOneElement(getLookup().getItems()).getLookupString());
|
||||
select();
|
||||
|
||||
Reference in New Issue
Block a user