Author: scabanovich
Date: 2010-11-18 07:23:57 -0500 (Thu, 18 Nov 2010)
New Revision: 26704
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
Log:
JBIDE-7616
https://jira.jboss.org/browse/JBIDE-7616
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2010-11-18
11:41:54 UTC (rev 26703)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamProject.java 2010-11-18
12:23:57 UTC (rev 26704)
@@ -167,11 +167,21 @@
/**
* Adds references to variables that provide short name if
- * seam package including the original variable is imported.
+ * seam package including the original variable is imported by components.xml.
* @return all seam context variables of project
*/
public Set<ISeamContextVariable> getVariables(boolean includeShortNames);
+ /**
+ * Adds references to variables that provide short name if
+ * seam package including the original variable is imported
+ * 1) by components.xml;
+ * 2) by Java type presented by context;
+ * 3) by Java package that contains Java type presented by context.
+ * @return all seam context variables of project
+ */
+ public Set<ISeamContextVariable> getVariables(ISeamJavaComponentDeclaration
context);
+
public void addVariable(ISeamContextVariable v);
public void removeVariable(ISeamContextVariable v);
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java 2010-11-18
11:41:54 UTC (rev 26703)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamJavaComponentDeclaration.java 2010-11-18
12:23:57 UTC (rev 26704)
@@ -71,7 +71,12 @@
String qname = s + "." + name;
Set<ISeamContextVariable> c = getSeamProject().getVariablesByName(qname);
if((c == null || c.isEmpty()) && getSeamProject().getParentProject() != null)
c = getSeamProject().getParentProject().getVariablesByName(qname);
- if(c != null && !c.isEmpty()) result.addAll(c);
+ if(c != null && !c.isEmpty()) {
+ result.addAll(c);
+ for (ISeamContextVariable v: c) {
+ result.add(new SeamContextShortVariable(v));
+ }
+ }
}
if(result.isEmpty()) {
List<SeamImport> is = ((SeamProject)getSeamProject()).getPackageImports(this);
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2010-11-18
11:41:54 UTC (rev 26703)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamProject.java 2010-11-18
12:23:57 UTC (rev 26704)
@@ -45,6 +45,7 @@
import org.jboss.tools.seam.core.IBijectedAttribute;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamComponentDeclaration;
+import org.jboss.tools.seam.core.ISeamContextShortVariable;
import org.jboss.tools.seam.core.ISeamContextVariable;
import org.jboss.tools.seam.core.ISeamFactory;
import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
@@ -1432,7 +1433,35 @@
return variables.getVariablesPlusShort();
}
}
-
+
+ public Set<ISeamContextVariable> getVariables(ISeamJavaComponentDeclaration
context) {
+ Set<ISeamContextVariable> result = getVariables(true);
+ Set<String> imports = new HashSet<String>();
+ if(context != null) {
+ imports = ((SeamJavaComponentDeclaration)context).getImports();
+ List<SeamImport> is = getPackageImports(context);
+ if(is != null) {
+ for (SeamImport i: is) imports.add(i.getSeamPackage());
+ }
+ }
+ if(!imports.isEmpty()) {
+ Set<ISeamContextVariable> vs = result;
+ result = new HashSet<ISeamContextVariable>();
+ result.addAll(vs);
+ for (ISeamContextVariable v: vs) {
+ if(v instanceof ISeamContextShortVariable) continue;
+ for (String q: imports) {
+ if(v.getName().startsWith(q + ".")) {
+ result.add(new SeamContextShortVariable(v));
+ break;
+ }
+ }
+ }
+ }
+
+ return result;
+ }
+
public boolean isImportedPackage(String packageName) {
for (IPath s: imports.importsBySource.keySet()) {
List<SeamImport> list = imports.importsBySource.get(s);
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2010-11-18
11:41:54 UTC (rev 26703)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2010-11-18
12:23:57 UTC (rev 26704)
@@ -123,14 +123,14 @@
ELInvocationExpression left = expr;
- ScopeType scope = getScope(project, file);
+// ScopeType scope = getScope(project, file);
if (expr.getLeft() == null && isIncomplete) {
- resolvedVariables = resolveVariables(project, scope, expr, true, true);
+ resolvedVariables = resolveVariables(project, file, expr, true, true);
} else {
while (left != null) {
List<ISeamContextVariable> resolvedVars = new
ArrayList<ISeamContextVariable>();
- resolvedVars = resolveVariables(project, scope, left,
+ resolvedVars = resolveVariables(project, file, left,
left == expr, true);
if (resolvedVars != null && !resolvedVars.isEmpty()) {
resolvedVariables = resolvedVars;
@@ -150,8 +150,8 @@
@Override
public List<ISeamContextVariable> resolveVariables(IFile file,
ELInvocationExpression expr, boolean isFinal, boolean onlyEqualNames) {
ISeamProject project = SeamCorePlugin.getSeamProject(file.getProject(), true);
- ScopeType scope = getScope(project, file);
- return resolveVariables(project, scope, expr, isFinal, onlyEqualNames);
+// ScopeType scope = getScope(project, file);
+ return resolveVariables(project, file, expr, isFinal, onlyEqualNames);
}
protected TypeInfoCollector.MemberInfo getMemberInfoByVariable(ISeamContextVariable var,
boolean onlyEqualNames) {
@@ -238,7 +238,7 @@
return null;
}
- public List<ISeamContextVariable> resolveVariables(ISeamProject project, ScopeType
scope, ELInvocationExpression expr, boolean isFinal, boolean onlyEqualNames) {
+ public List<ISeamContextVariable> resolveVariables(ISeamProject project, IFile
file, ELInvocationExpression expr, boolean isFinal, boolean onlyEqualNames) {
List<ISeamContextVariable>resolvedVars = new
ArrayList<ISeamContextVariable>();
if (project == null)
@@ -247,7 +247,7 @@
String varName = expr.toString();
if (varName != null) {
- resolvedVars = SeamExpressionResolver.resolveVariables(project, scope, varName,
onlyEqualNames);
+ resolvedVars = SeamExpressionResolver.resolveVariables(project, file, varName,
onlyEqualNames);
}
if (resolvedVars != null && !resolvedVars.isEmpty()) {
List<ISeamContextVariable> newResolvedVars = new
ArrayList<ISeamContextVariable>();
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java 2010-11-18
11:41:54 UTC (rev 26703)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java 2010-11-18
12:23:57 UTC (rev 26704)
@@ -13,9 +13,11 @@
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IMember;
@@ -52,6 +54,7 @@
import org.jboss.tools.seam.core.ScopeType;
import org.jboss.tools.seam.core.SeamComponentMethodType;
import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.internal.core.SeamJavaComponentDeclaration;
/**
* Utility class used to resolve Seam project variables and to get the methods/properties
and their presentation strings from type
@@ -68,19 +71,32 @@
* @param name
* @return
*/
- public static List<ISeamContextVariable> resolveVariables(ISeamProject project,
ScopeType scope, String name, boolean onlyEqualNames) {
+ public static List<ISeamContextVariable> resolveVariables(ISeamProject project,
IFile context, String name, boolean onlyEqualNames) {
if (project == null || name == null) return null;
ISeamProject parent = project.getParentProject();
if(parent != null) {
project = parent;
}
+
+ ISeamJavaComponentDeclaration declaration = null;
+
+ if(context != null) {
+ Set<ISeamComponent> cs = project.getComponentsByPath(context.getFullPath());
+ for (ISeamComponent c: cs) {
+ ISeamJavaComponentDeclaration d = c.getJavaDeclaration();
+ if(d != null && context.getFullPath().equals(d.getSourcePath())) {
+ declaration = d;
+ }
+ }
+
+ }
/*
* JBIDE-670 scope isn't used anymore
*/
// return (scope == null ? internalResolveVariables(project, name, onlyEqualNames) :
// internalResolveVariablesByScope(project, scope, name, onlyEqualNames));
- return internalResolveVariables(project, name, onlyEqualNames);
+ return internalResolveVariables(project, declaration, name, onlyEqualNames);
}
/**
@@ -91,15 +107,21 @@
* @param name
* @return
*/
- private static List<ISeamContextVariable> internalResolveVariables(ISeamProject
project, String name, boolean onlyEqualNames) {
- Set<ISeamContextVariable> variables = project.getVariables(true);
- return internalResolveVariables(project, name, onlyEqualNames, variables);
+ private static List<ISeamContextVariable> internalResolveVariables(ISeamProject
project, ISeamJavaComponentDeclaration context, String name, boolean onlyEqualNames) {
+ //TODO add variables from imported packages
+ Set<ISeamContextVariable> variables = project.getVariables(context);
+ return internalResolveVariables(project, context, name, onlyEqualNames, variables);
}
- private static List<ISeamContextVariable> internalResolveVariables(ISeamProject
project, String name, boolean onlyEqualNames, Set<ISeamContextVariable> variables)
{
+ private static List<ISeamContextVariable> internalResolveVariables(ISeamProject
project, ISeamJavaComponentDeclaration context, String name, boolean onlyEqualNames,
Set<ISeamContextVariable> variables) {
List<ISeamContextVariable> resolvedVariables = new
ArrayList<ISeamContextVariable>();
if(onlyEqualNames) {
- variables = project.getVariablesByName(name);
+ if(context != null) {
+ variables = context.getVariablesByName(name);
+ } else variables = new HashSet<ISeamContextVariable>();
+ if(variables.isEmpty()) {
+ variables = project.getVariablesByName(name);
+ }
if(variables != null) resolvedVariables.addAll(variables);
return resolvedVariables;
}