JBoss Tools SVN: r10603 - in trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui: search and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-10-01 11:35:28 -0400 (Wed, 01 Oct 2008)
New Revision: 10603
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/SeamFindQuickAssistProcessor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java
Log:
JBIDE-1497.
Refactoring
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/SeamFindQuickAssistProcessor.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/SeamFindQuickAssistProcessor.java 2008-10-01 15:34:53 UTC (rev 10602)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/SeamFindQuickAssistProcessor.java 2008-10-01 15:35:28 UTC (rev 10603)
@@ -89,7 +89,8 @@
private String[] getVariableNames(ISeamProject seamProject, IDocument document, int offset,
int start, int end) {
- ELInvocationExpression tokens = SeamELCompletionEngine.findExpressionAtOffset(
+ SeamELCompletionEngine engine = new SeamELCompletionEngine(seamProject);
+ ELInvocationExpression tokens = engine.findExpressionAtOffset(
document, offset, start, end);
if (tokens == null)
@@ -116,8 +117,10 @@
ISeamProject seamProject = getSeamProject(context);
if (seamProject == null)
return result;
+
+ SeamELCompletionEngine engine = new SeamELCompletionEngine(seamProject);
- ELInvocationExpression tokens = SeamELCompletionEngine.findExpressionAtOffset(
+ ELInvocationExpression tokens = engine.findExpressionAtOffset(
document,
context.getSelectionOffset(),
0, //TODO compute region start
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java 2008-10-01 15:34:53 UTC (rev 10602)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java 2008-10-01 15:35:28 UTC (rev 10603)
@@ -37,12 +37,12 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.search.core.text.TextSearchEngine;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.seam.core.ISeamContextVariable;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.internal.core.el.ElVarSearcher;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
-import org.jboss.tools.seam.internal.core.el.Var;
import org.jboss.tools.seam.ui.SeamGuiPlugin;
import org.jboss.tools.seam.ui.SeamUIMessages;
@@ -90,14 +90,13 @@
return Status.OK_STATUS;
}
- SeamELCompletionEngine engine = new SeamELCompletionEngine();
-
IProject project = (sourceFile == null ? null : sourceFile.getProject());
ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
if (seamProject == null)
return Status.OK_STATUS;
+ SeamELCompletionEngine engine = new SeamELCompletionEngine(seamProject);
//Find Seam variable names
@@ -126,7 +125,7 @@
}
// Try to find a local Var (a pair of variable-value attributes)
- ElVarSearcher varSearcher = new ElVarSearcher(seamProject, sourceFile, new SeamELCompletionEngine());
+ ElVarSearcher varSearcher = new ElVarSearcher(sourceFile, engine);
// Find a Var in the EL
int start = tokens.getStartPosition();
int end = tokens.getEndPosition();
@@ -137,11 +136,11 @@
if (elText == null || elText.length() == 0)
return Status.OK_STATUS;
- List<Var> allVars= ElVarSearcher.findAllVars(sourceFile, tokens.getStartPosition());
+ List<Var> allVars= varSearcher.findAllVars(sourceFile, tokens.getStartPosition());
Var var = varSearcher.findVarForEl(elText.toString(), allVars, true);
if (var == null) {
// Find a Var in the current offset assuming that it's a node with var/value attribute pair
- var = ElVarSearcher.findVar(sourceFile, tokens.getStartPosition());
+ var = varSearcher.findVar(sourceFile, tokens.getStartPosition());
}
if (var == null)
return Status.OK_STATUS;
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java 2008-10-01 15:34:53 UTC (rev 10602)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java 2008-10-01 15:35:28 UTC (rev 10603)
@@ -263,14 +263,14 @@
private IStatus queryByTokens(AbstractTextSearchResult textResult,
final IProgressMonitor monitor) {
- SeamELCompletionEngine engine = new SeamELCompletionEngine();
-
IProject project = (fSourceFile == null ? null : fSourceFile.getProject());
ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
if (seamProject == null)
return Status.OK_STATUS;
+ SeamELCompletionEngine engine = new SeamELCompletionEngine(seamProject);
+
// List<IJavaElement> elements = engine.getJavaElementsForELOperandTokens(seamProject, fSourceFile, fTokens)
SeamSearchResultCollector collector= new SeamSearchResultCollector(textResult, getParentRequestor());
return SeamSearchEngine.getInstance().search(fScope, collector, fSourceFile, fTokens, monitor);
@@ -279,14 +279,14 @@
private IStatus queryByJavaElements(
AbstractTextSearchResult textResult,
final IProgressMonitor monitor) {
- SeamELCompletionEngine engine = new SeamELCompletionEngine();
-
IProject project = (fSourceFile == null ? null : fSourceFile.getProject());
ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
if (seamProject == null)
return Status.OK_STATUS;
+ SeamELCompletionEngine engine = new SeamELCompletionEngine(seamProject);
+
SeamSearchResultCollector collector= new SeamSearchResultCollector(textResult, getParentRequestor());
return SeamSearchEngine.getInstance().search(fScope, collector, fSourceFile, fJavaElements, monitor);
}
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java 2008-10-01 15:34:53 UTC (rev 10602)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java 2008-10-01 15:35:28 UTC (rev 10603)
@@ -97,6 +97,9 @@
import org.jboss.tools.common.el.core.model.ELModel;
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserFactory;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.common.model.util.EclipseJavaUtil;
import org.jboss.tools.seam.core.BijectedAttributeType;
import org.jboss.tools.seam.core.IBijectedAttribute;
@@ -113,9 +116,7 @@
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.internal.core.AbstractSeamDeclaration;
import org.jboss.tools.seam.internal.core.SeamComponent;
-import org.jboss.tools.seam.internal.core.el.ElVarSearcher;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
-import org.jboss.tools.seam.internal.core.el.Var;
import org.jboss.tools.seam.internal.core.scanner.ScannerException;
import org.jboss.tools.seam.internal.core.scanner.java.AnnotatedASTNode;
import org.jboss.tools.seam.internal.core.scanner.java.ResolvedAnnotation;
@@ -151,7 +152,6 @@
private IFile fCurrentFile;
private final FileCharSequenceProvider fFileCharSequenceProvider;
- private final SeamELCompletionEngine fCompletionEngine;
interface ISeamMatcher {
String getName();
@@ -327,7 +327,6 @@
}
fFileCharSequenceProvider= new FileCharSequenceProvider();
fMatchAccess= new ReusableMatchAccess();
- fCompletionEngine = new SeamELCompletionEngine();
}
/**
@@ -351,7 +350,6 @@
}
fFileCharSequenceProvider= new FileCharSequenceProvider();
fMatchAccess= new ReusableMatchAccess();
- fCompletionEngine = new SeamELCompletionEngine();
}
/**
@@ -375,7 +373,6 @@
}
fFileCharSequenceProvider= new FileCharSequenceProvider();
fMatchAccess= new ReusableMatchAccess();
- fCompletionEngine = new SeamELCompletionEngine();
}
@@ -478,8 +475,9 @@
}
}
-
- fELVarSearcher = new ElVarSearcher(project, fCompletionEngine);
+
+ SeamELCompletionEngine fCompletionEngine = new SeamELCompletionEngine(project);
+ fELVarSearcher = new ElVarSearcher(fCompletionEngine);
fDocumentsInEditors= evalNonFileBufferDocuments();
boolean res= true;
for (int i = 0; files != null && i < files.length; i++) {
@@ -597,7 +595,7 @@
private void locateMatchesInChildNodes(IFile file, Node parent, CharSequence content)
throws CoreException {
- Var var = ElVarSearcher.findVar(parent);
+ Var var = fELVarSearcher.findVar(parent);
if(var!=null) {
fVarListForCurentValidatedNode.add(var);
}
@@ -696,7 +694,7 @@
private void locateMatchesInString(IFile file, String string, int offset, CharSequence content) throws CoreException {
int startEl = string.indexOf("#{"); //$NON-NLS-1$
if(startEl>-1) {
- ELParser parser = ELParserFactory.createJbossParser();
+ ELParser parser = ELParserUtil.getJbossFactory().createParser();
ELModel model = parser.parse(string);
List<ELInstance> is = model.getInstances();
for (ELInstance i: is) {
@@ -718,6 +716,7 @@
ELInvocationExpression expr = token;
while(expr != null) {
List<IJavaElement> elements = null;
+ SeamELCompletionEngine fCompletionEngine = new SeamELCompletionEngine(fCurrentSeamProject);
try {
elements = fCompletionEngine.getJavaElementsForELOperandTokens(fCurrentSeamProject, file, expr);
} catch (StringIndexOutOfBoundsException e) {
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java 2008-10-01 15:34:53 UTC (rev 10602)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java 2008-10-01 15:35:28 UTC (rev 10603)
@@ -54,14 +54,14 @@
import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
import org.eclipse.wst.xml.ui.internal.contentassist.AbstractContentAssistProcessor;
import org.eclipse.wst.xml.ui.internal.util.SharedXMLEditorPluginImageHelper;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.common.model.ui.texteditors.xmleditor.XMLTextEditor;
import org.jboss.tools.common.text.ext.IEditorWrapper;
import org.jboss.tools.common.text.ext.util.Utils;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.internal.core.el.ElVarSearcher;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
-import org.jboss.tools.seam.internal.core.el.Var;
import org.jboss.tools.seam.ui.SeamGuiPlugin;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -263,8 +263,6 @@
}
- private final SeamELCompletionEngine fEngine= new SeamELCompletionEngine();
-
/**
* Creates a new Seam EL completion proposal computer.
*/
@@ -350,7 +348,9 @@
//TODO Now this will work only for EL.
// If we need CA for expressions/variables without #{}, it should be handled separately.
- String prefix= SeamELCompletionEngine.getPrefix(viewer, offset, start, end);
+
+ SeamELCompletionEngine engine = new SeamELCompletionEngine(seamProject);
+ String prefix= engine.getPrefix(viewer, offset, start, end);
prefix = (prefix == null ? "" : prefix); //$NON-NLS-1$
String proposalPrefix = "";
@@ -388,11 +388,13 @@
proposalSufix = "}";
}
- List<Var> vars = ElVarSearcher.findAllVars(viewer, offset);
+ ElVarSearcher varSearcher = new ElVarSearcher(engine);
+ List<Var> vars = varSearcher.findAllVars(viewer, offset);
//TODO
- List<String> suggestions = fEngine.getCompletions(seamProject, file, document, prefix, offset + proposalPrefix.length() - prefix.length(), false, vars, start, end);
+ SeamELCompletionEngine fEngine= new SeamELCompletionEngine(seamProject);
+ List<String> suggestions = fEngine.getCompletions(file, document, prefix, offset + proposalPrefix.length() - prefix.length(), false, vars, start, end);
List<String> uniqueSuggestions = fEngine.makeUnique(suggestions);
List<ICompletionProposal> result= new ArrayList<ICompletionProposal>();
15 years, 7 months
JBoss Tools SVN: r10602 - trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-10-01 11:34:53 -0400 (Wed, 01 Oct 2008)
New Revision: 10602
Modified:
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java
trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java
Log:
JBIDE-1497.
Refactoring
Modified: trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java 2008-10-01 15:34:23 UTC (rev 10601)
+++ trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamBeanHyperlinkPartitioner.java 2008-10-01 15:34:53 UTC (rev 10602)
@@ -21,6 +21,8 @@
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
import org.jboss.tools.common.el.core.model.ELExpression;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.common.text.ext.hyperlink.AbstractHyperlinkPartitioner;
import org.jboss.tools.common.text.ext.hyperlink.HyperlinkRegion;
import org.jboss.tools.common.text.ext.hyperlink.IHyperLinkPartitionPriority;
@@ -31,9 +33,7 @@
import org.jboss.tools.common.text.ext.util.Utils;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.jboss.tools.seam.internal.core.el.ElVarSearcher;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
-import org.jboss.tools.seam.internal.core.el.Var;
import org.jboss.tools.seam.text.ext.SeamExtPlugin;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
@@ -202,8 +202,10 @@
start = ((IDOMNode)n).getStartOffset();
end = ((IDOMNode)n).getEndOffset();
}
-
- ELInvocationExpression tokens = SeamELCompletionEngine.findExpressionAtOffset(document, offset, start, end);
+
+ //TODO do we have and need seam project here?
+ SeamELCompletionEngine engine = new SeamELCompletionEngine(null);
+ ELInvocationExpression tokens = engine.findExpressionAtOffset(document, offset, start, end);
if (tokens == null /*|| tokens.size() == 0*/)
return null; // No EL Operand found
@@ -260,13 +262,14 @@
if (seamProject == null)
return null;
- SeamELCompletionEngine engine= new SeamELCompletionEngine();
+ SeamELCompletionEngine engine = new SeamELCompletionEngine(seamProject);
String prefix = propText;
- ELExpression expr = SeamELCompletionEngine.parseOperand(prefix);
+ ELExpression expr = engine.parseOperand(prefix);
if (expr == null)
return null; // No EL Operand found
-
+ expr.getModel().shift(r.getOffset() - expr.getFirstToken().getStart());
+
List<IJavaElement> javaElements = null;
try {
javaElements = engine.getJavaElementsForELOperandTokens(seamProject, file, (ELInvocationExpression)expr);
@@ -278,9 +281,10 @@
return null;
}
+ //Do not need it, vars handled in getJavaElementsForELOperandTokens
if (javaElements == null || javaElements.size() == 0) {
// Try to find a local Var (a pair of variable-value attributes)
- ElVarSearcher varSearcher = new ElVarSearcher(seamProject, file, new SeamELCompletionEngine());
+ ElVarSearcher varSearcher = new ElVarSearcher(file, engine);
// Find a Var in the EL
int start = expr.getStartPosition();
int end = expr.getEndPosition();
@@ -288,11 +292,11 @@
if (expr.getText().length() == 0)
return null;
- List<Var> allVars= ElVarSearcher.findAllVars(file, start);
+ List<Var> allVars= varSearcher.findAllVars(file, start);
Var var = varSearcher.findVarForEl(expr.getText(), allVars, true);
if (var == null) {
// Find a Var in the current offset assuming that it's a node with var/value attribute pair
- var = ElVarSearcher.findVar(file, start);
+ var = varSearcher.findVar(file, start);
}
if (var == null)
return null;
Modified: trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java 2008-10-01 15:34:23 UTC (rev 10601)
+++ trunk/seam/plugins/org.jboss.tools.seam.text.ext/src/org/jboss/tools/seam/text/ext/hyperlink/SeamELInJavaStringHyperlinkDetector.java 2008-10-01 15:34:53 UTC (rev 10602)
@@ -101,7 +101,7 @@
if (seamProject == null)
return null;
- SeamELCompletionEngine engine= new SeamELCompletionEngine();
+ SeamELCompletionEngine engine = new SeamELCompletionEngine(seamProject);
String prefix= engine.getJavaElementExpression(document, region.getOffset(), region, start, end);
prefix = (prefix == null ? "" : prefix);
15 years, 7 months
JBoss Tools SVN: r10601 - trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-10-01 11:34:23 -0400 (Wed, 01 Oct 2008)
New Revision: 10601
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandResolveStatus.java
Log:
JBIDE-1497.
Refactoring
Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandResolveStatus.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandResolveStatus.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandResolveStatus.java 2008-10-01 15:34:23 UTC (rev 10601)
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.el;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+import org.jboss.tools.common.el.core.resolver.ELOperandResolveStatus;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+
+public class SeamELOperandResolveStatus extends ELOperandResolveStatus {
+ public List<ISeamContextVariable> usedVariables;
+
+ public SeamELOperandResolveStatus(ELInvocationExpression tokens) {
+ super(tokens);
+ }
+
+ /**
+ * @return List of Seam Context Variables used in EL.
+ */
+ public List<ISeamContextVariable> getUsedVariables() {
+ return (usedVariables == null ? new ArrayList<ISeamContextVariable>() : usedVariables);
+ }
+
+ /**
+ * @param usedVariables List of Seam Context Variables used in EL.
+ */
+ public void setUsedVariables(List<ISeamContextVariable> usedVariables) {
+ this.usedVariables = usedVariables;
+ }
+}
15 years, 7 months
JBoss Tools SVN: r10599 - in trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam: internal/core/el and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-10-01 11:34:00 -0400 (Wed, 01 Oct 2008)
New Revision: 10599
Removed:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandResolveStatus.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/Var.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.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
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidatorManager.java
Log:
JBIDE-1497.
Refactoring
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.java 2008-10-01 15:33:13 UTC (rev 10598)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamCoreBuilder.java 2008-10-01 15:34:00 UTC (rev 10599)
@@ -21,7 +21,7 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osgi.util.NLS;
-import org.jboss.tools.common.model.util.TypeInfoCollector;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
import org.jboss.tools.seam.internal.core.SeamProject;
import org.jboss.tools.seam.internal.core.SeamResourceVisitor;
import org.jboss.tools.seam.internal.core.scanner.IFileScanner;
Deleted: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.java 2008-10-01 15:33:13 UTC (rev 10598)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.java 2008-10-01 15:34:00 UTC (rev 10599)
@@ -1,287 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.el;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
-import org.jboss.tools.common.el.core.model.ELExpression;
-import org.jboss.tools.seam.core.ISeamProject;
-import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- * This class helps to find var/value attributes in DOM tree.
- * @author Alexey Kazakov
- */
-public class ElVarSearcher {
-
- private final static String VAR_ATTRIBUTE_NAME = "var";
- private final static String VALUE_ATTRIBUTE_NAME = "value";
-
- private ISeamProject project;
- private IFile file;
- private SeamELCompletionEngine engine;
-
- /**
- * Constructor.
- * @param project Seam project where we will look for vars.
- * @param file File where we will look for vars.
- * @param engine Competion Engine that we will use for resolving vars.
- */
- public ElVarSearcher(ISeamProject project, IFile file, SeamELCompletionEngine engine) {
- this.project = project;
- this.file = file;
- this.engine = engine;
- }
-
- /**
- * Constructor.
- * @param project Seam project where we will look for vars.
- * @param engine Competion Engine that we will use for resolving vars.
- */
- public ElVarSearcher(ISeamProject project, SeamELCompletionEngine engine) {
- this(project, null, engine);
- }
-
- /**
- * @param file File where we will look for vars.
- */
- public void setFile(IFile file) {
- this.file = file;
- }
-
- /**
- * @param viewer
- * @param offset
- * @return
- */
- public static Node getNode(ITextViewer viewer, int offset) {
- IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, offset);
- if(treeNode instanceof Node) {
- return (Node)treeNode;
- }
- return null;
- }
-
- /**
- * @param viewer
- * @param offset
- * @return
- */
-
- public static Node getNode(IFile file, int offset) {
- IndexedRegion treeNode = getNodeAt(file, offset);
- if(treeNode instanceof Node) {
- return (Node)treeNode;
- }
- return null;
- }
-
- /**
- * Returns the closest IndexedRegion for the offset and viewer allowing
- * for differences between viewer offsets and model positions. note: this
- * method returns an IndexedRegion for read only
- *
- * @param file
- * the file whose document is used to compute the proposals
- * @param documentOffset
- * an offset within the document for which completions should
- * be computed
- * @return an IndexedRegion
- */
-
- public static IndexedRegion getNodeAt(IFile file, int documentOffset) {
-
- if (file == null)
- return null;
-
- IndexedRegion node = null;
- IModelManager mm = StructuredModelManager.getModelManager();
- IStructuredModel model = null;
- if (mm != null) {
- try {
- model = mm.getModelForRead(file);
- } catch (IOException e) {
- return null;
- } catch (CoreException e) {
- return null;
- }
- }
- try {
- if (model != null) {
- int lastOffset = documentOffset;
- node = model.getIndexedRegion(documentOffset);
- while (node == null && lastOffset >= 0) {
- lastOffset--;
- node = model.getIndexedRegion(lastOffset);
- }
- }
- } finally {
- if (model != null)
- model.releaseFromRead();
- }
- return node;
- }
-
- /**
- * @param node
- * @return All var/value that can be used in this position and null if can't find anyone.
- */
- public static List<Var> findAllVars(ITextViewer viewer, int offset) {
- Node node = getNode(viewer, offset);
- if(node!=null) {
- return findAllVars(node);
- }
- return null;
- }
-
- /**
- * @param node
- * @return All var/value that can be used in this position and null if can't find anyone.
- */
- public static List<Var> findAllVars(IFile file, int offset) {
- Node node = getNode(file, offset);
- if(node!=null) {
- return findAllVars(node);
- }
- return null;
- }
-
- /**
- * @param node
- * @return All var/value that can be used in node and null if can't find anyone.
- */
- public static List<Var> findAllVars(Node node) {
- ArrayList<Var> vars = null;
- Node parentNode = node.getParentNode();
- while(parentNode!=null) {
- Var var = findVar(parentNode);
- if(var!=null) {
- if(vars == null) {
- vars = new ArrayList<Var>();
- }
- vars.add(0, var);
- }
- parentNode = parentNode.getParentNode();
- }
- return vars;
- }
-
- /**
- * @param node
- * @return found var/value that can be used in this position and null if can't find anyone.
- */
- public static Var findVar(IFile file, int offset) {
- Node node = getNode(file, offset);
- if(node!=null) {
- return findVar(node);
- }
- return null;
- }
-
- /**
- * Finds var/value attribute in node
- * @param node
- * @param vars
- * @return found var/value or null
- */
- public static Var findVar(Node node) {
- if(node!=null && Node.ELEMENT_NODE == node.getNodeType()) {
- Element element = (Element)node;
- String var = element.getAttribute(VAR_ATTRIBUTE_NAME);
- if(var!=null) {
- int declOffset = 0;
- int declLength = 0;
- Node varAttr = element.getAttributeNode(VAR_ATTRIBUTE_NAME);
- if (varAttr instanceof IDOMAttr) {
- int varNameStart = ((IDOMAttr)varAttr).getNameRegionStartOffset();
- int varNameEnd = ((IDOMAttr)varAttr).getNameRegionEndOffset();
- declOffset = varNameStart;
- declLength = varNameEnd - varNameStart;
- }
- var = var.trim();
- if(!"".equals(var)) {
- String value = element.getAttribute(VALUE_ATTRIBUTE_NAME);
- if(value!=null) {
- value = value.trim();
- Var newVar = new Var(var, value, declOffset, declLength);
- if(newVar.getElToken()!=null) {
- return newVar;
- }
- }
- }
- }
- }
-
- return null;
- }
-
- /**
- * Finds var in list of vars that is used in given EL.
- * @param el EL without brackets.
- * @param vars
- * @param initializeNestedVars
- * @return
- */
- public Var findVarForEl(String el, List<Var> vars, boolean initializeNestedVars) {
- if(vars!=null) {
- ArrayList<Var> parentVars = new ArrayList<Var>();
- for (Var var : vars) {
- ELExpression token = var.getElToken();
- if(token!=null && !token.getText().endsWith(".")) {
- String varName = var.getName();
- if(el.startsWith(varName)) { //TODO it was el.equals(varName) and did not work. Why?
- if(var.getElToken()!=null && initializeNestedVars) {
- Var parentVar = findVarForEl(var.getElToken().getText(), parentVars, true);
- if(parentVar!=null) {
- ELExpression resolvedToken = parentVar.getResolvedElToken();
- if(resolvedToken==null && parentVar.getElToken()!=null) {
- try {
- // Initialize parent vars.
- engine.resolveSeamELOperand(project, file, var.getElToken(), true, parentVars, this);
- resolvedToken = parentVar.getResolvedElToken();
- } catch (StringIndexOutOfBoundsException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- } catch (BadLocationException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- }
- }
- if(resolvedToken!=null) {
- String oldText = var.getElToken().getText();
- String newValue = "#{" + resolvedToken.getText() + oldText.substring(parentVar.getName().length()) + "}";
- var.value = newValue;
- var.elToken = var.parseEl(newValue);
- }
- }
- }
- return var;
- }
- }
- parentVars.add(var);
- }
- }
- return null;
- }
-
-}
\ No newline at end of file
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 2008-10-01 15:33:13 UTC (rev 10598)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2008-10-01 15:34:00 UTC (rev 10599)
@@ -38,8 +38,13 @@
import org.jboss.tools.common.el.core.model.ELUtil;
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserFactory;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
import org.jboss.tools.common.el.core.parser.LexicalToken;
-import org.jboss.tools.common.model.util.TypeInfoCollector;
+import org.jboss.tools.common.el.core.resolver.ELCompletionEngine;
+import org.jboss.tools.common.el.core.resolver.ELOperandResolveStatus;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
+import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.seam.core.ISeamComponent;
import org.jboss.tools.seam.core.ISeamContextVariable;
import org.jboss.tools.seam.core.ISeamProject;
@@ -52,14 +57,21 @@
*
* @author Jeremy
*/
-public final class SeamELCompletionEngine {
+public final class SeamELCompletionEngine implements ELCompletionEngine {
+ ISeamProject project;
+ ELParserFactory factory = ELParserUtil.getJbossFactory();
/**
* Constructs SeamELCompletionEngine object
*/
- public SeamELCompletionEngine() {
+ public SeamELCompletionEngine(ISeamProject project) {
+ this.project = project;
}
+ public ELParserFactory getParserFactory() {
+ return factory;
+ }
+
/**
* Create the array of suggestions.
*
@@ -74,9 +86,9 @@
* @return the list of all possible suggestions
* @throws BadLocationException if accessing the current document fails
*/
- public List<String> getCompletions(ISeamProject project, IFile file, IDocument document, CharSequence prefix,
+ public List<String> getCompletions(IFile file, IDocument document, CharSequence prefix,
int position, List<Var> vars, int start, int end) throws BadLocationException, StringIndexOutOfBoundsException {
- return getCompletions(project, file, document, prefix, position, false, vars, start, end);
+ return getCompletions(file, document, prefix, position, false, vars, start, end);
}
/**
@@ -103,13 +115,13 @@
* @throws BadLocationException if accessing the current document fails
* @throws StringIndexOutOfBoundsException
*/
- public List<String> getCompletions(ISeamProject project, IFile file, IDocument document, CharSequence prefix,
+ public List<String> getCompletions(IFile file, IDocument document, CharSequence prefix,
int position, boolean returnEqualedVariablesOnly, List<Var> vars, int start, int end) throws BadLocationException, StringIndexOutOfBoundsException {
List<String> completions = new ArrayList<String>();
String prefix2 = getPrefix(document, position + prefix.length(), start, end);
- SeamELOperandResolveStatus status = resolveSeamELOperand(project, file, parseOperand(prefix2), returnEqualedVariablesOnly, vars, new ElVarSearcher(project, file, this));
+ ELOperandResolveStatus status = resolveELOperand(file, parseOperand(prefix2), returnEqualedVariablesOnly, vars, new ElVarSearcher(file, this));
if (status.isOK()) {
completions.addAll(status.getProposals());
}
@@ -131,7 +143,7 @@
return proposals;
}
- public SeamELOperandResolveStatus resolveSeamELOperand(ISeamProject project, IFile file, ELExpression operand,
+ public SeamELOperandResolveStatus resolveELOperand(IFile file, ELExpression operand,
boolean returnEqualedVariablesOnly, List<Var> vars, ElVarSearcher varSearcher) throws BadLocationException, StringIndexOutOfBoundsException {
if(operand == null) {
//TODO
@@ -142,7 +154,7 @@
String suffix = "";
String newEl = oldEl;
if(var!=null) {
- TypeInfoCollector.MemberInfo member = resolveSeamEL(project, file, var.getElToken());
+ TypeInfoCollector.MemberInfo member = resolveSeamEL(file, var.getElToken());
if(member!=null && !member.getType().isArray()) {
IType type = member.getMemberType();
if(type!=null) {
@@ -164,7 +176,7 @@
boolean prefixWasChanged = newEl != oldEl;
ELExpression newOperand = (prefixWasChanged) ? parseOperand(newEl) : operand;
- SeamELOperandResolveStatus status = resolveSeamELOperand(project, file, newOperand, returnEqualedVariablesOnly);
+ SeamELOperandResolveStatus status = resolveELOperand(file, newOperand, returnEqualedVariablesOnly);
if(prefixWasChanged) {
ELInvocationExpression newLastResolvedToken = status.getLastResolvedToken();
@@ -199,10 +211,10 @@
return status;
}
- public static ELExpression parseOperand(String operand) {
+ public ELExpression parseOperand(String operand) {
if(operand == null) return null;
String el = (operand.indexOf("#{") < 0) ? "#{" + operand + "}" : operand;
- ELParser p = ELParserFactory.createJbossParser();
+ ELParser p = factory.createParser();
ELModel model = p.parse(el);
List<ELInstance> is = model.getInstances();
if(is.size() == 0) return null;
@@ -218,10 +230,9 @@
* @throws BadLocationException
* @throws StringIndexOutOfBoundsException
*/
- public TypeInfoCollector.MemberInfo resolveSeamEL(ISeamProject project, IFile file, ELExpression operand) throws BadLocationException, StringIndexOutOfBoundsException {
+ public TypeInfoCollector.MemberInfo resolveSeamEL(IFile file, ELExpression operand) throws BadLocationException, StringIndexOutOfBoundsException {
if(!(operand instanceof ELInvocationExpression)) return null;
- SeamELOperandResolveStatus status = resolveSeamELOperand(project, file, operand, true);
-
+ ELOperandResolveStatus status = resolveELOperand(file, operand, true);
return status.getMemberOfResolvedOperand();
}
@@ -240,7 +251,7 @@
if(!el.startsWith("#{")) {
el = "#{" + el + "}";
}
- ELParser parser = ELParserFactory.createJbossParser();
+ ELParser parser = factory.createParser();
ELModel model = parser.parse(el);
List<ELInstance> is = model.getInstances();
if(is.size() < 1) return resolvedVariables;
@@ -253,17 +264,17 @@
boolean isIncomplete = expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION
&& ((ELPropertyInvocation) expr).getName() == null;
- SeamELOperandResolveStatus status = new SeamELOperandResolveStatus(expr);
+ ELOperandResolveStatus status = new ELOperandResolveStatus(expr);
ELInvocationExpression left = expr;
ScopeType scope = getScope(project, file);
if (expr.getLeft() == null && isIncomplete) {
- resolvedVariables = resolveVariables(project, scope, expr, true, true);
+ resolvedVariables = resolveVariables(scope, expr, true, true);
} else {
while (left != null) {
List<ISeamContextVariable> resolvedVars = new ArrayList<ISeamContextVariable>();
- resolvedVars = resolveVariables(project, scope, left,
+ resolvedVars = resolveVariables(scope, left,
left == expr, true);
if (resolvedVars != null && !resolvedVars.isEmpty()) {
resolvedVariables = resolvedVars;
@@ -281,7 +292,7 @@
return resolvedVariables;
}
- public SeamELOperandResolveStatus resolveSeamELOperand(ISeamProject project, IFile file, ELExpression operand,
+ public SeamELOperandResolveStatus resolveELOperand(IFile file, ELExpression operand,
boolean returnEqualedVariablesOnly) throws BadLocationException, StringIndexOutOfBoundsException {
if(!(operand instanceof ELInvocationExpression)) {
return new SeamELOperandResolveStatus(null);
@@ -298,13 +309,12 @@
ScopeType scope = getScope(project, file);
if (expr.getLeft() == null && isIncomplete) {
- resolvedVariables = resolveVariables(project, scope,
- expr, true,
+ resolvedVariables = resolveVariables(scope, expr, true,
returnEqualedVariablesOnly);
} else {
while(left != null) {
List<ISeamContextVariable>resolvedVars = new ArrayList<ISeamContextVariable>();
- resolvedVars = resolveVariables(project, scope,
+ resolvedVars = resolveVariables(scope,
left, left == expr,
returnEqualedVariablesOnly);
if (resolvedVars != null && !resolvedVars.isEmpty()) {
@@ -327,7 +337,7 @@
isIncomplete) {
// no vars are resolved
// the tokens are the part of var name ended with a separator (.)
- resolvedVariables = resolveVariables(project, scope, expr, true, returnEqualedVariablesOnly);
+ resolvedVariables = resolveVariables(scope, expr, true, returnEqualedVariablesOnly);
Set<String> proposals = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
for (ISeamContextVariable var : resolvedVariables) {
String varName = var.getName();
@@ -383,7 +393,7 @@
private List<TypeInfoCollector.MemberInfo> resolveSegment(ELInvocationExpression expr,
List<TypeInfoCollector.MemberInfo> members,
- SeamELOperandResolveStatus status,
+ ELOperandResolveStatus status,
boolean returnEqualedVariablesOnly) {
LexicalToken lt = (expr instanceof ELPropertyInvocation)
? ((ELPropertyInvocation)expr).getName()
@@ -444,11 +454,10 @@
private void resolveLastSegment(ELInvocationExpression expr,
List<TypeInfoCollector.MemberInfo> members,
- SeamELOperandResolveStatus status,
+ ELOperandResolveStatus status,
boolean returnEqualedVariablesOnly) {
Set<String> proposals = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
if (expr.getType() == ELObjectType.EL_PROPERTY_INVOCATION && ((ELPropertyInvocation)expr).getName() == null) {
-// if (token.getType() == ELOperandToken.EL_SEPARATOR_TOKEN) {
// return all the methods + properties
for (TypeInfoCollector.MemberInfo mbr : members) {
if (mbr instanceof MessagesInfo) {
@@ -506,15 +515,8 @@
}
for (TypeInfoCollector.MemberPresentation proposal : proposalsToFilter) {
// We do expect nothing but name for method tokens (No round brackets)
- LexicalToken lt = (expr instanceof ELPropertyInvocation)
- ? ((ELPropertyInvocation)expr).getName()
- : (expr instanceof ELMethodInvocation)
- ? ((ELMethodInvocation)expr).getName()
- : null;
- String filter = lt != null ? lt.getText() : ""; //token.getText();
-// if (filter.indexOf('(') != -1) {
-// filter = filter.substring(0, filter.indexOf('('));
-// }
+ String filter = expr.getMemberName();
+ if(filter == null) filter = "";
if(returnEqualedVariablesOnly) {
// This is used for validation.
if (proposal.getPresentation().equals(filter)) {
@@ -596,34 +598,8 @@
return null;
}
-/**
- private List<ISeamContextVariable> resolveVariables(ISeamProject project, ScopeType scope, List<ELOperandToken>part, List<ELOperandToken> tokens, boolean onlyEqualNames) {
+ private List<ISeamContextVariable> resolveVariables(ScopeType scope, ELInvocationExpression expr, boolean isFinal, boolean onlyEqualNames) {
List<ISeamContextVariable>resolvedVars = new ArrayList<ISeamContextVariable>();
- String varName = computeVariableName(part);
- if (varName != null) {
- resolvedVars = SeamExpressionResolver.resolveVariables(project, scope, varName, onlyEqualNames);
- }
- if (resolvedVars != null && resolvedVars.size() > 0) {
- List<ISeamContextVariable> newResolvedVars = new ArrayList<ISeamContextVariable>();
- for (ISeamContextVariable var : resolvedVars) {
- if(!areEqualExpressions(part, tokens)) {
- // Do filter by equals (name)
- // In case of the last pass - do not filter by startsWith(name) instead of equals
- if (varName.equals(var.getName())) {
- newResolvedVars.add(var);
- }
- } else {
- newResolvedVars.add(var);
- }
- }
- return newResolvedVars;
- }
- return new ArrayList<ISeamContextVariable>();
- }
-*/
-
- private List<ISeamContextVariable> resolveVariables(ISeamProject project, ScopeType scope, ELInvocationExpression expr, boolean isFinal, boolean onlyEqualNames) {
- List<ISeamContextVariable>resolvedVars = new ArrayList<ISeamContextVariable>();
String varName = expr.toString();
if (varName != null) {
resolvedVars = SeamExpressionResolver.resolveVariables(project, scope, varName, onlyEqualNames);
@@ -646,23 +622,6 @@
return new ArrayList<ISeamContextVariable>();
}
-/**
- public static List<List<ELOperandToken>> getPossibleVarsFromPrefix(List<ELOperandToken>prefix) {
- ArrayList<List<ELOperandToken>> result = new ArrayList<List<ELOperandToken>>();
- for (int i = 0; prefix != null && i < prefix.size(); i++) {
- ELOperandToken lastToken = prefix.get(i);
- if (lastToken.getType() != ELOperandToken.EL_SEPARATOR_TOKEN) {
- ArrayList<ELOperandToken> prefixPart = new ArrayList<ELOperandToken>();
- for (int j = 0; j <= i; j++) {
- prefixPart.add(prefix.get(j));
- }
- result.add(0, prefixPart);
- }
- }
- return result;
- }
-*/
-
/**
* Removes duplicates of completion strings
*
@@ -697,7 +656,7 @@
* @return
* @throws BadLocationException
*/
- public static String getPrefix(ITextViewer viewer, int offset, int start, int end) throws StringIndexOutOfBoundsException {
+ public String getPrefix(ITextViewer viewer, int offset, int start, int end) throws StringIndexOutOfBoundsException {
IDocument doc= viewer.getDocument();
if (doc == null || offset > doc.getLength())
return null;
@@ -714,7 +673,7 @@
* @return
* @throws StringIndexOutOfBoundsException
*/
- public static String getPrefix(IDocument document, int offset, int start, int end) throws StringIndexOutOfBoundsException {
+ public String getPrefix(IDocument document, int offset, int start, int end) throws StringIndexOutOfBoundsException {
if (document == null || document.get() == null || offset > document.get().length())
return null;
ELInvocationExpression expr = findExpressionAtOffset(document, offset, start, end);
@@ -773,154 +732,6 @@
return getJavaElementsForELOperandTokens(project, file, (ELInvocationExpression)expr);
}
-/**
- public List<IJavaElement> getJavaElementsForELOperandTokens(
- ISeamProject project, IFile file,
- List<ELOperandToken> tokens) throws BadLocationException, StringIndexOutOfBoundsException {
- List<IJavaElement> res= new ArrayList<IJavaElement>();
- if (tokens == null || tokens.size() == 0 || tokens.get(tokens.size() - 1).getType() == ELOperandToken.EL_SEPARATOR_TOKEN)
- return res;
-
- List<ELOperandToken> resolvedExpressionPart = new ArrayList<ELOperandToken>();
- List<ISeamContextVariable> resolvedVariables = new ArrayList<ISeamContextVariable>();
- ScopeType scope = getScope(project, file);
- List<List<ELOperandToken>> variations = getPossibleVarsFromPrefix(tokens);
-
- if (variations.isEmpty()) {
- resolvedVariables = resolveVariables(project, scope, tokens, tokens, true);
- } else {
- for (List<ELOperandToken> variation : variations) {
- List<ISeamContextVariable>resolvedVars = new ArrayList<ISeamContextVariable>();
- resolvedVars = resolveVariables(project, scope, variation, tokens, true);
- if (resolvedVars != null && !resolvedVars.isEmpty()) {
- resolvedVariables = resolvedVars;
- resolvedExpressionPart = variation;
- break;
- }
- }
- }
-
- // Here we have a list of vars for some part of expression
- // OK. we'll proceed with members of these vars
- if (areEqualExpressions(resolvedExpressionPart, tokens)) {
- // First segment is the last one
- for (ISeamContextVariable var : resolvedVariables) {
- IMember member = SeamExpressionResolver.getMemberByVariable(var, true);
- if (member instanceof IJavaElement){
- res.add((IJavaElement)member);
- }
- }
- return res;
- }
-
- // First segment is found - proceed with next tokens
- int startTokenIndex = (resolvedExpressionPart == null ? 0 : resolvedExpressionPart.size());
- List<TypeInfoCollector.MemberInfo> members = new ArrayList<TypeInfoCollector.MemberInfo>();
- for (ISeamContextVariable var : resolvedVariables) {
- TypeInfoCollector.MemberInfo member = SeamExpressionResolver.getMemberInfoByVariable(var, true);
- if (member != null && !members.contains(member))
- members.add(member);
- }
- for (int i = startTokenIndex;
- tokens != null && i < tokens.size() &&
- members != null && members.size() > 0;
- i++) {
- ELOperandToken token = tokens.get(i);
-
- if (i < tokens.size() - 1) { // inside expression
- if (token.getType() == ELOperandToken.EL_SEPARATOR_TOKEN)
- // proceed with next token
- continue;
-
- if (token.isNameToken()) {
- // Find properties for the token
- String name = token.getText();
- List<TypeInfoCollector.MemberInfo> newMembers = new ArrayList<TypeInfoCollector.MemberInfo>();
- for (TypeInfoCollector.MemberInfo mbr : members) {
- TypeInfoCollector infos = mbr.getTypeCollector();
- List<TypeInfoCollector.MemberInfo> properties = infos.getProperties();
- for (TypeInfoCollector.MemberInfo property : properties) {
- StringBuffer propertyName = new StringBuffer(property.getName());
- if (property instanceof TypeInfoCollector.MethodInfo) { // Setter or getter
- propertyName.delete(0, 3);
- propertyName.setCharAt(0, Character.toLowerCase(propertyName.charAt(0)));
- }
- if (name.equals(propertyName.toString())) {
- newMembers.add(property);
- }
- }
- }
- members = newMembers;
- }
- if (token.getType() == ELOperandToken.EL_METHOD_TOKEN) {
- // Find methods for the token
- String name = token.getText();
- if (name.indexOf('(') != -1) {
- name = name.substring(0, name.indexOf('('));
- }
- List<TypeInfoCollector.MemberInfo> newMembers = new ArrayList<TypeInfoCollector.MemberInfo>();
- for (TypeInfoCollector.MemberInfo mbr : members) {
- TypeInfoCollector infos = mbr.getTypeCollector();
- List<TypeInfoCollector.MemberInfo> methods = infos.getMethods();
- for (TypeInfoCollector.MemberInfo method : methods) {
- if (method instanceof TypeInfoCollector.MethodInfo
- && name.equals(method.getName())) {
- newMembers.add(method);
- }
- }
- }
- members = newMembers;
- }
- } else { // Last segment
- List<IJavaElement> javaElements = new ArrayList<IJavaElement>();
- if (token.getType() == ELOperandToken.EL_VARIABLE_NAME_TOKEN ||
- token.getType() == ELOperandToken.EL_PROPERTY_NAME_TOKEN ||
- token.getType() == ELOperandToken.EL_METHOD_TOKEN) {
- // return filtered methods + properties
- List<TypeInfoCollector.MemberInfo> javaElementInfosToFilter = new ArrayList<TypeInfoCollector.MemberInfo>();
- for (TypeInfoCollector.MemberInfo mbr : members) {
- TypeInfoCollector infos = mbr.getTypeCollector();
- javaElementInfosToFilter.addAll(infos.getMethods());
- javaElementInfosToFilter.addAll(infos.getProperties());
- }
-
- for (TypeInfoCollector.MemberInfo info : javaElementInfosToFilter) {
- // We do expect nothing but name for method tokens (No round brackets)
- String filter = token.getText();
- if (token.getType() == ELOperandToken.EL_METHOD_TOKEN) {
- if (filter.indexOf('(') >=0)
- filter = filter.substring(0, filter.indexOf('('));
- }
- // This is used for validation.
- if (info.getName().equals(filter)) {
- javaElements.add(info.getJavaElement());
- } else {
- if (info instanceof TypeInfoCollector.MethodInfo) {
- TypeInfoCollector.MethodInfo methodInfo = (TypeInfoCollector.MethodInfo)info;
- if(methodInfo.isGetter() || methodInfo.isSetter()) {
- StringBuffer name = new StringBuffer(methodInfo.getName());
- if(methodInfo.getName().startsWith("i")) { //$NON-NLS-1$
- name.delete(0, 2);
- } else {
- name.delete(0, 3);
- }
- name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
- String propertyName = name.toString();
- if (propertyName.equals(filter)) {
- javaElements.add(methodInfo.getJavaElement());
- }
- }
- }
- }
- }
- }
- res.addAll(javaElements);
- }
- }
- return res;
- }
-*/
-
/**
* Create the array of suggestions.
* @param project Seam project
@@ -945,17 +756,50 @@
while(left != null) {
List<ISeamContextVariable>resolvedVars = new ArrayList<ISeamContextVariable>();
- resolvedVars = resolveVariables(project, scope,
- left, left == expr,
- true);
+ resolvedVars = resolveVariables(scope, left, left == expr, true);
if (resolvedVars != null && !resolvedVars.isEmpty()) {
resolvedVariables = resolvedVars;
break;
}
- int y = 0;
left = (ELInvocationExpression)left.getLeft();
}
+ if(resolvedVariables.size() == 0) {
+
+ ElVarSearcher varSearcher = new ElVarSearcher(this);
+ List<Var> vars = varSearcher.findAllVars(file, expr.getStartPosition());
+ String oldEl = expr.getText();
+ Var var = varSearcher.findVarForEl(oldEl, vars, true);
+ String suffix = "";
+ String newEl = oldEl;
+ if(var!=null) {
+ TypeInfoCollector.MemberInfo member = resolveSeamEL(file, var.getElToken());
+ if(member!=null && !member.getType().isArray()) {
+ IType type = member.getMemberType();
+ if(type!=null) {
+ try {
+ if(TypeInfoCollector.isInstanceofType(type, "java.util.Map")) {
+ suffix = collectionAdditionForMapDataModel;
+ } else {
+ suffix = collectionAdditionForCollectionDataModel;
+ }
+ } catch (JavaModelException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ }
+ }
+ if(var.getElToken() != null) {
+ newEl = var.getElToken().getText() + suffix + oldEl.substring(var.getName().length());
+ ELExpression newOperand = parseOperand(newEl);
+ if(newOperand instanceof ELInvocationExpression) {
+ return getJavaElementsForELOperandTokens(project, file, (ELInvocationExpression)newOperand);
+ }
+ }
+ }
+
+
+ }
+ int i = 2;
// Here we have a list of vars for some part of expression
// OK. we'll proceed with members of these vars
if (left == expr) {
@@ -1054,12 +898,8 @@
for (TypeInfoCollector.MemberInfo info : javaElementInfosToFilter) {
// We do expect nothing but name for method tokens (No round brackets)
- LexicalToken lt = (expr instanceof ELPropertyInvocation)
- ? ((ELPropertyInvocation)expr).getName()
- : (expr instanceof ELMethodInvocation)
- ? ((ELMethodInvocation)expr).getName()
- : null;
- String filter = lt != null ? lt.getText() : ""; //token.getText();
+ String filter = expr.getMemberName();
+ if(filter == null) filter = "";
// This is used for validation.
if (info.getName().equals(filter)) {
@@ -1095,7 +935,7 @@
* @param end end of relevant region in document
* @return
*/
- public static ELInvocationExpression findExpressionAtOffset(IDocument document, int offset, int start, int end) {
+ public ELInvocationExpression findExpressionAtOffset(IDocument document, int offset, int start, int end) {
String content = document.get();
//TODO this naive calculations should be removed;
@@ -1103,7 +943,7 @@
if(start <= 0) start = guessStart(content, offset);
if(end >= content.length()) end = guessEnd(content, offset);
- ELParser parser = ELParserFactory.createJbossParser();
+ ELParser parser = factory.createParser();
ELModel model = parser.parse(content, start, end - start);
return ELUtil.findExpression(model, offset);
@@ -1133,54 +973,4 @@
return content.length();
}
-/**
- public static List<ELOperandToken> findTokensAtOffset(IDocument document, int offset) {
- List<ELOperandToken> result = new ArrayList<ELOperandToken>();
-
- int elStart = getELStart(document, offset);
-
- if (elStart == -1)
- elStart = offset;
-
- SeamELOperandTokenizerForward tokenizer = new SeamELOperandTokenizerForward(document, elStart);
- List<ELOperandToken> tokens = tokenizer.getTokens();
-
- ELOperandToken lastSeparator = null;
- for (int i = 0; tokens != null && i < tokens.size(); i++) {
- ELOperandToken token = tokens.get(i);
- if (token.getType() == ELOperandToken.EL_SEPARATOR_TOKEN) {
- lastSeparator = token;
- continue;
- }
- if (token.getType() == ELOperandToken.EL_VARIABLE_NAME_TOKEN ||
- token.getType() == ELOperandToken.EL_METHOD_TOKEN ||
- token.getType() == ELOperandToken.EL_PROPERTY_NAME_TOKEN) {
- if (token.getStart() <= offset) {
- if (lastSeparator != null)
- result.add(lastSeparator);
- result.add(token);
- } else {
- // Stop processing. We're not interrested of the rest of tokens
- break;
- }
- }
- }
-
- return result;
- }
-*/
-
-/**
- private static int getELStart(IDocument document, int offset) {
- SeamELOperandTokenizer tokenizer = new SeamELOperandTokenizer(document, offset);
- List<ELOperandToken> tokens = tokenizer.getTokens();
-
- if (tokens == null || tokens.size() == 0)
- return -1;
-
- ELOperandToken firstToken = tokens.get(0);
- return firstToken.getStart();
- }
-*/
-
}
Deleted: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandResolveStatus.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandResolveStatus.java 2008-10-01 15:33:13 UTC (rev 10598)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandResolveStatus.java 2008-10-01 15:34:00 UTC (rev 10599)
@@ -1,174 +0,0 @@
-package org.jboss.tools.seam.internal.core.el;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.jboss.tools.common.el.core.model.ELInvocationExpression;
-import org.jboss.tools.common.model.util.TypeInfoCollector;
-import org.jboss.tools.seam.core.ISeamContextVariable;
-
-/**
- * Status of EL resolving.
- * @author Jeremy
- */
-public class SeamELOperandResolveStatus {
- private ELInvocationExpression tokens;
- public List<ISeamContextVariable> usedVariables;
- Map<String, TypeInfoCollector.MethodInfo> unpairedGettersOrSetters;
- Set<String> proposals;
- private ELInvocationExpression lastResolvedToken;
- private boolean isMapOrCollectionOrBundleAmoungTheTokens = false;
- private TypeInfoCollector.MemberInfo memberOfResolvedOperand;
-
- /**
- * @return MemberInfo of last segment of EL operand. Null if El is not resolved.
- */
- public TypeInfoCollector.MemberInfo getMemberOfResolvedOperand() {
- return memberOfResolvedOperand;
- }
-
- /**
- * Sets MemberInfo for last segment of EL operand.
- * @param lastResolvedMember
- */
- public void setMemberOfResolvedOperand(
- TypeInfoCollector.MemberInfo lastResolvedMember) {
- this.memberOfResolvedOperand = lastResolvedMember;
- }
-
- /**
- * Constructor
- * @param tokens Tokens of EL
- */
- public SeamELOperandResolveStatus(ELInvocationExpression tokens) {
- this.tokens = tokens;
- }
-
- /**
- * @return true if EL contains any not parametrized Collection or ResourceBundle.
- */
- public boolean isMapOrCollectionOrBundleAmoungTheTokens() {
- return this.isMapOrCollectionOrBundleAmoungTheTokens;
- }
-
- public void setMapOrCollectionOrBundleAmoungTheTokens() {
- this.isMapOrCollectionOrBundleAmoungTheTokens = true;
- }
-
- /**
- * @return true if EL is resolved.
- */
- public boolean isOK() {
- return !getProposals().isEmpty() || isMapOrCollectionOrBundleAmoungTheTokens();
- }
-
- /**
- * @return false if El is not resolved.
- */
- public boolean isError() {
- return !isOK();
- }
-
- /**
- * @return List of resolved tokens of EL. Includes separators "."
- */
- public ELInvocationExpression getResolvedTokens() {
- return lastResolvedToken;
- }
-
- /**
- * @return List of unresolved tokens of EL.
- */
- public ELInvocationExpression getUnresolvedTokens() {
- if(lastResolvedToken == tokens) return null;
- if(lastResolvedToken != null && (lastResolvedToken.getParent() instanceof ELInvocationExpression)) {
- return (ELInvocationExpression)lastResolvedToken.getParent();
- }
- ELInvocationExpression l = tokens;
- while(l != null && l.getLeft() != lastResolvedToken) {
- l = l.getLeft();
- }
- return l;
- }
-
- /**
- * @return Last resolved token of EL. Can be separator "." // no, change it
- */
- public ELInvocationExpression getLastResolvedToken() {
- return lastResolvedToken;
- }
-
- /**
- * @param lastResolvedToken Last resolved token of EL. Can be separator "."
- */
- public void setLastResolvedToken(ELInvocationExpression lastResolvedToken) {
- this.lastResolvedToken = lastResolvedToken;
- }
-
- /**
- * @return Tokens of EL.
- */
- public ELInvocationExpression getTokens() {
- return tokens;
- }
-
- /**
- * @param tokens Tokens of EL.
- */
- public void setTokens(ELInvocationExpression tokens) {
- this.tokens = tokens;
- }
-
- /**
- * @return Set of proposals for EL.
- */
- public Set<String> getProposals() {
- return proposals == null ? new TreeSet<String>() : proposals;
- }
-
- /**
- * @param proposals Set of proposals.
- */
- public void setProposals(Set<String> proposals) {
- this.proposals = proposals;
- }
-
- /**
- * @return List of Seam Context Variables used in EL.
- */
- public List<ISeamContextVariable> getUsedVariables() {
- return (usedVariables == null ? new ArrayList<ISeamContextVariable>() : usedVariables);
- }
-
- /**
- * @param usedVariables List of Seam Context Variables used in EL.
- */
- public void setUsedVariables(List<ISeamContextVariable> usedVariables) {
- this.usedVariables = usedVariables;
- }
-
- /**
- * @return Map of unpaired getters and setters (getters/setters without proper setters/getters).
- * of all properties used in EL.
- * Key - name of property.
- * Value - MethodInfo of existed getter/setter.
- */
- public Map<String, TypeInfoCollector.MethodInfo> getUnpairedGettersOrSetters() {
- if (unpairedGettersOrSetters == null) {
- unpairedGettersOrSetters = new HashMap<String, TypeInfoCollector.MethodInfo>();
- }
- return unpairedGettersOrSetters;
- }
-
- /**
- * Clear Map of unpaired getters and setters.
- */
- public void clearUnpairedGettersOrSetters() {
- getUnpairedGettersOrSetters().clear();
- }
-
-}
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 2008-10-01 15:33:13 UTC (rev 10598)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamExpressionResolver.java 2008-10-01 15:34:00 UTC (rev 10599)
@@ -20,11 +20,11 @@
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
-import org.jboss.tools.common.model.util.TypeInfoCollector;
-import org.jboss.tools.common.model.util.TypeInfoCollector.MemberInfo;
-import org.jboss.tools.common.model.util.TypeInfoCollector.Type;
-import org.jboss.tools.common.model.util.TypeInfoCollector.TypeInfo;
-import org.jboss.tools.common.model.util.TypeInfoCollector.TypeMemberInfo;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector.MemberInfo;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector.Type;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector.TypeInfo;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector.TypeMemberInfo;
import org.jboss.tools.seam.core.BijectedAttributeType;
import org.jboss.tools.seam.core.IBijectedAttribute;
import org.jboss.tools.seam.core.ISeamComponent;
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java 2008-10-01 15:33:13 UTC (rev 10598)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamPromptingProvider.java 2008-10-01 15:34:00 UTC (rev 10599)
@@ -29,7 +29,7 @@
public static String VARIABLES = "seam.variables"; //$NON-NLS-1$
public static String MEMBERS = "seam.members"; //$NON-NLS-1$
- SeamELCompletionEngine engine= new SeamELCompletionEngine();
+// SeamELCompletionEngine engine= new SeamELCompletionEngine();
public SeamPromptingProvider() {}
Deleted: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/Var.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/Var.java 2008-10-01 15:33:13 UTC (rev 10598)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/Var.java 2008-10-01 15:34:00 UTC (rev 10599)
@@ -1,156 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.el;
-
-import java.util.List;
-
-import org.jboss.tools.common.el.core.model.ELExpression;
-import org.jboss.tools.common.el.core.model.ELInstance;
-import org.jboss.tools.common.el.core.model.ELModel;
-import org.jboss.tools.common.el.core.parser.ELParser;
-import org.jboss.tools.common.el.core.parser.ELParserFactory;
-
-/**
- * Represents "var"/"value" attributes.
- * @author Alexey Kazakov
- */
-public class Var {
- String name;
- String value;
- ELExpression elToken;
- String resolvedValue;
- ELExpression resolvedElToken;
- int declOffset;
- int declLength;
-
- /**
- * Constructor
- * @param name - value of "var" attribute.
- * @param value - value of "value" attribute.
- */
- public Var(String name, String value, int declOffset, int declLength) {
- super();
- this.name = name;
- this.value = value;
- elToken = parseEl(value);
- this.declOffset = declOffset;
- this.declLength = declLength;
- }
-
- /**
- * Constructor
- * @param name - value of "var" attribute.
- * @param value - value of "value" attribute.
- */
- public Var(String name, String value) {
- this(name, value, 0, 0);
- }
-
- ELExpression parseEl(String el) {
- if(el.length()>3 && el.startsWith("#{") && el.endsWith("}")) {
- ELParser parser = ELParserFactory.createJbossParser();
- ELModel model = parser.parse(el);
- if(model == null || parser.getSyntaxErrors().size() > 0) return null;
- List<ELInstance> is = model.getInstances();
- if(is.size() == 0) return null;
- return is.get(0).getExpression();
- }
- return null;
- }
-
- /**
- * Sets value to new resolved EL which we got as result of parsing value.
- * For example:
- * <h:datatable value="#{list}" var="item">
- * <h:dataTable value="#{item.anotherList}" var="innerItem">
- * ...
- * </h:dataTable>
- * </h:dataTable>
- * Original El is #{item.anotherList}
- * Resolved El is #{list.iterator().next().anotherList}
- * It's very useful for nested vars.
- * @param newEl
- */
- public void resolveValue(String newEl) {
- resolvedValue = newEl;
- resolvedElToken = parseEl(newEl);
- }
-
- /**
- * @return parsed EL from "value" attribute. Returns null if EL is not valid.
- */
- public ELExpression getElToken() {
- return elToken;
- }
-
- /**
- * @return parsed resolved EL from "value" attribute. May be null.
- */
- public ELExpression getResolvedElToken() {
- return resolvedElToken;
- }
-
- /**
- * @return name of variable.
- */
- public String getName() {
- return name;
- }
-
- /**
- * @return value of variable. It's EL.
- */
- public String getValue() {
- return value;
- }
-
- /**
- * @return resolved value of variable. It's EL. May be null.
- */
- public String getResolvedValue() {
- return resolvedValue;
- }
-
- /**
- * @return offset of the var declaration
- */
- public int getDeclarationOffset() {
- return declOffset;
- }
-
- /**
- * @return length of the var declaration
- */
- public int getDeclarationLength() {
- return declLength;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof Var) {
- Var compare = (Var)obj;
- String str = getName();
- if (str != null) {
- if (!str.equals(compare.getName()))
- return false;
- } else {
- if (compare.getName() != null)
- return false;
- }
- str = getValue();
- return (str != null ?
- str.equals(compare.getValue()) :
- compare.getValue() == null);
- }
- return false;
- }
-
-}
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2008-10-01 15:33:13 UTC (rev 10598)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamCoreValidator.java 2008-10-01 15:34:00 UTC (rev 10599)
@@ -31,8 +31,8 @@
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.validation.internal.core.ValidationException;
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.common.model.util.TypeInfoCollector;
import org.jboss.tools.seam.core.BijectedAttributeType;
import org.jboss.tools.seam.core.IBijectedAttribute;
import org.jboss.tools.seam.core.IRole;
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2008-10-01 15:33:13 UTC (rev 10598)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamELValidator.java 2008-10-01 15:34:00 UTC (rev 10599)
@@ -47,18 +47,20 @@
import org.jboss.tools.common.el.core.model.ELModel;
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserFactory;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
import org.jboss.tools.common.el.core.parser.SyntaxError;
-import org.jboss.tools.common.model.util.TypeInfoCollector;
+import org.jboss.tools.common.el.core.resolver.ELOperandResolveStatus;
+import org.jboss.tools.common.el.core.resolver.ElVarSearcher;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
+import org.jboss.tools.common.el.core.resolver.Var;
import org.jboss.tools.common.util.FileUtil;
import org.jboss.tools.seam.core.ISeamContextVariable;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCoreMessages;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.core.SeamPreferences;
-import org.jboss.tools.seam.internal.core.el.ElVarSearcher;
import org.jboss.tools.seam.internal.core.el.SeamELCompletionEngine;
import org.jboss.tools.seam.internal.core.el.SeamELOperandResolveStatus;
-import org.jboss.tools.seam.internal.core.el.Var;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -75,7 +77,7 @@
protected static final String VALIDATING_EL_FILE_MESSAGE_ID = "VALIDATING_EL_FILE";
- private SeamELCompletionEngine engine = new SeamELCompletionEngine();
+ private SeamELCompletionEngine engine;
private List<Var> varListForCurentValidatedNode = new ArrayList<Var>();
private ElVarSearcher elVarSearcher;
@@ -83,7 +85,8 @@
SeamContextValidationHelper coreHelper, IReporter reporter,
SeamValidationContext validationContext, ISeamProject project) {
super(validatorManager, coreHelper, reporter, validationContext, project);
- elVarSearcher = new ElVarSearcher(project, engine);
+ engine = new SeamELCompletionEngine(project);
+ elVarSearcher = new ElVarSearcher(engine);
}
/* (non-Javadoc)
@@ -213,7 +216,7 @@
String preferenceValue = SeamPreferences.getProjectPreference(project, SeamPreferences.CHECK_VARS);
Var var = null;
if (SeamPreferences.ENABLE.equals(preferenceValue)) {
- var = ElVarSearcher.findVar(parent);
+ var = elVarSearcher.findVar(parent);
}
if(var!=null) {
varListForCurentValidatedNode.add(var);
@@ -254,7 +257,7 @@
private void validateString(IFile file, String string, int offset) {
int startEl = string.indexOf("#{"); //$NON-NLS-1$
if(startEl>-1) {
- ELParser parser = ELParserFactory.createJbossParser();
+ ELParser parser = ELParserUtil.getJbossFactory().createParser();
ELModel model = parser.parse(string);
List<SyntaxError> errors = parser.getSyntaxErrors();
if(errors.size() > 0) {
@@ -298,7 +301,7 @@
if (!operand.endsWith(".")) { //$NON-NLS-1$
{
SeamELOperandResolveStatus status =
- engine.resolveSeamELOperand(project, file, operandToken, true, varListForCurentValidatedNode, elVarSearcher);
+ engine.resolveELOperand(file, operandToken, true, varListForCurentValidatedNode, elVarSearcher);
if(status.getUsedVariables().size()==0 && status.isError()) {
// Save resources with unknown variables names
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidatorManager.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidatorManager.java 2008-10-01 15:33:13 UTC (rev 10598)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/validation/SeamValidatorManager.java 2008-10-01 15:34:00 UTC (rev 10599)
@@ -19,7 +19,7 @@
import org.eclipse.wst.validation.internal.provisional.core.IReporter;
import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
import org.eclipse.wst.validation.internal.provisional.core.IValidatorJob;
-import org.jboss.tools.common.model.util.TypeInfoCollector;
+import org.jboss.tools.common.el.core.resolver.TypeInfoCollector;
import org.jboss.tools.seam.core.ISeamProject;
import org.jboss.tools.seam.internal.core.SeamProject;
15 years, 7 months
JBoss Tools SVN: r10598 - in trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp: support/kb and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-10-01 11:33:13 -0400 (Wed, 01 Oct 2008)
New Revision: 10598
Modified:
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletsHtmlContentAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java
trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBundlePropertyResource.java
Log:
JBIDE-1497.
Refactoring
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletsHtmlContentAssistProcessor.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletsHtmlContentAssistProcessor.java 2008-10-01 15:31:52 UTC (rev 10597)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/FaceletsHtmlContentAssistProcessor.java 2008-10-01 15:33:13 UTC (rev 10598)
@@ -51,6 +51,7 @@
import org.jboss.tools.common.el.core.model.ELUtil;
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserFactory;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
import org.jboss.tools.common.kb.AttributeDescriptor;
import org.jboss.tools.common.kb.KbConnectorFactory;
import org.jboss.tools.common.kb.KbConnectorType;
@@ -272,7 +273,7 @@
}
// No JBoss parser ?
- ELParser p = ELParserFactory.createDefaultParser();
+ ELParser p = ELParserUtil.getDefaultFactory().createParser();
ELModel model = p.parse(currentValue);
ELInstance instance = ELUtil.findInstance(model, offset);
if(instance != null && instance.getStartPosition() + 2 <= offset) {
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java 2008-10-01 15:31:52 UTC (rev 10597)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/contentassist/JSPActiveContentAssistProcessor.java 2008-10-01 15:33:13 UTC (rev 10598)
@@ -24,6 +24,7 @@
import org.jboss.tools.common.el.core.model.ELUtil;
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserFactory;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
import org.jboss.tools.common.kb.KbException;
import org.jboss.tools.common.kb.KbProposal;
import org.jboss.tools.common.kb.KbQuery;
@@ -270,7 +271,7 @@
* @return
*/
private int getELStartPosition(String matchString) {
- ELParser p = ELParserFactory.createJbossParser();
+ ELParser p = ELParserUtil.getJbossFactory().createParser();
ELModel model = p.parse(matchString);
ELInstance is = ELUtil.findInstance(model, matchString.length());
return is == null ? -1 : is.getStartPosition();
@@ -304,7 +305,7 @@
currentValue.length() < matchString.length())
return -1;
- ELParser p = ELParserFactory.createJbossParser();
+ ELParser p = ELParserUtil.getJbossFactory().createParser();
ELModel model = p.parse(currentValue);
ELInstance is = ELUtil.findInstance(model, matchString.length());
if(is == null || is.getCloseInstanceToken() == null) return -1;
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java 2008-10-01 15:31:52 UTC (rev 10597)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBeanPropertyResource.java 2008-10-01 15:33:13 UTC (rev 10598)
@@ -27,6 +27,7 @@
import org.jboss.tools.common.el.core.model.ELPropertyInvocation;
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserFactory;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
import org.jboss.tools.common.kb.KbDinamicResource;
import org.jboss.tools.common.kb.KbProposal;
import org.jboss.tools.common.kb.KbProposal.PostProcessing;
@@ -59,7 +60,7 @@
try {
if (!isReadyToUse()) return proposals;
- ELParser p = ELParserFactory.createDefaultParser();
+ ELParser p = ELParserUtil.getDefaultFactory().createParser();
ELModel model = p.parse(query);
List<ELInstance> is = model.getInstances();
@@ -178,7 +179,7 @@
class PostProcessingImpl implements PostProcessing {
public void process(KbProposal proposal, String value, int offset) {
- ELParser p = ELParserFactory.createDefaultParser();
+ ELParser p = ELParserUtil.getDefaultFactory().createParser();
ELModel model = p.parse(value);
List<ELInstance> is = model.getInstances();
ELInvocationExpression expr = null;
Modified: trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBundlePropertyResource.java
===================================================================
--- trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBundlePropertyResource.java 2008-10-01 15:31:52 UTC (rev 10597)
+++ trunk/jst/plugins/org.jboss.tools.jst.jsp/src/org/jboss/tools/jst/jsp/support/kb/WTPKbdBundlePropertyResource.java 2008-10-01 15:33:13 UTC (rev 10598)
@@ -25,6 +25,7 @@
import org.jboss.tools.common.el.core.model.ELModel;
import org.jboss.tools.common.el.core.parser.ELParser;
import org.jboss.tools.common.el.core.parser.ELParserFactory;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
import org.jboss.tools.common.kb.KbDinamicResource;
import org.jboss.tools.common.kb.KbProposal;
import org.jboss.tools.common.model.XModelObject;
@@ -49,7 +50,7 @@
try {
if (!isReadyToUse()) return proposals;
- ELParser p = ELParserFactory.createDefaultParser();
+ ELParser p = ELParserUtil.getDefaultFactory().createParser();
ELModel model = p.parse(query);
List<ELInstance> is = model.getInstances();
15 years, 7 months
JBoss Tools SVN: r10597 - trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-10-01 11:31:52 -0400 (Wed, 01 Oct 2008)
New Revision: 10597
Removed:
trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/TypeInfoCollector.java
Log:
JBIDE-1497.
Refactoring
Deleted: trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/TypeInfoCollector.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/TypeInfoCollector.java 2008-10-01 15:31:11 UTC (rev 10596)
+++ trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/TypeInfoCollector.java 2008-10-01 15:31:52 UTC (rev 10597)
@@ -1,1235 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is made available under the terms of the
- * Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.common.model.util;
-
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IMember;
-import org.eclipse.jdt.core.IMethod;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.ITypeHierarchy;
-import org.eclipse.jdt.core.ITypeParameter;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.Signature;
-import org.jboss.tools.common.model.plugin.ModelPlugin;
-
-/**
- * This class helps to collect information of java elements used in Seam EL.
- * @author Viktor Rubezhny, Alexey Kazakov
- */
-public class TypeInfoCollector {
- IType fType;
- MemberInfo fMember;
- TypeInfo fTypeInfo;
- List<MethodInfo> fMethods;
- List<FieldInfo> fFields;
-
- private static class ProjectCache {
- Map<IMember, MemberInfo> memberInfoCacheFalse = new HashMap<IMember, MemberInfo>();
- Map<IMember, MemberInfo> memberInfoCacheTrue = new HashMap<IMember, MemberInfo>();
- Map<IType, SuperTypeInfo> superTypesCache = new HashMap<IType, SuperTypeInfo>();
- }
-
- private static Caches caches = new Caches();
-
- private static class Caches {
- ProjectCache common = new ProjectCache();
-// Map<IProject, ProjectCache> cache = new HashMap<IProject, ProjectCache>();
-
- public boolean contains(IProject p) {
-// return p != null && cache.containsKey(p);
- return true;
- }
-
- public void clean(IProject p) {
-// if(contains(p)) {
-// cache.remove(p);
-// }
- common = new ProjectCache();
- }
-
- public ProjectCache get(IProject p) {
- if(p == null || !p.isAccessible()) return null;
- return common;
-// ProjectCache c = cache.get(p);
-// if(c == null) {
-// c = new ProjectCache();
-// cache.put(p, c);
-// }
-// return c;
- }
-
- public ProjectCache get(IJavaElement element) {
- if(element == null) {
- return null;
- }
- IJavaProject jp = element.getJavaProject();
- IProject p = jp == null ? null : jp.getProject();
- return get(p);
- }
- }
-
- public static class Type {
- private String fName;
- private String fQualifiedName;
- private Type[] fParameters;
- private IType fSource;
- private String fSignature;
- private boolean fIsArray;
- private Type fTypeOfArrayElement;
- private String fQualifiedTypeNameOfArrayElement;
-
- private Type() {
- }
-
- public static Type valueOf(String name) {
- Type instance = new Type();
- instance.setName(name);
- instance.setParameters(new Type[0]);
- return instance;
- }
-
- public Type(String signature, IType source) {
- if(signature!=null) {
- String erasureSignature = Signature.getTypeErasure(signature);
- String typeOfArraySiganture = Signature.getElementType(erasureSignature);
- fName = String.valueOf(Signature.toString(erasureSignature));
- if(!erasureSignature.equals(typeOfArraySiganture)) {
- // this is an array
- fIsArray = true;
- fTypeOfArrayElement = new Type(typeOfArraySiganture, source);
- }
- String[] signaturesOfParametersOfType = Signature.getTypeArguments(signature);
- fParameters = new Type[signaturesOfParametersOfType.length];
- for (int i = 0; i < signaturesOfParametersOfType.length; i++) {
- fParameters[i] = new Type(signaturesOfParametersOfType[i], source);
- }
- } else {
- fName = source.getFullyQualifiedName();
- setParameters(new Type[0]);
- }
- fSource = source;
- }
-
- public void initializeParameters(Map<String, Type> parameters) {
- Type type = parameters.get(fName);
- if(type!=null) {
- fName = type.getName();
- fParameters = type.getParameters();
- fSource = type.getSource();
- fIsArray = type.isArray();
- fTypeOfArrayElement = type.getTypeOfArrayElement();
- }
- for (int i = 0; i < fParameters.length; i++) {
- fParameters[i].initializeParameters(parameters);
- }
- }
-
- public Type getParameter(int index) {
- if(fParameters.length>index) {
- return fParameters[index];
- }
- return null;
- }
-
- public String getQualifiedTypeNameOfArrayElement() {
- if(fQualifiedTypeNameOfArrayElement==null && fSource!=null) {
- fQualifiedTypeNameOfArrayElement = EclipseJavaUtil.resolveType(fSource, fTypeOfArrayElement.getName());
- }
- return fQualifiedTypeNameOfArrayElement;
- }
-
- public String getQualifiedName() {
- if(fQualifiedName == null && fSource!=null) {
- fQualifiedName = EclipseJavaUtil.resolveType(fSource, fName);
- }
- return fQualifiedName;
- }
-
- public boolean isArray() {
- return fIsArray;
- }
-
- public void setArray(boolean array) {
- fIsArray = array;
- }
-
- public Type getTypeOfArrayElement() {
- return fTypeOfArrayElement;
- }
-
- public void setTypeOfArrayElement(Type typeOfArrayElement) {
- fTypeOfArrayElement = typeOfArrayElement;
- }
-
- public String getName() {
- return fName;
- }
-
- public void setName(String name) {
- fName = name;
- }
-
- public Type[] getParameters() {
- return fParameters;
- }
-
- public void setParameters(Type[] parameters) {
- this.fParameters = parameters;
- }
-
- public IType getSource() {
- return fSource;
- }
-
- public void setSource(IType source) {
- this.fSource = source;
- }
-
- public String getSignature() {
- return fSignature;
- }
-
- public void setSignature(String signature) {
- this.fSignature = signature;
- }
- }
-
- public abstract static class MemberInfo {
- private String fDeclaringTypeQualifiedName;
- private String fName;
- private int fModifiers;
- private IType fSourceType;
- private MemberInfo fParentMember;
- private IType fMemberType;
- private boolean isDataModel;
- private Type fType;
-
- protected MemberInfo (
- IType sourceType,
- String declaringTypeQualifiedName, String name, int modifiers, MemberInfo parentMember, boolean dataModel, Type type) {
- setSourceType(sourceType);
- setDeclaringTypeQualifiedName(declaringTypeQualifiedName);
- setName(name);
- setModifiers(modifiers);
- setParentMember(parentMember);
- setDataModel(dataModel);
- setType(type);
- }
-
- abstract void initializeParameters();
-
- protected void setType(Type type) {
- fType = type;
- }
-
- public Type getType() {
- return fType;
- }
-
- public void setSourceType(IType sourceType) {
- fSourceType = sourceType;
- }
-
- public IType getSourceType() {
- return fSourceType;
- }
-
- protected void setName (String name) {
- this.fName = name;
- }
-
- public String getName() {
- return fName;
- }
-
- protected void setDeclaringTypeQualifiedName(String declaringTypeQualifiedName) {
- this.fDeclaringTypeQualifiedName = declaringTypeQualifiedName;
- }
-
- public String getDeclaringTypeQualifiedName() {
- return fDeclaringTypeQualifiedName;
- }
-
- protected void setModifiers (int modifiers) {
- this.fModifiers = modifiers;
- }
-
- public int getModifiers() {
- return fModifiers;
- }
-
- public boolean isPublic() {
- return Modifier.isPublic(fModifiers);
- }
-
- public boolean isStatic() {
- return Modifier.isStatic(fModifiers);
- }
-
- public boolean isJavaLangObject() {
- return "java.lang.Object".equals(getDeclaringTypeQualifiedName());
- }
-
- public MemberInfo getParentMember() {
- return fParentMember;
- }
-
- protected void setParentMember(MemberInfo parentMember) {
- fParentMember = parentMember;
- }
-
- public IType getMemberType() {
- if(fMemberType==null) {
- initializeParameters();
- try {
- if(isDataModel() && getType().isArray()) {
- fMemberType = getSourceType().getJavaProject().findType(getType().getQualifiedTypeNameOfArrayElement());
- } else if(getType().getQualifiedName()!=null) {
- fMemberType = getSourceType().getJavaProject().findType(getType().getQualifiedName());
- }
- } catch (JavaModelException e) {
- ModelPlugin.getPluginLog().logError(e);
- }
- }
- return fMemberType;
- }
-
- public boolean isDataModel() {
- return isDataModel;
- }
-
- protected void setDataModel(boolean isDataModel) {
- this.isDataModel = isDataModel;
- }
-
- public TypeInfoCollector getTypeCollector() {
- // The rev. 7651 results in a deadlock, typeInfo is not stored anymore
- // The rev. 7623 results in a deadlock, so, it's rolled back
- // >>> Fix for JBIDE-2090
- return new TypeInfoCollector(this);
- // <<< Fix for JBIDE-2090
- }
-
- abstract public IJavaElement getJavaElement();
- }
-
- public static class TypeInfo extends MemberInfo {
- private IType fType;
- private TypeInfo superType;
- private Map<String, Type> params = new HashMap<String, Type>();
-
- public TypeInfo(IType type, MemberInfo parentMember, boolean dataModel) throws JavaModelException {
- super(type.getDeclaringType(),
- (type.getDeclaringType() == null ? null : type.getDeclaringType().getFullyQualifiedName()),
- type.getFullyQualifiedName(),
- type.getFlags(),
- parentMember,
- dataModel,
- Type.valueOf(type.getFullyQualifiedName()));
- this.fType = type;
- }
-
- public Type getParameterType(String name) {
- return params.get(name);
- }
-
- @Override
- public IType getMemberType() {
- return fType;
- }
-
- @Override
- public IJavaElement getJavaElement() {
- return fType;
- }
-
- /* (non-Javadoc)
- * @see org.jboss.tools.common.model.util.TypeInfoCollector.MemberInfo#initializeParameters()
- */
- @Override
- void initializeParameters() {
- try {
- MemberInfo parent = getParentMember();
- if(parent!=null && parent instanceof TypeMemberInfo) {
- ITypeParameter[] parameters = fType.getTypeParameters();
- for (int i = 0; i < parameters.length; i++) {
- Type type = parent.getType().getParameter(i);
- if(type!=null) {
- params.put(parameters[i].getElementName(), type);
- }
- }
- }
- if(superType!=null) {
- superType.initializeParameters(this);
- }
- } catch (JavaModelException e) {
- ModelPlugin.getPluginLog().logError(e);
- }
- }
-
- private void initializeParameters(TypeInfo inheritedType) throws JavaModelException {
- ITypeParameter[] parameters = fType.getTypeParameters();
- String signature = inheritedType.fType.getSuperclassTypeSignature();
- Type classType = new Type(signature, inheritedType.fType);
- for (int i = 0; i < parameters.length; i++) {
- Type paramType = classType.getParameter(i);
- if(paramType!=null) {
- Type resolvedType = inheritedType.getParameterType(paramType.getName());
- if(resolvedType!=null) {
- paramType = resolvedType;
- }
- params.put(parameters[i].getElementName(), paramType);
- }
- }
- if(superType!=null) {
- superType.initializeParameters(this);
- }
- }
-
- public TypeInfo getSuperType() {
- return superType;
- }
-
- public void setSuperType(TypeInfo superType) {
- this.superType = superType;
- }
- }
-
- public abstract static class TypeMemberInfo extends MemberInfo {
- private String[] fParametersNamesOfDeclaringType;
- private TypeInfo declaratedType;
-
- /**
- * @param sourceType
- * @param declaringTypeQualifiedName
- * @param name
- * @param modifiers
- * @param parentMember
- * @param dataModel
- * @param type
- */
- protected TypeMemberInfo(IType sourceType,
- String declaringTypeQualifiedName, String name, int modifiers,
- TypeInfo parentMember, TypeInfo declaratedType, boolean dataModel, Type type) {
- super(sourceType, declaringTypeQualifiedName, name, modifiers, parentMember,
- dataModel, type);
- this.declaratedType = declaratedType;
- }
-
- public String[] getParametersNamesOfDeclaringType() {
- return fParametersNamesOfDeclaringType;
- }
-
- void setParametersNamesOfDeclaringType(
- String[] parametersNamesOfDeclaringType) {
- fParametersNamesOfDeclaringType = parametersNamesOfDeclaringType;
- }
-
- protected void initializeParameters() {
- if(fParametersNamesOfDeclaringType!=null && fParametersNamesOfDeclaringType.length>0 && getParentMember()!=null) {
- Map<String, Type> parametersOfDeclaringType = new HashMap<String, Type>();
- TypeInfo parentTypeInfo = (TypeInfo)getParentMember();
- parentTypeInfo.initializeParameters();
- for (int i = 0; i < fParametersNamesOfDeclaringType.length; i++) {
- String parameterName = getParameterNameFromType(fParametersNamesOfDeclaringType[i]);
- Type paramType = declaratedType.getParameterType(parameterName);
- if(paramType!=null) {
- parametersOfDeclaringType.put(parameterName, paramType);
- }
- }
- getType().initializeParameters(parametersOfDeclaringType);
- }
- }
-
- public TypeInfo getDeclaratedType() {
- return declaratedType;
- }
-
- protected void setDeclaratedType(TypeInfo declaratedType) {
- this.declaratedType = declaratedType;
- }
- }
-
- public static class FieldInfo extends TypeMemberInfo {
- private IJavaElement fJavaElement;
-
- public FieldInfo(IField field, TypeInfo parentMember, TypeInfo declaratedType, boolean dataModel) throws JavaModelException {
- super(field.getDeclaringType(),
- (field.getDeclaringType() == null ? null : field.getDeclaringType().getFullyQualifiedName()),
- field.getElementName(),
- field.getFlags(),
- parentMember,
- declaratedType,
- dataModel,
- new Type(field.getTypeSignature(),
- field.getDeclaringType()));
-
- setParametersNamesOfDeclaringType(getTypeErasureFromSignatureArray(field.getDeclaringType().getTypeParameterSignatures()));
- }
-
- public IJavaElement getJavaElement () {
- if(fJavaElement == null) {
- try {
- if(getDeclaringTypeQualifiedName()==null) {
- return null;
- }
- IType declType = getSourceType().getJavaProject().findType(getDeclaringTypeQualifiedName());
- fJavaElement = (declType == null ? null : declType.getField(getName()));
- } catch (JavaModelException e) {
- ModelPlugin.getPluginLog().logError(e);
- }
- }
- return fJavaElement;
- }
- }
-
- public static class MethodInfo extends TypeMemberInfo {
- private String[] fParameterTypeNames;
- private String[] fParameterTypeQualifiedNames;
- private String[] fParameterNames;
- private IJavaElement fJavaElement;
-
- public MethodInfo(IType sourceType, String declaringTypeQualifiedName, String name,
- int modifiers, String[] parameterTypeQualifiedNames,
- String[] parameterNames,
- String returnTypeQualifiedName,
- TypeInfo parentMember,
- TypeInfo declaratedType,
- boolean dataModel) {
- super(sourceType, declaringTypeQualifiedName, name, modifiers, parentMember, declaratedType, dataModel, Type.valueOf(name));
- setParameterTypeNames(parameterTypeQualifiedNames);
- setParameterNames(parameterNames);
- }
-
- public MethodInfo(IMethod method, TypeInfo parentMember, TypeInfo declaratedType, boolean dataModel) throws JavaModelException {
- super(method.getDeclaringType(),
- (method.getDeclaringType() == null ? null : method.getDeclaringType().getFullyQualifiedName()),
- method.getElementName(),
- method.getFlags(),
- parentMember,
- declaratedType,
- dataModel,
- new Type(method.getReturnType(),
- method.getDeclaringType()));
-
- setParameterNames(method.getParameterNames());
- setParameterTypeNames(resolveSignatures(method.getDeclaringType(), method.getParameterTypes()));
- setParametersNamesOfDeclaringType(getTypeErasureFromSignatureArray(method.getDeclaringType().getTypeParameterSignatures()));
- }
-
- protected void setParameterTypeNames(String[] parameterTypeNames) {
- fParameterTypeNames = (parameterTypeNames == null ?
- new String[0] : parameterTypeNames);
- }
-
- public String[] getParameterTypeQualifiedNames() {
- if(fParameterTypeQualifiedNames==null) {
- fParameterTypeQualifiedNames = new String[fParameterTypeNames.length];
- for (int i = 0; i < fParameterTypeQualifiedNames.length; i++) {
- fParameterTypeQualifiedNames[i] = EclipseJavaUtil.resolveType(getSourceType(), fParameterTypeNames[i]);
- }
- }
- return fParameterTypeQualifiedNames;
- }
-
- public String[] getParameterTypeNames() {
- return fParameterTypeNames;
- }
-
- protected void setParameterNames(String[] parameterNames) {
- fParameterNames = (parameterNames == null ?
- new String[0] : parameterNames);
- }
-
- public String[] getParameterNames() {
- return fParameterNames;
- }
-
- public int getNumberOfParameters() {
- return (getParameterNames() == null ? 0 : getParameterNames().length);
- }
-
- public IType getReturnType() {
- return getMemberType();
- }
-
- public boolean isConstructor () {
- return getDeclaringTypeQualifiedName()!=null && getDeclaringTypeQualifiedName().equals(getName());
- }
-
- public boolean isGetter() {
- if (null == getType()) {
- return false;
- }
-
- return (((getName().startsWith("get") && !getName().equals("get")) || getName().startsWith("is")) && getNumberOfParameters() == 0);
- }
-
- public boolean isSetter() {
- return ((getName().startsWith("set") && !getName().equals("set")) && getNumberOfParameters() == 1);
- }
-
- public List<String> getAsPresentedStrings() {
- List<String> list = new ArrayList<String>(2);
- StringBuffer name = new StringBuffer(getName());
-
- // Add method as 'foo'
- list.add(name.toString());
-
- // Add method as 'foo(param1,param2)'
- name.append('(');
- String[] mParams = getParameterNames();
- for (int j = 0; mParams != null && j < mParams.length; j++) {
- if (j > 0) name.append(", "); //$NON-NLS-1$
- name.append(mParams[j]);
- }
- name.append(')');
- list.add(name.toString());
- return list;
- }
-
- @Override
- public IJavaElement getJavaElement () {
- if(fJavaElement == null) {
- try {
- IType declType = getSourceType().getJavaProject().findType(getDeclaringTypeQualifiedName());
- if(declType==null) {
- return null;
- }
- IMethod[] allMethods = declType.getMethods();
-
- // filter methods by name
- List<IMethod> methods = new ArrayList<IMethod>();
- for (int i = 0; allMethods != null && i < allMethods.length; i++) {
- if (allMethods[i].getElementName().equals(getName())) {
- methods.add(allMethods[i]);
- }
- }
- if (!methods.isEmpty()) {
- if (methods.size() == 1) {
- fJavaElement = methods.get(0);
- } else {
- // filter methods by number of parameters
- List<IMethod> filteredMethods = new ArrayList<IMethod>();
- for (IMethod method : methods) {
- if (method.getNumberOfParameters() == getNumberOfParameters()) {
- filteredMethods.add(method);
- }
- }
- if (!filteredMethods.isEmpty()) {
- if (filteredMethods.size() == 1) {
- fJavaElement = filteredMethods.get(0);
- } else {
- methods = filteredMethods;
-
- // filter methods by parameter types
- for(IMethod method : methods) {
- String[] methodParameterTypes =
- resolveSignatures(method.getDeclaringType(),
- method.getParameterTypes());
- String[] parameterTypes = getParameterTypeQualifiedNames();
-
- boolean equal = true;
- for (int i = 0; parameterTypes != null && i < parameterTypes.length; i++) {
- // simple types must be equal, but complex types may not
- if (!parameterTypes[i].equals(methodParameterTypes[i])) {
- // sure - it's Complex Type
- if (! (parameterTypes[i].indexOf('.') != -1)
- && (methodParameterTypes[i].indexOf('.') == -1)) {
- equal = false;
- break;
- }
- }
- }
- if (equal) {
- fJavaElement = method;
- }
- }
- }
- }
- }
- }
- } catch (JavaModelException e) {
- ModelPlugin.getPluginLog().logError(e);
- }
- }
- return fJavaElement;
- }
- }
-
- public TypeInfoCollector(MemberInfo member) {
- this.fMember = member;
- this.fType = member.getMemberType();
- collectInfo();
- }
-
- public IType getType() {
- return this.fType;
- }
-
- public void collectInfo() {
- if (fMethods == null) {
- fMethods = new ArrayList<MethodInfo>();
- } else {
- fMethods.clear();
- }
-
- if (fFields == null) {
- fFields = new ArrayList<FieldInfo>();
- } else {
- fFields.clear();
- }
-
- if (fType == null) {
- return;
- }
- try {
- IType binType = fType;
- MemberInfo originalParent = fMember;
- if(fMember instanceof TypeInfo) {
- fTypeInfo = (TypeInfo)fMember;
- } else {
- fTypeInfo = new TypeInfo(binType, fMember, fMember.isDataModel());
- }
- TypeInfo parent = fTypeInfo;
- while (binType != null) {
- IMethod[] binMethods = binType.getMethods();
- for (int i = 0; binMethods != null && i < binMethods.length; i++) {
- if (binMethods[i].isConstructor()) {
- continue;
- }
- fMethods.add(new MethodInfo(binMethods[i], fTypeInfo, parent, false));
- }
- binType = getSuperclass(binType);
- if(binType!=null) {
- TypeInfo superType = new TypeInfo(binType, originalParent, parent.isDataModel());
- parent.setSuperType(superType);
- parent = superType;
- }
- }
-
- // This inserts here methods "public int size()" and "public boolean isEmpty()" for javax.faces.model.DataModel
- // as requested by Gavin in JBIDE-1256
- if(isDataModelObject(fType)) {
- addInfoForDataModelObject();
- }
- // This inserts here methods "public int getRowCount()" for @DataModel variables.
- if(fMember.isDataModel) {
- addInfoForDataModelVariable();
- }
- } catch (JavaModelException e) {
- ModelPlugin.getPluginLog().logError(e);
- }
- }
-
- boolean isDataModelObject(IType type) throws JavaModelException {
- return isInstanceofType(type, "javax.faces.model.DataModel");
- }
-
- public static boolean isResourceBundle(IType type) {
- try {
- return isInstanceofType(type, "java.util.ResourceBundle");
- } catch (JavaModelException e) {
- return false;
- }
- }
-
- public static boolean isNotParameterizedCollection(TypeInfoCollector.MemberInfo mbr) {
- try {
- if(mbr.getType().getParameters()!=null && mbr.getType().getParameters().length>0) {
- return false;
- }
- IType type = mbr.getMemberType();
- if(type!=null) {
- return isInstanceofType(type, "java.util.Map") || isInstanceofType(type, "java.util.Collection");
- }
- return false;
- } catch (JavaModelException e) {
- return false;
- }
- }
-
- public static class SuperTypeInfo {
- IType type;
- Set<String> names = new HashSet<String>();
- IType[] superTypes = new IType[0];
-
- SuperTypeInfo(IType type) throws JavaModelException {
- this.type = type;
- ProjectCache cache = caches.get(type);
- if(cache != null) {
- cache.superTypesCache.put(type, this);
- }
- ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
- superTypes = typeHierarchy == null ? null : typeHierarchy.getAllSupertypes(type);
- if(superTypes != null) for (int i = 0; i < superTypes.length; i++) {
- names.add(superTypes[i].getFullyQualifiedName());
- }
- if(superTypes == null) superTypes = new IType[0];
- }
-
- public Set<String> getNames() {
- return names;
- }
-
- public IType[] getSuperTypes() {
- return superTypes;
- }
- }
-
- public static SuperTypeInfo getSuperTypes(IType type) throws JavaModelException {
- if(type == null) return null;
- ProjectCache cache = caches.get(type);
- SuperTypeInfo ts = (cache != null) ? cache.superTypesCache.get(type) : null;
- if(ts == null) {
- ts = new SuperTypeInfo(type);
- }
- return ts;
- }
-
- public static boolean isInstanceofType(IType type, String qualifiedTypeName) throws JavaModelException {
- if (qualifiedTypeName == null || type == null) return false;
- boolean isInstanceofType = qualifiedTypeName.equals(type.getFullyQualifiedName());
- if (!isInstanceofType) {
- SuperTypeInfo ts = getSuperTypes(type);
- if(ts != null && ts.getNames().contains(qualifiedTypeName)) {
- return true;
- }
- return false;
- }
- return true;
- }
-
- void addInfoForDataModelVariable() {
- fMethods.add(new MethodInfo(fType,
- fType.getFullyQualifiedName(),
- "getRowCount", Modifier.PUBLIC,
- new String[0],
- new String[0],
- "int",
- fTypeInfo,
- fTypeInfo,
- false));
- }
-
- void addInfoForDataModelObject() {
- fMethods.add(new MethodInfo(fType,
- fType.getFullyQualifiedName(),
- "size", Modifier.PUBLIC,
- new String[0],
- new String[0],
- "int",
- fTypeInfo,
- fTypeInfo,
- false));
- fMethods.add(new MethodInfo(fType,
- fType.getFullyQualifiedName(),
- "isEmpty", Modifier.PUBLIC,
- new String[0],
- new String[0],
- "boolean",
- fTypeInfo,
- fTypeInfo,
- false));
- }
-
- private static IType getSuperclass(IType type) throws JavaModelException {
- String superclassName = type.getSuperclassName();
- if(superclassName!=null) {
- String fullySuperclassName = EclipseJavaUtil.resolveType(type, superclassName);
- if(fullySuperclassName!=null&&!fullySuperclassName.equals("java.lang.Object")) { //$NON-NLS-1$
- if(fullySuperclassName.equals(type.getFullyQualifiedName())) {
- //FIX JBIDE-1642
- return null;
- }
- IType superType = type.getJavaProject().findType(fullySuperclassName);
- return superType;
- }
- }
- return null;
- }
-
- public MethodInfo[] findMethodInfos(IMethod iMethod) {
- List<MethodInfo> methods = new ArrayList<MethodInfo>();
-
- // filter methods by name
- for (MethodInfo info : fMethods) {
- if (info.getName().equals(iMethod.getElementName())) {
- methods.add(info);
- }
- }
- if (methods.isEmpty())
- return new MethodInfo[0];
-
- EclipseJavaUtil.getMemberTypeAsString(iMethod);
-
- if (methods.size() == 1)
- return methods.toArray(new MethodInfo[0]);
-
- // filter methods by number of parameters
- List<MethodInfo> filteredMethods = new ArrayList<MethodInfo>();
- for (MethodInfo method : methods) {
- if (method.getNumberOfParameters() == iMethod.getNumberOfParameters())
- filteredMethods.add(method);
- }
- if (filteredMethods.isEmpty())
- return new MethodInfo[0];
- if (filteredMethods.size() == 1)
- return filteredMethods.toArray(new MethodInfo[0]);
-
- methods = filteredMethods;
-
- // filter methods by parameter types
- filteredMethods = new ArrayList<MethodInfo>();
- for(MethodInfo method : methods) {
- String[] methodParameterTypes =
- resolveSignatures(iMethod.getDeclaringType(),
- iMethod.getParameterTypes());
- String[] parameterTypes = method.getParameterTypeQualifiedNames();
-
- boolean equal = true;
- for (int i = 0; equal && parameterTypes != null && i < parameterTypes.length; i++) {
- // simple types must be equal, but complex types may not
- if (!parameterTypes[i].equals(methodParameterTypes[i])) {
- // sure - it's Complex Type
- if ((parameterTypes[i].indexOf('.') != -1)
- && (methodParameterTypes[i].indexOf('.') == -1)) {
- equal = false;
- }
- }
- }
- if (equal) {
- filteredMethods.add(method);
- }
- }
- return filteredMethods.toArray(new MethodInfo[0]);
- }
-
- /**
- * Returns the methods for the type specified
- *
- * @return
- */
- public List<MemberInfo> getMethods() {
- List<MemberInfo> methods = new ArrayList<MemberInfo>();
- for (MethodInfo info : fMethods) {
- if (info.isPublic() && !info.isConstructor()
- && !info.isStatic() && !info.isJavaLangObject()
- && !info.isGetter() && !info.isSetter())
- methods.add(info);
- }
- return methods;
- }
-
- /**
- * String presentation of member
- * @author Alexey Kazakov
- */
- public static class MemberPresentation {
- private String presentation;
- private MemberInfo member;
-
- public MemberPresentation(String presentation, MemberInfo member) {
- super();
- this.presentation = presentation;
- this.member = member;
- }
-
- public String getPresentation() {
- return presentation;
- }
-
- public MemberInfo getMember() {
- return member;
- }
-
- @Override
- public boolean equals(Object obj) {
- if(obj!=null && obj instanceof MemberPresentation) {
- return presentation.equals(((MemberPresentation)obj).getPresentation());
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return presentation.hashCode();
- }
-
- @Override
- public String toString() {
- return presentation;
- }
- }
-
- private static class MemberPresentationComparator implements Comparator<MemberPresentation> {
- /* (non-Javadoc)
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- */
- public int compare(MemberPresentation m1, MemberPresentation m2) {
- return m1.getPresentation().compareTo(m2.getPresentation());
- }
- }
-
- public final static MemberPresentationComparator MEMBER_PRESENTATION_COMPARATOR = new MemberPresentationComparator();
-
- /**
- * Returns the method presentation strings for the type specified
- * @return
- */
- public Set<String> getMethodPresentationStrings() {
- Set<MemberPresentation> set = getMethodPresentations();
- Set<String> result = new HashSet<String>();
- for (MemberPresentation presentation : set) {
- result.add(presentation.getPresentation());
- }
- return result;
- }
-
- /**
- * Returns the method presentations for the type specified
- * @return
- */
- public Set<MemberPresentation> getMethodPresentations() {
- Set<MemberPresentation> methods = new TreeSet<MemberPresentation>(MEMBER_PRESENTATION_COMPARATOR);
- List<MemberInfo> mthds = getMethods();
- for (MemberInfo info : mthds) {
- if (!(info instanceof MethodInfo))
- continue;
-
- MethodInfo method = (MethodInfo)info;
-
- StringBuffer name = new StringBuffer(method.getName());
-
- // Add method as 'foo'
- methods.add(new MemberPresentation(name.toString(), method));
-
- // Add method as 'foo(param1,param2)'
- name.append('(');
- String[] mParams = method.getParameterNames();
- for (int j = 0; mParams != null && j < mParams.length; j++) {
- if (j > 0) name.append(", "); //$NON-NLS-1$
- name.append(mParams[j]);
- }
- name.append(')');
-
- methods.add(new MemberPresentation(name.toString(), method));
- }
- return methods;
- }
-
- /**
- * Returns the properties for the type specified
- *
- * @return
- */
- public List<MemberInfo> getProperties() {
- List<MemberInfo> properties = new ArrayList<MemberInfo>();
- for (MethodInfo info : fMethods) {
- if (info.isPublic() && !info.isConstructor()
- && !info.isStatic() && !info.isJavaLangObject()
- && (info.isGetter() || info.isSetter()))
- properties.add(info);
- }
-
- /*
- * The following code was excluded due to the following issue:
- *
- * http://jira.jboss.com/jira/browse/JBIDE-1203#action_12385823
- *
- *
- for (FieldInfo info : fFields) {
- if (info.isPublic()
- && !info.isStatic() && !info.isJavaLangObject())
- properties.add(info);
- }
- */
-
- return properties;
- }
-
- /**
- * Returns the property presentations for the type specified
- *
- * @return
- */
- public Set<MemberPresentation> getPropertyPresentations() {
- return getPropertyPresentations(null);
- }
-
- /**
- * Returns the property presentation strings for the type specified
- *
- * @return
- */
- public Set<String> getPropertyPresentationStrings() {
- return getPropertyPresentationStrings(null);
- }
-
- /**
- * Returns the property presentation strings for the type specified
- *
- * @param unpairedGettersOrSetters - map of unpaired getters or setters of type's properties. 'key' is property name.
- * @return
- */
- public Set<String> getPropertyPresentationStrings(Map<String, MethodInfo> unpairedGettersOrSetters) {
- Set<MemberPresentation> set = getPropertyPresentations(unpairedGettersOrSetters);
- Set<String> result = new HashSet<String>();
- for (MemberPresentation presentation : set) {
- result.add(presentation.getPresentation());
- }
- return result;
- }
-
- /**
- * Returns the property presentations for the type specified
- *
- * @param unpairedGettersOrSetters - map of unpaired getters or setters of type's properties. 'key' is property name.
- * @return
- */
- public Set<MemberPresentation> getPropertyPresentations(Map<String, MethodInfo> unpairedGettersOrSetters) {
- Set<MemberPresentation> properties = new TreeSet<MemberPresentation>(MEMBER_PRESENTATION_COMPARATOR);
- List<MemberInfo> props = getProperties();
- HashMap<String, MethodInfo> getters = new HashMap<String, MethodInfo>();
- HashMap<String, MethodInfo> setters = new HashMap<String, MethodInfo>();
- for (MemberInfo info : props) {
- if (info instanceof MethodInfo) {
- MethodInfo m = (MethodInfo)info;
-
- if (m.isGetter() || m.isSetter()) {
- StringBuffer name = new StringBuffer(m.getName());
- if(m.getName().startsWith("i")) { //$NON-NLS-1$
- name.delete(0, 2);
- } else {
- name.delete(0, 3);
- }
- if(name.length()<2 || Character.isLowerCase(name.charAt(1))) {
- name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
- }
- String propertyName = name.toString();
- MemberPresentation pr = new MemberPresentation(propertyName, m);
- if(!properties.contains(pr)) {
- properties.add(pr);
- }
- if(unpairedGettersOrSetters!=null) {
- MethodInfo previousGetter = getters.get(propertyName);
- MethodInfo previousSetter = setters.get(propertyName);
- if((previousGetter!=null && m.isSetter())||(previousSetter!=null && m.isGetter())) {
- // We have both Getter and Setter
- unpairedGettersOrSetters.remove(propertyName);
- } else if(m.isSetter()) {
- setters.put(propertyName, m);
- unpairedGettersOrSetters.put(propertyName, m);
- } else if(m.isGetter()) {
- getters.put(propertyName, m);
- unpairedGettersOrSetters.put(propertyName, m);
- }
- }
- }
- } else {
- properties.add(new MemberPresentation(info.getName(), info));
- }
- }
- return properties;
- }
-
- public static void cleanCache() {
- caches = new Caches();
- }
-
- public static MemberInfo createMemberInfo(IMember member, boolean dataModel) {
- ProjectCache pcache = caches.get(member);
-
- Map<IMember, MemberInfo> cache = null;
- if(pcache != null) {
- cache = dataModel ? pcache.memberInfoCacheTrue : pcache.memberInfoCacheFalse;
- }
- MemberInfo result = cache == null ? null : cache.get(member);
- if(result != null) return result;
- try {
- if (member instanceof IType) {
- result = new TypeInfo((IType)member, null, dataModel);
- } else if (member instanceof IField) {
- IField field = (IField)member;
- TypeInfo declaringType = new TypeInfo(field.getDeclaringType(), null, dataModel);
- result = new FieldInfo(field, declaringType, declaringType, dataModel);
- } else if (member instanceof IMethod) {
- IMethod method = (IMethod)member;
- TypeInfo declaringType = new TypeInfo(method.getDeclaringType(), null, dataModel);
- result = new MethodInfo(method, declaringType, declaringType, dataModel);
- }
- } catch (JavaModelException e) {
- ModelPlugin.getPluginLog().logError(e);
- }
- if(result != null) {
- cache.put(member, result);
- }
-
- return result;
- }
-
- public static MemberInfo createMemberInfo(IMember member) {
- return createMemberInfo(member, false);
- }
-
- static String[] resolveSignatures (IType type, String[] signatures) {
- if (signatures == null || signatures.length == 0)
- return new String[0];
-
- String[] resolvedSignatures = new String[signatures.length];
- for (int i = 0; i < signatures.length; i++) {
- resolvedSignatures[i] = EclipseJavaUtil.resolveTypeAsString(type, signatures[i]);
- }
- return resolvedSignatures;
- }
-
- static String[] convertToStringArray(char[][] names) {
- if (names == null || names.length == 0)
- return new String[0];
- String[] sNames = new String[names.length];
- for (int i = 0; i < sNames.length; i++) {
- sNames[i] = String.valueOf(names[i]);
- }
- return sNames;
- }
-
- static String[] getTypeErasureFromSignatureArray(String[] signatures) {
- if (signatures == null || signatures.length == 0)
- return new String[0];
- String[] result = new String[signatures.length];
- for (int i = 0; i < signatures.length; i++) {
- result[i] = Signature.getTypeErasure(signatures[i]);
- }
- return result;
- }
-
- static String getParameterNameFromType(String typeSignatures) {
- if(typeSignatures==null) {
- return null;
- }
- return Signature.getTypeVariable(typeSignatures);
- }
-}
\ No newline at end of file
15 years, 7 months
JBoss Tools SVN: r10596 - in trunk/common/plugins/org.jboss.tools.common.el.core: src/org/jboss/tools/common/el/core and 4 other directories.
by jbosstools-commits@lists.jboss.org
Author: scabanovich
Date: 2008-10-01 11:31:11 -0400 (Wed, 01 Oct 2008)
New Revision: 10596
Added:
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserUtil.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELCompletionEngine.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELOperandResolveStatus.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ElVarSearcher.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/Var.java
Modified:
trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/Activator.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELModel.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserFactory.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/LexicalToken.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/TokenizerFactory.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELModelImpl.java
trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELObjectImpl.java
Log:
JBIDE-1497.
Refactoring
Modified: trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF 2008-10-01 15:26:10 UTC (rev 10595)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/META-INF/MANIFEST.MF 2008-10-01 15:31:11 UTC (rev 10596)
@@ -7,10 +7,16 @@
Bundle-Version: 2.0.0
Provide-Package: org.jboss.tools.common.el.core,
org.jboss.tools.common.el.core.model,
- org.jboss.tools.common.el.core.parser
+ org.jboss.tools.common.el.core.parser,
+ org.jboss.tools.common.el.core.resolver
Bundle-Activator: org.jboss.tools.common.el.core.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources,
+ org.eclipse.jdt.core,
org.eclipse.jface.text,
+ org.eclipse.wst.sse.core,
+ org.eclipse.wst.sse.ui,
+ org.jboss.tools.common,
+ org.jboss.tools.common.model,
org.jboss.tools.common.resref.core;reprovide=true
Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/Activator.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/Activator.java 2008-10-01 15:26:10 UTC (rev 10595)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/Activator.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -10,13 +10,14 @@
******************************************************************************/
package org.jboss.tools.common.el.core;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.jboss.tools.common.log.BaseUIPlugin;
+import org.jboss.tools.common.log.IPluginLog;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
-public class Activator extends AbstractUIPlugin {
+public class Activator extends BaseUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.jboss.tools.common.el";
@@ -57,4 +58,8 @@
return plugin;
}
+ public static IPluginLog getPluginLog() {
+ return getDefault();
+ }
+
}
Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELModel.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELModel.java 2008-10-01 15:26:10 UTC (rev 10595)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/model/ELModel.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -25,4 +25,6 @@
public List<ELInstance> getInstances();
+ public void shift(int delta);
+
}
Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserFactory.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserFactory.java 2008-10-01 15:26:10 UTC (rev 10595)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserFactory.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -10,58 +10,13 @@
******************************************************************************/
package org.jboss.tools.common.el.core.parser;
-import java.util.List;
-
-import org.jboss.tools.common.el.core.model.ELModel;
-import org.jboss.tools.common.el.internal.core.model.ELModelImpl;
-import org.jboss.tools.common.el.internal.core.parser.ELParserImpl;
-
/**
*
* @author V. Kabanovich
*
*/
-public class ELParserFactory {
+public interface ELParserFactory {
- public static ELParser createDefaultParser() {
- return new DefaultParser() {
- protected Tokenizer createTokenizer() {
- return TokenizerFactory.createDefaultTokenizer();
- }
- };
- }
+ public ELParser createParser();
- public static ELParser createJbossParser() {
- return new DefaultParser() {
- protected Tokenizer createTokenizer() {
- return TokenizerFactory.createJbossTokenizer();
- }
- };
- }
-
- private static abstract class DefaultParser implements ELParser {
- ELParserImpl impl = new ELParserImpl();
- List<SyntaxError> errors = null;
-
- public ELModel parse(String source) {
- return parse(source, 0, source.length());
- }
-
- public ELModel parse(String source, int start, int length) {
- Tokenizer t = createTokenizer();
- LexicalToken token = t.parse(source, start, length);
- errors = t.getErrors();
- ELModelImpl model = impl.parse(token);
- model.setSource(source);
- model.setErrors(errors);
- return model;
- }
-
- public List<SyntaxError> getSyntaxErrors() {
- return errors;
- }
-
- protected abstract Tokenizer createTokenizer();
- }
-
}
Added: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserUtil.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserUtil.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/ELParserUtil.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.el.core.parser;
+
+import java.util.List;
+
+import org.jboss.tools.common.el.core.model.ELModel;
+import org.jboss.tools.common.el.internal.core.model.ELModelImpl;
+import org.jboss.tools.common.el.internal.core.parser.ELParserImpl;
+
+/**
+ *
+ * @author V. Kabanovich
+ *
+ */
+public class ELParserUtil {
+
+ public static ELParserFactory getDefaultFactory() {
+ return new ELParserFactory() {
+ public ELParser createParser() {
+ return new DefaultParser() {
+ protected Tokenizer createTokenizer() {
+ return TokenizerFactory.createDefaultTokenizer();
+ }
+ };
+ }
+ };
+ }
+
+ public static ELParserFactory getJbossFactory() {
+ return new ELParserFactory() {
+ public ELParser createParser() {
+ return new DefaultParser() {
+ protected Tokenizer createTokenizer() {
+ return TokenizerFactory.createJbossTokenizer();
+ }
+ };
+ }
+ };
+ }
+
+ private static abstract class DefaultParser implements ELParser {
+ ELParserImpl impl = new ELParserImpl();
+ List<SyntaxError> errors = null;
+
+ public ELModel parse(String source) {
+ return parse(source, 0, source.length());
+ }
+
+ public ELModel parse(String source, int start, int length) {
+ Tokenizer t = createTokenizer();
+ LexicalToken token = t.parse(source, start, length);
+ errors = t.getErrors();
+ ELModelImpl model = impl.parse(token);
+ model.setSource(source);
+ model.setErrors(errors);
+ return model;
+ }
+
+ public List<SyntaxError> getSyntaxErrors() {
+ return errors;
+ }
+
+ protected abstract Tokenizer createTokenizer();
+ }
+
+}
Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/LexicalToken.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/LexicalToken.java 2008-10-01 15:26:10 UTC (rev 10595)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/LexicalToken.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -138,4 +138,9 @@
return next.findTokenForward(type);
}
+ public void shift(int delta) {
+ start += delta;
+ if(next != null) next.shift(delta);
+ }
+
}
Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/TokenizerFactory.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/TokenizerFactory.java 2008-10-01 15:26:10 UTC (rev 10595)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/parser/TokenizerFactory.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -13,6 +13,7 @@
import java.util.List;
import org.jboss.tools.common.el.core.model.ELExpression;
+import org.jboss.tools.common.el.core.model.ELInstance;
import org.jboss.tools.common.el.core.model.ELInvocationExpression;
import org.jboss.tools.common.el.core.model.ELModel;
import org.jboss.tools.common.el.core.model.ELUtil;
@@ -101,13 +102,14 @@
}
public static void main(String[] args) {
- String text = "#{g11.g12.y13} #{a14.b15(x.t.u(uu.ii[9], j)).b16(m17(v18(i19[2]).u20).)+ a21(c.).b.}";
+ String text = "#{.8 +(.9d / - (-.8))}";
+//"#{g11.g12.y13} #{#{ #{a14.b15(x.t.u(uu.ii[9], j)).b16(m17(v18(i19[2]).u20).)+ a21(c.).b.}";
//"#{not a.b(x,y) + s.h((6 != -8) & (7 + -iy88.g[9].h(7 div 8).i.j)+(8) ? 4 : 7,'p', a.b.c.d[null])}";
//"q82#{a( g.h(7 + 8) + 8, g['h'].j(),'p')}k#{b}";
Tokenizer t = createJbossTokenizer();
LexicalToken token = t.parse(text);
LexicalToken ti = token;
-
+
while(ti != null) {
int type = ti.getType();
System.out.println(type + ":" + ti.getText() + ":");
@@ -117,9 +119,10 @@
for (SyntaxError e: errors) {
System.out.println("state=" + e.getState() + " position=" + e.getPosition());
}
- ELParser parser = ELParserFactory.createJbossParser();
- ELModel model = parser.parse(text, 0, 13);
+ ELParser parser = ELParserUtil.getJbossFactory().createParser();
+ ELModel model = parser.parse(text, 0, 90);
System.out.println(model);
+
ELExpression expr = model.getInstances().get(0).getExpression();
System.out.println("Expression=" + expr);
List<ELInvocationExpression> is = expr.getInvocations();
Added: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELCompletionEngine.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELCompletionEngine.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELCompletionEngine.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -0,0 +1,26 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.el.core.resolver;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.text.BadLocationException;
+import org.jboss.tools.common.el.core.model.ELExpression;
+import org.jboss.tools.common.el.core.parser.ELParserFactory;
+
+public interface ELCompletionEngine {
+
+ public ELOperandResolveStatus resolveELOperand(IFile file, ELExpression operand,
+ boolean returnEqualedVariablesOnly, List<Var> vars, ElVarSearcher varSearcher) throws BadLocationException, StringIndexOutOfBoundsException;
+
+ public ELParserFactory getParserFactory();
+}
Added: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELOperandResolveStatus.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELOperandResolveStatus.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ELOperandResolveStatus.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -0,0 +1,165 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.el.core.resolver;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.jboss.tools.common.el.core.model.ELInvocationExpression;
+
+/**
+ * Status of EL resolving.
+ * @author Jeremy
+ */
+public class ELOperandResolveStatus {
+ private ELInvocationExpression tokens;
+ Map<String, TypeInfoCollector.MethodInfo> unpairedGettersOrSetters;
+ Set<String> proposals;
+ private ELInvocationExpression lastResolvedToken;
+ private boolean isMapOrCollectionOrBundleAmoungTheTokens = false;
+ private TypeInfoCollector.MemberInfo memberOfResolvedOperand;
+
+ /**
+ * @return MemberInfo of last segment of EL operand. Null if El is not resolved.
+ */
+ public TypeInfoCollector.MemberInfo getMemberOfResolvedOperand() {
+ return memberOfResolvedOperand;
+ }
+
+ /**
+ * Sets MemberInfo for last segment of EL operand.
+ * @param lastResolvedMember
+ */
+ public void setMemberOfResolvedOperand(
+ TypeInfoCollector.MemberInfo lastResolvedMember) {
+ this.memberOfResolvedOperand = lastResolvedMember;
+ }
+
+ /**
+ * Constructor
+ * @param tokens Tokens of EL
+ */
+ public ELOperandResolveStatus(ELInvocationExpression tokens) {
+ this.tokens = tokens;
+ }
+
+ /**
+ * @return true if EL contains any not parametrized Collection or ResourceBundle.
+ */
+ public boolean isMapOrCollectionOrBundleAmoungTheTokens() {
+ return this.isMapOrCollectionOrBundleAmoungTheTokens;
+ }
+
+ public void setMapOrCollectionOrBundleAmoungTheTokens() {
+ this.isMapOrCollectionOrBundleAmoungTheTokens = true;
+ }
+
+ /**
+ * @return true if EL is resolved.
+ */
+ public boolean isOK() {
+ return !getProposals().isEmpty() || isMapOrCollectionOrBundleAmoungTheTokens();
+ }
+
+ /**
+ * @return false if El is not resolved.
+ */
+ public boolean isError() {
+ return !isOK();
+ }
+
+ /**
+ * @return List of resolved tokens of EL. Includes separators "."
+ */
+ public ELInvocationExpression getResolvedTokens() {
+ return lastResolvedToken;
+ }
+
+ /**
+ * @return List of unresolved tokens of EL.
+ */
+ public ELInvocationExpression getUnresolvedTokens() {
+ if(lastResolvedToken == tokens) return null;
+ if(lastResolvedToken != null && (lastResolvedToken.getParent() instanceof ELInvocationExpression)) {
+ return (ELInvocationExpression)lastResolvedToken.getParent();
+ }
+ ELInvocationExpression l = tokens;
+ while(l != null && l.getLeft() != lastResolvedToken) {
+ l = l.getLeft();
+ }
+ return l;
+ }
+
+ /**
+ * @return Last resolved token of EL. Can be separator "." // no, change it
+ */
+ public ELInvocationExpression getLastResolvedToken() {
+ return lastResolvedToken;
+ }
+
+ /**
+ * @param lastResolvedToken Last resolved token of EL. Can be separator "."
+ */
+ public void setLastResolvedToken(ELInvocationExpression lastResolvedToken) {
+ this.lastResolvedToken = lastResolvedToken;
+ }
+
+ /**
+ * @return Tokens of EL.
+ */
+ public ELInvocationExpression getTokens() {
+ return tokens;
+ }
+
+ /**
+ * @param tokens Tokens of EL.
+ */
+ public void setTokens(ELInvocationExpression tokens) {
+ this.tokens = tokens;
+ }
+
+ /**
+ * @return Set of proposals for EL.
+ */
+ public Set<String> getProposals() {
+ return proposals == null ? new TreeSet<String>() : proposals;
+ }
+
+ /**
+ * @param proposals Set of proposals.
+ */
+ public void setProposals(Set<String> proposals) {
+ this.proposals = proposals;
+ }
+
+ /**
+ * @return Map of unpaired getters and setters (getters/setters without proper setters/getters).
+ * of all properties used in EL.
+ * Key - name of property.
+ * Value - MethodInfo of existed getter/setter.
+ */
+ public Map<String, TypeInfoCollector.MethodInfo> getUnpairedGettersOrSetters() {
+ if (unpairedGettersOrSetters == null) {
+ unpairedGettersOrSetters = new HashMap<String, TypeInfoCollector.MethodInfo>();
+ }
+ return unpairedGettersOrSetters;
+ }
+
+ /**
+ * Clear Map of unpaired getters and setters.
+ */
+ public void clearUnpairedGettersOrSetters() {
+ getUnpairedGettersOrSetters().clear();
+ }
+
+}
Copied: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ElVarSearcher.java (from rev 10526, trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ElVarSearcher.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/ElVarSearcher.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -0,0 +1,284 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.el.core.resolver;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMAttr;
+import org.jboss.tools.common.el.core.Activator;
+import org.jboss.tools.common.el.core.model.ELExpression;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * This class helps to find var/value attributes in DOM tree.
+ * @author Alexey Kazakov
+ */
+public class ElVarSearcher {
+
+ private final static String VAR_ATTRIBUTE_NAME = "var";
+ private final static String VALUE_ATTRIBUTE_NAME = "value";
+
+ private IFile file;
+ private ELCompletionEngine engine;
+
+ /**
+ * Constructor.
+ * @param project Seam project where we will look for vars.
+ * @param file File where we will look for vars.
+ * @param engine Competion Engine that we will use for resolving vars.
+ */
+ public ElVarSearcher(IFile file, ELCompletionEngine engine) {
+ this.file = file;
+ this.engine = engine;
+ }
+
+ /**
+ * Constructor.
+ * @param project Seam project where we will look for vars.
+ * @param engine Competion Engine that we will use for resolving vars.
+ */
+ public ElVarSearcher(ELCompletionEngine engine) {
+ this(null, engine);
+ }
+
+ /**
+ * @param file File where we will look for vars.
+ */
+ public void setFile(IFile file) {
+ this.file = file;
+ }
+
+ /**
+ * @param viewer
+ * @param offset
+ * @return
+ */
+ public static Node getNode(ITextViewer viewer, int offset) {
+ IndexedRegion treeNode = ContentAssistUtils.getNodeAt(viewer, offset);
+ if(treeNode instanceof Node) {
+ return (Node)treeNode;
+ }
+ return null;
+ }
+
+ /**
+ * @param viewer
+ * @param offset
+ * @return
+ */
+
+ public static Node getNode(IFile file, int offset) {
+ IndexedRegion treeNode = getNodeAt(file, offset);
+ if(treeNode instanceof Node) {
+ return (Node)treeNode;
+ }
+ return null;
+ }
+
+ /**
+ * Returns the closest IndexedRegion for the offset and viewer allowing
+ * for differences between viewer offsets and model positions. note: this
+ * method returns an IndexedRegion for read only
+ *
+ * @param file
+ * the file whose document is used to compute the proposals
+ * @param documentOffset
+ * an offset within the document for which completions should
+ * be computed
+ * @return an IndexedRegion
+ */
+
+ public static IndexedRegion getNodeAt(IFile file, int documentOffset) {
+
+ if (file == null)
+ return null;
+
+ IndexedRegion node = null;
+ IModelManager mm = StructuredModelManager.getModelManager();
+ IStructuredModel model = null;
+ if (mm != null) {
+ try {
+ model = mm.getModelForRead(file);
+ } catch (IOException e) {
+ return null;
+ } catch (CoreException e) {
+ return null;
+ }
+ }
+ try {
+ if (model != null) {
+ int lastOffset = documentOffset;
+ node = model.getIndexedRegion(documentOffset);
+ while (node == null && lastOffset >= 0) {
+ lastOffset--;
+ node = model.getIndexedRegion(lastOffset);
+ }
+ }
+ } finally {
+ if (model != null)
+ model.releaseFromRead();
+ }
+ return node;
+ }
+
+ /**
+ * @param node
+ * @return All var/value that can be used in this position and null if can't find anyone.
+ */
+ public List<Var> findAllVars(ITextViewer viewer, int offset) {
+ Node node = getNode(viewer, offset);
+ if(node!=null) {
+ return findAllVars(node);
+ }
+ return null;
+ }
+
+ /**
+ * @param node
+ * @return All var/value that can be used in this position and null if can't find anyone.
+ */
+ public List<Var> findAllVars(IFile file, int offset) {
+ Node node = getNode(file, offset);
+ if(node!=null) {
+ return findAllVars(node);
+ }
+ return null;
+ }
+
+ /**
+ * @param node
+ * @return All var/value that can be used in node and null if can't find anyone.
+ */
+ public List<Var> findAllVars(Node node) {
+ ArrayList<Var> vars = null;
+ Node parentNode = node.getParentNode();
+ while(parentNode!=null) {
+ Var var = findVar(parentNode);
+ if(var!=null) {
+ if(vars == null) {
+ vars = new ArrayList<Var>();
+ }
+ vars.add(0, var);
+ }
+ parentNode = parentNode.getParentNode();
+ }
+ return vars;
+ }
+
+ /**
+ * @param node
+ * @return found var/value that can be used in this position and null if can't find anyone.
+ */
+ public Var findVar(IFile file, int offset) {
+ Node node = getNode(file, offset);
+ if(node!=null) {
+ return findVar(node);
+ }
+ return null;
+ }
+
+ /**
+ * Finds var/value attribute in node
+ * @param node
+ * @param vars
+ * @return found var/value or null
+ */
+ public Var findVar(Node node) {
+ if(node!=null && Node.ELEMENT_NODE == node.getNodeType()) {
+ Element element = (Element)node;
+ String var = element.getAttribute(VAR_ATTRIBUTE_NAME);
+ if(var!=null) {
+ int declOffset = 0;
+ int declLength = 0;
+ Node varAttr = element.getAttributeNode(VAR_ATTRIBUTE_NAME);
+ if (varAttr instanceof IDOMAttr) {
+ int varNameStart = ((IDOMAttr)varAttr).getNameRegionStartOffset();
+ int varNameEnd = ((IDOMAttr)varAttr).getNameRegionEndOffset();
+ declOffset = varNameStart;
+ declLength = varNameEnd - varNameStart;
+ }
+ var = var.trim();
+ if(!"".equals(var)) {
+ String value = element.getAttribute(VALUE_ATTRIBUTE_NAME);
+ if(value!=null) {
+ value = value.trim();
+ Var newVar = new Var(engine.getParserFactory(), var, value, declOffset, declLength);
+ if(newVar.getElToken()!=null) {
+ return newVar;
+ }
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Finds var in list of vars that is used in given EL.
+ * @param el EL without brackets.
+ * @param vars
+ * @param initializeNestedVars
+ * @return
+ */
+ public Var findVarForEl(String el, List<Var> vars, boolean initializeNestedVars) {
+ if(vars!=null) {
+ ArrayList<Var> parentVars = new ArrayList<Var>();
+ for (Var var : vars) {
+ ELExpression token = var.getElToken();
+ if(token!=null && !token.getText().endsWith(".")) {
+ String varName = var.getName();
+ if(el.startsWith(varName)) { //TODO it was el.equals(varName) and did not work. Why?
+ if(var.getElToken()!=null && initializeNestedVars) {
+ Var parentVar = findVarForEl(var.getElToken().getText(), parentVars, true);
+ if(parentVar!=null) {
+ ELExpression resolvedToken = parentVar.getResolvedElToken();
+ if(resolvedToken==null && parentVar.getElToken()!=null) {
+ try {
+ // Initialize parent vars.
+ engine.resolveELOperand(file, var.getElToken(), true, parentVars, this);
+ resolvedToken = parentVar.getResolvedElToken();
+ } catch (StringIndexOutOfBoundsException e) {
+ Activator.getPluginLog().logError(e);
+ } catch (BadLocationException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+ if(resolvedToken!=null) {
+ String oldText = var.getElToken().getText();
+ String newValue = "#{" + resolvedToken.getText() + oldText.substring(parentVar.getName().length()) + "}";
+ var.value = newValue;
+ var.elToken = var.parseEl(newValue);
+ }
+ }
+ }
+ return var;
+ }
+ }
+ parentVars.add(var);
+ }
+ }
+ return null;
+ }
+
+}
Copied: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java (from rev 10439, trunk/common/plugins/org.jboss.tools.common.model/src/org/jboss/tools/common/model/util/TypeInfoCollector.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/TypeInfoCollector.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -0,0 +1,1236 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.common.el.core.resolver;
+
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.ITypeHierarchy;
+import org.eclipse.jdt.core.ITypeParameter;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
+import org.jboss.tools.common.el.core.Activator;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+
+/**
+ * This class helps to collect information of java elements used in Seam EL.
+ * @author Viktor Rubezhny, Alexey Kazakov
+ */
+public class TypeInfoCollector {
+ IType fType;
+ MemberInfo fMember;
+ TypeInfo fTypeInfo;
+ List<MethodInfo> fMethods;
+ List<FieldInfo> fFields;
+
+ private static class ProjectCache {
+ Map<IMember, MemberInfo> memberInfoCacheFalse = new HashMap<IMember, MemberInfo>();
+ Map<IMember, MemberInfo> memberInfoCacheTrue = new HashMap<IMember, MemberInfo>();
+ Map<IType, SuperTypeInfo> superTypesCache = new HashMap<IType, SuperTypeInfo>();
+ }
+
+ private static Caches caches = new Caches();
+
+ private static class Caches {
+ ProjectCache common = new ProjectCache();
+// Map<IProject, ProjectCache> cache = new HashMap<IProject, ProjectCache>();
+
+ public boolean contains(IProject p) {
+// return p != null && cache.containsKey(p);
+ return true;
+ }
+
+ public void clean(IProject p) {
+// if(contains(p)) {
+// cache.remove(p);
+// }
+ common = new ProjectCache();
+ }
+
+ public ProjectCache get(IProject p) {
+ if(p == null || !p.isAccessible()) return null;
+ return common;
+// ProjectCache c = cache.get(p);
+// if(c == null) {
+// c = new ProjectCache();
+// cache.put(p, c);
+// }
+// return c;
+ }
+
+ public ProjectCache get(IJavaElement element) {
+ if(element == null) {
+ return null;
+ }
+ IJavaProject jp = element.getJavaProject();
+ IProject p = jp == null ? null : jp.getProject();
+ return get(p);
+ }
+ }
+
+ public static class Type {
+ private String fName;
+ private String fQualifiedName;
+ private Type[] fParameters;
+ private IType fSource;
+ private String fSignature;
+ private boolean fIsArray;
+ private Type fTypeOfArrayElement;
+ private String fQualifiedTypeNameOfArrayElement;
+
+ private Type() {
+ }
+
+ public static Type valueOf(String name) {
+ Type instance = new Type();
+ instance.setName(name);
+ instance.setParameters(new Type[0]);
+ return instance;
+ }
+
+ public Type(String signature, IType source) {
+ if(signature!=null) {
+ String erasureSignature = Signature.getTypeErasure(signature);
+ String typeOfArraySiganture = Signature.getElementType(erasureSignature);
+ fName = String.valueOf(Signature.toString(erasureSignature));
+ if(!erasureSignature.equals(typeOfArraySiganture)) {
+ // this is an array
+ fIsArray = true;
+ fTypeOfArrayElement = new Type(typeOfArraySiganture, source);
+ }
+ String[] signaturesOfParametersOfType = Signature.getTypeArguments(signature);
+ fParameters = new Type[signaturesOfParametersOfType.length];
+ for (int i = 0; i < signaturesOfParametersOfType.length; i++) {
+ fParameters[i] = new Type(signaturesOfParametersOfType[i], source);
+ }
+ } else {
+ fName = source.getFullyQualifiedName();
+ setParameters(new Type[0]);
+ }
+ fSource = source;
+ }
+
+ public void initializeParameters(Map<String, Type> parameters) {
+ Type type = parameters.get(fName);
+ if(type!=null) {
+ fName = type.getName();
+ fParameters = type.getParameters();
+ fSource = type.getSource();
+ fIsArray = type.isArray();
+ fTypeOfArrayElement = type.getTypeOfArrayElement();
+ }
+ for (int i = 0; i < fParameters.length; i++) {
+ fParameters[i].initializeParameters(parameters);
+ }
+ }
+
+ public Type getParameter(int index) {
+ if(fParameters.length>index) {
+ return fParameters[index];
+ }
+ return null;
+ }
+
+ public String getQualifiedTypeNameOfArrayElement() {
+ if(fQualifiedTypeNameOfArrayElement==null && fSource!=null) {
+ fQualifiedTypeNameOfArrayElement = EclipseJavaUtil.resolveType(fSource, fTypeOfArrayElement.getName());
+ }
+ return fQualifiedTypeNameOfArrayElement;
+ }
+
+ public String getQualifiedName() {
+ if(fQualifiedName == null && fSource!=null) {
+ fQualifiedName = EclipseJavaUtil.resolveType(fSource, fName);
+ }
+ return fQualifiedName;
+ }
+
+ public boolean isArray() {
+ return fIsArray;
+ }
+
+ public void setArray(boolean array) {
+ fIsArray = array;
+ }
+
+ public Type getTypeOfArrayElement() {
+ return fTypeOfArrayElement;
+ }
+
+ public void setTypeOfArrayElement(Type typeOfArrayElement) {
+ fTypeOfArrayElement = typeOfArrayElement;
+ }
+
+ public String getName() {
+ return fName;
+ }
+
+ public void setName(String name) {
+ fName = name;
+ }
+
+ public Type[] getParameters() {
+ return fParameters;
+ }
+
+ public void setParameters(Type[] parameters) {
+ this.fParameters = parameters;
+ }
+
+ public IType getSource() {
+ return fSource;
+ }
+
+ public void setSource(IType source) {
+ this.fSource = source;
+ }
+
+ public String getSignature() {
+ return fSignature;
+ }
+
+ public void setSignature(String signature) {
+ this.fSignature = signature;
+ }
+ }
+
+ public abstract static class MemberInfo {
+ private String fDeclaringTypeQualifiedName;
+ private String fName;
+ private int fModifiers;
+ private IType fSourceType;
+ private MemberInfo fParentMember;
+ private IType fMemberType;
+ private boolean isDataModel;
+ private Type fType;
+
+ protected MemberInfo (
+ IType sourceType,
+ String declaringTypeQualifiedName, String name, int modifiers, MemberInfo parentMember, boolean dataModel, Type type) {
+ setSourceType(sourceType);
+ setDeclaringTypeQualifiedName(declaringTypeQualifiedName);
+ setName(name);
+ setModifiers(modifiers);
+ setParentMember(parentMember);
+ setDataModel(dataModel);
+ setType(type);
+ }
+
+ abstract void initializeParameters();
+
+ protected void setType(Type type) {
+ fType = type;
+ }
+
+ public Type getType() {
+ return fType;
+ }
+
+ public void setSourceType(IType sourceType) {
+ fSourceType = sourceType;
+ }
+
+ public IType getSourceType() {
+ return fSourceType;
+ }
+
+ protected void setName (String name) {
+ this.fName = name;
+ }
+
+ public String getName() {
+ return fName;
+ }
+
+ protected void setDeclaringTypeQualifiedName(String declaringTypeQualifiedName) {
+ this.fDeclaringTypeQualifiedName = declaringTypeQualifiedName;
+ }
+
+ public String getDeclaringTypeQualifiedName() {
+ return fDeclaringTypeQualifiedName;
+ }
+
+ protected void setModifiers (int modifiers) {
+ this.fModifiers = modifiers;
+ }
+
+ public int getModifiers() {
+ return fModifiers;
+ }
+
+ public boolean isPublic() {
+ return Modifier.isPublic(fModifiers);
+ }
+
+ public boolean isStatic() {
+ return Modifier.isStatic(fModifiers);
+ }
+
+ public boolean isJavaLangObject() {
+ return "java.lang.Object".equals(getDeclaringTypeQualifiedName());
+ }
+
+ public MemberInfo getParentMember() {
+ return fParentMember;
+ }
+
+ protected void setParentMember(MemberInfo parentMember) {
+ fParentMember = parentMember;
+ }
+
+ public IType getMemberType() {
+ if(fMemberType==null) {
+ initializeParameters();
+ try {
+ if(isDataModel() && getType().isArray()) {
+ fMemberType = getSourceType().getJavaProject().findType(getType().getQualifiedTypeNameOfArrayElement());
+ } else if(getType().getQualifiedName()!=null) {
+ fMemberType = getSourceType().getJavaProject().findType(getType().getQualifiedName());
+ }
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+ return fMemberType;
+ }
+
+ public boolean isDataModel() {
+ return isDataModel;
+ }
+
+ protected void setDataModel(boolean isDataModel) {
+ this.isDataModel = isDataModel;
+ }
+
+ public TypeInfoCollector getTypeCollector() {
+ // The rev. 7651 results in a deadlock, typeInfo is not stored anymore
+ // The rev. 7623 results in a deadlock, so, it's rolled back
+ // >>> Fix for JBIDE-2090
+ return new TypeInfoCollector(this);
+ // <<< Fix for JBIDE-2090
+ }
+
+ abstract public IJavaElement getJavaElement();
+ }
+
+ public static class TypeInfo extends MemberInfo {
+ private IType fType;
+ private TypeInfo superType;
+ private Map<String, Type> params = new HashMap<String, Type>();
+
+ public TypeInfo(IType type, MemberInfo parentMember, boolean dataModel) throws JavaModelException {
+ super(type.getDeclaringType(),
+ (type.getDeclaringType() == null ? null : type.getDeclaringType().getFullyQualifiedName()),
+ type.getFullyQualifiedName(),
+ type.getFlags(),
+ parentMember,
+ dataModel,
+ Type.valueOf(type.getFullyQualifiedName()));
+ this.fType = type;
+ }
+
+ public Type getParameterType(String name) {
+ return params.get(name);
+ }
+
+ @Override
+ public IType getMemberType() {
+ return fType;
+ }
+
+ @Override
+ public IJavaElement getJavaElement() {
+ return fType;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.common.model.util.TypeInfoCollector.MemberInfo#initializeParameters()
+ */
+ @Override
+ void initializeParameters() {
+ try {
+ MemberInfo parent = getParentMember();
+ if(parent!=null && parent instanceof TypeMemberInfo) {
+ ITypeParameter[] parameters = fType.getTypeParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ Type type = parent.getType().getParameter(i);
+ if(type!=null) {
+ params.put(parameters[i].getElementName(), type);
+ }
+ }
+ }
+ if(superType!=null) {
+ superType.initializeParameters(this);
+ }
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+
+ private void initializeParameters(TypeInfo inheritedType) throws JavaModelException {
+ ITypeParameter[] parameters = fType.getTypeParameters();
+ String signature = inheritedType.fType.getSuperclassTypeSignature();
+ Type classType = new Type(signature, inheritedType.fType);
+ for (int i = 0; i < parameters.length; i++) {
+ Type paramType = classType.getParameter(i);
+ if(paramType!=null) {
+ Type resolvedType = inheritedType.getParameterType(paramType.getName());
+ if(resolvedType!=null) {
+ paramType = resolvedType;
+ }
+ params.put(parameters[i].getElementName(), paramType);
+ }
+ }
+ if(superType!=null) {
+ superType.initializeParameters(this);
+ }
+ }
+
+ public TypeInfo getSuperType() {
+ return superType;
+ }
+
+ public void setSuperType(TypeInfo superType) {
+ this.superType = superType;
+ }
+ }
+
+ public abstract static class TypeMemberInfo extends MemberInfo {
+ private String[] fParametersNamesOfDeclaringType;
+ private TypeInfo declaratedType;
+
+ /**
+ * @param sourceType
+ * @param declaringTypeQualifiedName
+ * @param name
+ * @param modifiers
+ * @param parentMember
+ * @param dataModel
+ * @param type
+ */
+ protected TypeMemberInfo(IType sourceType,
+ String declaringTypeQualifiedName, String name, int modifiers,
+ TypeInfo parentMember, TypeInfo declaratedType, boolean dataModel, Type type) {
+ super(sourceType, declaringTypeQualifiedName, name, modifiers, parentMember,
+ dataModel, type);
+ this.declaratedType = declaratedType;
+ }
+
+ public String[] getParametersNamesOfDeclaringType() {
+ return fParametersNamesOfDeclaringType;
+ }
+
+ void setParametersNamesOfDeclaringType(
+ String[] parametersNamesOfDeclaringType) {
+ fParametersNamesOfDeclaringType = parametersNamesOfDeclaringType;
+ }
+
+ protected void initializeParameters() {
+ if(fParametersNamesOfDeclaringType!=null && fParametersNamesOfDeclaringType.length>0 && getParentMember()!=null) {
+ Map<String, Type> parametersOfDeclaringType = new HashMap<String, Type>();
+ TypeInfo parentTypeInfo = (TypeInfo)getParentMember();
+ parentTypeInfo.initializeParameters();
+ for (int i = 0; i < fParametersNamesOfDeclaringType.length; i++) {
+ String parameterName = getParameterNameFromType(fParametersNamesOfDeclaringType[i]);
+ Type paramType = declaratedType.getParameterType(parameterName);
+ if(paramType!=null) {
+ parametersOfDeclaringType.put(parameterName, paramType);
+ }
+ }
+ getType().initializeParameters(parametersOfDeclaringType);
+ }
+ }
+
+ public TypeInfo getDeclaratedType() {
+ return declaratedType;
+ }
+
+ protected void setDeclaratedType(TypeInfo declaratedType) {
+ this.declaratedType = declaratedType;
+ }
+ }
+
+ public static class FieldInfo extends TypeMemberInfo {
+ private IJavaElement fJavaElement;
+
+ public FieldInfo(IField field, TypeInfo parentMember, TypeInfo declaratedType, boolean dataModel) throws JavaModelException {
+ super(field.getDeclaringType(),
+ (field.getDeclaringType() == null ? null : field.getDeclaringType().getFullyQualifiedName()),
+ field.getElementName(),
+ field.getFlags(),
+ parentMember,
+ declaratedType,
+ dataModel,
+ new Type(field.getTypeSignature(),
+ field.getDeclaringType()));
+
+ setParametersNamesOfDeclaringType(getTypeErasureFromSignatureArray(field.getDeclaringType().getTypeParameterSignatures()));
+ }
+
+ public IJavaElement getJavaElement () {
+ if(fJavaElement == null) {
+ try {
+ if(getDeclaringTypeQualifiedName()==null) {
+ return null;
+ }
+ IType declType = getSourceType().getJavaProject().findType(getDeclaringTypeQualifiedName());
+ fJavaElement = (declType == null ? null : declType.getField(getName()));
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+ return fJavaElement;
+ }
+ }
+
+ public static class MethodInfo extends TypeMemberInfo {
+ private String[] fParameterTypeNames;
+ private String[] fParameterTypeQualifiedNames;
+ private String[] fParameterNames;
+ private IJavaElement fJavaElement;
+
+ public MethodInfo(IType sourceType, String declaringTypeQualifiedName, String name,
+ int modifiers, String[] parameterTypeQualifiedNames,
+ String[] parameterNames,
+ String returnTypeQualifiedName,
+ TypeInfo parentMember,
+ TypeInfo declaratedType,
+ boolean dataModel) {
+ super(sourceType, declaringTypeQualifiedName, name, modifiers, parentMember, declaratedType, dataModel, Type.valueOf(name));
+ setParameterTypeNames(parameterTypeQualifiedNames);
+ setParameterNames(parameterNames);
+ }
+
+ public MethodInfo(IMethod method, TypeInfo parentMember, TypeInfo declaratedType, boolean dataModel) throws JavaModelException {
+ super(method.getDeclaringType(),
+ (method.getDeclaringType() == null ? null : method.getDeclaringType().getFullyQualifiedName()),
+ method.getElementName(),
+ method.getFlags(),
+ parentMember,
+ declaratedType,
+ dataModel,
+ new Type(method.getReturnType(),
+ method.getDeclaringType()));
+
+ setParameterNames(method.getParameterNames());
+ setParameterTypeNames(resolveSignatures(method.getDeclaringType(), method.getParameterTypes()));
+ setParametersNamesOfDeclaringType(getTypeErasureFromSignatureArray(method.getDeclaringType().getTypeParameterSignatures()));
+ }
+
+ protected void setParameterTypeNames(String[] parameterTypeNames) {
+ fParameterTypeNames = (parameterTypeNames == null ?
+ new String[0] : parameterTypeNames);
+ }
+
+ public String[] getParameterTypeQualifiedNames() {
+ if(fParameterTypeQualifiedNames==null) {
+ fParameterTypeQualifiedNames = new String[fParameterTypeNames.length];
+ for (int i = 0; i < fParameterTypeQualifiedNames.length; i++) {
+ fParameterTypeQualifiedNames[i] = EclipseJavaUtil.resolveType(getSourceType(), fParameterTypeNames[i]);
+ }
+ }
+ return fParameterTypeQualifiedNames;
+ }
+
+ public String[] getParameterTypeNames() {
+ return fParameterTypeNames;
+ }
+
+ protected void setParameterNames(String[] parameterNames) {
+ fParameterNames = (parameterNames == null ?
+ new String[0] : parameterNames);
+ }
+
+ public String[] getParameterNames() {
+ return fParameterNames;
+ }
+
+ public int getNumberOfParameters() {
+ return (getParameterNames() == null ? 0 : getParameterNames().length);
+ }
+
+ public IType getReturnType() {
+ return getMemberType();
+ }
+
+ public boolean isConstructor () {
+ return getDeclaringTypeQualifiedName()!=null && getDeclaringTypeQualifiedName().equals(getName());
+ }
+
+ public boolean isGetter() {
+ if (null == getType()) {
+ return false;
+ }
+
+ return (((getName().startsWith("get") && !getName().equals("get")) || getName().startsWith("is")) && getNumberOfParameters() == 0);
+ }
+
+ public boolean isSetter() {
+ return ((getName().startsWith("set") && !getName().equals("set")) && getNumberOfParameters() == 1);
+ }
+
+ public List<String> getAsPresentedStrings() {
+ List<String> list = new ArrayList<String>(2);
+ StringBuffer name = new StringBuffer(getName());
+
+ // Add method as 'foo'
+ list.add(name.toString());
+
+ // Add method as 'foo(param1,param2)'
+ name.append('(');
+ String[] mParams = getParameterNames();
+ for (int j = 0; mParams != null && j < mParams.length; j++) {
+ if (j > 0) name.append(", "); //$NON-NLS-1$
+ name.append(mParams[j]);
+ }
+ name.append(')');
+ list.add(name.toString());
+ return list;
+ }
+
+ @Override
+ public IJavaElement getJavaElement () {
+ if(fJavaElement == null) {
+ try {
+ IType declType = getSourceType().getJavaProject().findType(getDeclaringTypeQualifiedName());
+ if(declType==null) {
+ return null;
+ }
+ IMethod[] allMethods = declType.getMethods();
+
+ // filter methods by name
+ List<IMethod> methods = new ArrayList<IMethod>();
+ for (int i = 0; allMethods != null && i < allMethods.length; i++) {
+ if (allMethods[i].getElementName().equals(getName())) {
+ methods.add(allMethods[i]);
+ }
+ }
+ if (!methods.isEmpty()) {
+ if (methods.size() == 1) {
+ fJavaElement = methods.get(0);
+ } else {
+ // filter methods by number of parameters
+ List<IMethod> filteredMethods = new ArrayList<IMethod>();
+ for (IMethod method : methods) {
+ if (method.getNumberOfParameters() == getNumberOfParameters()) {
+ filteredMethods.add(method);
+ }
+ }
+ if (!filteredMethods.isEmpty()) {
+ if (filteredMethods.size() == 1) {
+ fJavaElement = filteredMethods.get(0);
+ } else {
+ methods = filteredMethods;
+
+ // filter methods by parameter types
+ for(IMethod method : methods) {
+ String[] methodParameterTypes =
+ resolveSignatures(method.getDeclaringType(),
+ method.getParameterTypes());
+ String[] parameterTypes = getParameterTypeQualifiedNames();
+
+ boolean equal = true;
+ for (int i = 0; parameterTypes != null && i < parameterTypes.length; i++) {
+ // simple types must be equal, but complex types may not
+ if (!parameterTypes[i].equals(methodParameterTypes[i])) {
+ // sure - it's Complex Type
+ if (! (parameterTypes[i].indexOf('.') != -1)
+ && (methodParameterTypes[i].indexOf('.') == -1)) {
+ equal = false;
+ break;
+ }
+ }
+ }
+ if (equal) {
+ fJavaElement = method;
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+ return fJavaElement;
+ }
+ }
+
+ public TypeInfoCollector(MemberInfo member) {
+ this.fMember = member;
+ this.fType = member.getMemberType();
+ collectInfo();
+ }
+
+ public IType getType() {
+ return this.fType;
+ }
+
+ public void collectInfo() {
+ if (fMethods == null) {
+ fMethods = new ArrayList<MethodInfo>();
+ } else {
+ fMethods.clear();
+ }
+
+ if (fFields == null) {
+ fFields = new ArrayList<FieldInfo>();
+ } else {
+ fFields.clear();
+ }
+
+ if (fType == null) {
+ return;
+ }
+ try {
+ IType binType = fType;
+ MemberInfo originalParent = fMember;
+ if(fMember instanceof TypeInfo) {
+ fTypeInfo = (TypeInfo)fMember;
+ } else {
+ fTypeInfo = new TypeInfo(binType, fMember, fMember.isDataModel());
+ }
+ TypeInfo parent = fTypeInfo;
+ while (binType != null) {
+ IMethod[] binMethods = binType.getMethods();
+ for (int i = 0; binMethods != null && i < binMethods.length; i++) {
+ if (binMethods[i].isConstructor()) {
+ continue;
+ }
+ fMethods.add(new MethodInfo(binMethods[i], fTypeInfo, parent, false));
+ }
+ binType = getSuperclass(binType);
+ if(binType!=null) {
+ TypeInfo superType = new TypeInfo(binType, originalParent, parent.isDataModel());
+ parent.setSuperType(superType);
+ parent = superType;
+ }
+ }
+
+ // This inserts here methods "public int size()" and "public boolean isEmpty()" for javax.faces.model.DataModel
+ // as requested by Gavin in JBIDE-1256
+ if(isDataModelObject(fType)) {
+ addInfoForDataModelObject();
+ }
+ // This inserts here methods "public int getRowCount()" for @DataModel variables.
+ if(fMember.isDataModel) {
+ addInfoForDataModelVariable();
+ }
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ }
+
+ boolean isDataModelObject(IType type) throws JavaModelException {
+ return isInstanceofType(type, "javax.faces.model.DataModel");
+ }
+
+ public static boolean isResourceBundle(IType type) {
+ try {
+ return isInstanceofType(type, "java.util.ResourceBundle");
+ } catch (JavaModelException e) {
+ return false;
+ }
+ }
+
+ public static boolean isNotParameterizedCollection(TypeInfoCollector.MemberInfo mbr) {
+ try {
+ if(mbr.getType().getParameters()!=null && mbr.getType().getParameters().length>0) {
+ return false;
+ }
+ IType type = mbr.getMemberType();
+ if(type!=null) {
+ return isInstanceofType(type, "java.util.Map") || isInstanceofType(type, "java.util.Collection");
+ }
+ return false;
+ } catch (JavaModelException e) {
+ return false;
+ }
+ }
+
+ public static class SuperTypeInfo {
+ IType type;
+ Set<String> names = new HashSet<String>();
+ IType[] superTypes = new IType[0];
+
+ SuperTypeInfo(IType type) throws JavaModelException {
+ this.type = type;
+ ProjectCache cache = caches.get(type);
+ if(cache != null) {
+ cache.superTypesCache.put(type, this);
+ }
+ ITypeHierarchy typeHierarchy = type.newSupertypeHierarchy(new NullProgressMonitor());
+ superTypes = typeHierarchy == null ? null : typeHierarchy.getAllSupertypes(type);
+ if(superTypes != null) for (int i = 0; i < superTypes.length; i++) {
+ names.add(superTypes[i].getFullyQualifiedName());
+ }
+ if(superTypes == null) superTypes = new IType[0];
+ }
+
+ public Set<String> getNames() {
+ return names;
+ }
+
+ public IType[] getSuperTypes() {
+ return superTypes;
+ }
+ }
+
+ public static SuperTypeInfo getSuperTypes(IType type) throws JavaModelException {
+ if(type == null) return null;
+ ProjectCache cache = caches.get(type);
+ SuperTypeInfo ts = (cache != null) ? cache.superTypesCache.get(type) : null;
+ if(ts == null) {
+ ts = new SuperTypeInfo(type);
+ }
+ return ts;
+ }
+
+ public static boolean isInstanceofType(IType type, String qualifiedTypeName) throws JavaModelException {
+ if (qualifiedTypeName == null || type == null) return false;
+ boolean isInstanceofType = qualifiedTypeName.equals(type.getFullyQualifiedName());
+ if (!isInstanceofType) {
+ SuperTypeInfo ts = getSuperTypes(type);
+ if(ts != null && ts.getNames().contains(qualifiedTypeName)) {
+ return true;
+ }
+ return false;
+ }
+ return true;
+ }
+
+ void addInfoForDataModelVariable() {
+ fMethods.add(new MethodInfo(fType,
+ fType.getFullyQualifiedName(),
+ "getRowCount", Modifier.PUBLIC,
+ new String[0],
+ new String[0],
+ "int",
+ fTypeInfo,
+ fTypeInfo,
+ false));
+ }
+
+ void addInfoForDataModelObject() {
+ fMethods.add(new MethodInfo(fType,
+ fType.getFullyQualifiedName(),
+ "size", Modifier.PUBLIC,
+ new String[0],
+ new String[0],
+ "int",
+ fTypeInfo,
+ fTypeInfo,
+ false));
+ fMethods.add(new MethodInfo(fType,
+ fType.getFullyQualifiedName(),
+ "isEmpty", Modifier.PUBLIC,
+ new String[0],
+ new String[0],
+ "boolean",
+ fTypeInfo,
+ fTypeInfo,
+ false));
+ }
+
+ private static IType getSuperclass(IType type) throws JavaModelException {
+ String superclassName = type.getSuperclassName();
+ if(superclassName!=null) {
+ String fullySuperclassName = EclipseJavaUtil.resolveType(type, superclassName);
+ if(fullySuperclassName!=null&&!fullySuperclassName.equals("java.lang.Object")) { //$NON-NLS-1$
+ if(fullySuperclassName.equals(type.getFullyQualifiedName())) {
+ //FIX JBIDE-1642
+ return null;
+ }
+ IType superType = type.getJavaProject().findType(fullySuperclassName);
+ return superType;
+ }
+ }
+ return null;
+ }
+
+ public MethodInfo[] findMethodInfos(IMethod iMethod) {
+ List<MethodInfo> methods = new ArrayList<MethodInfo>();
+
+ // filter methods by name
+ for (MethodInfo info : fMethods) {
+ if (info.getName().equals(iMethod.getElementName())) {
+ methods.add(info);
+ }
+ }
+ if (methods.isEmpty())
+ return new MethodInfo[0];
+
+ EclipseJavaUtil.getMemberTypeAsString(iMethod);
+
+ if (methods.size() == 1)
+ return methods.toArray(new MethodInfo[0]);
+
+ // filter methods by number of parameters
+ List<MethodInfo> filteredMethods = new ArrayList<MethodInfo>();
+ for (MethodInfo method : methods) {
+ if (method.getNumberOfParameters() == iMethod.getNumberOfParameters())
+ filteredMethods.add(method);
+ }
+ if (filteredMethods.isEmpty())
+ return new MethodInfo[0];
+ if (filteredMethods.size() == 1)
+ return filteredMethods.toArray(new MethodInfo[0]);
+
+ methods = filteredMethods;
+
+ // filter methods by parameter types
+ filteredMethods = new ArrayList<MethodInfo>();
+ for(MethodInfo method : methods) {
+ String[] methodParameterTypes =
+ resolveSignatures(iMethod.getDeclaringType(),
+ iMethod.getParameterTypes());
+ String[] parameterTypes = method.getParameterTypeQualifiedNames();
+
+ boolean equal = true;
+ for (int i = 0; equal && parameterTypes != null && i < parameterTypes.length; i++) {
+ // simple types must be equal, but complex types may not
+ if (!parameterTypes[i].equals(methodParameterTypes[i])) {
+ // sure - it's Complex Type
+ if ((parameterTypes[i].indexOf('.') != -1)
+ && (methodParameterTypes[i].indexOf('.') == -1)) {
+ equal = false;
+ }
+ }
+ }
+ if (equal) {
+ filteredMethods.add(method);
+ }
+ }
+ return filteredMethods.toArray(new MethodInfo[0]);
+ }
+
+ /**
+ * Returns the methods for the type specified
+ *
+ * @return
+ */
+ public List<MemberInfo> getMethods() {
+ List<MemberInfo> methods = new ArrayList<MemberInfo>();
+ for (MethodInfo info : fMethods) {
+ if (info.isPublic() && !info.isConstructor()
+ && !info.isStatic() && !info.isJavaLangObject()
+ && !info.isGetter() && !info.isSetter())
+ methods.add(info);
+ }
+ return methods;
+ }
+
+ /**
+ * String presentation of member
+ * @author Alexey Kazakov
+ */
+ public static class MemberPresentation {
+ private String presentation;
+ private MemberInfo member;
+
+ public MemberPresentation(String presentation, MemberInfo member) {
+ super();
+ this.presentation = presentation;
+ this.member = member;
+ }
+
+ public String getPresentation() {
+ return presentation;
+ }
+
+ public MemberInfo getMember() {
+ return member;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if(obj!=null && obj instanceof MemberPresentation) {
+ return presentation.equals(((MemberPresentation)obj).getPresentation());
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return presentation.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return presentation;
+ }
+ }
+
+ private static class MemberPresentationComparator implements Comparator<MemberPresentation> {
+ /* (non-Javadoc)
+ * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+ */
+ public int compare(MemberPresentation m1, MemberPresentation m2) {
+ return m1.getPresentation().compareTo(m2.getPresentation());
+ }
+ }
+
+ public final static MemberPresentationComparator MEMBER_PRESENTATION_COMPARATOR = new MemberPresentationComparator();
+
+ /**
+ * Returns the method presentation strings for the type specified
+ * @return
+ */
+ public Set<String> getMethodPresentationStrings() {
+ Set<MemberPresentation> set = getMethodPresentations();
+ Set<String> result = new HashSet<String>();
+ for (MemberPresentation presentation : set) {
+ result.add(presentation.getPresentation());
+ }
+ return result;
+ }
+
+ /**
+ * Returns the method presentations for the type specified
+ * @return
+ */
+ public Set<MemberPresentation> getMethodPresentations() {
+ Set<MemberPresentation> methods = new TreeSet<MemberPresentation>(MEMBER_PRESENTATION_COMPARATOR);
+ List<MemberInfo> mthds = getMethods();
+ for (MemberInfo info : mthds) {
+ if (!(info instanceof MethodInfo))
+ continue;
+
+ MethodInfo method = (MethodInfo)info;
+
+ StringBuffer name = new StringBuffer(method.getName());
+
+ // Add method as 'foo'
+ methods.add(new MemberPresentation(name.toString(), method));
+
+ // Add method as 'foo(param1,param2)'
+ name.append('(');
+ String[] mParams = method.getParameterNames();
+ for (int j = 0; mParams != null && j < mParams.length; j++) {
+ if (j > 0) name.append(", "); //$NON-NLS-1$
+ name.append(mParams[j]);
+ }
+ name.append(')');
+
+ methods.add(new MemberPresentation(name.toString(), method));
+ }
+ return methods;
+ }
+
+ /**
+ * Returns the properties for the type specified
+ *
+ * @return
+ */
+ public List<MemberInfo> getProperties() {
+ List<MemberInfo> properties = new ArrayList<MemberInfo>();
+ for (MethodInfo info : fMethods) {
+ if (info.isPublic() && !info.isConstructor()
+ && !info.isStatic() && !info.isJavaLangObject()
+ && (info.isGetter() || info.isSetter()))
+ properties.add(info);
+ }
+
+ /*
+ * The following code was excluded due to the following issue:
+ *
+ * http://jira.jboss.com/jira/browse/JBIDE-1203#action_12385823
+ *
+ *
+ for (FieldInfo info : fFields) {
+ if (info.isPublic()
+ && !info.isStatic() && !info.isJavaLangObject())
+ properties.add(info);
+ }
+ */
+
+ return properties;
+ }
+
+ /**
+ * Returns the property presentations for the type specified
+ *
+ * @return
+ */
+ public Set<MemberPresentation> getPropertyPresentations() {
+ return getPropertyPresentations(null);
+ }
+
+ /**
+ * Returns the property presentation strings for the type specified
+ *
+ * @return
+ */
+ public Set<String> getPropertyPresentationStrings() {
+ return getPropertyPresentationStrings(null);
+ }
+
+ /**
+ * Returns the property presentation strings for the type specified
+ *
+ * @param unpairedGettersOrSetters - map of unpaired getters or setters of type's properties. 'key' is property name.
+ * @return
+ */
+ public Set<String> getPropertyPresentationStrings(Map<String, MethodInfo> unpairedGettersOrSetters) {
+ Set<MemberPresentation> set = getPropertyPresentations(unpairedGettersOrSetters);
+ Set<String> result = new HashSet<String>();
+ for (MemberPresentation presentation : set) {
+ result.add(presentation.getPresentation());
+ }
+ return result;
+ }
+
+ /**
+ * Returns the property presentations for the type specified
+ *
+ * @param unpairedGettersOrSetters - map of unpaired getters or setters of type's properties. 'key' is property name.
+ * @return
+ */
+ public Set<MemberPresentation> getPropertyPresentations(Map<String, MethodInfo> unpairedGettersOrSetters) {
+ Set<MemberPresentation> properties = new TreeSet<MemberPresentation>(MEMBER_PRESENTATION_COMPARATOR);
+ List<MemberInfo> props = getProperties();
+ HashMap<String, MethodInfo> getters = new HashMap<String, MethodInfo>();
+ HashMap<String, MethodInfo> setters = new HashMap<String, MethodInfo>();
+ for (MemberInfo info : props) {
+ if (info instanceof MethodInfo) {
+ MethodInfo m = (MethodInfo)info;
+
+ if (m.isGetter() || m.isSetter()) {
+ StringBuffer name = new StringBuffer(m.getName());
+ if(m.getName().startsWith("i")) { //$NON-NLS-1$
+ name.delete(0, 2);
+ } else {
+ name.delete(0, 3);
+ }
+ if(name.length()<2 || Character.isLowerCase(name.charAt(1))) {
+ name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
+ }
+ String propertyName = name.toString();
+ MemberPresentation pr = new MemberPresentation(propertyName, m);
+ if(!properties.contains(pr)) {
+ properties.add(pr);
+ }
+ if(unpairedGettersOrSetters!=null) {
+ MethodInfo previousGetter = getters.get(propertyName);
+ MethodInfo previousSetter = setters.get(propertyName);
+ if((previousGetter!=null && m.isSetter())||(previousSetter!=null && m.isGetter())) {
+ // We have both Getter and Setter
+ unpairedGettersOrSetters.remove(propertyName);
+ } else if(m.isSetter()) {
+ setters.put(propertyName, m);
+ unpairedGettersOrSetters.put(propertyName, m);
+ } else if(m.isGetter()) {
+ getters.put(propertyName, m);
+ unpairedGettersOrSetters.put(propertyName, m);
+ }
+ }
+ }
+ } else {
+ properties.add(new MemberPresentation(info.getName(), info));
+ }
+ }
+ return properties;
+ }
+
+ public static void cleanCache() {
+ caches = new Caches();
+ }
+
+ public static MemberInfo createMemberInfo(IMember member, boolean dataModel) {
+ ProjectCache pcache = caches.get(member);
+
+ Map<IMember, MemberInfo> cache = null;
+ if(pcache != null) {
+ cache = dataModel ? pcache.memberInfoCacheTrue : pcache.memberInfoCacheFalse;
+ }
+ MemberInfo result = cache == null ? null : cache.get(member);
+ if(result != null) return result;
+ try {
+ if (member instanceof IType) {
+ result = new TypeInfo((IType)member, null, dataModel);
+ } else if (member instanceof IField) {
+ IField field = (IField)member;
+ TypeInfo declaringType = new TypeInfo(field.getDeclaringType(), null, dataModel);
+ result = new FieldInfo(field, declaringType, declaringType, dataModel);
+ } else if (member instanceof IMethod) {
+ IMethod method = (IMethod)member;
+ TypeInfo declaringType = new TypeInfo(method.getDeclaringType(), null, dataModel);
+ result = new MethodInfo(method, declaringType, declaringType, dataModel);
+ }
+ } catch (JavaModelException e) {
+ Activator.getPluginLog().logError(e);
+ }
+ if(result != null) {
+ cache.put(member, result);
+ }
+
+ return result;
+ }
+
+ public static MemberInfo createMemberInfo(IMember member) {
+ return createMemberInfo(member, false);
+ }
+
+ static String[] resolveSignatures (IType type, String[] signatures) {
+ if (signatures == null || signatures.length == 0)
+ return new String[0];
+
+ String[] resolvedSignatures = new String[signatures.length];
+ for (int i = 0; i < signatures.length; i++) {
+ resolvedSignatures[i] = EclipseJavaUtil.resolveTypeAsString(type, signatures[i]);
+ }
+ return resolvedSignatures;
+ }
+
+ static String[] convertToStringArray(char[][] names) {
+ if (names == null || names.length == 0)
+ return new String[0];
+ String[] sNames = new String[names.length];
+ for (int i = 0; i < sNames.length; i++) {
+ sNames[i] = String.valueOf(names[i]);
+ }
+ return sNames;
+ }
+
+ static String[] getTypeErasureFromSignatureArray(String[] signatures) {
+ if (signatures == null || signatures.length == 0)
+ return new String[0];
+ String[] result = new String[signatures.length];
+ for (int i = 0; i < signatures.length; i++) {
+ result[i] = Signature.getTypeErasure(signatures[i]);
+ }
+ return result;
+ }
+
+ static String getParameterNameFromType(String typeSignatures) {
+ if(typeSignatures==null) {
+ return null;
+ }
+ return Signature.getTypeVariable(typeSignatures);
+ }
+}
\ No newline at end of file
Copied: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/Var.java (from rev 10454, trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/Var.java)
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/Var.java (rev 0)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/core/resolver/Var.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.common.el.core.resolver;
+
+import java.util.List;
+
+import org.jboss.tools.common.el.core.model.ELExpression;
+import org.jboss.tools.common.el.core.model.ELInstance;
+import org.jboss.tools.common.el.core.model.ELModel;
+import org.jboss.tools.common.el.core.parser.ELParser;
+import org.jboss.tools.common.el.core.parser.ELParserFactory;
+import org.jboss.tools.common.el.core.parser.ELParserUtil;
+
+/**
+ * Represents "var"/"value" attributes.
+ * @author Alexey Kazakov
+ */
+public class Var {
+ String name;
+ String value;
+ ELExpression elToken;
+ String resolvedValue;
+ ELExpression resolvedElToken;
+ int declOffset;
+ int declLength;
+ ELParserFactory factory;
+
+ /**
+ * Constructor
+ * @param name - value of "var" attribute.
+ * @param value - value of "value" attribute.
+ */
+ public Var(ELParserFactory factory, String name, String value, int declOffset, int declLength) {
+ this.factory = factory;
+ this.name = name;
+ this.value = value;
+ elToken = parseEl(value);
+ this.declOffset = declOffset;
+ this.declLength = declLength;
+ }
+
+ ELExpression parseEl(String el) {
+ if(el.length()>3 && el.startsWith("#{") && el.endsWith("}")) {
+ ELParser parser = factory.createParser();
+ ELModel model = parser.parse(el);
+ if(model == null || parser.getSyntaxErrors().size() > 0) return null;
+ List<ELInstance> is = model.getInstances();
+ if(is.size() == 0) return null;
+ return is.get(0).getExpression();
+ }
+ return null;
+ }
+
+ /**
+ * Sets value to new resolved EL which we got as result of parsing value.
+ * For example:
+ * <h:datatable value="#{list}" var="item">
+ * <h:dataTable value="#{item.anotherList}" var="innerItem">
+ * ...
+ * </h:dataTable>
+ * </h:dataTable>
+ * Original El is #{item.anotherList}
+ * Resolved El is #{list.iterator().next().anotherList}
+ * It's very useful for nested vars.
+ * @param newEl
+ */
+ public void resolveValue(String newEl) {
+ resolvedValue = newEl;
+ resolvedElToken = parseEl(newEl);
+ }
+
+ /**
+ * @return parsed EL from "value" attribute. Returns null if EL is not valid.
+ */
+ public ELExpression getElToken() {
+ return elToken;
+ }
+
+ /**
+ * @return parsed resolved EL from "value" attribute. May be null.
+ */
+ public ELExpression getResolvedElToken() {
+ return resolvedElToken;
+ }
+
+ /**
+ * @return name of variable.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return value of variable. It's EL.
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * @return resolved value of variable. It's EL. May be null.
+ */
+ public String getResolvedValue() {
+ return resolvedValue;
+ }
+
+ /**
+ * @return offset of the var declaration
+ */
+ public int getDeclarationOffset() {
+ return declOffset;
+ }
+
+ /**
+ * @return length of the var declaration
+ */
+ public int getDeclarationLength() {
+ return declLength;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Var) {
+ Var compare = (Var)obj;
+ String str = getName();
+ if (str != null) {
+ if (!str.equals(compare.getName()))
+ return false;
+ } else {
+ if (compare.getName() != null)
+ return false;
+ }
+ str = getValue();
+ return (str != null ?
+ str.equals(compare.getValue()) :
+ compare.getValue() == null);
+ }
+ return false;
+ }
+
+}
Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELModelImpl.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELModelImpl.java 2008-10-01 15:26:10 UTC (rev 10595)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELModelImpl.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -26,6 +26,7 @@
public class ELModelImpl extends ELObjectImpl implements ELModel {
String source;
List<ELInstance> instances = new ArrayList<ELInstance>();
+ int delta = 0;
public ELModelImpl() {}
@@ -83,4 +84,10 @@
}
+ public void shift(int delta) {
+ this.delta = delta;
+ if(instances.size() > 0) {
+ instances.get(0).getFirstToken().shift(delta);
+ }
+ }
}
Modified: trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELObjectImpl.java
===================================================================
--- trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELObjectImpl.java 2008-10-01 15:26:10 UTC (rev 10595)
+++ trunk/common/plugins/org.jboss.tools.common.el.core/src/org/jboss/tools/common/el/internal/core/model/ELObjectImpl.java 2008-10-01 15:31:11 UTC (rev 10596)
@@ -49,9 +49,9 @@
public String getText() {
if(getModel() == null) return null;
String source = getModel().getSource();
- int start = firstToken.getStart();
+ int start = firstToken.getStart() - getModel().delta;
LexicalToken lt = (lastToken != null) ? lastToken : firstToken;
- int end = lt.getStart() + lt.getLength();
+ int end = lt.getStart() + lt.getLength() - getModel().delta;
return source.substring(start, end);
}
15 years, 7 months
JBoss Tools SVN: r10595 - in trunk/documentation: jbosstools-jdocbook-style/src/main/com/css/css and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: artdaw
Date: 2008-10-01 11:26:10 -0400 (Wed, 01 Oct 2008)
New Revision: 10595
Modified:
trunk/documentation/jbosstools-docbook-xslt/src/main/resources/xslt/com/jboss/tools/common.xsl
trunk/documentation/jbosstools-jdocbook-style/src/main/com/css/css/tools.css
Log:
https://jira.jboss.org/jira/browse/JBDS-399 - 2 templates for adding 'added', 'changed' icons to all of the titles are done
Modified: trunk/documentation/jbosstools-docbook-xslt/src/main/resources/xslt/com/jboss/tools/common.xsl
===================================================================
--- trunk/documentation/jbosstools-docbook-xslt/src/main/resources/xslt/com/jboss/tools/common.xsl 2008-10-01 15:12:54 UTC (rev 10594)
+++ trunk/documentation/jbosstools-docbook-xslt/src/main/resources/xslt/com/jboss/tools/common.xsl 2008-10-01 15:26:10 UTC (rev 10595)
@@ -187,4 +187,131 @@
</xsl:with-param>
</xsl:call-template>
</xsl:template>
+
+<!-- THERE ARE 2 TEMPLATES FOR ADDING 'ADDED', 'CHANGED' ICONS TO ALL OF THE TITLES-->
+
+<xsl:template name="component.title">
+ <xsl:param name="node" select="."/>
+
+ <xsl:variable name="level">
+ <xsl:choose>
+ <xsl:when test="ancestor::section">
+ <xsl:value-of select="count(ancestor::section)+1"/>
+ </xsl:when>
+ <xsl:when test="ancestor::sect5">6</xsl:when>
+ <xsl:when test="ancestor::sect4">5</xsl:when>
+ <xsl:when test="ancestor::sect3">4</xsl:when>
+ <xsl:when test="ancestor::sect2">3</xsl:when>
+ <xsl:when test="ancestor::sect1">2</xsl:when>
+ <xsl:otherwise>1</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- Let's handle the case where a component (bibliography, for example)
+ occurs inside a section; will we need parameters for this? -->
+ <xsl:variable name="revflag">
+ <xsl:choose>
+ <xsl:when test="../@role='new' or ../@role='updated'">
+ <xsl:value-of select="../@role"/>
+ </xsl:when>
+ <!-- For mkdiff compatibility-->
+ <xsl:when test="../@revisionflag='added' or ../@revisionflag='changed'">
+ <xsl:value-of select="../@revisionflag"/>
+ </xsl:when>
+ <xsl:otherwise></xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:element name="h{$level+1}">
+ <xsl:attribute name="class">
+ title
+ <xsl:value-of select="$revflag" />
+ </xsl:attribute>
+ <xsl:if test="$generate.id.attributes = 0">
+ <xsl:call-template name="anchor">
+ <xsl:with-param name="node" select="$node"/>
+ <xsl:with-param name="conditional" select="0"/>
+ </xsl:call-template>
+ </xsl:if>
+ <xsl:apply-templates select="$node" mode="object.title.markup">
+ <xsl:with-param name="allow-anchors" select="1"/>
+ </xsl:apply-templates>
+ </xsl:element>
+</xsl:template>
+
+<!-- ==================================================================== -->
+
+<xsl:template name="section.heading">
+ <xsl:param name="section" select="."/>
+ <xsl:param name="level" select="1"/>
+ <xsl:param name="allow-anchors" select="1"/>
+ <xsl:param name="title"/>
+ <xsl:param name="class" select="'title'"/>
+
+ <xsl:variable name="id">
+ <xsl:choose>
+ <!-- if title is in an *info wrapper, get the grandparent -->
+ <xsl:when test="contains(local-name(..), 'info')">
+ <xsl:call-template name="object.id">
+ <xsl:with-param name="object" select="../.."/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="object.id">
+ <xsl:with-param name="object" select=".."/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <!-- HTML H level is one higher than section level -->
+ <xsl:variable name="hlevel">
+ <xsl:choose>
+ <!-- highest valid HTML H level is H6; so anything nested deeper
+ than 5 levels down just becomes H6 -->
+ <xsl:when test="$level > 5">6</xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$level + 1"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="revflag">
+ <xsl:choose>
+ <xsl:when test="../@role='new' or ../@role='updated'">
+ <xsl:value-of select="../@role"/>
+ </xsl:when>
+ <!-- For mkdiff compatibility-->
+ <xsl:when test="../@revisionflag='added' or ../@revisionflag='changed'">
+ <xsl:value-of select="../@revisionflag"/>
+ </xsl:when>
+ <xsl:otherwise></xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:element name="h{$hlevel}">
+ <xsl:attribute name="class">
+ <xsl:value-of select="$class"/>
+ <xsl:text> </xsl:text>
+ <xsl:value-of select="$revflag"/>
+ </xsl:attribute>
+ <xsl:if test="$css.decoration != '0'">
+ <xsl:if test="$hlevel<3">
+ <xsl:attribute name="style">clear: both</xsl:attribute>
+ </xsl:if>
+ </xsl:if>
+ <xsl:if test="$allow-anchors != 0 and $generate.id.attributes = 0">
+ <xsl:call-template name="anchor">
+ <xsl:with-param name="node" select="$section"/>
+ <xsl:with-param name="conditional" select="0"/>
+ </xsl:call-template>
+ </xsl:if>
+ <xsl:if test="$generate.id.attributes != 0 and not(local-name(.) = 'appendix')">
+ <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
+ </xsl:if>
+ <xsl:copy-of select="$title"/>
+ </xsl:element>
+</xsl:template>
+
+<!-- ==================================================================== -->
+
</xsl:stylesheet>
Modified: trunk/documentation/jbosstools-jdocbook-style/src/main/com/css/css/tools.css
===================================================================
--- trunk/documentation/jbosstools-jdocbook-style/src/main/com/css/css/tools.css 2008-10-01 15:12:54 UTC (rev 10594)
+++ trunk/documentation/jbosstools-jdocbook-style/src/main/com/css/css/tools.css 2008-10-01 15:26:10 UTC (rev 10595)
@@ -93,11 +93,20 @@
text-align:right;
}
-a.new {
+.new, .added {
background:transparent url(../images/new.png) no-repeat scroll right top;
padding-right:70px;
}
-a.updated {
+.updated, .changed {
background:transparent url(../images/updated.png) no-repeat scroll right top;
padding-right:70px;
}
+span.diffmkwrapper{
+ background-color: #cce2f6;
+}
+
+div.diffmkwrapper p{
+ background-color: #c8d7e4;
+ padding:0px;
+ margin-left:56px;
+}
15 years, 7 months
JBoss Tools SVN: r10594 - in trunk/vpe/plugins/org.jboss.tools.vpe: src/org/jboss/tools/vpe/editor/template and 1 other directories.
by jbosstools-commits@lists.jboss.org
Author: mareshkau
Date: 2008-10-01 11:12:54 -0400 (Wed, 01 Oct 2008)
New Revision: 10594
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAnyCreator.java
trunk/vpe/plugins/org.jboss.tools.vpe/ve/init.html
Log:
=show borders attribute now used for creation unknown tag presentation
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-10-01 14:41:58 UTC (rev 10593)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualDomBuilder.java 2008-10-01 15:12:54 UTC (rev 10594)
@@ -445,7 +445,7 @@
sourceNode)) {
sourceNodeClone = (sourceNode).cloneNode(true);
if(sourceNodeClone instanceof Element){
- ((Element)sourceNodeClone).setAttribute(PARENT,"");
+ ((Element)sourceNodeClone).setAttribute(PARENT,""); //$NON-NLS-1$
Attr a = ((Element)sourceNodeClone).getAttributeNode(PARENT);
a.setUserData(PARENT, sourceNode.getParentNode(),null);
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAnyCreator.java
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAnyCreator.java 2008-10-01 14:41:58 UTC (rev 10593)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeAnyCreator.java 2008-10-01 15:12:54 UTC (rev 10594)
@@ -14,6 +14,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+
+import org.jboss.tools.jst.jsp.preferences.VpePreference;
import org.jboss.tools.vpe.VpePlugin;
import org.jboss.tools.vpe.editor.context.VpePageContext;
import org.jboss.tools.vpe.editor.template.expression.VpeExpression;
@@ -179,6 +181,10 @@
String styleString = getExprValue(pageContext, styleExpr, sourceNode);
+ if ("yes".equalsIgnoreCase(VpePreference.SHOW_BORDER_FOR_UNKNOWN_TAGS.getValue())) { //$NON-NLS-1$
+ styleString = "border: 1px solid green;" +styleString; //$NON-NLS-1$
+ }
+
anyElement.setAttribute(HTML.ATTR_STYLE, styleString);
if (propertyCreators != null) {
@@ -194,8 +200,6 @@
}
}
-// setStyles(pageContext, sourceNode, div, span);
-
String valueStr = getExprValue(pageContext, valueExpr, sourceNode);
nsIDOMNode valueNode = visualDocument.createTextNode(valueStr);
anyElement.appendChild(valueNode);
Modified: trunk/vpe/plugins/org.jboss.tools.vpe/ve/init.html
===================================================================
--- trunk/vpe/plugins/org.jboss.tools.vpe/ve/init.html 2008-10-01 14:41:58 UTC (rev 10593)
+++ trunk/vpe/plugins/org.jboss.tools.vpe/ve/init.html 2008-10-01 15:12:54 UTC (rev 10594)
@@ -16,7 +16,6 @@
padding: 2px 1px 1px 1px;
}
.__any__tag__caption {
- border: 1px solid black;
color:#006727;
font-size: 12px;
padding: 0px 2px 0px 2px;
15 years, 7 months