aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzzhongwei2012-08-19 09:11:35 (EDT)
committerzzhongwei2012-08-19 09:11:35 (EDT)
commitee85aa3af9009c1e18f7912cc32982a0cd2dc69e (patch)
treef7fe60f0149bce21d56a82217b08daf27ffc8419
parent20ad5b1ceac66b16e219be0dae76d21f0c781b63 (diff)
downloadorg.eclipse.pdt-ee85aa3af9009c1e18f7912cc32982a0cd2dc69e.zip
org.eclipse.pdt-ee85aa3af9009c1e18f7912cc32982a0cd2dc69e.tar.gz
org.eclipse.pdt-ee85aa3af9009c1e18f7912cc32982a0cd2dc69e.tar.bz2
387554: Content Assist should be able to show variables from include,
include_once, require and require_once expressions https://bugs.eclipse.org/bugs/show_bug.cgi?id=387554
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/PHPCoreConstants.java1
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/GlobalVariablesStrategy.java54
-rw-r--r--plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/preferences/CorePreferenceConstants.java3
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.java2
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.properties1
-rw-r--r--plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PHPContentAssistOptionsConfigurationBlock.java17
6 files changed, 70 insertions, 8 deletions
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/PHPCoreConstants.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/PHPCoreConstants.java
index 9eb1416..ba1147b 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/PHPCoreConstants.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/PHPCoreConstants.java
@@ -200,6 +200,7 @@ public interface PHPCoreConstants {
* </p>
*/
public final static String CODEASSIST_SHOW_VARIABLES_FROM_OTHER_FILES = "contentAssistShowVariablesFromOtherFiles"; //$NON-NLS-1$
+ public final static String CODEASSIST_SHOW_VARIABLES_FROM_REFERENCED_FILES = "contentAssistShowVariablesFromReferencedFiles"; //$NON-NLS-1$
/**
* PHP Task Marker
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/GlobalVariablesStrategy.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/GlobalVariablesStrategy.java
index 2e6ee49..0a4639d 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/GlobalVariablesStrategy.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/codeassist/strategies/GlobalVariablesStrategy.java
@@ -11,13 +11,15 @@
*******************************************************************************/
package org.eclipse.php.internal.core.codeassist.strategies;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eclipse.core.runtime.Platform;
import org.eclipse.dltk.ast.Modifiers;
-import org.eclipse.dltk.core.CompletionRequestor;
-import org.eclipse.dltk.core.IField;
-import org.eclipse.dltk.core.IModelElement;
-import org.eclipse.dltk.core.ISourceModule;
+import org.eclipse.dltk.core.*;
import org.eclipse.dltk.core.index2.search.ISearchEngine.MatchRule;
+import org.eclipse.dltk.core.search.BasicSearchEngine;
import org.eclipse.dltk.core.search.IDLTKSearchScope;
import org.eclipse.dltk.core.search.SearchEngine;
import org.eclipse.dltk.internal.core.ModelElement;
@@ -30,6 +32,9 @@ import org.eclipse.php.internal.core.PHPCorePlugin;
import org.eclipse.php.internal.core.PHPVersion;
import org.eclipse.php.internal.core.codeassist.ICompletionReporter;
import org.eclipse.php.internal.core.codeassist.contexts.AbstractCompletionContext;
+import org.eclipse.php.internal.core.filenetwork.FileNetworkUtility;
+import org.eclipse.php.internal.core.filenetwork.ReferenceTree;
+import org.eclipse.php.internal.core.filenetwork.ReferenceTree.Node;
import org.eclipse.php.internal.core.language.PHPVariables;
import org.eclipse.php.internal.core.model.PhpModelAccess;
import org.eclipse.php.internal.core.typeinference.FakeField;
@@ -77,10 +82,15 @@ public class GlobalVariablesStrategy extends GlobalElementStrategy {
}
IField[] fields;
- if (showVarsFromOtherFiles()) {
+ if (showVarsFromOtherFiles(PHPCoreConstants.CODEASSIST_SHOW_VARIABLES_FROM_OTHER_FILES)) {
IDLTKSearchScope scope = createSearchScope();
fields = PhpModelAccess.getDefault().findFields(prefix, matchRule,
Modifiers.AccGlobal, Modifiers.AccConstant, scope, null);
+ } else if (showVarsFromOtherFiles(PHPCoreConstants.CODEASSIST_SHOW_VARIABLES_FROM_REFERENCED_FILES)) {
+ IDLTKSearchScope scope = createSearchScopeWithReferencedFiles(abstractContext
+ .getSourceModule());
+ fields = PhpModelAccess.getDefault().findFields(prefix, matchRule,
+ Modifiers.AccGlobal, Modifiers.AccConstant, scope, null);
} else {
fields = PHPModelUtils.getFileFields(
abstractContext.getSourceModule(), prefix, false, null);
@@ -107,10 +117,38 @@ public class GlobalVariablesStrategy extends GlobalElementStrategy {
}
}
- protected boolean showVarsFromOtherFiles() {
+ private IDLTKSearchScope createSearchScopeWithReferencedFiles(
+ ISourceModule sourceModule) {
+ ReferenceTree tree = FileNetworkUtility.buildReferencedFilesTree(
+ sourceModule, null);
+ if (tree != null && tree.getRoot() != null) {
+ Collection<Node> allIncludedNodes = tree.getRoot().getChildren();
+ if (allIncludedNodes != null) {
+ Set<ISourceModule> list = new HashSet<ISourceModule>();
+ list.add(sourceModule);
+ getNodeChildren(tree.getRoot(), list);
+ return BasicSearchEngine.createSearchScope(
+ list.toArray(new ISourceModule[list.size()]),
+ DLTKLanguageManager.getLanguageToolkit(sourceModule));
+ }
+ }
+ return super.createSearchScope();
+ }
+
+ private void getNodeChildren(Node root, Set<ISourceModule> list) {
+ if (root.getChildren() == null) {
+ return;
+ }
+ for (Node includedNode : root.getChildren()) {
+ ISourceModule sm = includedNode.getFile();
+ list.add(sm);
+ getNodeChildren(includedNode, list);
+ }
+ }
+
+ protected boolean showVarsFromOtherFiles(String id) {
return Platform.getPreferencesService().getBoolean(PHPCorePlugin.ID,
- PHPCoreConstants.CODEASSIST_SHOW_VARIABLES_FROM_OTHER_FILES,
- true, null);
+ id, true, null);
}
@Override
diff --git a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/preferences/CorePreferenceConstants.java b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/preferences/CorePreferenceConstants.java
index 0bbdf28..e58bb72 100644
--- a/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/preferences/CorePreferenceConstants.java
+++ b/plugins/org.eclipse.php.core/src/org/eclipse/php/internal/core/preferences/CorePreferenceConstants.java
@@ -67,6 +67,9 @@ public class CorePreferenceConstants {
PHPCoreConstants.CODEASSIST_SHOW_VARIABLES_FROM_OTHER_FILES,
false);
node.putBoolean(
+ PHPCoreConstants.CODEASSIST_SHOW_VARIABLES_FROM_REFERENCED_FILES,
+ false);
+ node.putBoolean(
PHPCoreConstants.CODEASSIST_INSERT_FULL_QUALIFIED_NAME_FOR_NAMESPACE,
true);
node.putBoolean(PHPCoreConstants.CODEASSIST_SHOW_STRICT_OPTIONS, false);
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.java
index a06cf36..c1d54f1 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.java
@@ -974,6 +974,8 @@ public final class PHPUIMessages extends NLS {
public static String OpenAction_declaration_label;
public static String CodeTemplateBlock_templates_edit_button;
+ public static String CodeAssistPreferencePage_showVariablesFromReferencedFiles;
+
static {
NLS.initializeMessages(BUNDLE_NAME, PHPUIMessages.class);
}
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.properties b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.properties
index 65591c1..3c39390 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.properties
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/PHPUIMessages.properties
@@ -310,6 +310,7 @@ CodeAssistPreferencePage_insertSignleProposals=Insert single proposals automatic
CodeAssistPreferencePage_optionsSectionLabel=Options
CodeAssistPreferencePage_showStrictOptions=Show strict options
CodeAssistPreferencePage_showVariablesFromOtherFiles=Show variables from other files
+CodeAssistPreferencePage_showVariablesFromReferencedFiles=Show variables from referenced files
CodeAssistPreferencePage_insertFullyQualifiedNameForNamespace=Insert full qualified name for use statement
CodeAssistPreferencePage_fillParameterNamesOnMethodCompletion=I&nsert parameter names
CoreUtility_buildall_taskname=Build all...
diff --git a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PHPContentAssistOptionsConfigurationBlock.java b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PHPContentAssistOptionsConfigurationBlock.java
index 8c85ac8..b8c71f2 100644
--- a/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PHPContentAssistOptionsConfigurationBlock.java
+++ b/plugins/org.eclipse.php.ui/src/org/eclipse/php/internal/ui/preferences/PHPContentAssistOptionsConfigurationBlock.java
@@ -17,6 +17,8 @@ import org.eclipse.php.internal.core.PHPCoreConstants;
import org.eclipse.php.internal.core.PHPCorePlugin;
import org.eclipse.php.internal.ui.PHPUIMessages;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
@@ -34,6 +36,7 @@ public class PHPContentAssistOptionsConfigurationBlock extends
protected Button completionOverrideRadioButton;
protected Button insertSingleproposalsCheckBox;
protected Button showVariableFromOtherFilesCheckBox;
+ protected Button showVariableFromReferencedFilesCheckBox;
protected Button insertFullyQualifiedNameForNamespaceCheckBox;
protected Button fInsertParameterNamesRadioButton;
@@ -73,6 +76,20 @@ public class PHPContentAssistOptionsConfigurationBlock extends
composite,
PHPUIMessages.CodeAssistPreferencePage_showVariablesFromOtherFiles,
PHPCoreConstants.CODEASSIST_SHOW_VARIABLES_FROM_OTHER_FILES, 0);
+ showVariableFromOtherFilesCheckBox
+ .addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ showVariableFromReferencedFilesCheckBox
+ .setEnabled(!showVariableFromOtherFilesCheckBox
+ .getSelection());
+ }
+ });
+
+ showVariableFromReferencedFilesCheckBox = addCheckBox(
+ composite,
+ PHPUIMessages.CodeAssistPreferencePage_showVariablesFromReferencedFiles,
+ PHPCoreConstants.CODEASSIST_SHOW_VARIABLES_FROM_REFERENCED_FILES,
+ 0);
insertFullyQualifiedNameForNamespaceCheckBox = addCheckBox(
composite,