aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManju Mathew2013-04-08 11:12:50 (EDT)
committerDani Megert2013-04-08 11:12:50 (EDT)
commit4a050305939c6d797c481566c3915e524c770989 (patch)
treef2d7da297766c3e554a11dbf12b55e213540d83f
parent4fe3abfa7bf8bd25e5b545c33710b4c55bcdbc5d (diff)
downloadeclipse.jdt.ui-4a050305939c6d797c481566c3915e524c770989.zip
eclipse.jdt.ui-4a050305939c6d797c481566c3915e524c770989.tar.gz
eclipse.jdt.ui-4a050305939c6d797c481566c3915e524c770989.tar.bz2
Fixed bug 198748: [content assist] Pressing ';' should work with all methodsI20130409-0900I20130409-0800
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java28
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java4
-rw-r--r--org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ParameterGuessingProposal.java12
3 files changed, 35 insertions, 9 deletions
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
index 9c6aeb3..edcd774 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/AbstractJavaCompletionProposal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2012 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -361,14 +361,28 @@ public abstract class AbstractJavaCompletionProposal implements IJavaCompletionP
String replacement;
if (isSmartTrigger || trigger == (char) 0) {
+ int referenceOffset= getReplacementOffset() + getReplacementLength();
replacement= getReplacementString();
+ //add ; to the replacement string if replacement string do not end with a semicolon and the document do not already have a ; at the reference offset.
+ if (trigger == ';' && replacement.charAt(replacement.length() - 1) != ';' && (referenceOffset >= document.getLength() || document.getChar(referenceOffset) != ';')) {
+ replacement= replacement + ";"; //$NON-NLS-1$
+ setReplacementString(replacement);
+ }
} else {
StringBuffer buffer= new StringBuffer(getReplacementString());
// fix for PR #5533. Assumes that no eating takes place.
if ((getCursorPosition() > 0 && getCursorPosition() <= buffer.length() && buffer.charAt(getCursorPosition() - 1) != trigger)) {
- buffer.insert(getCursorPosition(), trigger);
- setCursorPosition(getCursorPosition() + 1);
+ // insert trigger ';' for methods with parameter at the end of the replacement string and not at the cursor position.
+ int length= getReplacementString().length();
+ if (trigger == ';' && getCursorPosition() != length) {
+ if (buffer.charAt(length - 1) != trigger) {
+ buffer.insert(length, trigger);
+ }
+ } else {
+ buffer.insert(getCursorPosition(), trigger);
+ setCursorPosition(getCursorPosition() + 1);
+ }
}
replacement= buffer.toString();
@@ -386,8 +400,12 @@ public abstract class AbstractJavaCompletionProposal implements IJavaCompletionP
setReplacementOffset(referenceOffset - (replacement == null ? 0 : replacement.length()));
// PR 47097
- if (isSmartTrigger)
- handleSmartTrigger(document, trigger, referenceOffset);
+ if (isSmartTrigger) {
+ // avoid inserting redundant semicolon when smart insert is enabled.
+ if (!(trigger == ';' && (replacement.endsWith(";") || document.getChar(referenceOffset) == ';'))) { //$NON-NLS-1$
+ handleSmartTrigger(document, trigger, referenceOffset);
+ }
+ }
} catch (BadLocationException x) {
// ignore
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java
index 6a99476..30a84df 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/JavaMethodCompletionProposal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 IBM Corporation and others.
+ * Copyright (c) 2005, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -38,7 +38,7 @@ public class JavaMethodCompletionProposal extends LazyJavaCompletionProposal {
/** Triggers for method proposals without parameters. Do not modify. */
protected final static char[] METHOD_TRIGGERS= new char[] { ';', ',', '.', '\t', '[' };
/** Triggers for method proposals. Do not modify. */
- protected final static char[] METHOD_WITH_ARGUMENTS_TRIGGERS= new char[] { '(', '-', ' ' };
+ protected final static char[] METHOD_WITH_ARGUMENTS_TRIGGERS= new char[] { ';', '(', '-', ' ' };
/** Triggers for method name proposals (static imports). Do not modify. */
protected final static char[] METHOD_NAME_TRIGGERS= new char[] { ';' };
diff --git a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ParameterGuessingProposal.java b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ParameterGuessingProposal.java
index 5b71a26..6d5966d 100644
--- a/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ParameterGuessingProposal.java
+++ b/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/text/java/ParameterGuessingProposal.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -153,7 +153,9 @@ public class ParameterGuessingProposal extends JavaMethodCompletionProposal {
LinkedModeUI ui= new EditorLinkedModeUI(model, getTextViewer());
ui.setExitPosition(getTextViewer(), baseOffset + replacement.length(), 0, Integer.MAX_VALUE);
- ui.setExitPolicy(new ExitPolicy(')', document) {
+ // exit character can be either ')' or ';'
+ final char exitChar= replacement.charAt(replacement.length() - 1);
+ ui.setExitPolicy(new ExitPolicy(exitChar, document) {
@Override
public ExitFlags doExit(LinkedModeModel model2, VerifyEvent event, int offset2, int length) {
if (event.character == ',') {
@@ -165,6 +167,12 @@ public class ParameterGuessingProposal extends JavaMethodCompletionProposal {
return null;
}
}
+ } else if (event.character == ')' && exitChar != ')') {
+ // exit from link mode when user is in the last ')' position.
+ Position position= fPositions[fPositions.length - 1];
+ if (position.offset <= offset2 && offset2 + length <= position.offset + position.length) {
+ return new ExitFlags(ILinkedModeListener.UPDATE_CARET, false);
+ }
}
return super.doExit(model2, event, offset2, length);
}