aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-12-12 03:21:35 (EST)
committerzzhongwei2012-12-12 03:21:35 (EST)
commitbf38791d4eb8d6d67ed1573e60b7aafad27acbec (patch)
treee95f905ce7ebd11f41df726de5a7d8a8b6aca508
parenta522077620bc5112dc396f1b3d6951c19a1a9893 (diff)
downloadorg.eclipse.pdt-bf38791d4eb8d6d67ed1573e60b7aafad27acbec.zip
org.eclipse.pdt-bf38791d4eb8d6d67ed1573e60b7aafad27acbec.tar.gz
org.eclipse.pdt-bf38791d4eb8d6d67ed1573e60b7aafad27acbec.tar.bz2
396373: CA: add "\" to global classes for throw new statement
https://bugs.eclipse.org/bugs/show_bug.cgi?id=396373
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposalCollector.java2
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/ParameterGuessingProposal.java46
-rw-r--r--tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/extend.pdtt20
-rw-r--r--tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/instanceof1.pdtt16
-rw-r--r--tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/thrownew.pdtt14
5 files changed, 94 insertions, 4 deletions
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposalCollector.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposalCollector.java
index cc47af6..d653842 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposalCollector.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/PHPCompletionProposalCollector.java
@@ -202,7 +202,7 @@ public class PHPCompletionProposalCollector extends
int start, int length, String label, String string, Object extraInfo) {
return new ParameterGuessingProposal(proposal, scriptProject,
sourceModule, name, paramTypes, start, length, label, string,
- false, extraInfo);
+ false, extraInfo, document);
}
protected IScriptCompletionProposal createTypeProposal(
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/ParameterGuessingProposal.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/ParameterGuessingProposal.java
index cd8525a..075e5b6 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/ParameterGuessingProposal.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/editor/contentassist/ParameterGuessingProposal.java
@@ -23,11 +23,16 @@ import org.eclipse.jface.text.*;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.link.*;
+import org.eclipse.php.core.compiler.PHPFlags;
import org.eclipse.php.internal.core.PHPCoreConstants;
import org.eclipse.php.internal.core.PHPCorePlugin;
+import org.eclipse.php.internal.core.PHPVersion;
import org.eclipse.php.internal.core.codeassist.AliasType;
import org.eclipse.php.internal.core.codeassist.ProposalExtraInfo;
+import org.eclipse.php.internal.core.compiler.ast.nodes.NamespaceReference;
+import org.eclipse.php.internal.core.project.ProjectOptions;
import org.eclipse.php.internal.core.typeinference.FakeConstructor;
+import org.eclipse.php.internal.core.typeinference.PHPModelUtils;
import org.eclipse.php.internal.ui.PHPUiPlugin;
import org.eclipse.php.internal.ui.text.template.contentassist.PositionBasedCompletionProposal;
import org.eclipse.swt.graphics.Point;
@@ -56,17 +61,22 @@ public final class ParameterGuessingProposal extends
private Object extraInfo;
private boolean fReplacementLengthComputed;
private String alias = null;
+ private IDocument document = null;
+ private IScriptProject sProject = null;
public ParameterGuessingProposal(CompletionProposal proposal,
IScriptProject jproject, ISourceModule cu, String methodName,
String[] paramTypes, int start, int length, String displayName,
- String completionProposal, boolean fillBestGuess, Object extraInfo) {
+ String completionProposal, boolean fillBestGuess, Object extraInfo,
+ IDocument document) {
super(jproject, cu, methodName, paramTypes, start, length, displayName,
completionProposal);
this.fProposal = proposal;
method = (IMethod) fProposal.getModelElement();
this.fFillBestGuess = fillBestGuess;
this.extraInfo = extraInfo;
+ this.document = document;
+ this.sProject = jproject;
}
/**
@@ -243,8 +253,35 @@ public final class ParameterGuessingProposal extends
}
public String getReplacementString() {
+ String prefix = "";
+ try {
+ if (method.isConstructor()) {
+ IType type = method.getDeclaringType();
+ try {
+ int flags = type.getFlags();
+ IType currentNamespace = PHPModelUtils.getCurrentNamespace(
+ fSourceModule, getReplacementOffset());
+ IType namespace = PHPModelUtils.getCurrentNamespace(type);
+ if (!PHPFlags.isNamespace(flags)
+ && namespace == null
+ && currentNamespace != null
+ && !ProjectOptions.getPhpVersion(
+ sProject.getProject()).isLessThan(
+ PHPVersion.PHP5_3)
+ && document.getChar(getReplacementOffset() - 1) != NamespaceReference.NAMESPACE_SEPARATOR) {
+ prefix = prefix
+ + NamespaceReference.NAMESPACE_SEPARATOR;
+ }
+ } catch (ModelException e) {
+ PHPUiPlugin.log(e);
+ } catch (BadLocationException e) {
+ PHPUiPlugin.log(e);
+ }
+ }
+ } catch (ModelException e) {
+ }
if (ProposalExtraInfo.isMethodOnly(extraInfo)) {
- setReplacementString(method.getElementName());
+ setReplacementString(prefix + method.getElementName());
return super.getReplacementString();
}
boolean fileArgumentNames = Platform.getPreferencesService()
@@ -252,7 +289,10 @@ public final class ParameterGuessingProposal extends
PHPCoreConstants.CODEASSIST_FILL_ARGUMENT_NAMES, true,
null);
if (fileArgumentNames && !fReplacementStringComputed)
- setReplacementString(computeReplacementString());
+ setReplacementString(prefix + computeReplacementString());
+ if (!fileArgumentNames)
+ setReplacementString(prefix + super.getReplacementString());
+
return super.getReplacementString();
}
diff --git a/tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/extend.pdtt b/tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/extend.pdtt
new file mode 100644
index 0000000..7baf217
--- /dev/null
+++ b/tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/extend.pdtt
@@ -0,0 +1,20 @@
+--TEST--
+Test instance of class
+--PREFERENCES--
+org.eclipse.php.core/contentAssistInsertCompletion=true
+--FILE--
+<?php
+namespace test;
+class Testddd extends Exception|{
+ public static function run( ){
+ }
+}
+?>
+--EXPECT--
+<?php
+namespace test;
+class Testddd extends \Exception{
+ public static function run( ){
+ }
+}
+?>
diff --git a/tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/instanceof1.pdtt b/tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/instanceof1.pdtt
new file mode 100644
index 0000000..09e8b9e
--- /dev/null
+++ b/tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/instanceof1.pdtt
@@ -0,0 +1,16 @@
+--TEST--
+Test instance of class
+--PREFERENCES--
+org.eclipse.php.core/contentAssistInsertCompletion=true
+--FILE--
+<?php
+namespace test;
+if ($a instanceof Exception|) {
+}
+?>
+--EXPECT--
+<?php
+namespace test;
+if ($a instanceof \Exception) {
+}
+?>
diff --git a/tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/thrownew.pdtt b/tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/thrownew.pdtt
new file mode 100644
index 0000000..967815f
--- /dev/null
+++ b/tests/org.eclipse.php.ui.tests/workspace/codeassist/php53/thrownew.pdtt
@@ -0,0 +1,14 @@
+--TEST--
+Test instance of class
+--PREFERENCES--
+org.eclipse.php.core/contentAssistInsertCompletion=true
+--FILE--
+<?php
+namespace test;
+throw new Exception|
+?>
+--EXPECT--
+<?php
+namespace test;
+throw new \Exception()
+?>