JBoss Tools SVN: r6734 - trunk/seam/plugins/org.jboss.tools.seam.ui.
by jbosstools-commits@lists.jboss.org
Author: vrubezhny
Date: 2008-03-06 16:03:04 -0500 (Thu, 06 Mar 2008)
New Revision: 6734
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
Log:
http://jira.jboss.org/jira/browse/JBIDE-509 intelligent navigation support for seam variable names
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2008-03-06 21:02:35 UTC (rev 6733)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2008-03-06 21:03:04 UTC (rev 6734)
@@ -343,17 +343,6 @@
</hyperlinkDetector>
</extension>
- <!--======================================================================================-->
- <!-- queryParticipant to participate in java serches -->
- <!--======================================================================================-->
- <!-- extension point="org.eclipse.jdt.ui.queryParticipants">
- <queryParticipant
- name="Seam Query_Participant_Extension_Element"
- nature="org.eclipse.jdt.core.javanature"
- class="org.jboss.tools.seam.ui.text.java.search.SeamQueryParticipant"
- id="org.jboss.tools.seam.ui.java.search.ui.SeamQueryParticipant" />
- </extension -->
-
<extension
point="org.jboss.tools.common.text.xml.contentAssistProcessor"
id="org.jboss.tools.seam.ui.contentAssistProcessor"
16 years, 3 months
JBoss Tools SVN: r6733 - in trunk/seam/plugins/org.jboss.tools.seam.ui: META-INF and 5 other directories.
by jbosstools-commits@lists.jboss.org
Author: vrubezhny
Date: 2008-03-06 16:02:35 -0500 (Thu, 06 Mar 2008)
New Revision: 6733
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamDeclarationsAction.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamReferencesAction.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamElementMatch.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/SeamSearchRequestor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResultPage.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchScope.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchViewLabelProvider.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/search/SeamTableContentProvider.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTreeContentProvider.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF
trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties
Log:
http://jira.jboss.org/jira/browse/JBIDE-509 intelligent navigation support for seam variable names
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF 2008-03-06 20:47:05 UTC (rev 6732)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF 2008-03-06 21:02:35 UTC (rev 6733)
@@ -52,7 +52,9 @@
org.eclipse.wst.server.core,
org.eclipse.wst.server.ui,
org.eclipse.debug.ui,
- org.jboss.tools.jst.web
+ org.jboss.tools.jst.web,
+ org.eclipse.search,
+ org.jboss.tools.jst.jsp
Eclipse-LazyStart: true
Export-Package: org.jboss.tools.seam.ui,
org.jboss.tools.seam.ui.actions,
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2008-03-06 20:47:05 UTC (rev 6732)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2008-03-06 21:02:35 UTC (rev 6733)
@@ -333,6 +333,27 @@
</javaCompletionProposalComputer>
</extension>
+ <extension
+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
+ <hyperlinkDetector
+ class="org.jboss.tools.seam.ui.text.java.JavaStringHyperlinkDetector"
+ id="org.jboss.tools.seam.ui.text.java.JavaStringHyperlinkDetector"
+ name="Java String"
+ targetId="org.eclipse.jdt.ui.javaCode">
+ </hyperlinkDetector>
+ </extension>
+
+ <!--======================================================================================-->
+ <!-- queryParticipant to participate in java serches -->
+ <!--======================================================================================-->
+ <!-- extension point="org.eclipse.jdt.ui.queryParticipants">
+ <queryParticipant
+ name="Seam Query_Participant_Extension_Element"
+ nature="org.eclipse.jdt.core.javanature"
+ class="org.jboss.tools.seam.ui.text.java.search.SeamQueryParticipant"
+ id="org.jboss.tools.seam.ui.java.search.ui.SeamQueryParticipant" />
+ </extension -->
+
<extension
point="org.jboss.tools.common.text.xml.contentAssistProcessor"
id="org.jboss.tools.seam.ui.contentAssistProcessor"
@@ -436,6 +457,28 @@
toolbarPath="org.eclipse.search.searchActionSet/Search"
tooltip="Open Seam Component">
</action>
+ <action
+ class="org.jboss.tools.seam.ui.actions.FindSeamDeclarationsAction"
+ definitionId="org.jboss.tools.seam.ui.find.declarations"
+ helpContextId="org.eclipse.jdt.ui.find_declarations_action"
+ icon="icons/open_seam_component.gif"
+ id="findDeclarations"
+ label="Find Seam Declarations"
+ menubarPath="navigate/open.ext2"
+ toolbarPath="org.eclipse.search.searchActionSet/Search"
+ tooltip="Find Seam Declarations">
+ </action>
+ <action
+ class="org.jboss.tools.seam.ui.actions.FindSeamReferencesAction"
+ definitionId="org.jboss.tools.seam.ui.find.references"
+ helpContextId="org.eclipse.jdt.ui.find_references_action"
+ icon="icons/open_seam_component.gif"
+ id="findReferences"
+ label="Find Seam References"
+ menubarPath="navigate/open.ext2"
+ toolbarPath="org.eclipse.search.searchActionSet/Search"
+ tooltip="Find Seam References">
+ </action>
</actionSet>
</extension>
<extension
@@ -446,6 +489,18 @@
id="org.jboss.tools.seam.ui.open.component"
name="Open Seam Component">
</command>
+ <command
+ categoryId="org.eclipse.ui.category.navigate"
+ description="Find Declarations"
+ id="org.jboss.tools.seam.ui.find.declarations"
+ name="Find Seam Declarations">
+ </command>
+ <command
+ categoryId="org.eclipse.ui.category.navigate"
+ description="Find References"
+ id="org.jboss.tools.seam.ui.find.references"
+ name="Find Seam References">
+ </command>
</extension>
<extension
point="org.eclipse.ui.bindings">
@@ -454,5 +509,25 @@
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+M2+Z">
</key>
+ <key
+ commandId="org.jboss.tools.seam.ui.find.declarations"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+G">
+ </key>
+ <key
+ commandId="org.jboss.tools.seam.ui.find.references"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+M2+G">
+ </key>
</extension>
+
+ <extension
+ id="SeamSearchResultPage"
+ point="org.eclipse.search.searchResultViewPages">
+ <viewPage
+ id="org.jboss.tools.seam.ui.search.SeamSearchResultPage"
+ searchResultClass="org.jboss.tools.seam.ui.search.SeamSearchResult"
+ class="org.jboss.tools.seam.ui.search.SeamSearchResultPage">
+ </viewPage>
+ </extension>
</plugin>
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java 2008-03-06 20:47:05 UTC (rev 6732)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamUIMessages.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -412,7 +412,36 @@
public static String RUNTIME_DELETE_NOT_USED_CONFIRM;
public static String RUNTIME_DELETE_USED_CONFIRM;
+
+ public static String FIND_DECLARATIONS_ACTION_ACTION_NAME;
+ public static String FIND_DECLARATIONS_ACTION_DESCRIPTION;
+ public static String FIND_DECLARATIONS_ACTION_MESSAGE;
+ public static String FIND_DECLARATIONS_ACTION_TOOL_TIP;
+ public static String FIND_REFERENCES_ACTION_ACTION_NAME;
+ public static String FIND_REFERENCES_ACTION_DESCRIPTION;
+ public static String FIND_REFERENCES_ACTION_MESSAGE;
+ public static String FIND_REFERENCES_ACTION_TOOL_TIP;
+
+ public static String SeamSearchQuery_task_label;
+ public static String SeamSearchQuery_label;
+ public static String SeamSearchQuery_error_unsupported_pattern;
+
+ public static String SeamSearchQuery_singularPatternWithLimitTo;
+ public static String SeamSearchQuery_pluralPatternWithLimitTo;
+
+ public static String SeamSearchScope_scope_empty;
+ public static String SeamSearchScope_scope_single;
+ public static String SeamSearchScope_scope_double;
+ public static String SeamSearchScope_scope_multiple;
+
+ public static String SeamSearchScope_scope_LimitToDeclarations;
+ public static String SeamSearchScope_scope_LimitToReferences;
+ public static String SeamSearchQuery_pluralPattern;
+ public static String SeamSearchQuery_singularLabel;
+
+ public static String SeamSearchVisitor_scanning;
+
static {
// load message values from bundle file
NLS.initializeMessages(BUNDLE_NAME, SeamUIMessages.class);
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,323 @@
+package org.jboss.tools.seam.ui.actions;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
+import org.eclipse.jdt.internal.ui.search.SearchMessages;
+import org.eclipse.jdt.internal.ui.search.SearchUtil;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionDelegate2;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.progress.IProgressService;
+import org.jboss.tools.common.model.ui.ModelUIPlugin;
+import org.jboss.tools.jst.jsp.jspeditor.JSPMultiPageEditor;
+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.ELOperandToken;
+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.SeamELOperandTokenizer;
+import org.jboss.tools.seam.internal.core.el.SeamELOperandTokenizerForward;
+import org.jboss.tools.seam.internal.core.el.ElVarSearcher.Var;
+import org.jboss.tools.seam.ui.SeamGuiPlugin;
+import org.jboss.tools.seam.ui.SeamUIMessages;
+import org.jboss.tools.seam.ui.search.SeamSearchQuery;
+import org.jboss.tools.seam.ui.search.SeamSearchScope;
+
+abstract public class FindSeamAction extends Action implements IWorkbenchWindowActionDelegate, IActionDelegate2 {
+
+ protected FindSeamAction() {
+ }
+
+ public void run() {
+ runWithEvent(null);
+ }
+
+ private Shell getShell() {
+ try {
+ return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ } catch (Throwable x) {
+ return null;
+ }
+ }
+
+ public void runWithEvent(Event e) {
+ IEditorPart editor = ModelUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
+ IEditorInput input = editor.getEditorInput();
+ IDocument document = null;
+
+
+ ISourceViewer viewer = null;
+
+ if (editor instanceof JSPMultiPageEditor) {
+ viewer = ((JSPMultiPageEditor)editor).getJspEditor().getTextViewer();
+ } else if (editor instanceof CompilationUnitEditor) {
+ viewer = ((CompilationUnitEditor)editor).getViewer();
+ }
+
+ if (viewer == null)
+ return;
+
+
+ document = viewer.getDocument();
+
+ ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection();
+ if (selection.isEmpty())
+ return;
+
+
+ int selectionOffset = 0;
+ if (selection instanceof ITextSelection) {
+ ITextSelection tSel = (ITextSelection)selection;
+ selectionOffset = tSel.getOffset();
+ } else {
+ return;
+ }
+
+ IFile file = null;
+
+ if (input instanceof IFileEditorInput) {
+ file = ((IFileEditorInput)input).getFile();
+ }
+
+ IProject project = (file == null ? null : file.getProject());
+
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
+ if (seamProject == null)
+ return;
+
+ SeamELCompletionEngine engine= new SeamELCompletionEngine();
+
+ int elStart = getELStart(document, selectionOffset);
+
+ if (elStart == -1)
+ elStart = selectionOffset;
+
+ SeamELOperandTokenizerForward tokenizer = new SeamELOperandTokenizerForward(document, elStart);
+ List<ELOperandToken> tokens = tokenizer.getTokens();
+
+ if (tokens == null || tokens.size() == 0)
+ return; // No EL Operand found
+
+ List<List<ELOperandToken>> variations = SeamELCompletionEngine.getPossibleVarsFromPrefix(tokens);
+
+ // Define the Seam project variables to search for declarations
+ List<ISeamContextVariable> variables = new ArrayList<ISeamContextVariable>();
+
+ for (List<ELOperandToken> variation : variations) {
+ try {
+ int start = variation.get(0).getStart();
+ int end = variation.get(variation.size() - 1).getStart() +
+ variation.get(variation.size() - 1).getLength();
+ String variationText = document.get(start, end - start);
+
+ Set<ISeamContextVariable> vars = seamProject.getVariablesByName(variationText);
+ variables.addAll(vars);
+ } catch (BadLocationException e1) {
+ SeamGuiPlugin.getPluginLog().logError(e1);
+ }
+ }
+
+ if (variables.size() != 0) {
+ // Some variable/variables are found - perform search for their declarations
+ String[] varNamesToSearch = new String[variables.size()];
+ for (int i = 0; i < variables.size(); i++) {
+ varNamesToSearch[i] = variables.get(i).getName();
+ }
+
+ try {
+ performNewSearch(varNamesToSearch, project);
+ } catch (JavaModelException jme) {
+ SeamGuiPlugin.getPluginLog().logError(jme);
+ } catch (InterruptedException ie) {
+ SeamGuiPlugin.getPluginLog().logError(ie);
+ }
+ return;
+ }
+
+ // Try to look into "var"/"variable" attributes (if we're in the XML-like document)
+
+ if ("java".equalsIgnoreCase(file.getFileExtension())) { //$NON-NLS-1$
+ return;
+ }
+ ElVarSearcher varSearcher = new ElVarSearcher(seamProject, file, engine);
+ List<Var> allVars = ElVarSearcher.findAllVars(viewer, selectionOffset);
+ if (allVars == null || allVars.size() == 0)
+ return;
+
+ int start = tokens.get(0).getStart();
+ int end = tokens.get(tokens.size() - 1).getStart() +
+ tokens.get(tokens.size() - 1).getLength();
+
+ String elText;
+ try {
+ elText = document.get(start, end - start);
+ } catch (BadLocationException ble) {
+ SeamGuiPlugin.getPluginLog().logError(ble);
+ return;
+ }
+ if (elText == null || elText.length() == 0)
+ return;
+
+ Var var = varSearcher.findVarForEl(elText, allVars, false);
+ if (var == null)
+ return;
+ try {
+ performNewLocalSearch(var, file);
+ } catch (JavaModelException jme) {
+ SeamGuiPlugin.getPluginLog().logError(jme);
+ } catch (InterruptedException ie) {
+ SeamGuiPlugin.getPluginLog().logError(ie);
+ }
+ }
+
+
+
+ // ---- IWorkbenchWindowActionDelegate
+ // ------------------------------------------------
+
+ public void run(IAction action) {
+ run();
+ }
+
+ public void dispose() {
+ // do nothing.
+ }
+
+ public void init(IWorkbenchWindow window) {
+ // do nothing.
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ // do nothing. Action doesn't depend on selection.
+ }
+
+ // ---- IActionDelegate2
+ // ------------------------------------------------
+
+ public void runWithEvent(IAction action, Event event) {
+ runWithEvent(event);
+ }
+
+ public void init(IAction action) {
+ // do nothing.
+ }
+
+ /*
+ * Scans the document from the offset to the beginning to find start of Seam EL operand
+ * Returns the start position of first Seam EL operand token
+ */
+ private 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();
+ }
+
+ /*
+ * Scans the document from the offset to the beginning to find start of Seam EL operand
+ * Returns the end position of last Seam EL operand token
+ */
+ private int getELEnd(IDocument document, int offset) {
+ SeamELOperandTokenizer tokenizer = new SeamELOperandTokenizerForward(document, offset);
+ List<ELOperandToken> tokens = tokenizer.getTokens();
+
+ if (tokens == null || tokens.size() == 0)
+ return -1;
+
+ ELOperandToken lastToken = tokens.get(tokens.size() - 1);
+ return lastToken.getStart() + lastToken.getLength();
+ }
+
+ private SeamSearchQuery createQuery(String[] patterns, IProject root) throws JavaModelException, InterruptedException {
+
+ SeamSearchScope scope = new SeamSearchScope(new IProject[] {root}, getLimitTo());
+
+ return new SeamSearchQuery(patterns, scope);
+ }
+
+ private SeamSearchQuery createQuery(Var var, IFile root) throws JavaModelException, InterruptedException {
+
+ SeamSearchScope scope = new SeamSearchScope(new IFile[] {root}, getLimitTo());
+
+ return new SeamSearchQuery(var, scope);
+ }
+
+ abstract protected int getLimitTo();
+
+ private void performNewSearch(String[] patterns, IProject root) throws JavaModelException, InterruptedException {
+ SeamSearchQuery query= createQuery(patterns, root);
+ if (query.canRunInBackground()) {
+ /*
+ * This indirection with Object as parameter is needed to prevent the loading
+ * of the Search plug-in: the VM verifies the method call and hence loads the
+ * types used in the method signature, eventually triggering the loading of
+ * a plug-in (in this case ISearchQuery results in Search plug-in being loaded).
+ */
+ SearchUtil.runQueryInBackground(query);
+ } else {
+ IProgressService progressService= PlatformUI.getWorkbench().getProgressService();
+ /*
+ * This indirection with Object as parameter is needed to prevent the loading
+ * of the Search plug-in: the VM verifies the method call and hence loads the
+ * types used in the method signature, eventually triggering the loading of
+ * a plug-in (in this case it would be ISearchQuery).
+ */
+ IStatus status= SearchUtil.runQueryInForeground(progressService, query);
+ if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) {
+ ErrorDialog.openError(getShell(), SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message, status);
+ }
+ }
+ }
+
+ private void performNewLocalSearch(Var var, IFile root) throws JavaModelException, InterruptedException {
+ SeamSearchQuery query= createQuery(var, root);
+ if (query.canRunInBackground()) {
+ /*
+ * This indirection with Object as parameter is needed to prevent the loading
+ * of the Search plug-in: the VM verifies the method call and hence loads the
+ * types used in the method signature, eventually triggering the loading of
+ * a plug-in (in this case ISearchQuery results in Search plug-in being loaded).
+ */
+ SearchUtil.runQueryInBackground(query);
+ } else {
+ IProgressService progressService= PlatformUI.getWorkbench().getProgressService();
+ /*
+ * This indirection with Object as parameter is needed to prevent the loading
+ * of the Search plug-in: the VM verifies the method call and hence loads the
+ * types used in the method signature, eventually triggering the loading of
+ * a plug-in (in this case it would be ISearchQuery).
+ */
+ IStatus status= SearchUtil.runQueryInForeground(progressService, query);
+ if (status.matches(IStatus.ERROR | IStatus.INFO | IStatus.WARNING)) {
+ ErrorDialog.openError(getShell(), SearchMessages.Search_Error_search_title, SearchMessages.Search_Error_search_message, status);
+ }
+ }
+ }
+
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamDeclarationsAction.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamDeclarationsAction.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamDeclarationsAction.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,17 @@
+package org.jboss.tools.seam.ui.actions;
+
+import org.jboss.tools.seam.ui.SeamUIMessages;
+import org.jboss.tools.seam.ui.search.SeamSearchScope;
+
+public class FindSeamDeclarationsAction extends FindSeamAction {
+
+ public FindSeamDeclarationsAction() {
+ setText(SeamUIMessages.FIND_DECLARATIONS_ACTION_ACTION_NAME);
+ setDescription(SeamUIMessages.FIND_DECLARATIONS_ACTION_DESCRIPTION);
+ setToolTipText(SeamUIMessages.FIND_DECLARATIONS_ACTION_TOOL_TIP);
+ }
+
+ protected int getLimitTo() {
+ return SeamSearchScope.SEARCH_FOR_DECLARATIONS;
+ }
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamDeclarationsAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamReferencesAction.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamReferencesAction.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamReferencesAction.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,17 @@
+package org.jboss.tools.seam.ui.actions;
+
+import org.jboss.tools.seam.ui.SeamUIMessages;
+import org.jboss.tools.seam.ui.search.SeamSearchScope;
+
+public class FindSeamReferencesAction extends FindSeamAction {
+
+ public FindSeamReferencesAction() {
+ setText(SeamUIMessages.FIND_REFERENCES_ACTION_ACTION_NAME);
+ setDescription(SeamUIMessages.FIND_REFERENCES_ACTION_DESCRIPTION);
+ setToolTipText(SeamUIMessages.FIND_REFERENCES_ACTION_TOOL_TIP);
+ }
+
+ protected int getLimitTo() {
+ return SeamSearchScope.SEARCH_FOR_REFERENCES;
+ }
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/actions/FindSeamReferencesAction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties 2008-03-06 20:47:05 UTC (rev 6732)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/messages.properties 2008-03-06 21:02:35 UTC (rev 6733)
@@ -202,4 +202,30 @@
OPEN_SEAM_COMPONENT_ACTION_MESSAGE=Enter seam component name prefix or pattern (? = any character, * = any string):
OPEN_SEAM_COMPONENT_DIALOG_LOADING=Seam components loading
OPEN_SEAM_COMPONENT_DIALOG_NAME=OpenSeamComponentDialog
-SEAM_SETTINGS_PREFERENCES_PAGE_SEAM_PROJECT=Main Seam Project:
\ No newline at end of file
+SEAM_SETTINGS_PREFERENCES_PAGE_SEAM_PROJECT=Main Seam Project:
+FIND_DECLARATIONS_ACTION_ACTION_NAME=Find Seam Declarations
+FIND_DECLARATIONS_ACTION_DESCRIPTION=Find Seam Declarations
+FIND_DECLARATIONS_ACTION_TOOL_TIP=Find Seam Declarations
+FIND_DECLARATIONS_ACTION_MESSAGE=&Choose a name of the seam variable or pattern (? = any character, * = any string):
+FIND_REFERENCES_ACTION_ACTION_NAME=Find Seam References
+FIND_REFERENCES_ACTION_DESCRIPTION=Find Seam References
+FIND_REFERENCES_ACTION_TOOL_TIP=Find Seam References
+FIND_REFERENCES_ACTION_MESSAGE=&Choose a name of the seam variable or pattern (? = any character, * = any string):
+SeamSearchQuery_task_label=Searching for ''{0}''...
+SeamSearchQuery_label=Seam {0} Search
+SeamSearchQuery_error_unsupported_pattern=Unsupported search pattern: "{0}"
+# The first argument will be replaced by the pattern, the second by the scope, last by limitTo patterns
+SeamSearchQuery_singularPatternWithLimitTo= ''{0}'' - 1 match in {1} ({2})
+# The first argument will be replaced by the pattern, the second by the count and the third by the scope, last by limitTo patterns
+SeamSearchQuery_pluralPatternWithLimitTo=''{0}'' - {1} matches in {2} ({3})
+SeamSearchScope_scope_empty=empty scope
+SeamSearchScope_scope_single=''{0}''
+SeamSearchScope_scope_double=''{0}'', ''{1}''
+SeamSearchScope_scope_multiple=''{0}'', ''{1}'', ...
+SeamSearchScope_scope_LimitToDeclarations=Declarations
+SeamSearchScope_scope_LimitToReferences=References
+# The first argument will be replaced by the pattern, the second by the count and the third by the scope
+SeamSearchQuery_pluralPattern= ''{0}'' - {1} matches in {2} ({3})
+# The first argument will be replaced by the pattern, the second by the scope
+SeamSearchQuery_singularLabel= ''{0}'' - 1 match in {1} ({2})
+SeamSearchVisitor_scanning= Scanning Seam project {1} of {2}: {0}
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamElementMatch.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamElementMatch.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamElementMatch.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,49 @@
+package org.jboss.tools.seam.ui.search;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.search.ui.text.Match;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamDeclaration;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+import org.jboss.tools.seam.internal.core.el.ElVarSearcher.Var;
+
+public class SeamElementMatch extends Match {
+ private long fCreationTimeStamp;
+
+ public SeamElementMatch(ISeamElement element) {
+ super(element, 0, 0);
+ fCreationTimeStamp= element.getResource().getModificationStamp();
+ }
+
+ public SeamElementMatch(ISeamJavaSourceReference element) {
+ super(element, 0, 0);
+ fCreationTimeStamp= element.getSourceMember().getResource().getModificationStamp();
+ }
+
+ public SeamElementMatch(ISeamDeclaration element) {
+ super(element, 0, 0);
+ fCreationTimeStamp= element.getResource().getModificationStamp();
+ }
+
+ public SeamElementMatch(IFile element, int offset, int length) {
+ super(element, offset, length);
+ fCreationTimeStamp= ((IFile)element).getModificationStamp();
+ }
+
+ public IFile getFile() {
+ if (getElement() instanceof ISeamJavaSourceReference) {
+ return (IFile) ((ISeamJavaSourceReference)getElement()).getSourceMember().getResource();
+ } else if (getElement() instanceof ISeamDeclaration) {
+ return (IFile) ((ISeamDeclaration)getElement()).getResource();
+ } else if (getElement() instanceof IFile) {
+ return (IFile)getElement();
+ }
+ return (IFile) ((ISeamElement)getElement()).getResource();
+ }
+
+ public long getCreationTimeStamp() {
+ return fCreationTimeStamp;
+ }
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamElementMatch.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: 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 (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,67 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.util.regex.Pattern;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+
+import org.eclipse.core.resources.IFile;
+
+import org.eclipse.search.core.text.TextSearchRequestor;
+import org.eclipse.search.core.text.TextSearchEngine;
+import org.eclipse.search.core.text.TextSearchScope;
+import org.eclipse.search.internal.ui.SearchPlugin;
+
+public abstract class SeamSearchEngine {
+
+ /**
+ * Creates an instance of the search engine. By default this is the default text search engine (see {@link #createDefault()}),
+ * but extensions can offer more sophisticated search engine implementations.
+ * @return the created {@link TextSearchEngine}.
+ */
+ public static SeamSearchEngine create() {
+ return createDefault();
+ }
+
+ /**
+ * Creates the default, built-in, text search engine that implements a brute-force search, not using
+ * any search index.
+ * Note that clients should always use the search engine provided by {@link #create()}.
+ * @return an instance of the default text search engine {@link TextSearchEngine}.
+ */
+ public static SeamSearchEngine createDefault() {
+ return new SeamSearchEngine() {
+ public IStatus search(TextSearchScope scope, SeamSearchRequestor requestor, Pattern[] searchPatterns, IProgressMonitor monitor) {
+ return new SeamSearchVisitor(requestor, searchPatterns).search(scope, monitor);
+ }
+
+// public IStatus search(IFile[] scope, SeamSearchRequestor requestor, Pattern[] searchPatterns, IProgressMonitor monitor) {
+// return new SeamSearchVisitor(requestor, searchPatterns).search(scope, monitor);
+// }
+ };
+ }
+
+ /**
+ * Uses a given search pattern to find matches in the content of workspace file resources. If a file is open in an editor, the
+ * editor buffer is searched.
+
+ * @param requestor the search requestor that gets the search results
+ * @param scope the scope defining the resources to search in
+ * @param searchPattern The search pattern used to find matches in the file contents.
+ * @param monitor the progress monitor to use
+ * @return the status containing information about problems in resources searched.
+ */
+ public abstract IStatus search(TextSearchScope scope, SeamSearchRequestor requestor, Pattern[] searchPatterns, IProgressMonitor monitor);
+
+ /**
+ * Uses a given search pattern to find matches in the content of workspace file resources. If a file is open in an editor, the
+ * editor buffer is searched.
+
+ * @param requestor the search requestor that gets the search results
+ * @param scope the files to search in
+ * @param searchPattern The search pattern used to find matches in the file contents.
+ * @param monitor the progress monitor to use
+ * @return the status containing information about problems in resources searched.
+ */
+// public abstract IStatus search(IFile[] scope, SeamSearchRequestor requestor, Pattern[] searchPatterns, IProgressMonitor monitor);
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchEngine.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: 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 (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,278 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.ui.search.ElementQuerySpecification;
+import org.eclipse.jdt.ui.search.IMatchPresentation;
+import org.eclipse.jdt.ui.search.IQueryParticipant;
+import org.eclipse.jdt.ui.search.ISearchRequestor;
+import org.eclipse.jdt.ui.search.QuerySpecification;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.search.core.text.TextSearchEngine;
+import org.eclipse.search.core.text.TextSearchMatchAccess;
+import org.eclipse.search.core.text.TextSearchRequestor;
+import org.eclipse.search.core.text.TextSearchScope;
+import org.eclipse.search.internal.core.text.PatternConstructor;
+import org.eclipse.search.internal.core.text.TextSearchVisitor;
+import org.eclipse.search.internal.ui.Messages;
+import org.eclipse.search.internal.ui.SearchMessages;
+import org.eclipse.search.internal.ui.text.FileMatch;
+import org.eclipse.search.internal.ui.text.FileSearchResult;
+import org.eclipse.search.internal.ui.text.SearchResultUpdater;
+import org.eclipse.search.ui.ISearchQuery;
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.eclipse.search.ui.text.FileTextSearchScope;
+import org.eclipse.search.ui.text.IFileMatchAdapter;
+import org.eclipse.search.ui.text.Match;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamDeclaration;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+import org.jboss.tools.seam.internal.core.el.ElVarSearcher.Var;
+import org.jboss.tools.seam.ui.SeamUIMessages;
+
+public class SeamSearchQuery implements ISearchQuery {
+
+ private final static class SeamSearchResultCollector extends SeamSearchRequestor {
+ private final AbstractTextSearchResult fResult;
+// private final boolean fSearchInBinaries;
+ private ArrayList fCachedMatches;
+
+ private SeamSearchResultCollector(AbstractTextSearchResult result) {
+ fResult= result;
+// fSearchInBinaries= searchInBinaries;
+
+ }
+
+ public boolean acceptFile(IFile file) throws CoreException {
+// if (fIsFileSearchOnly) {
+// fResult.addMatch(new FileMatch(file, 0, 0));
+// }
+ flushMatches();
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.search.core.text.TextSearchRequestor#reportBinaryFile(org.eclipse.core.resources.IFile)
+ */
+ public boolean reportBinaryFile(IFile file) {
+ return false;
+ }
+
+ public boolean acceptPatternMatch(TextSearchMatchAccess matchRequestor) throws CoreException {
+ fCachedMatches.add(new FileMatch(matchRequestor.getFile(), matchRequestor.getMatchOffset(), matchRequestor.getMatchLength()));
+ return true;
+ }
+
+ public boolean acceptSeamDeclarationSourceReferenceMatch(ISeamJavaSourceReference element) throws CoreException {
+ fCachedMatches.add(new SeamElementMatch(element));
+ return true;
+ }
+
+ public boolean acceptSeamDeclarationMatch(ISeamDeclaration element) throws CoreException {
+ fCachedMatches.add(new SeamElementMatch(element));
+ return true;
+ }
+
+ public void beginReporting() {
+ fCachedMatches= new ArrayList();
+ }
+
+ public void endReporting() {
+ flushMatches();
+ fCachedMatches= null;
+ }
+
+ private void flushMatches() {
+ if (!fCachedMatches.isEmpty()) {
+ fResult.addMatches((Match[]) fCachedMatches.toArray(new Match[fCachedMatches.size()]));
+ fCachedMatches.clear();
+ }
+ }
+ }
+
+ private final SeamSearchScope fScope;
+ private final String[] fVariables;
+ private final Var fVar;
+ private SeamSearchResult fResult;
+
+ public SeamSearchQuery(String[] variables, SeamSearchScope scope) {
+ fVariables = variables;
+ fVar = null;
+ fScope= scope;
+ }
+
+ public SeamSearchQuery(Var var, SeamSearchScope scope) {
+ fVariables = null;
+ fVar = var;
+ fScope= scope;
+ }
+
+ public SeamSearchScope getSearchScope() {
+ return fScope;
+ }
+
+ public boolean canRunInBackground() {
+ return true;
+ }
+
+
+ public IStatus run(final IProgressMonitor monitor) {
+ AbstractTextSearchResult textResult= (AbstractTextSearchResult) getSearchResult();
+ textResult.removeAll();
+
+ if (fVariables != null) {
+ Pattern[] searchPatterns = new Pattern[fVariables == null ? 0 : fVariables.length];
+ for (int i = 0; i < searchPatterns.length; i++) {
+ searchPatterns[i]= getSearchPattern(fVariables[i]);
+ }
+ SeamSearchResultCollector collector= new SeamSearchResultCollector(textResult);
+ return SeamSearchEngine.create().search(fScope, collector, searchPatterns, monitor);
+ } else if (fVar != null) {
+ if (fScope.isLimitToDeclarations()) {
+ textResult.addMatch(new SeamElementMatch((IFile)fScope.getRoots()[0], fVar.getDeclarationOffset(), fVar.getDeclarationLength()));
+ } else {
+ Pattern[] searchPatterns = new Pattern[fVar == null ? 0 : 1];
+ if (searchPatterns.length > 0) {
+ searchPatterns[0]= getSearchPattern(fVar.getName());
+ }
+ SeamSearchResultCollector collector= new SeamSearchResultCollector(textResult);
+ return SeamSearchEngine.create().search(fScope, collector, searchPatterns, monitor);
+
+ }
+ return Status.OK_STATUS;
+ }
+ return Status.OK_STATUS;
+ }
+
+ private boolean isScopeAllFileTypes() {
+ String[] fileNamePatterns= fScope.getFileNamePatterns();
+ if (fileNamePatterns == null)
+ return true;
+ for (int i= 0; i < fileNamePatterns.length; i++) {
+ if ("*".equals(fileNamePatterns[i])) { //$NON-NLS-1$
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public String getLabel() {
+ Object[] args= { fScope.getLimitToDescription() };
+ return Messages.format(SeamUIMessages.SeamSearchQuery_label, args);
+ }
+
+ public String getSearchString() {
+ String searchString = "";
+ if (fVariables != null) {
+ StringBuffer buf= new StringBuffer();
+ for (int i= 0; i < fVariables.length; i++) {
+ if (i > 0) {
+ buf.append(", "); //$NON-NLS-1$
+ }
+ buf.append(fVariables[i]);
+ }
+ searchString = buf.toString();
+ } else if (fVar != null) {
+ searchString = fVar.getName();
+ }
+ return searchString;
+ }
+
+ public String getResultLabel(int nMatches) {
+ String searchString= getSearchString();
+ if (searchString.length() > 0) {
+ if (fScope.isLimitToDeclarations()) {
+ // search is limited to declarations only
+ if (nMatches == 1) {
+ Object[] args= { searchString, fScope.getDescription(), fScope.getLimitToDescription() };
+ return Messages.format(SeamUIMessages.SeamSearchQuery_singularPatternWithLimitTo, args);
+ }
+ Object[] args= { searchString, new Integer(nMatches), fScope.getDescription(), fScope.getLimitToDescription() };
+ return Messages.format(SeamUIMessages.SeamSearchQuery_pluralPatternWithLimitTo, args);
+ }
+ if (fScope.isLimitToReferences()) {
+ // text search
+ if (isScopeAllFileTypes()) {
+ // search all file extensions
+ if (nMatches == 1) {
+ Object[] args= { searchString, fScope.getDescription(), fScope.getLimitToDescription() };
+ return Messages.format(SeamUIMessages.SeamSearchQuery_singularLabel, args);
+ }
+ Object[] args= { searchString, new Integer(nMatches), fScope.getDescription(), fScope.getLimitToDescription() };
+ return Messages.format(SeamUIMessages.SeamSearchQuery_pluralPattern, args);
+ }
+ }
+ // text search
+ if (isScopeAllFileTypes()) {
+ // search all file extensions
+ if (nMatches == 1) {
+ Object[] args= { searchString, fScope.getDescription() };
+ return Messages.format(SearchMessages.FileSearchQuery_singularLabel, args);
+ }
+ Object[] args= { searchString, new Integer(nMatches), fScope.getDescription() };
+ return Messages.format(SearchMessages.FileSearchQuery_pluralPattern, args);
+ }
+ // search selected file extensions
+ if (nMatches == 1) {
+ Object[] args= { searchString, fScope.getDescription(), fScope.getFilterDescription() };
+ return Messages.format(SearchMessages.FileSearchQuery_singularPatternWithFileExt, args);
+ }
+ Object[] args= { searchString, new Integer(nMatches), fScope.getDescription(), fScope.getFilterDescription() };
+ return Messages.format(SearchMessages.FileSearchQuery_pluralPatternWithFileExt, args);
+ }
+ // file search
+ if (nMatches == 1) {
+ Object[] args= { fScope.getFilterDescription(), fScope.getDescription() };
+ return Messages.format(SearchMessages.FileSearchQuery_singularLabel_fileNameSearch, args);
+ }
+ Object[] args= { fScope.getFilterDescription(), new Integer(nMatches), fScope.getDescription() };
+ return Messages.format(SearchMessages.FileSearchQuery_pluralPattern_fileNameSearch, args);
+ }
+
+ /**
+ * @param result all result are added to this search result
+ * @param monitor the progress monitor to use
+ * @param file the file to search in
+ * @return returns the status of the operation
+ */
+/* public IStatus searchInFile(final AbstractTextSearchResult result, final IProgressMonitor monitor, IFile file) {
+ FileTextSearchScope scope= FileTextSearchScope.newSearchScope(new IResource[] { file }, new String[] { "*" }, true); //$NON-NLS-1$
+
+ Pattern[] searchPatterns= new Pattern[fVariables == null ? 0 : fVariables.length];
+ for (int i = 0; fVariables != null && i < fVariables.length; i++) {
+ searchPatterns[i]= getSearchPattern(fVariables[i]);
+ }
+ SeamSearchResultCollector collector= new SeamSearchResultCollector(result, true);
+
+ return SeamSearchEngine.create().search(scope, collector, searchPatterns, monitor);
+ }
+*/
+ protected Pattern getSearchPattern(String variableName) {
+ return PatternConstructor.createPattern(variableName, true, false);
+ }
+
+ public boolean canRerun() {
+ return true;
+ }
+
+ public ISearchResult getSearchResult() {
+ if (fResult == null) {
+ fResult= new SeamSearchResult(this);
+ new SearchResultUpdater(fResult);
+ }
+ return fResult;
+ }
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchQuery.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,46 @@
+package org.jboss.tools.seam.ui.search;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.search.core.text.TextSearchRequestor;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamDeclaration;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+
+public class SeamSearchRequestor extends TextSearchRequestor {
+
+ /**
+ * Notification sent before search starts in the given Seam Java Source Reference. This method is called for all Seam Java Source References are contained
+ * in the search scope.
+ * Implementors can decide if the Seam Java Source Reference's content should be searched for search matches or not.
+ * <p>
+ * The default behaviour is to search the file for matches.
+ * </p>
+ * @param Seam Java Source Reference the file resource to be searched.
+ * @return If false, no pattern matches will be reported for the content of this file.
+ * @throws CoreException implementors can throw a {@link CoreException} if accessing the resource fails or another
+ * problem prevented the processing of the search match.
+ */
+ public boolean acceptSeamDeclarationSourceReferenceMatch(ISeamJavaSourceReference reference) throws CoreException {
+ return true;
+ }
+
+ /**
+ * Notification sent before search starts in the given Seam Element. This method is called for all Seam Java Source References are contained
+ * in the search scope.
+ * Implementors can decide if the Seam Java Source Reference's content should be searched for search matches or not.
+ * <p>
+ * The default behaviour is to search the file for matches.
+ * </p>
+ * @param Seam Java Source Reference the file resource to be searched.
+ * @return If false, no pattern matches will be reported for the content of this file.
+ * @throws CoreException implementors can throw a {@link CoreException} if accessing the resource fails or another
+ * problem prevented the processing of the search match.
+ */
+ public boolean acceptSeamDeclarationMatch(ISeamDeclaration element) throws CoreException {
+ return true;
+ }
+
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchRequestor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,79 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.util.Map;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.ui.search.IMatchPresentation;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.search.internal.ui.SearchPluginImages;
+import org.eclipse.search.internal.ui.text.FileSearchQuery;
+import org.eclipse.search.ui.ISearchQuery;
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.search.ui.ISearchResultListener;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.eclipse.search.ui.text.IEditorMatchAdapter;
+import org.eclipse.search.ui.text.IFileMatchAdapter;
+import org.eclipse.search.ui.text.Match;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.jboss.tools.seam.ui.SeamGuiPlugin;
+
+public class SeamSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter, IFileMatchAdapter {
+ private final Match[] EMPTY_ARR= new Match[0];
+
+ private SeamSearchQuery fQuery;
+
+ public SeamSearchResult(SeamSearchQuery job) {
+ fQuery= job;
+ }
+ public ImageDescriptor getImageDescriptor() {
+ return SearchPluginImages.DESC_OBJ_TSEARCH_DPDN;
+ }
+ public String getLabel() {
+ return fQuery.getResultLabel(getMatchCount());
+ }
+ public String getTooltip() {
+ return getLabel();
+ }
+
+ public Match[] computeContainedMatches(AbstractTextSearchResult result, IFile file) {
+ return getMatches(file);
+ }
+
+ public IFile getFile(Object element) {
+ if (element instanceof IFile)
+ return (IFile)element;
+ return null;
+ }
+
+ public boolean isShownInEditor(Match match, IEditorPart editor) {
+ IEditorInput ei= editor.getEditorInput();
+ if (ei instanceof IFileEditorInput) {
+ IFileEditorInput fi= (IFileEditorInput) ei;
+ return match.getElement().equals(fi.getFile());
+ }
+ return false;
+ }
+
+ public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
+ IEditorInput ei= editor.getEditorInput();
+ if (ei instanceof IFileEditorInput) {
+ IFileEditorInput fi= (IFileEditorInput) ei;
+ return getMatches(fi.getFile());
+ }
+ return EMPTY_ARR;
+ }
+
+ public ISearchQuery getQuery() {
+ return fQuery;
+ }
+
+ public IFileMatchAdapter getFileMatchAdapter() {
+ return this;
+ }
+
+ public IEditorMatchAdapter getEditorMatchAdapter() {
+ return this;
+ }
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResult.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResultPage.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResultPage.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResultPage.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,342 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.util.HashMap;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.ILabelProvider;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredViewer;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
+import org.eclipse.search.internal.ui.Messages;
+import org.eclipse.search.internal.ui.SearchMessages;
+import org.eclipse.search.internal.ui.text.EditorOpener;
+import org.eclipse.search.internal.ui.text.FileLabelProvider;
+import org.eclipse.search.internal.ui.text.FileSearchPage;
+import org.eclipse.search.internal.ui.text.FileSearchQuery;
+import org.eclipse.search.internal.ui.text.FileTableContentProvider;
+import org.eclipse.search.internal.ui.text.FileTreeContentProvider;
+import org.eclipse.search.internal.ui.text.IFileSearchContentProvider;
+import org.eclipse.search.internal.ui.text.NewTextSearchActionGroup;
+//import org.eclipse.search.internal.ui.text.ReplaceAction2;
+import org.eclipse.search.internal.ui.text.ResourceTransferDragAdapter;
+import org.eclipse.search.internal.ui.text.SortAction;
+import org.eclipse.search.internal.ui.text.TextSearchPage;
+import org.eclipse.search.internal.ui.text.FileSearchPage.DecoratorIgnoringViewerSorter;
+import org.eclipse.search.ui.IContextMenuConstants;
+import org.eclipse.search.ui.ISearchResult;
+import org.eclipse.search.ui.ISearchResultPage;
+import org.eclipse.search.ui.ISearchResultViewPart;
+import org.eclipse.search.ui.NewSearchUI;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
+import org.eclipse.search.ui.text.Match;
+import org.eclipse.search2.internal.ui.OpenSearchPreferencesAction;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IMemento;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionContext;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.ide.IDE;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.part.IPageSite;
+import org.eclipse.ui.part.IShowInTargetList;
+import org.eclipse.ui.part.ResourceTransfer;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.seam.core.IOpenableElement;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+
+public class SeamSearchResultPage extends AbstractTextSearchViewPage implements IAdaptable {
+
+ public static class DecoratorIgnoringViewerSorter extends ViewerComparator {
+ private final ILabelProvider fLabelProvider;
+
+ public DecoratorIgnoringViewerSorter(ILabelProvider labelProvider) {
+ fLabelProvider= labelProvider;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jface.viewers.ViewerComparator#category(java.lang.Object)
+ */
+ public int category(Object element) {
+ if (element instanceof IContainer) {
+ return 1;
+ }
+ return 2;
+ }
+
+ public int compare(Viewer viewer, Object e1, Object e2) {
+ int cat1 = category(e1);
+ int cat2 = category(e2);
+
+ if (cat1 != cat2) {
+ return cat1 - cat2;
+ }
+
+ String name1= fLabelProvider.getText(e1);
+ String name2= fLabelProvider.getText(e2);
+ if (name1 == null)
+ name1 = "";//$NON-NLS-1$
+ if (name2 == null)
+ name2 = "";//$NON-NLS-1$
+ return getComparator().compare(name1, name2);
+ }
+ }
+
+ private static final String KEY_SORTING= "org.eclipse.search.resultpage.sorting"; //$NON-NLS-1$
+ private static final String KEY_LIMIT= "org.eclipse.search.resultpage.limit"; //$NON-NLS-1$
+
+ private static final int DEFAULT_ELEMENT_LIMIT = 1000;
+
+ private ActionGroup fActionGroup;
+ private IFileSearchContentProvider fContentProvider;
+ private int fCurrentSortOrder;
+// private SortAction fSortByNameAction;
+// private SortAction fSortByPathAction;
+
+ private EditorOpener fEditorOpener= new EditorOpener();
+
+
+ private static final String[] SHOW_IN_TARGETS= new String[] { IPageLayout.ID_RES_NAV };
+ private static final IShowInTargetList SHOW_IN_TARGET_LIST= new IShowInTargetList() {
+ public String[] getShowInTargetIds() {
+ return SHOW_IN_TARGETS;
+ }
+ };
+
+ public SeamSearchResultPage() {
+// fSortByNameAction= new SortAction(SearchMessages.FileSearchPage_sort_name_label, this, FileLabelProvider.SHOW_LABEL_PATH);
+// fSortByPathAction= new SortAction(SearchMessages.FileSearchPage_sort_path_label, this, FileLabelProvider.SHOW_PATH_LABEL);
+
+ setElementLimit(new Integer(DEFAULT_ELEMENT_LIMIT));
+ }
+
+ public void setElementLimit(Integer elementLimit) {
+ super.setElementLimit(elementLimit);
+ int limit= elementLimit.intValue();
+ getSettings().put(KEY_LIMIT, limit);
+ }
+
+ public StructuredViewer getViewer() {
+ return super.getViewer();
+ }
+
+ private void addDragAdapters(StructuredViewer viewer) {
+ Transfer[] transfers= new Transfer[] { ResourceTransfer.getInstance() };
+ int ops= DND.DROP_COPY | DND.DROP_LINK;
+ viewer.addDragSupport(ops, transfers, new ResourceTransferDragAdapter(viewer));
+ }
+
+ protected void configureTableViewer(TableViewer viewer) {
+ viewer.setUseHashlookup(true);
+ SeamSearchViewLabelProvider innerLabelProvider= new SeamSearchViewLabelProvider(this, FileLabelProvider.SHOW_LABEL_PATH);
+ viewer.setLabelProvider(new DecoratingLabelProvider(innerLabelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
+ viewer.setContentProvider(new SeamTableContentProvider(this));
+ viewer.setComparator(new DecoratorIgnoringViewerSorter(innerLabelProvider));
+ fContentProvider= (IFileSearchContentProvider) viewer.getContentProvider();
+ addDragAdapters(viewer);
+ }
+
+ protected void configureTreeViewer(TreeViewer viewer) {
+ viewer.setUseHashlookup(true);
+ SeamSearchViewLabelProvider innerLabelProvider= new SeamSearchViewLabelProvider(this, FileLabelProvider.SHOW_LABEL_PATH);
+ viewer.setLabelProvider(new DecoratingLabelProvider(innerLabelProvider, PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator()));
+ viewer.setContentProvider(new SeamTreeContentProvider(this, viewer));
+ viewer.setComparator(new DecoratorIgnoringViewerSorter(innerLabelProvider));
+ fContentProvider= (IFileSearchContentProvider) viewer.getContentProvider();
+ addDragAdapters(viewer);
+ }
+
+ protected void showMatch(Match match, int offset, int length, boolean activate) throws PartInitException {
+ if (match.getElement() instanceof ISeamJavaSourceReference) {
+ IJavaElement javaElement = ((ISeamJavaSourceReference)match.getElement()).getSourceMember();
+ try {
+ IEditorPart part = JavaUI.openInEditor(javaElement);
+ if (part != null) {
+ JavaUI.revealInEditor(part, (IJavaElement)javaElement);
+ }
+ } catch (PartInitException e) {
+// SeamExtPlugin.getPluginLog().logError(e);
+ } catch (JavaModelException e) {
+ // Ignore. It is probably because of Java element is not found
+ }
+ } else if (match.getElement() instanceof IOpenableElement) {
+ ((IOpenableElement)match.getElement()).open();
+ } else if (match.getElement() instanceof IFile) {
+ IFile file= (IFile) match.getElement();
+ IEditorPart editor= fEditorOpener.open(file, activate);
+ offset = match.getOffset();
+ length = match.getLength();
+ if (offset != 0 && length != 0) {
+ if (editor instanceof ITextEditor) {
+ ITextEditor textEditor= (ITextEditor) editor;
+ textEditor.selectAndReveal(offset, length);
+ } else if (editor != null) {
+ showWithMarker(editor, file, offset, length);
+ }
+ }
+ }
+ }
+
+ private void showWithMarker(IEditorPart editor, IFile file, int offset, int length) throws PartInitException {
+ IMarker marker= null;
+ try {
+ marker= file.createMarker(NewSearchUI.SEARCH_MARKER);
+ HashMap attributes= new HashMap(4);
+ attributes.put(IMarker.CHAR_START, new Integer(offset));
+ attributes.put(IMarker.CHAR_END, new Integer(offset + length));
+ marker.setAttributes(attributes);
+ IDE.gotoMarker(editor, marker);
+ } catch (CoreException e) {
+ throw new PartInitException(SearchMessages.FileSearchPage_error_marker, e);
+ } finally {
+ if (marker != null)
+ try {
+ marker.delete();
+ } catch (CoreException e) {
+ // ignore
+ }
+ }
+ }
+
+ protected void fillContextMenu(IMenuManager mgr) {
+ super.fillContextMenu(mgr);
+ addSortActions(mgr);
+ fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection()));
+ fActionGroup.fillContextMenu(mgr);
+ FileSearchQuery query= (FileSearchQuery) getInput().getQuery();
+ if (!"".equals(query.getSearchString())) { //$NON-NLS-1$
+// ReplaceAction2 replaceAction= new ReplaceAction2(this, (IStructuredSelection) getViewer().getSelection());
+// if (replaceAction.isEnabled())
+// mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAction);
+
+// ReplaceAction2 replaceAll= new ReplaceAction2(this);
+// if (replaceAll.isEnabled())
+// mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAll);
+ }
+ }
+
+ private void addSortActions(IMenuManager mgr) {
+ if (getLayout() != FLAG_LAYOUT_FLAT)
+ return;
+ MenuManager sortMenu= new MenuManager(SearchMessages.FileSearchPage_sort_by_label);
+// sortMenu.add(fSortByNameAction);
+// sortMenu.add(fSortByPathAction);
+
+// fSortByNameAction.setChecked(fCurrentSortOrder == fSortByNameAction.getSortOrder());
+// fSortByPathAction.setChecked(fCurrentSortOrder == fSortByPathAction.getSortOrder());
+
+ mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenu);
+ }
+
+ public void setViewPart(ISearchResultViewPart part) {
+ super.setViewPart(part);
+ fActionGroup= new NewTextSearchActionGroup(part);
+ }
+
+ public void init(IPageSite site) {
+ super.init(site);
+ IMenuManager menuManager = site.getActionBars().getMenuManager();
+ menuManager.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, new OpenSearchPreferencesAction());
+ }
+
+ public void dispose() {
+ fActionGroup.dispose();
+ super.dispose();
+ }
+
+ protected void elementsChanged(Object[] objects) {
+ if (fContentProvider != null)
+ fContentProvider.elementsChanged(objects);
+ }
+
+ protected void clear() {
+ if (fContentProvider != null)
+ fContentProvider.clear();
+ }
+
+ public void setSortOrder(int sortOrder) {
+ fCurrentSortOrder= sortOrder;
+ DecoratingLabelProvider lpWrapper= (DecoratingLabelProvider) getViewer().getLabelProvider();
+ ((FileLabelProvider) lpWrapper.getLabelProvider()).setOrder(sortOrder);
+ getViewer().refresh();
+ getSettings().put(KEY_SORTING, fCurrentSortOrder);
+ }
+
+ public void restoreState(IMemento memento) {
+ super.restoreState(memento);
+ try {
+ fCurrentSortOrder= getSettings().getInt(KEY_SORTING);
+ } catch (NumberFormatException e) {
+// fCurrentSortOrder= fSortByNameAction.getSortOrder();
+ }
+ int elementLimit= DEFAULT_ELEMENT_LIMIT;
+ try {
+ elementLimit= getSettings().getInt(KEY_LIMIT);
+ } catch (NumberFormatException e) {
+ }
+ if (memento != null) {
+ Integer value= memento.getInteger(KEY_SORTING);
+ if (value != null)
+ fCurrentSortOrder= value.intValue();
+
+ value= memento.getInteger(KEY_LIMIT);
+ if (value != null)
+ elementLimit= value.intValue();
+ }
+ setElementLimit(new Integer(elementLimit));
+ }
+ public void saveState(IMemento memento) {
+ super.saveState(memento);
+ memento.putInteger(KEY_SORTING, fCurrentSortOrder);
+ memento.putInteger(KEY_LIMIT, getElementLimit().intValue());
+ }
+
+ public Object getAdapter(Class adapter) {
+ if (IShowInTargetList.class.equals(adapter)) {
+ return SHOW_IN_TARGET_LIST;
+ }
+ return null;
+ }
+
+ public String getLabel() {
+ String label= super.getLabel();
+ StructuredViewer viewer= getViewer();
+ if (viewer instanceof TableViewer) {
+ TableViewer tv= (TableViewer) viewer;
+
+ AbstractTextSearchResult result= getInput();
+ if (result != null) {
+ int itemCount= ((IStructuredContentProvider) tv.getContentProvider()).getElements(getInput()).length;
+ int fileCount= getInput().getElements().length;
+ if (itemCount < fileCount) {
+ String format= SearchMessages.FileSearchPage_limited_format;
+ return Messages.format(format, new Object[]{label, new Integer(itemCount), new Integer(fileCount)});
+ }
+ }
+ }
+ return label;
+ }
+
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchResultPage.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchScope.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchScope.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchScope.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,156 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.search.core.text.TextSearchScope;
+import org.eclipse.search.internal.core.text.FilesOfScopeCalculator;
+import org.eclipse.search.internal.core.text.PatternConstructor;
+import org.eclipse.search.internal.ui.Messages;
+import org.eclipse.search.internal.ui.SearchMessages;
+import org.eclipse.search.internal.ui.WorkingSetComparator;
+import org.eclipse.search.internal.ui.util.FileTypeEditor;
+import org.eclipse.search.ui.text.FileTextSearchScope;
+import org.eclipse.ui.IWorkingSet;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.ui.SeamUIMessages;
+
+public class SeamSearchScope extends TextSearchScope {
+ public static final int SEARCH_FOR_DECLARATIONS = 0;
+ public static final int SEARCH_FOR_REFERENCES = 1;
+
+ private static final String[] FILE_NAMES = new String[] {
+ "*"
+ };
+
+ int fLimitTo;
+ String fDescription;
+ FileTextSearchScope fFileTextSearchScope;
+
+ public SeamSearchScope(IResource[] resources, int limitTo) {
+ fFileTextSearchScope = FileTextSearchScope.newSearchScope(resources,
+ FILE_NAMES, true);
+
+ String description;
+
+ if (resources.length == 0) {
+ description= SeamUIMessages.SeamSearchScope_scope_empty;
+ } else if (resources.length == 1) {
+ String label= SeamUIMessages.SeamSearchScope_scope_single;
+ description= Messages.format(label, resources[0].getName());
+ } else if (resources.length == 2) {
+ String label= SeamUIMessages.SeamSearchScope_scope_double;
+ description= Messages.format(label, new String[] { resources[0].getName(), resources[1].getName()});
+ } else {
+ String label= SeamUIMessages.SeamSearchScope_scope_multiple;
+ description= Messages.format(label, new String[] { resources[0].getName(), resources[1].getName()});
+ }
+
+ fLimitTo = limitTo;
+ }
+
+ public int getLimitTo() {
+ return fLimitTo;
+ }
+
+ public boolean isLimitToDeclarations() {
+ return (SEARCH_FOR_DECLARATIONS == fLimitTo);
+ }
+
+ public boolean isLimitToReferences() {
+ return (SEARCH_FOR_REFERENCES == fLimitTo);
+ }
+
+ @Override
+ public boolean contains(IResourceProxy proxy) {
+ return fFileTextSearchScope.contains(proxy);
+ }
+
+ /**
+ * Returns the file name pattern configured for this scope or <code>null</code> to match
+ * all file names.
+ *
+ * @return the file name pattern strings
+ */
+ public String[] getFileNamePatterns() {
+ return fFileTextSearchScope.getFileNamePatterns();
+ }
+
+ /**
+ * Returns the description of the scope
+ *
+ * @return the description of the scope
+ */
+ public String getDescription() {
+ return fFileTextSearchScope.getDescription();
+ }
+
+ /**
+ * Returns the description of the scope
+ *
+ * @return the description of the scope
+ */
+ public String getLimitToDescription() {
+ return isLimitToDeclarations() ?
+ SeamUIMessages.SeamSearchScope_scope_LimitToDeclarations :
+ SeamUIMessages.SeamSearchScope_scope_LimitToReferences;
+ }
+
+ /**
+ * Returns a description describing the file name patterns and content types.
+ *
+ * @return the description of the scope
+ */
+ public String getFilterDescription() {
+ return fFileTextSearchScope.getFilterDescription();
+ }
+
+ /**
+ * Returns the resources that form the root. Roots can not contain each other. Root elements are only part of the
+ * scope if they are also accepted by {@link #contains(IResourceProxy)}.
+ *
+ * @return returns the set of root resources. The default behavior is to return the workspace root.
+ */
+ public IResource[] getRoots() {
+ return fFileTextSearchScope.getRoots();
+ }
+
+
+ /**
+ * Evaluates all Seam Projects in this scope.
+ *
+ * @param status a {@link MultiStatus} to collect the error status that occurred while collecting resources.
+ * @return returns the files in the scope.
+ */
+ public ISeamProject[] evaluateSeamProjectsInScope(MultiStatus status) {
+ IFile[] files = evaluateFilesInScope(status);
+ ArrayList<IProject> projects = new ArrayList<IProject>();
+ ArrayList<ISeamProject> seamProjects = new ArrayList<ISeamProject>();
+
+ for (int i = 0; files != null && i < files.length; i++) {
+ IProject project = (files[i] == null ? null : files[i].getProject());
+ if (project == null || projects.contains(project))
+ continue;
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
+ if (seamProject != null && !seamProjects.contains(seamProject)) {
+ projects.add(project);
+ seamProjects.add(seamProject);
+ }
+ }
+ return (ISeamProject[]) seamProjects.toArray(new ISeamProject[seamProjects.size()]);
+ }
+
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchScope.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchViewLabelProvider.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchViewLabelProvider.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchViewLabelProvider.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,81 @@
+package org.jboss.tools.seam.ui.search;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.search.internal.ui.text.FileLabelProvider;
+import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
+import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.ui.views.SeamLabelProvider;
+
+public class SeamSearchViewLabelProvider extends LabelProvider {
+ private FileLabelProvider fFileLabelProvider;
+ private SeamLabelProvider fSeamLabelProvider;
+ private AbstractTextSearchViewPage fPage;
+ private int fOrderFlag;
+
+ public SeamSearchViewLabelProvider(AbstractTextSearchViewPage page, int orderFlag) {
+ fPage = page;
+ fOrderFlag = orderFlag;
+ fFileLabelProvider = new FileLabelProvider(page, orderFlag);
+ fSeamLabelProvider = new SeamLabelProvider();
+ }
+
+ @Override
+ public Image getImage(Object element) {
+ if (element instanceof ISeamContextVariable ||
+ element instanceof ISeamJavaSourceReference) {
+ return fSeamLabelProvider.getImage(element);
+ }
+ if (element instanceof ISeamElement) {
+ return fSeamLabelProvider.getImage(element);
+ }
+ if (element instanceof IProject) {
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject((IProject)element, false);
+ if (seamProject != null) {
+ return fSeamLabelProvider.getImage(seamProject);
+ }
+ return fFileLabelProvider.getImage(element);
+ }
+ if (element instanceof IFolder) {
+ return fFileLabelProvider.getImage(element);
+ }
+ if (element instanceof IFile) {
+ return fFileLabelProvider.getImage(element);
+ }
+ return null;
+ }
+
+ @Override
+ public String getText(Object element) {
+ if (element instanceof ISeamContextVariable ||
+ element instanceof ISeamJavaSourceReference) {
+ return fSeamLabelProvider.getText(element);
+ }
+ if (element instanceof ISeamElement) {
+ return fSeamLabelProvider.getText(element);
+ }
+ if (element instanceof IProject) {
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject((IProject)element, false);
+ if (seamProject != null) {
+ return fSeamLabelProvider.getText(seamProject);
+ }
+ return fFileLabelProvider.getText(element);
+ }
+
+ if (element instanceof IFile) {
+ return fFileLabelProvider.getText(element);
+ }
+ if (element instanceof IFolder) {
+ return fFileLabelProvider.getText(element);
+ }
+ return null;
+ }
+
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchViewLabelProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: 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 (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,858 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.io.IOException;
+import java.nio.charset.IllegalCharsetNameException;
+import java.nio.charset.UnsupportedCharsetException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.eclipse.core.filebuffers.FileBuffers;
+import org.eclipse.core.filebuffers.ITextFileBuffer;
+import org.eclipse.core.filebuffers.ITextFileBufferManager;
+import org.eclipse.core.filebuffers.LocationKind;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentDescription;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.content.IContentTypeManager;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.internal.ui.text.FastJavaPartitionScanner;
+import org.eclipse.jdt.ui.text.IJavaPartitions;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.Document;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.search.core.text.TextSearchScope;
+import org.eclipse.search.internal.core.text.DocumentCharSequence;
+import org.eclipse.search.internal.core.text.FileCharSequenceProvider;
+import org.eclipse.search.internal.core.text.FilesOfScopeCalculator;
+import org.eclipse.search.internal.core.text.TextSearchVisitor;
+import org.eclipse.search.internal.core.text.TextSearchVisitor.ReusableMatchAccess;
+import org.eclipse.search.internal.ui.Messages;
+import org.eclipse.search.internal.ui.SearchMessages;
+import org.eclipse.search.internal.ui.SearchPlugin;
+import org.eclipse.search.ui.NewSearchUI;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.texteditor.ITextEditor;
+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.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegionList;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode;
+import org.eclipse.wst.xml.core.internal.regions.DOMRegionContext;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.seam.core.BijectedAttributeType;
+import org.jboss.tools.seam.core.IBijectedAttribute;
+import org.jboss.tools.seam.core.IOpenableElement;
+import org.jboss.tools.seam.core.IRole;
+import org.jboss.tools.seam.core.ISeamComponentDeclaration;
+import org.jboss.tools.seam.core.ISeamContextShortVariable;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamDeclaration;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamFactory;
+import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
+import org.jboss.tools.seam.core.ISeamJavaSourceReference;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.ISeamScope;
+import org.jboss.tools.seam.core.ISeamTextSourceReference;
+import org.jboss.tools.seam.core.ISeamXmlFactory;
+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.AbstractSeamDeclaration;
+import org.jboss.tools.seam.internal.core.BijectedAttribute;
+import org.jboss.tools.seam.internal.core.Role;
+import org.jboss.tools.seam.internal.core.SeamComponent;
+import org.jboss.tools.seam.internal.core.SeamJavaContextVariable;
+import org.jboss.tools.seam.internal.core.el.ELOperandToken;
+import org.jboss.tools.seam.internal.core.el.ELStringToken;
+import org.jboss.tools.seam.internal.core.el.ELToken;
+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.SeamELOperandTokenizerForward;
+import org.jboss.tools.seam.internal.core.el.SeamELStringTokenizer;
+import org.jboss.tools.seam.internal.core.el.SeamELTokenizer;
+import org.jboss.tools.seam.internal.core.el.ElVarSearcher.Var;
+import org.jboss.tools.seam.ui.SeamGuiPlugin;
+import org.jboss.tools.seam.ui.SeamUIMessages;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class SeamSearchVisitor {
+ private final Matcher[] fMatchers;
+ private final SeamSearchRequestor fCollector;
+
+ private final MultiStatus fStatus;
+ private IProgressMonitor fProgressMonitor;
+ private int fNumberOfScannedFiles;
+ private int fNumberOfFilesToScan;
+ private ISeamProject fCurrentSeamProject;
+ private Map fDocumentsInEditors;
+ private final TextSearchVisitor.ReusableMatchAccess fMatchAccess;
+
+ private IFile fCurrentFile;
+ private final FileCharSequenceProvider fFileCharSequenceProvider;
+ private final SeamELCompletionEngine fCompletionEngine;
+
+ public SeamSearchVisitor(SeamSearchRequestor collector,
+ Pattern[] searchPatterns) {
+ fCollector= collector;
+ fStatus= new MultiStatus(NewSearchUI.PLUGIN_ID, IStatus.OK, SearchMessages.TextSearchEngine_statusMessage, null);
+ fMatchers = new Matcher[searchPatterns == null ? 0 : searchPatterns.length];
+ for (int i = 0; searchPatterns != null && i < searchPatterns.length; i++) {
+ fMatchers[i]= searchPatterns[i].pattern().length() == 0 ? null : searchPatterns[i].matcher(new String());
+ }
+ fFileCharSequenceProvider= new FileCharSequenceProvider();
+ fMatchAccess= new ReusableMatchAccess();
+ fCompletionEngine = new SeamELCompletionEngine();
+ }
+
+ SeamSearchScope fCurrentScope = null;
+ public IStatus search(TextSearchScope scope, IProgressMonitor monitor) {
+ try {
+ if (scope instanceof SeamSearchScope) {
+ fCurrentScope = (SeamSearchScope)scope;
+ if (((SeamSearchScope)scope).isLimitToDeclarations()) {
+ return searchForDeclarations(((SeamSearchScope)scope).evaluateSeamProjectsInScope(fStatus), monitor);
+ } else {
+ return searchForReferences(((SeamSearchScope)scope).evaluateSeamProjectsInScope(fStatus), monitor);
+ }
+
+ }
+ } finally {
+ fCurrentScope = null;
+ }
+ return Status.OK_STATUS;
+ }
+
+ public IStatus searchForDeclarations(ISeamProject[] projects, IProgressMonitor monitor) {
+ fProgressMonitor= monitor == null ? new NullProgressMonitor() : monitor;
+ fNumberOfScannedFiles= 0;
+ fNumberOfFilesToScan= projects.length;
+ fCurrentSeamProject= null;
+
+ Job monitorUpdateJob= new MonitorUpdateJob();
+
+ try {
+ fProgressMonitor.beginTask(getTaskName(), fNumberOfFilesToScan);
+ monitorUpdateJob.setSystem(true);
+ monitorUpdateJob.schedule();
+ try {
+ fCollector.beginReporting();
+ processSeamProjects(projects, true);
+ return fStatus;
+ } finally {
+ monitorUpdateJob.cancel();
+ }
+ } finally {
+ fProgressMonitor.done();
+ fCollector.endReporting();
+ }
+ }
+
+ private void processSeamProjects(ISeamProject[] projects, boolean searchDeclarations) {
+ for (int i= 0; i < projects.length; i++) {
+ fCurrentSeamProject= projects[i];
+ boolean res= searchDeclarations ? processSeamDeclarationsInProject(fCurrentSeamProject) :
+ processSeamReferencesInProject(fCurrentSeamProject);
+ if (!res)
+ break;
+ }
+ }
+
+ private ElVarSearcher fELVarSearcher;
+ public boolean processSeamReferencesInProject(ISeamProject project) {
+ IFile[] files = fCurrentScope == null ? null :
+ fCurrentScope.evaluateFilesInScope(fStatus);
+
+
+
+ fELVarSearcher = new ElVarSearcher(project, fCompletionEngine);
+ fDocumentsInEditors= evalNonFileBufferDocuments();
+ boolean res= true;
+ for (int i = 0; files != null && i < files.length; i++) {
+ res= processSeamReferencesInFile(files[i]);
+ if (!res)
+ break;
+
+ }
+ fDocumentsInEditors= null;
+ fELVarSearcher = null;
+ return res;
+ }
+
+ private boolean processSeamReferencesInFile(IFile file) {
+ try {
+ if (!fCollector.acceptFile(file) || fMatchers == null) {
+ return true;
+ }
+
+ IDocument document= getOpenDocument(file);
+
+ if (document != null) {
+ DocumentCharSequence documentCharSequence= new DocumentCharSequence(document);
+ // assume all documents are non-binary
+ locateMatches(file, documentCharSequence);
+ } else {
+ CharSequence seq= null;
+ try {
+ seq= fFileCharSequenceProvider.newCharSequence(file);
+ if (hasBinaryContent(seq, file) && !fCollector.reportBinaryFile(file)) {
+ return true;
+ }
+ locateMatches(file, seq);
+ } catch (FileCharSequenceProvider.FileCharSequenceException e) {
+ e.throwWrappedException();
+ } finally {
+ if (seq != null) {
+ try {
+ fFileCharSequenceProvider.releaseCharSequence(seq);
+ } catch (IOException e) {
+ SearchPlugin.log(e);
+ }
+ }
+ }
+ }
+ } catch (UnsupportedCharsetException e) {
+ String[] args= { getCharSetName(file), file.getFullPath().makeRelative().toString()};
+ String message= Messages.format(SearchMessages.TextSearchVisitor_unsupportedcharset, args);
+ fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+ } catch (IllegalCharsetNameException e) {
+ String[] args= { getCharSetName(file), file.getFullPath().makeRelative().toString()};
+ String message= Messages.format(SearchMessages.TextSearchVisitor_illegalcharset, args);
+ fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+ } catch (IOException e) {
+ String[] args= { getExceptionMessage(e), file.getFullPath().makeRelative().toString()};
+ String message= Messages.format(SearchMessages.TextSearchVisitor_error, args);
+ fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+ } catch (CoreException e) {
+ String[] args= { getExceptionMessage(e), file.getFullPath().makeRelative().toString()};
+ String message= Messages.format(SearchMessages.TextSearchVisitor_error, args);
+ fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+ } catch (StackOverflowError e) {
+ String message= SearchMessages.TextSearchVisitor_patterntoocomplex0;
+ fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
+ return false;
+ } finally {
+ fNumberOfScannedFiles++;
+ }
+ if (fProgressMonitor.isCanceled())
+ throw new OperationCanceledException(SearchMessages.TextSearchVisitor_canceled);
+
+ return true;
+ }
+
+
+ private void locateMatches(IFile file, CharSequence searchInput) throws CoreException {
+ fELVarSearcher.setFile(file);
+ if("java".equalsIgnoreCase(file.getFileExtension())) { //$NON-NLS-1$
+ locateMatchesInJava(file, searchInput);
+ } else {
+ locateMatchesInDom(file, searchInput);
+ }
+ }
+
+ private List<Var> varListForCurentValidatedNode = new ArrayList<Var>();
+ private void locateMatchesInDom(IFile file, CharSequence content) {
+ varListForCurentValidatedNode.clear();
+ IModelManager manager = StructuredModelManager.getModelManager();
+ if(manager == null) {
+ // this can happen if plugin org.eclipse.wst.sse.core
+ // is stopping or uninstalled, that is Eclipse is shutting down.
+ // there is no need to report it, just stop validation.
+ return;
+ }
+ IStructuredModel model = null;
+ try {
+ model = manager.getModelForRead(file);
+ if (model instanceof IDOMModel) {
+ IDOMModel domModel = (IDOMModel) model;
+ IDOMDocument document = domModel.getDocument();
+ locateMatchesInChildNodes(file, document, content);
+ }
+ } catch (CoreException e) {
+ SeamCorePlugin.getDefault().logError(SeamCoreMessages.SEAM_EL_VALIDATOR_ERROR_VALIDATING_SEAM_EL, e);
+ } catch (IOException e) {
+ SeamCorePlugin.getDefault().logError(SeamCoreMessages.SEAM_EL_VALIDATOR_ERROR_VALIDATING_SEAM_EL, e);
+ } finally {
+ if (model != null) {
+ model.releaseFromRead();
+ }
+ }
+ return;
+ }
+
+ private void locateMatchesInChildNodes(IFile file, Node parent, CharSequence content)
+ throws CoreException {
+ Var var = ElVarSearcher.findVar(parent);
+ if(var!=null) {
+ varListForCurentValidatedNode.add(var);
+ }
+ NodeList children = parent.getChildNodes();
+ for(int i=0; i<children.getLength(); i++) {
+ Node curentValidatedNode = children.item(i);
+ if(Node.ELEMENT_NODE == curentValidatedNode.getNodeType()) {
+ locateMatchesInNodeContent(file, ((IDOMNode)curentValidatedNode).getFirstStructuredDocumentRegion(), DOMRegionContext.XML_TAG_ATTRIBUTE_VALUE, content);
+ } else if(Node.TEXT_NODE == curentValidatedNode.getNodeType()) {
+ locateMatchesInNodeContent(file, ((IDOMNode)curentValidatedNode).getFirstStructuredDocumentRegion(), DOMRegionContext.XML_CONTENT, content);
+ }
+ locateMatchesInChildNodes(file, curentValidatedNode, content);
+ }
+ if(var!=null) {
+ varListForCurentValidatedNode.remove(var);
+ }
+ }
+
+ private void locateMatchesInNodeContent(IFile file, IStructuredDocumentRegion node,
+ String regionType, CharSequence content) throws CoreException {
+ ITextRegionList regions = node.getRegions();
+ for(int i=0; i<regions.size(); i++) {
+ ITextRegion region = regions.get(i);
+ if(region.getType() == regionType) {
+ String text = node.getFullText(region);
+ if(text.indexOf("{")>-1) { //$NON-NLS-1$
+ int offset = node.getStartOffset() + region.getStart();
+ locateMatchesInString(file, text, offset, content);
+ }
+ }
+ }
+ }
+
+ private void locateMatchesInJava(IFile file, CharSequence content) throws CoreException {
+ try {
+ FastJavaPartitionScanner scaner = new FastJavaPartitionScanner();
+ Document document = new Document(content.subSequence(0, content.length()).toString());
+ scaner.setRange(document, 0, document.getLength());
+ IToken token = scaner.nextToken();
+ while(token!=null && token!=Token.EOF) {
+ if(IJavaPartitions.JAVA_STRING.equals(token.getData())) {
+ int length = scaner.getTokenLength();
+ int offset = scaner.getTokenOffset();
+ String value = document.get(offset, length);
+ if(value.indexOf('{')>-1) {
+ locateMatchesInString(file, value, offset, content);
+ } else if (false) {
+ // TODO: Insert here the check for named Seam annotations
+
+ } else if (true) {
+
+ }
+ }
+ token = scaner.nextToken();
+ }
+ } catch (BadLocationException e) {
+ SeamGuiPlugin.getDefault().logError(e);
+ }
+ }
+
+ /**
+ * @param offset - offset of string in file
+ * @param length - length of string in file
+ */
+ private void locateMatchesInString(IFile file, String string, int offset, CharSequence content) throws CoreException {
+ int startEl = string.indexOf("#{"); //$NON-NLS-1$
+ if(startEl>-1) {
+ SeamELStringTokenizer st = new SeamELStringTokenizer(string);
+ List<ELStringToken> tokens = st.getTokens();
+ for (ELStringToken stringToken : tokens) {
+ stringToken.setStart(offset + stringToken.getStart() + 2);
+ locateMatchesInEL(file, stringToken, content);
+ }
+ }
+ }
+
+ private void locateMatchesInEL(IFile file, ELStringToken el, CharSequence content) throws CoreException {
+ String exp = el.getBody();
+ SeamELTokenizer elTokenizer = new SeamELTokenizer(exp);
+ List<ELToken> tokens = elTokenizer.getTokens();
+ for (ELToken token : tokens) {
+ if(token.getType()==ELToken.EL_VARIABLE_TOKEN) {
+// validateElOperand(file, token, el.getStart());
+ String operand = token.getText();
+ String varName = operand;
+ int offsetOfToken = el.getStart() + token.getStart();
+ SeamELOperandTokenizerForward forwardTokenizer = new SeamELOperandTokenizerForward(operand, 0);
+ List<ELOperandToken>operandTokens = forwardTokenizer.getTokens();
+ List<List<ELOperandToken>> variations = SeamELCompletionEngine.getPossibleVarsFromPrefix(operandTokens);
+
+ for (List<ELOperandToken> variation : variations) {
+ int start = variation.get(0).getStart();
+ int end = variation.get(variation.size() - 1).getStart() +
+ variation.get(variation.size() - 1).getLength();
+ String variationText = operand.substring(start, end);
+
+ if (!matches(variationText))
+ continue;
+
+ int offsetOfOperandToken = offsetOfToken + start;
+ int lengthOfOperandToken = end - start;
+ fMatchAccess.initialize(file, offsetOfOperandToken, lengthOfOperandToken, content);
+ boolean res= fCollector.acceptPatternMatch(fMatchAccess);
+ if (!res) {
+ return; // no further reporting requested
+ }
+
+ System.out.println("");
+ }
+ }
+ }
+ }
+
+
+
+ public boolean processSeamDeclarationsInProject(ISeamProject project) {
+ try {
+ Set<ISeamContextVariable> variables = project.getVariables(true);
+ Set<String> namesToExclude = new HashSet<String>();
+ boolean continueSearch = true; // Is to be set to false in case of at least one component or role/out/databinder declaration is found
+
+ // Search for Seam components and @Name, @Role, @Out/DataBinder
+ for (ISeamContextVariable variable : variables) {
+ String varName = variable.getName();
+ ISeamContextVariable origin = variable;
+
+ if (!matches(varName))
+ continue;
+
+ if (variable instanceof ISeamContextShortVariable) {
+ variable = ((ISeamContextShortVariable)variable).getOriginal();
+ }
+
+ if (variable instanceof SeamComponent) {
+ namesToExclude.add(varName);
+ SeamComponent comp = (SeamComponent)variable;
+ Set<ISeamComponentDeclaration> declarations = comp.getAllDeclarations();
+ for (ISeamComponentDeclaration decl : declarations) {
+ if (decl instanceof ISeamJavaSourceReference) {
+ ISeamJavaSourceReference sourceRef = (ISeamJavaSourceReference)decl;
+ IResource resource = sourceRef.getSourceMember().getResource();
+ IJavaElement sourceMember = sourceRef.getSourceMember();
+ String name = sourceRef.getSourceMember().getElementName();
+ int offset = sourceRef.getStartPosition();
+ int length = sourceRef.getLength();
+ //fMatchAccess.initialize((IFile)resource, offset, length, (CharSequence)name);
+ boolean res= fCollector.acceptSeamDeclarationSourceReferenceMatch(sourceRef);
+ if (!res) {
+ return true; // no further reporting requested
+ }
+ continueSearch = false;
+ } else if (decl instanceof IOpenableElement) {
+ IResource resource = decl.getResource();
+ String name = decl.getName();
+
+ ISeamTextSourceReference textSourceReference = decl.getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME);
+ int offset = textSourceReference == null ? decl.getStartPosition() : textSourceReference.getStartPosition();
+ int length = textSourceReference == null ? decl.getLength() : textSourceReference.getLength();
+
+ fMatchAccess.initialize((IFile)resource, offset, length, (CharSequence)name);
+ boolean res= fCollector.acceptPatternMatch(fMatchAccess);
+ if (!res) {
+ return true; // no further reporting requested
+ }
+ continueSearch = false;
+ }
+ }
+ } else if (variable instanceof IRole) {
+ namesToExclude.add(varName);
+ // add the declaration
+ ISeamDeclaration decl = (ISeamDeclaration)variable;
+ IResource resource = decl.getResource();
+ String name = decl.getName();
+
+ ISeamTextSourceReference textSourceReference = decl.getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME);
+ if (textSourceReference != null) {
+ int offset = textSourceReference.getStartPosition();
+ int length = textSourceReference.getLength();
+ fMatchAccess.initialize((IFile)resource, offset, length, (CharSequence)name);
+ boolean res= fCollector.acceptPatternMatch(fMatchAccess);
+ if (!res) {
+ return true; // no further reporting requested
+ }
+ continueSearch = false;
+ }
+
+ } else if (variable instanceof IBijectedAttribute) {
+ namesToExclude.add(varName);
+ IBijectedAttribute ba = (IBijectedAttribute)variable;
+ BijectedAttributeType[] types = ba.getTypes();
+ boolean hasDeclarationType = false;
+ for (int i = 0; !hasDeclarationType && types != null && i < types.length; i++) {
+ if (types[i] == BijectedAttributeType.OUT ||
+ types[i] == BijectedAttributeType.DATA_BINDER ||
+ types[i] == BijectedAttributeType.DATA_MODEL_SELECTION) {
+ hasDeclarationType = true;
+ }
+ }
+ if (hasDeclarationType) {
+ // add the declaration
+ ISeamDeclaration decl = (ISeamDeclaration)variable;
+ IResource resource = decl.getResource();
+ String name = decl.getName();
+
+ ISeamTextSourceReference textSourceReference = decl.getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME);
+ if (textSourceReference != null) {
+ int offset = textSourceReference.getStartPosition();
+ int length = textSourceReference.getLength();
+
+ fMatchAccess.initialize((IFile)resource, offset, length, (CharSequence)name);
+ boolean res= fCollector.acceptPatternMatch(fMatchAccess);
+ if (!res) {
+ return true; // no further reporting requested
+ }
+ continueSearch = false;
+ }
+ }
+ }
+ }
+ if (continueSearch) {
+ // Search for Seam factories
+ for (ISeamContextVariable variable : variables) {
+ String varName = variable.getName();
+ if (namesToExclude.contains(varName)) // Do not process used names
+ continue;
+ if (!matches(varName))
+ continue;
+
+ if (variable instanceof ISeamDeclaration) {
+ ISeamDeclaration decl = (ISeamDeclaration)variable;
+ IResource resource = decl.getResource();
+ String name = decl.getName();
+
+ ISeamTextSourceReference textSourceReference = decl.getLocationFor(AbstractSeamDeclaration.PATH_OF_NAME);
+ if (textSourceReference != null) {
+ int offset = textSourceReference.getStartPosition();
+ int length = textSourceReference.getLength();
+
+ boolean res= fCollector.acceptSeamDeclarationMatch(decl);
+ if (!res) {
+ return true; // no further reporting requested
+ }
+ }
+ }
+ }
+ }
+ } catch (CoreException ce) {
+ String[] args= { getExceptionMessage(ce), project.getResource().getFullPath().makeRelative().toString()};
+ String message= Messages.format(SearchMessages.TextSearchVisitor_error, args);
+ fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, ce));
+ }
+ if (fProgressMonitor.isCanceled())
+ throw new OperationCanceledException(SearchMessages.TextSearchVisitor_canceled);
+
+ return true;
+/*
+ IFile file = null; // was a parameter
+ try {
+ if (!fCollector.acceptFile(file) || fMatcher == null) {
+ return true;
+ }
+
+ IDocument document= getOpenDocument(file);
+
+ if (document != null) {
+ DocumentCharSequence documentCharSequence= new DocumentCharSequence(document);
+ // assume all documents are non-binary
+ locateMatches(file, documentCharSequence);
+ } else {
+ CharSequence seq= null;
+ try {
+ seq= fFileCharSequenceProvider.newCharSequence(file);
+ if (hasBinaryContent(seq, file) && !fCollector.reportBinaryFile(file)) {
+ return true;
+ }
+ locateMatches(file, seq);
+ } catch (FileCharSequenceProvider.FileCharSequenceException e) {
+ e.throwWrappedException();
+ } finally {
+ if (seq != null) {
+ try {
+ fFileCharSequenceProvider.releaseCharSequence(seq);
+ } catch (IOException e) {
+ SearchPlugin.log(e);
+ }
+ }
+ }
+ }
+ } catch (UnsupportedCharsetException e) {
+ String[] args= { getCharSetName(file), file.getFullPath().makeRelative().toString()};
+ String message= Messages.format(SearchMessages.TextSearchVisitor_unsupportedcharset, args);
+ fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+ } catch (IOException e) {
+ String[] args= { getExceptionMessage(e), file.getFullPath().makeRelative().toString()};
+ String message= Messages.format(SearchMessages.TextSearchVisitor_error, args);
+ fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+ } catch (CoreException e) {
+ String[] args= { getExceptionMessage(e), file.getFullPath().makeRelative().toString()};
+ String message= Messages.format(SearchMessages.TextSearchVisitor_error, args);
+ fStatus.add(new Status(IStatus.WARNING, NewSearchUI.PLUGIN_ID, IStatus.WARNING, message, e));
+ } catch (StackOverflowError e) {
+ String message= SearchMessages.TextSearchVisitor_patterntoocomplex0;
+ fStatus.add(new Status(IStatus.ERROR, NewSearchUI.PLUGIN_ID, IStatus.ERROR, message, e));
+ return false;
+ } finally {
+ fNumberOfScannedFiles++;
+ }
+ if (fProgressMonitor.isCanceled())
+ throw new OperationCanceledException(SearchMessages.TextSearchVisitor_canceled);
+
+ return true;
+ */
+ }
+
+ private class MonitorUpdateJob extends Job {
+ private int fLastNumberOfScannedFiles= 0;
+
+ MonitorUpdateJob() {
+ super(SearchMessages.TextSearchVisitor_progress_updating_job);
+ }
+
+ public IStatus run(IProgressMonitor inner) {
+ while (!inner.isCanceled()) {
+ ISeamProject seamProject= fCurrentSeamProject;
+ if (seamProject != null) {
+ String seamProjectName= seamProject.getProject().getName();
+ Object[] args= { seamProjectName, new Integer(fNumberOfScannedFiles), new Integer(fNumberOfFilesToScan)};
+ fProgressMonitor.subTask(Messages.format(SeamUIMessages.SeamSearchVisitor_scanning, args));
+ int steps= fNumberOfScannedFiles - fLastNumberOfScannedFiles;
+ fProgressMonitor.worked(steps);
+ fLastNumberOfScannedFiles += steps;
+ }
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ return Status.OK_STATUS;
+ }
+ }
+ return Status.OK_STATUS;
+ }
+ }
+
+ private String getTaskName() {
+ String taskName= fMatchers[0] == null ? SearchMessages.TextSearchVisitor_filesearch_task_label : Messages.format(SearchMessages.TextSearchVisitor_textsearch_task_label, fMatchers[0].pattern());
+
+ return taskName;
+ }
+
+ public IStatus searchForReferences(ISeamProject[] projects, IProgressMonitor monitor) {
+ fProgressMonitor= monitor == null ? new NullProgressMonitor() : monitor;
+ fNumberOfScannedFiles= 0;
+ fNumberOfFilesToScan= projects.length;
+ fCurrentSeamProject= null;
+
+ Job monitorUpdateJob= new MonitorUpdateJob();
+
+ try {
+ fProgressMonitor.beginTask(getTaskName(), fNumberOfFilesToScan);
+ monitorUpdateJob.setSystem(true);
+ monitorUpdateJob.schedule();
+ try {
+ fCollector.beginReporting();
+ processSeamProjects(projects, false);
+ return fStatus;
+ } finally {
+ monitorUpdateJob.cancel();
+ }
+ } finally {
+ fProgressMonitor.done();
+ fCollector.endReporting();
+ }
+ }
+
+
+
+ private boolean matches(CharSequence searchInput) {
+ try {
+ for (int i = 0; fMatchers != null && i < fMatchers.length; i++) {
+ if (fMatchers[i] == null)
+ continue;
+ fMatchers[i].reset(searchInput);
+ if (fMatchers[i].find() && fMatchers[i].group().equals(searchInput)) {
+ return true;
+ }
+ }
+ } finally {
+// fMatcher.reset();
+ }
+ return false;
+ }
+
+ private String getExceptionMessage(Exception e) {
+ String message= e.getLocalizedMessage();
+ if (message == null) {
+ return e.getClass().getName();
+ }
+ return message;
+ }
+
+ private boolean hasBinaryContent(CharSequence seq, IFile file) throws CoreException {
+ IContentDescription desc= file.getContentDescription();
+ if (desc != null) {
+ IContentType contentType= desc.getContentType();
+ if (contentType != null && contentType.isKindOf(Platform.getContentTypeManager().getContentType(IContentTypeManager.CT_TEXT))) {
+ return false;
+ }
+ }
+
+ // avoid calling seq.length() at it runs through the complete file,
+ // thus it would do so for all binary files.
+ try {
+ int limit= FileCharSequenceProvider.BUFFER_SIZE;
+ for (int i= 0; i < limit; i++) {
+ if (seq.charAt(i) == '\0') {
+ return true;
+ }
+ }
+ } catch (IndexOutOfBoundsException e) {
+ }
+ return false;
+ }
+
+ /**
+ * @return returns a map from IFile to IDocument for all open, dirty editors
+ */
+ private Map evalNonFileBufferDocuments() {
+ Map result= new HashMap();
+ IWorkbench workbench= SearchPlugin.getDefault().getWorkbench();
+ IWorkbenchWindow[] windows= workbench.getWorkbenchWindows();
+ for (int i= 0; i < windows.length; i++) {
+ IWorkbenchPage[] pages= windows[i].getPages();
+ for (int x= 0; x < pages.length; x++) {
+ IEditorReference[] editorRefs= pages[x].getEditorReferences();
+ for (int z= 0; z < editorRefs.length; z++) {
+ IEditorPart ep= editorRefs[z].getEditor(false);
+ if (ep instanceof ITextEditor && ep.isDirty()) { // only dirty editors
+ evaluateTextEditor(result, ep);
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ private void evaluateTextEditor(Map result, IEditorPart ep) {
+ IEditorInput input= ep.getEditorInput();
+ if (input instanceof IFileEditorInput) {
+ IFile file= ((IFileEditorInput) input).getFile();
+ if (!result.containsKey(file)) { // take the first editor found
+ ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager();
+ ITextFileBuffer textFileBuffer= bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
+ if (textFileBuffer != null) {
+ // file buffer has precedence
+ result.put(file, textFileBuffer.getDocument());
+ } else {
+ // use document provider
+ IDocument document= ((ITextEditor) ep).getDocumentProvider().getDocument(input);
+ if (document != null) {
+ result.put(file, document);
+ }
+ }
+ }
+ }
+ }
+
+ private IDocument getOpenDocument(IFile file) {
+ IDocument document= (IDocument) fDocumentsInEditors.get(file);
+ if (document == null) {
+ ITextFileBufferManager bufferManager= FileBuffers.getTextFileBufferManager();
+ ITextFileBuffer textFileBuffer= bufferManager.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
+ if (textFileBuffer != null) {
+ document= textFileBuffer.getDocument();
+ }
+ }
+ return document;
+ }
+
+ private String getCharSetName(IFile file) {
+ try {
+ return file.getCharset();
+ } catch (CoreException e) {
+ return "unknown"; //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Evaluates all files in this scope.
+ *
+ * @param status a {@link MultiStatus} to collect the error status that occurred while collecting resources.
+ * @return returns the files in the scope.
+ */
+ public IFile[] evaluateProjectFilesInScope(IProject project, MultiStatus status) {
+ return new ProjectFilesOfScopeCalculator(project, fCurrentScope, status).process();
+ }
+
+ class ProjectFilesOfScopeCalculator implements IResourceProxyVisitor {
+ private final IProject fProject;
+ private final TextSearchScope fScope;
+ private final MultiStatus fStatus;
+ private ArrayList fFiles;
+
+ public ProjectFilesOfScopeCalculator(IProject project, SeamSearchScope scope, MultiStatus status) {
+ fProject = project;
+ fScope = scope;
+ fStatus= status;
+ }
+
+ public boolean visit(IResourceProxy proxy) {
+ if (fScope == null)
+ return false;
+ boolean inScope= fScope.contains(proxy);
+
+ if (inScope && proxy.getType() == IResource.FILE &&
+ fProject == proxy.requestResource().getProject()) {
+ fFiles.add(proxy.requestResource());
+ }
+ return inScope;
+ }
+
+ public IFile[] process() {
+ fFiles= new ArrayList();
+ try {
+ IResource[] roots= fScope.getRoots();
+ for (int i= 0; i < roots.length; i++) {
+ try {
+ IResource resource= roots[i];
+ if (resource.isAccessible()) {
+ resource.accept(this, 0);
+ }
+ } catch (CoreException ex) {
+ // report and ignore
+ fStatus.add(ex.getStatus());
+ }
+ }
+ return (IFile[]) fFiles.toArray(new IFile[fFiles.size()]);
+ } finally {
+ fFiles= null;
+ }
+ }
+ }
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamSearchVisitor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTableContentProvider.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTableContentProvider.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTableContentProvider.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,72 @@
+package org.jboss.tools.seam.ui.search;
+
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.search.internal.ui.text.IFileSearchContentProvider;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+
+public class SeamTableContentProvider implements IStructuredContentProvider, IFileSearchContentProvider {
+
+ private final Object[] EMPTY_ARR= new Object[0];
+
+ private SeamSearchResultPage fPage;
+ private AbstractTextSearchResult fResult;
+
+ public SeamTableContentProvider(SeamSearchResultPage page) {
+ fPage= page;
+ }
+
+ public void dispose() {
+ // nothing to do
+ }
+
+ public Object[] getElements(Object inputElement) {
+ if (inputElement instanceof SeamSearchResult) {
+ int elementLimit= getElementLimit();
+ Object[] elements= ((SeamSearchResult)inputElement).getElements();
+ if (elementLimit != -1 && elements.length > elementLimit) {
+ Object[] shownElements= new Object[elementLimit];
+ System.arraycopy(elements, 0, shownElements, 0, elementLimit);
+ return shownElements;
+ }
+ return elements;
+ }
+ return EMPTY_ARR;
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (newInput instanceof SeamSearchResult) {
+ fResult= (SeamSearchResult) newInput;
+ }
+ }
+
+ public void elementsChanged(Object[] updatedElements) {
+ TableViewer viewer= getViewer();
+ int elementLimit= getElementLimit();
+ boolean tableLimited= elementLimit != -1;
+ for (int i= 0; i < updatedElements.length; i++) {
+ if (fResult.getMatchCount(updatedElements[i]) > 0) {
+ if (viewer.testFindItem(updatedElements[i]) != null)
+ viewer.update(updatedElements[i], null);
+ else {
+ if (!tableLimited || viewer.getTable().getItemCount() < elementLimit)
+ viewer.add(updatedElements[i]);
+ }
+ } else
+ viewer.remove(updatedElements[i]);
+ }
+ }
+
+ private int getElementLimit() {
+ return fPage.getElementLimit().intValue();
+ }
+
+ private TableViewer getViewer() {
+ return (TableViewer) fPage.getViewer();
+ }
+
+ public void clear() {
+ getViewer().refresh();
+ }
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTableContentProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTreeContentProvider.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTreeContentProvider.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTreeContentProvider.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,187 @@
+package org.jboss.tools.seam.ui.search;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.search.internal.ui.text.IFileSearchContentProvider;
+import org.eclipse.search.ui.text.AbstractTextSearchResult;
+import org.jboss.tools.seam.core.IRole;
+import org.jboss.tools.seam.core.ISeamComponent;
+import org.jboss.tools.seam.core.ISeamElement;
+import org.jboss.tools.seam.core.ISeamPackage;
+import org.jboss.tools.seam.core.ISeamScope;
+
+public class SeamTreeContentProvider implements ITreeContentProvider, IFileSearchContentProvider {
+
+ private final Object[] EMPTY_ARR= new Object[0];
+
+ private AbstractTextSearchResult fResult;
+ private SeamSearchResultPage fPage;
+ private AbstractTreeViewer fTreeViewer;
+ private Map fChildrenMap;
+
+ SeamTreeContentProvider(SeamSearchResultPage page, AbstractTreeViewer viewer) {
+ fPage= page;
+ fTreeViewer= viewer;
+ }
+
+ public Object[] getElements(Object inputElement) {
+ Object[] children= getChildren(inputElement);
+ int elementLimit= getElementLimit();
+ if (elementLimit != -1 && elementLimit < children.length) {
+ Object[] limitedChildren= new Object[elementLimit];
+ System.arraycopy(children, 0, limitedChildren, 0, elementLimit);
+ return limitedChildren;
+ }
+ return children;
+ }
+
+ private int getElementLimit() {
+ return fPage.getElementLimit().intValue();
+ }
+
+ public void dispose() {
+ // nothing to do
+ }
+
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (newInput instanceof SeamSearchResult) {
+ initialize((SeamSearchResult) newInput);
+ }
+ }
+
+
+ protected synchronized void initialize(AbstractTextSearchResult result) {
+ fResult= result;
+ fChildrenMap= new HashMap();
+ if (result != null) {
+ Object[] elements= result.getElements();
+ for (int i= 0; i < elements.length; i++) {
+ insert(elements[i], false);
+ }
+ }
+ }
+
+ protected void insert(Object child, boolean refreshViewer) {
+
+ Object parent= getParent(child);
+ while (parent != null) {
+ if (insertChild(parent, child)) {
+ if (refreshViewer)
+ fTreeViewer.add(parent, child);
+ } else {
+ if (refreshViewer)
+ fTreeViewer.refresh(parent);
+ return;
+ }
+ child= parent;
+ parent= getParent(child);
+ }
+ if (insertChild(fResult, child)) {
+ if (refreshViewer)
+ fTreeViewer.add(fResult, child);
+ }
+ }
+
+ /**
+ * returns true if the child already was a child of parent.
+ *
+ * @param parent
+ * @param child
+ * @return Returns <code>trye</code> if the child was added
+ */
+ private boolean insertChild(Object parent, Object child) {
+ Set children= (Set) fChildrenMap.get(parent);
+ if (children == null) {
+ children= new HashSet();
+ fChildrenMap.put(parent, children);
+ }
+ return children.add(child);
+ }
+
+ protected void remove(Object element, boolean refreshViewer) {
+ // precondition here: fResult.getMatchCount(child) <= 0
+
+ if (hasChildren(element)) {
+ if (refreshViewer)
+ fTreeViewer.refresh(element);
+ } else {
+ if (fResult.getMatchCount(element) == 0) {
+ fChildrenMap.remove(element);
+ Object parent= getParent(element);
+ if (parent != null) {
+ removeFromSiblings(element, parent);
+ remove(parent, refreshViewer);
+ } else {
+ removeFromSiblings(element, fResult);
+ if (refreshViewer)
+ fTreeViewer.refresh();
+ }
+ } else {
+ if (refreshViewer) {
+ fTreeViewer.refresh(element);
+ }
+ }
+ }
+ }
+
+ private void removeFromSiblings(Object element, Object parent) {
+ Set siblings= (Set) fChildrenMap.get(parent);
+ if (siblings != null) {
+ siblings.remove(element);
+ }
+ }
+
+ public Object[] getChildren(Object parentElement) {
+ Set children= (Set) fChildrenMap.get(parentElement);
+ if (children == null)
+ return EMPTY_ARR;
+ return children.toArray();
+ }
+
+ public boolean hasChildren(Object element) {
+ return getChildren(element).length > 0;
+ }
+
+ public synchronized void elementsChanged(Object[] updatedElements) {
+ for (int i= 0; i < updatedElements.length; i++) {
+ if (fResult.getMatchCount(updatedElements[i]) > 0)
+ insert(updatedElements[i], true);
+ else
+ remove(updatedElements[i], true);
+ }
+ }
+
+ public void clear() {
+ initialize(fResult);
+ fTreeViewer.refresh();
+ }
+
+ public Object getParent(Object element) {
+ if (element instanceof IProject)
+ return null;
+ if (element instanceof IResource) {
+ IResource resource = (IResource) element;
+ return resource.getParent();
+ }
+ if(element instanceof IRole) {
+ ISeamElement p = ((IRole)element).getParent();
+ return p == null ? p : p.getParent();
+ } else if(element instanceof ISeamElement) {
+ if(element instanceof ISeamComponent) {
+ ISeamComponent c = (ISeamComponent)element;
+ return c.getSeamProject().getPackage(c);
+ }
+ return ((ISeamElement)element).getParent();
+ }
+
+ return null;
+ }
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/search/SeamTreeContentProvider.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,357 @@
+/*******************************************************************************
+ * 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.ui.text.java;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.MemberValuePair;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.StringLiteral;
+import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.seam.core.IOpenableElement;
+import org.jboss.tools.seam.core.ISeamComponentDeclaration;
+import org.jboss.tools.seam.core.ISeamContextShortVariable;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamFactory;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.internal.core.BijectedAttribute;
+import org.jboss.tools.seam.internal.core.Role;
+import org.jboss.tools.seam.internal.core.SeamComponent;
+import org.jboss.tools.seam.internal.core.SeamJavaContextVariable;
+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;
+import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
+import org.jboss.tools.seam.ui.SeamGuiPlugin;
+import org.jboss.tools.seam.ui.text.java.scanner.JavaAnnotationScanner;
+
+/**
+ * @author Jeremy
+ */
+public class JavaStringHyperlinkDetector extends AbstractHyperlinkDetector {
+
+ /*
+ * If the hyperlink is performed from the @Factory annotation value
+ * the declaration of the variable will be openned in the editor
+ *
+ * @see org.eclipse.jface.text.hyperlink.IHyperlinkDetector#detectHyperlinks(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion, boolean)
+ */
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
+ ITextEditor textEditor= (ITextEditor)getAdapter(ITextEditor.class);
+ if (region == null || canShowMultipleHyperlinks || !(textEditor instanceof JavaEditor))
+ return null;
+
+ int offset= region.getOffset();
+
+ IJavaElement input= EditorUtility.getEditorInputJavaElement(textEditor, false);
+ if (input == null)
+ return null;
+
+ if (input.getResource() == null || input.getResource().getProject() == null)
+ return null;
+
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(input.getResource().getProject(), true);
+
+ IDocument document= textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+ IRegion wordRegion= JavaWordFinder.findWord(document, offset);
+ if (wordRegion == null)
+ return null;
+
+ JavaAnnotationScanner annotationScanner = new JavaAnnotationScanner();
+ Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> loadedAnnotations = null;
+ IType loadedType = null;
+
+ try {
+ annotationScanner.parse((ICompilationUnit)input);
+ loadedAnnotations = annotationScanner.getResolvedAnnotations();
+ loadedType = annotationScanner.getResolvedType();
+
+ } catch (ScannerException e) {
+ SeamGuiPlugin.getPluginLog().logError(e);
+ return null;
+ }
+
+ ResolvedAnnotation a = findAnnotationByValueOffset(loadedAnnotations, offset);
+ if (!isAnnotationOfType(a, SeamAnnotations.FACTORY_ANNOTATION_TYPE))
+ return null;
+
+ String value = getAnnotationValue(a);
+
+ // Look at the annotated method:
+ // If its return type is not void - the Declaration is the factory itself
+ // If its return type is void - search for the declarations
+ AnnotatedASTNode<ASTNode> node = loadedAnnotations.get(a);
+ if (!(node.getNode() instanceof MethodDeclaration))
+ return null;
+
+ MethodDeclaration mDecl = (MethodDeclaration)node.getNode();
+ IMember member = findMethod(loadedType, mDecl);
+ IMethod method = (member instanceof IMethod ? (IMethod)member : null);
+ if (method == null)
+ return null;
+
+ String returnType = null;
+ try {
+ returnType = method.getReturnType();
+ } catch (JavaModelException e) {
+ SeamGuiPlugin.getPluginLog().logError(e);
+ return null;
+ }
+
+ if ("V".equals(returnType)) {
+ // search for the declaration of the variable
+ Set<ISeamContextVariable> variables = seamProject.getVariablesByName(value);
+ if (variables != null && !variables.isEmpty()) {
+ for (ISeamContextVariable var : variables) {
+ if (var instanceof ISeamContextShortVariable) {
+ // Extract the original variable
+ var = ((ISeamContextShortVariable)var).getOriginal();
+ }
+
+ if (var instanceof SeamComponent) {
+ SeamComponent comp = (SeamComponent)var;
+ Set<ISeamComponentDeclaration> declarations = comp.getAllDeclarations();
+ for (ISeamComponentDeclaration decl : declarations) {
+ if (decl instanceof IOpenableElement)
+ return new IHyperlink[] {new SeamOpenableElementHyperlink(wordRegion, (IOpenableElement)decl)};
+ }
+ }
+ if (var instanceof BijectedAttribute ||
+ var instanceof Role) {
+ return new IHyperlink[] {new JavaMemberHyperlink(wordRegion, ((SeamJavaContextVariable)var).getSourceMember())};
+ }
+ }
+ }
+ return null;
+ }
+
+ // open the factory method itself as the declaration
+ return new IHyperlink[] {new JavaMemberHyperlink(wordRegion, method)};
+ }
+
+ /*
+ * Finds the IMethod in IType by its MethodDeclaration
+ *
+ * @param type
+ * @param m
+ *
+ * @return IMethod found
+ */
+ public IMethod findMethod(IType type, MethodDeclaration m) {
+ if(m == null || m.getName() == null) return null;
+ IMethod[] ms = null;
+ try {
+ ms = type.getMethods();
+ } catch (JavaModelException e) {
+ //ignore
+ }
+ String name = m.getName().getIdentifier();
+ if(ms != null) for (int i = 0; i < ms.length; i++) {
+ if(!name.equals(ms[i].getElementName())) continue;
+ int s = m.getStartPosition() + m.getLength() / 2;
+ try {
+ ISourceRange range = ms[i].getSourceRange();
+ if(range == null) {
+ //no source and we cannot check position.
+ return ms[i];
+ }
+ int b = range.getOffset();
+ int e = b + range.getLength();
+ if(s >= b && s <= e) return ms[i];
+ } catch (JavaModelException e) {
+ return ms[i];
+ }
+ }
+ return null;
+ }
+
+ /*
+ * Detects if the type of annotation equals to the selected SeamAnnotations' type
+ *
+ * @param annotation
+ * @param typeName
+ *
+ * @return
+ */
+ private boolean isAnnotationOfType(ResolvedAnnotation annotation, String typeName) {
+ if (annotation == null || typeName == null)
+ return false;
+
+ return (typeName.equals(annotation.getType()));
+ }
+
+ /*
+ * Returns the annotation's value text
+ *
+ * @param annotation
+ * @return
+ */
+ private String getAnnotationValue(ResolvedAnnotation annotation) {
+ if (annotation.getAnnotation() instanceof SingleMemberAnnotation) {
+ SingleMemberAnnotation sma = (SingleMemberAnnotation)annotation.getAnnotation();
+ Object vpd = sma.getStructuralProperty(SingleMemberAnnotation.VALUE_PROPERTY);
+ if (vpd instanceof StringLiteral) {
+ return ((StringLiteral)vpd).getLiteralValue();
+ }
+ return vpd.toString();
+ } else if (annotation.getAnnotation() instanceof NormalAnnotation) {
+ NormalAnnotation na = (NormalAnnotation)annotation.getAnnotation();
+ Object vpd = na.getStructuralProperty(NormalAnnotation.VALUES_PROPERTY);
+ if (vpd instanceof List) {
+ for (Object item : (List)vpd) {
+ if (item instanceof ASTNode) {
+ ASTNode node = (ASTNode)item;
+ if (node.getNodeType() != ASTNode.MEMBER_VALUE_PAIR)
+ continue;
+ MemberValuePair mvp = (MemberValuePair)node;
+ SimpleName name = mvp.getName();
+ if (!"value".equals(name.getIdentifier())) {
+ continue;
+ }
+ return ((StringLiteral)mvp.getValue()).getLiteralValue();
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private ResolvedAnnotation findAnnotationByValueOffset(Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> annotations, int offset) {
+ if (annotations == null)
+ return null;
+
+ for (ResolvedAnnotation a : annotations.keySet()) {
+ if (a.getAnnotation() instanceof SingleMemberAnnotation) {
+ SingleMemberAnnotation sma = (SingleMemberAnnotation)a.getAnnotation();
+ Object vpd = sma.getStructuralProperty(SingleMemberAnnotation.VALUE_PROPERTY);
+ if (vpd instanceof ASTNode) {
+ ASTNode node = (ASTNode)vpd;
+ int start = node.getStartPosition();
+ int length = node.getLength();
+ if (offset >= start && offset < start + length) {
+ return a;
+ }
+ }
+ } else if (a.getAnnotation() instanceof NormalAnnotation) {
+ NormalAnnotation na = (NormalAnnotation)a.getAnnotation();
+ Object vpd = na.getStructuralProperty(NormalAnnotation.VALUES_PROPERTY);
+ if (vpd instanceof List) {
+ for (Object item : (List)vpd) {
+ if (item instanceof ASTNode) {
+ ASTNode node = (ASTNode)item;
+ if (node.getNodeType() != ASTNode.MEMBER_VALUE_PAIR)
+ continue;
+ MemberValuePair mvp = (MemberValuePair)node;
+ SimpleName name = mvp.getName();
+ if (!"value".equals(name.getIdentifier())) {
+ continue;
+ }
+ int start = node.getStartPosition();
+ int length = node.getLength();
+ if (offset >= start && offset < start + length) {
+ return a;
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+
+ class JavaMemberHyperlink implements IHyperlink {
+
+ private final IRegion fRegion;
+ private final IMember fMember;
+
+ IMember member;
+ public JavaMemberHyperlink(IRegion region, IMember member) {
+ this.fRegion = region;
+ this.fMember = member;
+ }
+
+ public IRegion getHyperlinkRegion() {
+ return fRegion;
+ }
+ public String getHyperlinkText() {
+ return null;
+ }
+ public String getTypeLabel() {
+ return null;
+ }
+
+ public void open() {
+ try {
+ IEditorPart part = JavaUI.openInEditor(fMember);
+ if (part != null) {
+ JavaUI.revealInEditor(part, (IJavaElement)fMember);
+ }
+ } catch (PartInitException e) {
+// SeamExtPlugin.getPluginLog().logError(e);
+ } catch (JavaModelException e) {
+ // Ignore. It is probably because of Java element is not found
+ }
+ }
+ }
+
+ class SeamOpenableElementHyperlink implements IHyperlink {
+ private final IRegion fRegion;
+ private final IOpenableElement fOpenable;
+
+ IMember member;
+ public SeamOpenableElementHyperlink(IRegion region, IOpenableElement openable) {
+ this.fRegion = region;
+ this.fOpenable = openable;
+ }
+
+ public IRegion getHyperlinkRegion() {
+ return fRegion;
+ }
+ public String getHyperlinkText() {
+ return null;
+ }
+ public String getTypeLabel() {
+ return null;
+ }
+
+ public void open() {
+ fOpenable.open();
+ }
+ }
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/JavaStringHyperlinkDetector.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java 2008-03-06 21:02:35 UTC (rev 6733)
@@ -0,0 +1,244 @@
+package org.jboss.tools.seam.ui.text.java.scanner;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.ASTRequestor;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.Annotation;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.MarkerAnnotation;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.NormalAnnotation;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.osgi.util.NLS;
+import org.jboss.tools.common.model.util.EclipseJavaUtil;
+import org.jboss.tools.common.model.util.EclipseResourceUtil;
+import org.jboss.tools.common.util.FileUtil;
+import org.jboss.tools.seam.core.SeamCoreMessages;
+import org.jboss.tools.seam.internal.core.scanner.IFileScanner;
+import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
+import org.jboss.tools.seam.internal.core.scanner.ScannerException;
+import org.jboss.tools.seam.internal.core.scanner.Util;
+import org.jboss.tools.seam.internal.core.scanner.java.ASTVisitorImpl;
+import org.jboss.tools.seam.internal.core.scanner.java.AnnotatedASTNode;
+import org.jboss.tools.seam.internal.core.scanner.java.ComponentBuilder;
+import org.jboss.tools.seam.internal.core.scanner.java.JavaScanner;
+import org.jboss.tools.seam.internal.core.scanner.java.ResolvedAnnotation;
+import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
+
+public class JavaAnnotationScanner {
+
+ public JavaAnnotationScanner() {}
+
+ /**
+ * Returns component or list of component
+ * TODO change return type
+ * @param f
+ * @return
+ * @throws ScannerException
+ */
+/* public LoadedDeclarations parse(IFile f) throws ScannerException {
+ ICompilationUnit u = null;
+ try {
+ u = getCompilationUnit(f);
+ } catch (CoreException e) {
+ throw new ScannerException(
+ NLS.bind(SeamCoreMessages.JAVA_SCANNER_CANNOT_GET_COMPILATION_UNIT_FOR,f), e);
+ }
+ if(u == null) return null;
+ ASTRequestorImpl requestor = new ASTRequestorImpl(f);
+ ICompilationUnit[] us = new ICompilationUnit[]{u};
+ ASTParser p = ASTParser.newParser(AST.JLS3);
+ p.setSource(u);
+ p.setResolveBindings(true);
+ p.createASTs(us, new String[0], requestor, null);
+ return requestor.getDeclarations();
+ }
+*/
+ /**
+ * Returns component or list of component
+ * TODO change return type
+ * @param u
+ * @return
+ * @throws ScannerException
+ */
+ public void parse(ICompilationUnit u) throws ScannerException {
+ resolvedAnnotations = null;
+ resolvedType = null;
+ if(u == null) return;
+ ASTRequestorImpl requestor = new ASTRequestorImpl(u);
+ ICompilationUnit[] us = new ICompilationUnit[]{u};
+ ASTParser p = ASTParser.newParser(AST.JLS3);
+ p.setSource(u);
+ p.setResolveBindings(true);
+ p.createASTs(us, new String[0], requestor, null);
+ resolvedType = requestor.getType();
+ resolvedAnnotations = requestor.getAnnotations();
+ }
+
+ Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> resolvedAnnotations = null;
+ IType resolvedType = null;
+
+ public Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> getResolvedAnnotations() {
+ return resolvedAnnotations;
+ }
+
+ public IType getResolvedType() {
+ return resolvedType;
+ }
+
+
+ private ICompilationUnit getCompilationUnit(IFile f) throws CoreException {
+ IProject project = f.getProject();
+ IJavaProject javaProject = (IJavaProject)project.getNature(JavaCore.NATURE_ID);
+ IResource[] rs = EclipseResourceUtil.getJavaSourceRoots(project);
+ for (int i = 0; i < rs.length; i++) {
+ if(rs[i].getFullPath().isPrefixOf(f.getFullPath())) {
+ IPath path = f.getFullPath().removeFirstSegments(rs[i].getFullPath().segmentCount());
+ IJavaElement e = javaProject.findElement(path);
+ if(e instanceof ICompilationUnit) {
+ return (ICompilationUnit)e;
+ }
+ }
+ }
+ return null;
+ }
+
+
+ class ASTRequestorImpl extends ASTRequestor {
+ private ASTVisitorImpl visitor = new ASTVisitorImpl();
+// LoadedDeclarations ds = new LoadedDeclarations();
+ List<ResolvedAnnotation> annotations = new ArrayList<ResolvedAnnotation>();
+ IResource resource;
+ IPath sourcePath;
+ ICompilationUnit unit;
+
+ public ASTRequestorImpl(IResource resource) {
+ this.resource = resource;
+ this.sourcePath = resource.getFullPath();
+ }
+ public ASTRequestorImpl(ICompilationUnit unit) {
+ this.unit = unit;
+ this.resource = unit.getResource();
+ this.sourcePath = resource.getFullPath();
+ }
+
+// public LoadedDeclarations getDeclarations() {
+// return ds;
+// }
+
+ public Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> getAnnotations() {
+ return annotationMap;
+ }
+
+ public IType getType() {
+ return type;
+ }
+
+ public void acceptAST(ICompilationUnit source, CompilationUnit ast) {
+ IType[] ts = null;
+ try {
+ ts = source.getTypes();
+ } catch (JavaModelException e) {
+ //ignore
+ }
+ if(ts == null || ts.length == 0) return;
+ for (int i = 0; i < ts.length; i++) {
+ visitor.setType(null);
+ int f = 0;
+ try {
+ f = ts[i].getFlags();
+ } catch (JavaModelException e) {
+ //ignore
+ continue;
+ }
+ if(Flags.isPublic(f)) {
+ visitor.setType(ts[i]);
+ ast.accept(visitor);
+ if(!visitor.hasSeamComponent()) continue;
+ processTypeData(visitor.root);
+ }
+ }
+ }
+
+ IType type = null;
+ AnnotatedASTNode<TypeDeclaration> annotatedType = null;
+ Set<AnnotatedASTNode<FieldDeclaration>> annotatedFields = null;
+ Set<AnnotatedASTNode<MethodDeclaration>> annotatedMethods = null;
+
+ Map<ResolvedAnnotation, AnnotatedASTNode<ASTNode>> annotationMap = new HashMap<ResolvedAnnotation, AnnotatedASTNode<ASTNode>>();
+
+ private void processTypeData(ASTVisitorImpl.TypeData data) {
+ type = data.type;
+ annotatedType = data.annotatedType;
+ annotatedFields = data.annotatedFields;
+ annotatedMethods = data.annotatedMethods;
+
+ ResolvedAnnotation[] annotations = annotatedType.getAnnotations();
+ for (int i = 0; annotations != null && i < annotations.length; i++) {
+ annotationMap.put(annotations[i], (AnnotatedASTNode)annotatedType);
+ }
+
+ if (annotatedMethods != null) {
+ for (AnnotatedASTNode annotatedMethod : annotatedMethods) {
+ annotations = annotatedMethod.getAnnotations();
+ for (int i = 0; annotations != null && i < annotations.length; i++) {
+ annotationMap.put(annotations[i], (AnnotatedASTNode)annotatedMethod);
+ }
+ }
+ }
+
+ if (annotatedFields != null) {
+ for (AnnotatedASTNode annotatedField : annotatedFields) {
+ annotations = annotatedField.getAnnotations();
+ for (int i = 0; annotations != null && i < annotations.length; i++) {
+ annotationMap.put(annotations[i], (AnnotatedASTNode)annotatedField);
+ }
+ }
+ }
+// this.annotations = annotations;
+ }
+ }
+
+ static String getResolvedType(IType type, String n) {
+
+ String[][] rs;
+ try {
+ rs = type.resolveType(n);
+ if(rs != null && rs.length > 0) {
+ return (rs[0][0].length() == 0) ? rs[0][1] : rs[0][0] + "." + rs[0][1]; //$NON-NLS-1$
+ }
+ } catch (JavaModelException e) {
+ // ignore
+ }
+
+ return n;
+ }
+
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/scanner/JavaAnnotationScanner.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 3 months
JBoss Tools SVN: r6732 - trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java.
by jbosstools-commits@lists.jboss.org
Author: vrubezhny
Date: 2008-03-06 15:47:05 -0500 (Thu, 06 Mar 2008)
New Revision: 6732
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-509 intelligent navigation support for seam variable names
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java 2008-03-06 20:31:25 UTC (rev 6731)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java 2008-03-06 20:47:05 UTC (rev 6732)
@@ -40,16 +40,16 @@
*/
public class ASTVisitorImpl extends ASTVisitor implements SeamAnnotations {
- static class TypeData {
+ public static class TypeData {
TypeData parent = null;
List<TypeData> children = new ArrayList<TypeData>();
- IType type;
+ public IType type;
int innerLock = 0;
- AnnotatedASTNode<TypeDeclaration> annotatedType = null;
- Set<AnnotatedASTNode<FieldDeclaration>> annotatedFields = new HashSet<AnnotatedASTNode<FieldDeclaration>>();
- Set<AnnotatedASTNode<MethodDeclaration>> annotatedMethods = new HashSet<AnnotatedASTNode<MethodDeclaration>>();
+ public AnnotatedASTNode<TypeDeclaration> annotatedType = null;
+ public Set<AnnotatedASTNode<FieldDeclaration>> annotatedFields = new HashSet<AnnotatedASTNode<FieldDeclaration>>();
+ public Set<AnnotatedASTNode<MethodDeclaration>> annotatedMethods = new HashSet<AnnotatedASTNode<MethodDeclaration>>();
AnnotatedASTNode<?> currentAnnotatedNode = null;
AnnotatedASTNode<FieldDeclaration> currentAnnotatedField = null;
@@ -71,10 +71,10 @@
}
- TypeData root = null;
+ public TypeData root = null;
TypeData current = null;
- ASTVisitorImpl() {}
+ public ASTVisitorImpl() {}
public void setType(IType type) {
root = new TypeData();
16 years, 3 months
JBoss Tools SVN: r6731 - trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el.
by jbosstools-commits@lists.jboss.org
Author: vrubezhny
Date: 2008-03-06 15:31:25 -0500 (Thu, 06 Mar 2008)
New Revision: 6731
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-509 intelligent navigation support for seam variable names
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java 2008-03-06 20:28:22 UTC (rev 6730)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizer.java 2008-03-06 20:31:25 UTC (rev 6731)
@@ -23,14 +23,14 @@
* @author Jeremy
*/
public class SeamELOperandTokenizer {
- static final int STATE_INITIAL = 0;
- static final int STATE_VAR = 1;
- static final int STATE_METHOD = 2;
- static final int STATE_SEPARATOR = 3;
+ protected static final int STATE_INITIAL = 0;
+ protected static final int STATE_VAR = 1;
+ protected static final int STATE_METHOD = 2;
+ protected static final int STATE_SEPARATOR = 3;
- String documentContent;
- List<ELOperandToken> fTokens;
- int index;
+ protected String documentContent;
+ protected List<ELOperandToken> fTokens;
+ protected int index;
/**
* Constructs SeamELTokenizer object.
@@ -174,7 +174,7 @@
*
* @return
*/
- ELOperandToken readMethodToken() {
+ private ELOperandToken readMethodToken() {
fState = STATE_METHOD;
int endOfToken = index;
@@ -199,7 +199,7 @@
* @param length
* @return
*/
- private CharSequence getCharSequence(int start, int length) {
+ protected CharSequence getCharSequence(int start, int length) {
String text = ""; //$NON-NLS-1$
try {
text = documentContent.substring(start, start + length);
@@ -214,7 +214,7 @@
/*
* Skips the space characters in the document
*/
- boolean skipSpaceChars() {
+ private boolean skipSpaceChars() {
int ch;
while ((ch = readCharBackward()) != -1) {
if (!Character.isSpaceChar(ch)) {
@@ -247,7 +247,7 @@
*
* @return boolean true if complete parameters set had been read
*/
- boolean skipMethodParameters() {
+ private boolean skipMethodParameters() {
int ch = readCharBackward();
if (ch != ')')
return false;
@@ -277,7 +277,7 @@
* Skips the quoted characters
*
*/
- void skipQuotedChars(char pair) {
+ private void skipQuotedChars(char pair) {
int ch = readCharBackward();
while (ch != -1) {
@@ -303,7 +303,7 @@
*
* @return
*/
- ELOperandToken readSeparatorToken() {
+ private ELOperandToken readSeparatorToken() {
fState = STATE_SEPARATOR;
int ch = readCharBackward();
@@ -315,7 +315,7 @@
*
* @return
*/
- ELOperandToken readVarToken() {
+ private ELOperandToken readVarToken() {
fState = STATE_VAR;
int endOfToken = index;
int ch;
@@ -334,7 +334,7 @@
*
* @return
*/
- int readCharBackward() {
+ private int readCharBackward() {
if (--index < 0 ||
documentContent == null ||
documentContent.length() <= index)
@@ -350,7 +350,7 @@
/*
* returns the character to the document
*/
- void releaseChar() {
+ private void releaseChar() {
if (index < documentContent.length())
index++;
}
Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java 2008-03-06 20:31:25 UTC (rev 6731)
@@ -0,0 +1,309 @@
+ /*******************************************************************************
+ * 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.ArrayList;
+
+import org.eclipse.jface.text.IDocument;
+
+/**
+ * EL string parser.
+ * Creates list of tokens for the name, method and separator parts
+ * Forward parsing
+ *
+ * @author Jeremy
+ */
+
+public class SeamELOperandTokenizerForward extends SeamELOperandTokenizer {
+
+ /**
+ * Constructs SeamELOperandTokenizerForward object.
+ * Parse expression from offset to last operator or space.
+ * Tokenizer parses document from offset to ending.
+ * For example: documentContetn is '<tag attr="#{var1.pr!=var2.pr}"/>'
+ * offset = 29 ("...var2.pr|}")
+ * then tokens are {"pr",".","var2"}
+ * @param documentContent
+ * @param offset
+ */
+ public SeamELOperandTokenizerForward(String documentContent, int offset) {
+ super(documentContent, offset);
+ this.documentContent = documentContent;
+ index = (documentContent == null || documentContent.length() < offset? -1 : offset);
+ fTokens = new ArrayList<ELOperandToken>();
+ parseForward();
+ }
+
+ /**
+ * Constructs SeamELOperandTokenizerForward object.
+ * Parse expression from offset to last operator or space.
+ * Tokenizer parses document from offset to ending.
+ * For example: documentContetn is '<tag attr="#{var1.pr!=var2.pr}"/>'
+ * offset = 29 ("...var2.pr|}")
+ * then tokens are {"pr",".","var2"}
+ * @param document
+ * @param offset
+ */
+ public SeamELOperandTokenizerForward(IDocument document, int offset) {
+ this(document.get(), offset);
+ }
+
+ /*
+ * Performs forward parsing of document text for expression
+ */
+ private void parseForward() {
+ ELOperandToken token;
+ fState = STATE_INITIAL;
+ while ((token = getNextToken()) != ELOperandToken.EOF) {
+ if (token.type == ELOperandToken.EL_VARIABLE_NAME_TOKEN ||
+ token.type == ELOperandToken.EL_PROPERTY_NAME_TOKEN ||
+ token.type == ELOperandToken.EL_METHOD_TOKEN ||
+ token.type == ELOperandToken.EL_SEPARATOR_TOKEN) {
+
+ fTokens.add(token);
+ }
+ }
+ // set first token as variable
+ for (int i=0; i<fTokens.size(); i++) {
+ token = fTokens.get(i);
+ if(token.isNameToken()) {
+ token.type = ELOperandToken.EL_VARIABLE_NAME_TOKEN;
+ break;
+ }
+ }
+ }
+
+ /*
+ * Calculates and returns next token for expression.
+ * Forward parsing
+ *
+ * @return
+ */
+ private ELOperandToken getNextToken() {
+ switch (fState) {
+ case STATE_INITIAL: // Just started
+ {
+ int ch = readCharForward();
+ if (ch == -1) {
+ return ELOperandToken.EOF;
+ }
+ if (Character.isJavaIdentifierPart((char)ch)) {
+ releaseChar();
+ return readVarOrMethodToken();
+ }
+ if (ch == '.') {
+ releaseChar();
+ return readSeparatorToken();
+ }
+ releaseChar();
+ return ELOperandToken.EOF;
+ }
+ case STATE_VAR: // Variable name is read - expecting a separator
+ {
+ int ch = readCharForward();
+ if (ch == -1) {
+ return ELOperandToken.EOF;
+ }
+ if (ch == '.') {
+ releaseChar();
+ return readSeparatorToken();
+ }
+ releaseChar();
+ return ELOperandToken.EOF;
+ }
+ case STATE_METHOD: // Method name and parameters are read - expecting a separator
+ {
+ int ch = readCharForward();
+ if (ch == -1) {
+ return ELOperandToken.EOF;
+ }
+ if (ch == '.') {
+ releaseChar();
+ return readSeparatorToken();
+ }
+ releaseChar();
+ return ELOperandToken.EOF;
+ }
+ case STATE_SEPARATOR: // Separator is read - expecting a var or method
+ {
+ int ch = readCharForward();
+ if (ch == -1) {
+ return ELOperandToken.EOF;
+ }
+ if (Character.isJavaIdentifierStart((char)ch)) {
+ releaseChar();
+ return readVarOrMethodToken();
+ }
+ releaseChar();
+ return ELOperandToken.EOF;
+ }
+ }
+ return ELOperandToken.EOF;
+ }
+
+ /* Reads the next character in the document
+ *
+ * @return
+ */
+ int readCharForward() {
+ if (index >= documentContent.length() ||
+ documentContent == null ||
+ index < 0)
+ return -1;
+
+ try {
+ int ch = documentContent.charAt(index);
+ index++;
+ return ch;
+ } catch (StringIndexOutOfBoundsException e) {
+ return -1;
+ }
+ }
+
+ /* Reads and returns the variable token from the expression
+ * Forward parsing
+ *
+ * @return
+ */
+ private ELOperandToken readVarOrMethodToken() {
+ fState = STATE_VAR;
+ int startOfToken = index;
+ int ch;
+ while((ch = readCharForward()) != -1) {
+ if (!Character.isJavaIdentifierPart(ch)) {
+ int marker = index - 1; // save the current index (end of var name)
+ // skip spaces between the method's name and it's parameters
+ if (Character.isSpaceChar(ch)) {
+ if (!skipSpaceChars()) {
+ // EOF - return the var
+ index = marker; // restore the end of var name in the current index
+ return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index - startOfToken, getCharSequence(startOfToken, index - startOfToken), ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
+ }
+ }
+ if (ch == -1) {
+ // EOF - return the var
+ index = marker; // restore the end of var name in the current index
+ return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index - startOfToken, getCharSequence(startOfToken, index - startOfToken), ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
+ }
+
+ if (ch != '(') {
+ // not a method - return the var
+ index = marker; // restore the end of var name in the current index
+ return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index - startOfToken, getCharSequence(startOfToken, index - startOfToken), ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
+ }
+ releaseChar();
+ fState = STATE_METHOD;
+
+ // read the method parameters
+ skipMethodParameters(); // Do not use the return value (not a matter)
+ // broken/unfinished a method - return part of the method
+ releaseChar();
+ return (index - startOfToken> 0 ? new ELOperandToken(startOfToken, index - startOfToken, getCharSequence(startOfToken, index - startOfToken), ELOperandToken.EL_METHOD_TOKEN) : ELOperandToken.EOF);
+ }
+ }
+ return (index - startOfToken > 0 ? new ELOperandToken(startOfToken, index - startOfToken, getCharSequence(startOfToken, index - startOfToken), ELOperandToken.EL_PROPERTY_NAME_TOKEN) : ELOperandToken.EOF);
+ }
+
+ /* Reads and returns the separator token from the expression
+ * Forward parsing
+ *
+ * @return
+ */
+ private ELOperandToken readSeparatorToken() {
+ fState = STATE_SEPARATOR;
+ int ch = readCharForward();
+
+ return (ch == '.' ? new ELOperandToken(index - 1, 1, getCharSequence(index - 1, 1), ELOperandToken.EL_SEPARATOR_TOKEN) :
+ ELOperandToken.EOF);
+ }
+
+
+ /*
+ * Skips the space characters in the document
+ */
+ private boolean skipSpaceChars() {
+ int ch;
+ while ((ch = readCharForward()) != -1) {
+ if (!Character.isSpaceChar(ch)) {
+ releaseChar();
+ break;
+ }
+ }
+ return true;
+ }
+
+ /*
+ * Skips the method parameters characters in the document
+ * Forward parsing
+ *
+ * @return boolean true if complete parameters set had been read
+ */
+ private boolean skipMethodParameters() {
+ int ch = readCharForward();
+ if (ch != '(')
+ return false;
+ int pCount = 1;
+ while (pCount > 0) {
+ ch = readCharForward();
+ if (ch == -1)
+ return false;
+
+ if (ch == '"' || ch == '\'') {
+ skipQuotedChars((char)ch);
+ continue;
+ }
+ if (ch == '(') {
+ pCount++;
+ continue;
+ }
+ if (ch == ')') {
+ pCount--;
+ continue;
+ }
+ }
+ return true;
+ }
+
+ /*
+ * Skips the quoted characters
+ * Forward parsing
+ *
+ */
+ private void skipQuotedChars(char pair) {
+ int ch = readCharForward();
+
+ while (ch != -1) {
+ if (ch == pair)
+ return;
+
+ if (ch == '\\') {
+ int backSlashCount = 0;
+ while (ch == '\\') {
+ backSlashCount++;
+ ch = readCharForward();
+ }
+ releaseChar(); // Return the last non-slash char to the buffer
+ if ((backSlashCount/2)*2 == backSlashCount) {
+ return;
+ }
+ }
+ ch = readCharForward();
+ }
+ }
+
+ /*
+ * returns the character to the document
+ */
+ private void releaseChar() {
+ if (index > 0)
+ index--;
+ }
+}
Property changes on: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELOperandTokenizerForward.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
16 years, 3 months
JBoss Tools SVN: r6730 - trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2008-03-06 15:28:22 -0500 (Thu, 06 Mar 2008)
New Revision: 6730
Modified:
trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/TwiddleLaunchConfiguration.java
Log:
Twiddle launcher dialog was broken. Fixed.
Modified: trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/TwiddleLaunchConfiguration.java
===================================================================
--- trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/TwiddleLaunchConfiguration.java 2008-03-06 20:28:21 UTC (rev 6729)
+++ trunk/as/plugins/org.jboss.ide.eclipse.as.core/jbosscore/org/jboss/ide/eclipse/as/core/server/internal/launch/TwiddleLaunchConfiguration.java 2008-03-06 20:28:22 UTC (rev 6730)
@@ -60,7 +60,8 @@
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_PROGRAM_ARGUMENTS, args);
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_MAIN_TYPE_NAME, TWIDDLE_MAIN_TYPE);
wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, serverHome + Path.SEPARATOR + "bin");
-
+ wc.setAttribute(TwiddleLaunchConfiguration.SERVER_ID, server.getId());
+
ArrayList classpath = new ArrayList();
addCPEntry(classpath, jbs, TWIDDLE_JAR_LOC);
// Twiddle requires more classes and I'm too lazy to actually figure OUT which ones it needs.
16 years, 3 months
JBoss Tools SVN: r6729 - trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el.
by jbosstools-commits@lists.jboss.org
Author: vrubezhny
Date: 2008-03-06 15:28:21 -0500 (Thu, 06 Mar 2008)
New Revision: 6729
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-509 intelligent navigation support for seam variable names
Modified: 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-03-06 20:25:42 UTC (rev 6728)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/ElVarSearcher.java 2008-03-06 20:28:21 UTC (rev 6729)
@@ -18,6 +18,7 @@
import org.eclipse.jface.text.ITextViewer;
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.seam.core.ISeamProject;
import org.jboss.tools.seam.core.SeamCorePlugin;
import org.w3c.dom.Element;
@@ -120,12 +121,21 @@
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);
+ Var newVar = new Var(var, value, declOffset, declLength);
if(newVar.getElToken()!=null) {
return newVar;
}
@@ -194,19 +204,32 @@
ELToken elToken;
String resolvedValue;
ELToken resolvedElToken;
-
+ int declOffset;
+ int declLength;
+
/**
* Constructor
* @param name - value of "var" attribute.
* @param value - value of "value" attribute.
*/
- public Var(String name, String value) {
+ 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);
+ }
+
private ELToken parseEl(String el) {
if(el.length()>3 && el.startsWith("#{") && el.endsWith("}")) {
String elBody = el.substring(0, el.length()-1).substring(2);
@@ -273,5 +296,20 @@
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;
+ }
+
}
}
\ No newline at end of file
16 years, 3 months
JBoss Tools SVN: r6728 - trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el.
by jbosstools-commits@lists.jboss.org
Author: vrubezhny
Date: 2008-03-06 15:25:42 -0500 (Thu, 06 Mar 2008)
New Revision: 6728
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java
Log:
http://jira.jboss.org/jira/browse/JBIDE-509 intelligent navigation support for seam variable names
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-03-06 19:32:07 UTC (rev 6727)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/el/SeamELCompletionEngine.java 2008-03-06 20:25:42 UTC (rev 6728)
@@ -724,13 +724,13 @@
return new ArrayList<ISeamContextVariable>();
}
- /*
+ /**
* Creates and returns list of possible variable name combinations from expression starting from the longest name
*
* @param prefix
* @return
*/
- private List<List<ELOperandToken>> getPossibleVarsFromPrefix(List<ELOperandToken>prefix) {
+ 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);
16 years, 3 months
JBoss Tools SVN: r6727 - in trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test: xb and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2008-03-06 14:32:07 -0500 (Thu, 06 Mar 2008)
New Revision: 6727
Added:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/UnmarshallTest.java
Removed:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/MarshallUnmarshallTest.java
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/ValidationTest.java
Modified:
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/MarshallTest.java
Log:
More tests
Modified: trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java
===================================================================
--- trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java 2008-03-06 19:30:44 UTC (rev 6726)
+++ trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/ArchivesTestSuite.java 2008-03-06 19:32:07 UTC (rev 6727)
@@ -6,16 +6,14 @@
import org.jboss.ide.eclipse.archives.test.core.ArchivesCoreTest;
import org.jboss.ide.eclipse.archives.test.util.TruezipUtilTest;
import org.jboss.ide.eclipse.archives.test.xb.MarshallTest;
-import org.jboss.ide.eclipse.archives.test.xb.MarshallUnmarshallTest;
-import org.jboss.ide.eclipse.archives.test.xb.ValidationTest;
+import org.jboss.ide.eclipse.archives.test.xb.UnmarshallTest;
public class ArchivesTestSuite extends TestSuite {
public static Test suite() {
TestSuite suite = new TestSuite("Archives Tests");
suite.addTestSuite(ArchivesCoreTest.class);
suite.addTestSuite(MarshallTest.class);
- suite.addTestSuite(MarshallUnmarshallTest.class);
- suite.addTestSuite(ValidationTest.class);
+ suite.addTestSuite(UnmarshallTest.class);
suite.addTestSuite(TruezipUtilTest.class);
suite.addTestSuite(ModelUtilTest.class);
Modified: trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/MarshallTest.java
===================================================================
--- trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/MarshallTest.java 2008-03-06 19:30:44 UTC (rev 6726)
+++ trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/MarshallTest.java 2008-03-06 19:32:07 UTC (rev 6727)
@@ -4,7 +4,7 @@
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
-* This is free software; you can redistribute it and/or modify it
+ * This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
@@ -32,8 +32,12 @@
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbAction;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFileSet;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFolder;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbProperty;
import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
import org.jboss.ide.eclipse.archives.test.ArchivesTest;
import org.jboss.ide.eclipse.archives.test.util.FileIOUtil;
@@ -41,7 +45,7 @@
/**
* @author rob.stryker <rob.stryker(a)redhat.com>
- *
+ *
*/
public class MarshallTest extends TestCase {
private Bundle bundle;
@@ -97,11 +101,8 @@
}
}
- public void testWriteFailingPackage() {
+ protected void write(XbPackages packs, boolean shouldPass) {
XbException e = null;
- XbPackages packs = new XbPackages();
- XbPackage pack = new XbPackage();
- packs.addChild(pack);
try {
IPath out = outputs.append("test.xml");
XMLBinding.marshallToFile(packs, out, new NullProgressMonitor());
@@ -110,9 +111,137 @@
}catch( XbException xbe ) {
e = xbe;
} finally {
- if( e == null ) {
+ if( e == null && !shouldPass) {
fail("Incomplete Model saved when it should not have been.");
}
+ if( e != null && shouldPass) {
+ fail("Model failed to save when it should have saved. " + e.getMessage());
+ }
}
}
+
+ protected void writePackage(String name, String toDir, boolean shouldPass) {
+ XbException e = null;
+ XbPackages packs = new XbPackages();
+ XbPackage pack = new XbPackage();
+ pack.setName(name);
+ pack.setToDir(toDir);
+ packs.addChild(pack);
+ write(packs, shouldPass);
+ }
+
+ public void testWritePackageSuccess() {
+ writePackage("someName", "someFile.jar", true);
+ }
+ public void testWritePackageMissingName() {
+ writePackage(null, "someFile.jar", false);
+ }
+
+ public void testWritePackageMissingDir() {
+ writePackage("someName", null, false);
+ }
+
+ protected void writeProperties(String name, String value, boolean shouldPass) {
+ XbPackages packs = new XbPackages();
+ XbPackage pack = new XbPackage();
+ pack.setName("test");
+ pack.setToDir("test2");
+ XbProperty property = new XbProperty();
+
+ try {
+ property.setName(name);
+ property.setValue(value);
+ pack.getProperties().addProperty(property);
+ } catch( NullPointerException npe ) {
+ if( shouldPass )
+ fail("Model failed to save when it should have saved. - " + npe.getMessage());
+ return; // success
+ }
+
+ packs.addChild(pack);
+ write(packs, shouldPass);
+ }
+
+ public void testWritePropertiesSuccess() {
+ writeProperties("name", "val", true);
+ }
+
+ public void testWritePropertiesMissingName() {
+ writeProperties(null, "val", false);
+ }
+
+ public void testWritePropertiesMissingValue() {
+ writeProperties("name", null, false);
+ }
+
+ public void writeFolder(String name, boolean shouldPass) {
+ XbPackages packs = new XbPackages();
+ XbPackage pack = new XbPackage();
+ pack.setName("name");
+ pack.setToDir("todir");
+ packs.addChild(pack);
+ XbFolder folder = new XbFolder();
+ folder.setName(name);
+ pack.addChild(folder);
+ write(packs, shouldPass);
+ }
+
+ public void testWriteFolderSuccess() {
+ writeFolder("someFolder", true);
+ }
+
+ public void testWriteFolderMissingName() {
+ writeFolder(null, false);
+ }
+
+ public void writeFileset(String dir, String includes, boolean shouldSucceed) {
+ XbPackages packs = new XbPackages();
+ XbPackage pack = new XbPackage();
+ pack.setName("name");
+ pack.setToDir("todir");
+ packs.addChild(pack);
+ XbFileSet fs = new XbFileSet();
+ fs.setDir(dir);
+ fs.setIncludes(includes);
+ pack.addChild(fs);
+ write(packs, shouldSucceed);
+ }
+
+ public void testWriteFilesetSuccess() {
+ writeFileset("folder", "includes", true);
+ }
+
+ public void testWriteFilesetMissingFolder() {
+ writeFileset(null, "includes", false);
+ }
+
+ public void testWriteFilesetMissingIncludes() {
+ writeFileset("path", null, false);
+ }
+
+
+ protected void writeAction(String time, String type, boolean shouldSucceed) {
+ XbPackages packs = new XbPackages();
+ XbPackage pack = new XbPackage();
+ pack.setName("name");
+ pack.setToDir("todir");
+ packs.addChild(pack);
+ XbAction act = new XbAction();
+ act.setTime(time);
+ act.setType(type);
+ pack.addChild(act);
+ write(packs, shouldSucceed);
+ }
+
+ public void testWriteActionSuccess() {
+ writeAction("preBuild", "ant", true);
+ }
+
+ public void testWriteActionMissingTime() {
+ writeAction(null, "ant", false);
+ }
+
+ public void testWriteActionMissingType() {
+ writeAction("preBuild", null, false);
+ }
}
Deleted: trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/MarshallUnmarshallTest.java
===================================================================
--- trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/MarshallUnmarshallTest.java 2008-03-06 19:30:44 UTC (rev 6726)
+++ trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/MarshallUnmarshallTest.java 2008-03-06 19:32:07 UTC (rev 6727)
@@ -1,174 +0,0 @@
-package org.jboss.ide.eclipse.archives.test.xb;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.net.URL;
-
-import junit.framework.TestCase;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFileSet;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFolder;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
-import org.jboss.ide.eclipse.archives.test.ArchivesTest;
-import org.jboss.ide.eclipse.archives.test.util.FileIOUtil;
-import org.osgi.framework.Bundle;
-
-public class MarshallUnmarshallTest extends TestCase {
- private Bundle bundle;
- private IPath bundlePath;
- private IPath archiveDescriptors;
- protected void setUp() {
- if( bundlePath == null ) {
- try {
- bundle = ArchivesTest.getDefault().getBundle();
- URL bundleURL = FileLocator.toFileURL(bundle.getEntry(""));
- bundlePath = new Path(bundleURL.getFile());
- archiveDescriptors = bundlePath.append("inputs").append("archiveDescriptors");
- } catch( IOException ioe) {}
- }
- }
-
-
- public void tearDown() {
- FileIOUtil.clearFolder(bundlePath.append("tmp").toFile().listFiles());
- }
-
- public void testUnmarshall() {
- FileInputStream fis = null;
- try {
- // unmarshall from file
- fis = new FileInputStream(archiveDescriptors.append("descriptor1.xml").toFile());
- XbPackages packs = XMLBinding.unmarshal(fis, new NullProgressMonitor());
- assertDescriptor1Accurate(packs);
-
- // unmarshall from string
- String content = fileAsString(archiveDescriptors.append("descriptor1.xml").toFile());
- packs = XMLBinding.unmarshal(content, new NullProgressMonitor());
- assertDescriptor1Accurate(packs);
-
- } catch( Exception e ) {
- fail(e.getMessage());
- }
- }
-
- public String fileAsString(File f) throws Exception {
- FileInputStream fis = new FileInputStream(f);
- int x= fis.available();
- byte b[]= new byte[x];
- fis.read(b);
- return new String(b);
- }
-
- public void testMarshall() {
- IPath tmpFolder = bundlePath.append("tmp");
-
- XbPackages packs = new XbPackages();
- XbPackage pack1 = new XbPackage();
- pack1.setName("TestProject.jar");
- pack1.setPackageType("jar");
- pack1.setToDir("/some/external/path");
- pack1.setExploded(false);
- pack1.setInWorkspace(false);
- packs.addChild(pack1);
-
- XbPackage pack2 = new XbPackage();
- pack2.setName("TestProject2.jar");
- pack2.setPackageType("jar");
- pack2.setToDir("/SomeProject");
- pack2.setExploded(true);
- pack2.setInWorkspace(true);
- packs.addChild(pack2);
-
- XbFolder folder1 = new XbFolder();
- folder1.setName("folder");
- pack1.addChild(folder1);
-
- XbFolder folder2 = new XbFolder();
- folder2.setName("folder2");
- pack1.addChild(folder2);
-
- XbFolder inner1 = new XbFolder();
- inner1.setName("inner1");
- folder2.addChild(inner1);
-
- XbFileSet fs = new XbFileSet();
- fs.setDir("/some/global/path");
- fs.setIncludes("**/*.xml");
- fs.setInWorkspace(false);
- inner1.addChild(fs);
-
- assertDescriptor1Accurate(packs);
-
- try {
- String packsAsString = XMLBinding.serializePackages(packs, new NullProgressMonitor());
- XbPackages packsFromString = XMLBinding.unmarshal(packsAsString, new NullProgressMonitor());
- assertDescriptor1Accurate(packsFromString);
-
- OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmpFolder.append("marshallTest.xml").toFile()));
- XMLBinding.marshall(packs, writer, new NullProgressMonitor());
- writer.close();
-
- XbPackages packsFromFile = XMLBinding.unmarshal(new FileInputStream(tmpFolder.append("marshallTest.xml").toFile()), new NullProgressMonitor());
- assertDescriptor1Accurate(packsFromFile);
- } catch(XbException e) {
- fail(e.getMessage());
- } catch( IOException ioe ) {
- fail(ioe.getMessage());
- }
- }
-
- void assertDescriptor1Accurate(XbPackages packs) {
- assertEquals(2, packs.getAllChildren().size());
- assertEquals(2, packs.getChildren(XbPackage.class).size());
-
- XbPackage pack1 = (XbPackage)packs.getAllChildren().get(0);
- XbPackage pack2 = (XbPackage)packs.getAllChildren().get(1);
-
- // pack 1
- assertEquals("TestProject.jar", pack1.getName());
- assertEquals("/some/external/path", pack1.getToDir());
- assertEquals("jar", pack1.getPackageType());
- assertFalse(pack1.isExploded());
- assertFalse(pack1.isInWorkspace());
- assertEquals(2, pack1.getAllChildren().size());
- assertEquals(2, pack1.getChildren(XbFolder.class).size());
-
- XbFolder folder1 = (XbFolder)pack1.getAllChildren().get(0);
- XbFolder folder2 = (XbFolder)pack1.getAllChildren().get(1);
-
- assertEquals(0, folder1.getAllChildren().size());
- assertEquals("folder", folder1.getName());
-
- assertEquals(1, folder2.getAllChildren().size());
- assertEquals(1, folder2.getChildren(XbFolder.class).size());
- assertEquals("folder2", folder2.getName());
-
- XbFolder innerFolder = (XbFolder)folder2.getAllChildren().get(0);
- assertEquals("inner1", innerFolder.getName());
- assertEquals(1, innerFolder.getAllChildren().size());
- assertEquals(1, innerFolder.getChildren(XbFileSet.class).size());
-
- XbFileSet fs = (XbFileSet)innerFolder.getAllChildren().get(0);
- assertEquals(fs.getIncludes(), "**/*.xml");
- assertEquals(fs.getDir(), "/some/global/path");
- assertFalse(fs.isInWorkspace());
-
- // pack 2
- assertEquals(0, pack2.getAllChildren().size());
- assertEquals("TestProject2.jar", pack2.getName());
- assertEquals("/SomeProject", pack2.getToDir());
- assertEquals("jar", pack2.getPackageType());
- assertTrue(pack2.isExploded());
- assertTrue(pack2.isInWorkspace());
- }
-}
Copied: trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/UnmarshallTest.java (from rev 6614, trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/ValidationTest.java)
===================================================================
--- trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/UnmarshallTest.java (rev 0)
+++ trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/UnmarshallTest.java 2008-03-06 19:32:07 UTC (rev 6727)
@@ -0,0 +1,225 @@
+/**
+ * JBoss, a Division of Red Hat
+ * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+* This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ide.eclipse.archives.test.xb;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFileSet;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
+import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
+import org.jboss.ide.eclipse.archives.test.ArchivesTest;
+import org.jboss.ide.eclipse.archives.test.util.FileIOUtil;
+import org.osgi.framework.Bundle;
+
+/**
+ * Tests whether the xml files can be validated
+ *
+ * @author rob.stryker <rob.stryker(a)redhat.com>
+ *
+ */
+public class UnmarshallTest extends TestCase {
+ private Bundle bundle;
+ private IPath bundlePath;
+ private IPath archiveDescriptors;
+ protected void setUp() {
+ if( bundlePath == null ) {
+ try {
+ bundle = ArchivesTest.getDefault().getBundle();
+ URL bundleURL = FileLocator.toFileURL(bundle.getEntry(""));
+ bundlePath = new Path(bundleURL.getFile());
+ archiveDescriptors = bundlePath.append("inputs").append("archiveDescriptors").append("validation");
+ } catch( IOException ioe) {
+ fail("Failed to set up " + getClass().getName());
+ }
+ }
+ }
+
+ public void tearDown() {
+ FileIOUtil.clearFolder(bundlePath.append("tmp").toFile().listFiles());
+ }
+
+ /*
+ * The tests
+ */
+
+ public void testAbsoluteSchemaFailure() {
+ parse("AbsoluteSchemaFailure.xml", false, "Broken schema successfully parsed.");
+ }
+
+ public void testAttributeSchemaFailure() {
+ parse("AttributeSchemaFailure.xml", false, "Schema with random attribute successfully parsed.");
+ }
+
+
+ public void testCorrectPackage() {
+ parse("CorrectPackage.xml", true, shouldParse("CorrectPackage.xml"));
+ }
+
+ public void testPackageMissingPackageName() {
+ parse("MissingPackageName.xml", false, failedMissingRequiredAtt("name"));
+ }
+
+ public void testPackageMissingDirectory() {
+ parse("MissingPackageDir.xml", false, failedMissingRequiredAtt("todir"));
+ }
+
+ public void testPackageMissingOptionalType() {
+ parse("MissingPackageType.xml", true, failedFalsePositiveRequiredAtt("type"));
+ }
+
+ public void testPackageMissingOptionalExploded() {
+ XbPackages packs = parse("MissingPackageExploded.xml", true, failedFalsePositiveRequiredAtt("exploded"));
+ XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
+ assertFalse(pack.isExploded());
+ }
+
+ public void testPackageMissingOptionalInWorkspace() {
+ XbPackages packs = parse("MissingPackageInWorkspace.xml", true, failedFalsePositiveRequiredAtt("inWorkspace"));
+ XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
+ assertTrue(pack.isInWorkspace());
+ }
+
+ public void testPackageMissingOptionalId() {
+ XbPackages packs = parse("MissingPackageID.xml", true, failedMissingRequiredAtt("id"));
+ XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
+ assertNull(pack.getId());
+ }
+
+ public void testCorrectFolder() {
+ parse("CorrectFolder.xml", true, shouldParse("CorrectFolder.xml"));
+ }
+
+ public void testFolderMissingName() {
+ parse("MissingFolderName.xml", false, failedMissingRequiredAtt("name"));
+ }
+
+ public void testCorrectProperties() {
+ parse("CorrectProperties.xml", true, shouldParse("CorrectProperties.xml"));
+ }
+
+ public void testPropertiesMissingKey() {
+ parse("MissingPropertiesName.xml", false, failedMissingRequiredAtt("name"));
+ }
+
+ public void testPropertiesMissingValue() {
+ parse("MissingPropertiesValue.xml", false, failedMissingRequiredAtt("value"));
+ }
+
+
+ public void testCorrectFileset() {
+ parse("CorrectFileset.xml", true, shouldParse("CorrectFileset.xml"));
+ }
+
+ public void testFilesetMissingDir() {
+ parse("MissingFilesetDir.xml", false, failedMissingRequiredAtt("todir"));
+ }
+
+ public void testFilesetMissingIncludes() {
+ parse("MissingFilesetIncludes.xml", false, failedMissingRequiredAtt("includes"));
+ }
+
+ public void testFilesetMissingOptionalExcludes() {
+ parse("MissingFilesetExcludes.xml", true, failedFalsePositiveRequiredAtt("excludes"));
+ // no default
+ }
+
+ public void testFilesetMissingOptionalInWorkspace() {
+ XbPackages packs = parse("MissingFilesetInWorkspace.xml", true, failedFalsePositiveRequiredAtt("inWorkspace"));
+ // no default
+ XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
+ List l = pack.getChildren(XbFileSet.class);
+ assertNotNull(l);
+ assertEquals(1, l.size());
+ XbFileSet fs = (XbFileSet)l.get(0);
+ assertTrue(fs.isInWorkspace());
+ }
+
+ public void testFilesetMissingOptionalFlattened() {
+ XbPackages packs = parse("MissingFilesetFlattened.xml", true, failedFalsePositiveRequiredAtt("flattened"));
+ // no default
+ XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
+ List l = pack.getChildren(XbFileSet.class);
+ assertNotNull(l);
+ assertEquals(1, l.size());
+ XbFileSet fs = (XbFileSet)l.get(0);
+ assertFalse(fs.isFlattened());
+ }
+
+
+ public void testCorrectAction() {
+ parse("CorrectAction.xml", true, shouldParse("CorrectAction.xml"));
+ }
+
+ public void testActionMissingTime() {
+ parse("MissingActionTime.xml", false, failedMissingRequiredAtt("time"));
+ }
+
+ public void testActionMissingType() {
+ parse("MissingActionType.xml", false, failedMissingRequiredAtt("type"));
+ }
+
+
+ /*
+ * Utility
+ */
+
+ protected XbPackages parse(String file, boolean shouldSucceed, String failMsg) {
+ FileInputStream fis = null;
+ XbPackages packs = null;
+ try {
+ fis = new FileInputStream(archiveDescriptors.append(file).toFile());
+ packs = XMLBinding.unmarshal(fis, new NullProgressMonitor());
+ } catch( IOException ioe ) {
+ fail(ioe.getMessage());
+ } catch( XbException e ) {
+ if( shouldSucceed )
+ fail(failMsg + " - " + e.getMessage());
+ return packs;
+ }
+ if( !shouldSucceed )
+ fail(failMsg);
+ return packs;
+ }
+
+ protected String failedMissingRequiredAtt(String att) {
+ return "File parsed while missing a required attribute: " + att;
+ }
+
+ protected String failedFalsePositiveRequiredAtt(String attribute) {
+ return "File failed to parse even though \"" + attribute + "\" is not required";
+ }
+
+ protected String shouldParse(String file) {
+ return file + " should parse correctly.";
+ }
+}
Deleted: trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/ValidationTest.java
===================================================================
--- trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/ValidationTest.java 2008-03-06 19:30:44 UTC (rev 6726)
+++ trunk/core/tests/org.jboss.ide.eclipse.archives.test/src/org/jboss/ide/eclipse/archives/test/xb/ValidationTest.java 2008-03-06 19:32:07 UTC (rev 6727)
@@ -1,225 +0,0 @@
-/**
- * JBoss, a Division of Red Hat
- * Copyright 2006, Red Hat Middleware, LLC, and individual contributors as indicated
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
-* This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.jboss.ide.eclipse.archives.test.xb;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.URL;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eclipse.core.runtime.FileLocator;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.NullProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbFileSet;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackage;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XbPackages;
-import org.jboss.ide.eclipse.archives.core.model.internal.xb.XMLBinding.XbException;
-import org.jboss.ide.eclipse.archives.test.ArchivesTest;
-import org.jboss.ide.eclipse.archives.test.util.FileIOUtil;
-import org.osgi.framework.Bundle;
-
-/**
- * Tests whether the xml files can be validated
- *
- * @author rob.stryker <rob.stryker(a)redhat.com>
- *
- */
-public class ValidationTest extends TestCase {
- private Bundle bundle;
- private IPath bundlePath;
- private IPath archiveDescriptors;
- protected void setUp() {
- if( bundlePath == null ) {
- try {
- bundle = ArchivesTest.getDefault().getBundle();
- URL bundleURL = FileLocator.toFileURL(bundle.getEntry(""));
- bundlePath = new Path(bundleURL.getFile());
- archiveDescriptors = bundlePath.append("inputs").append("archiveDescriptors").append("validation");
- } catch( IOException ioe) {
- fail("Failed to set up " + getClass().getName());
- }
- }
- }
-
- public void tearDown() {
- FileIOUtil.clearFolder(bundlePath.append("tmp").toFile().listFiles());
- }
-
- /*
- * The tests
- */
-
- public void testAbsoluteSchemaFailure() {
- parse("AbsoluteSchemaFailure.xml", false, "Broken schema successfully parsed.");
- }
-
- public void testAttributeSchemaFailure() {
- parse("AttributeSchemaFailure.xml", false, "Schema with random attribute successfully parsed.");
- }
-
-
- public void testCorrectPackage() {
- parse("CorrectPackage.xml", true, shouldParse("CorrectPackage.xml"));
- }
-
- public void testPackageMissingPackageName() {
- parse("MissingPackageName.xml", false, failedMissingRequiredAtt("name"));
- }
-
- public void testPackageMissingDirectory() {
- parse("MissingPackageDir.xml", false, failedMissingRequiredAtt("todir"));
- }
-
- public void testPackageMissingOptionalType() {
- parse("MissingPackageType.xml", true, failedFalsePositiveRequiredAtt("type"));
- }
-
- public void testPackageMissingOptionalExploded() {
- XbPackages packs = parse("MissingPackageExploded.xml", true, failedFalsePositiveRequiredAtt("exploded"));
- XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
- assertFalse(pack.isExploded());
- }
-
- public void testPackageMissingOptionalInWorkspace() {
- XbPackages packs = parse("MissingPackageInWorkspace.xml", true, failedFalsePositiveRequiredAtt("inWorkspace"));
- XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
- assertTrue(pack.isInWorkspace());
- }
-
- public void testPackageMissingOptionalId() {
- XbPackages packs = parse("MissingPackageID.xml", true, failedMissingRequiredAtt("id"));
- XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
- assertNull(pack.getId());
- }
-
- public void testCorrectFolder() {
- parse("CorrectFolder.xml", true, shouldParse("CorrectFolder.xml"));
- }
-
- public void testFolderMissingName() {
- parse("MissingFolderName.xml", false, failedMissingRequiredAtt("name"));
- }
-
- public void testCorrectProperties() {
- parse("CorrectProperties.xml", true, shouldParse("CorrectProperties.xml"));
- }
-
- public void testPropertiesMissingKey() {
- parse("MissingPropertiesName.xml", false, failedMissingRequiredAtt("name"));
- }
-
- public void testPropertiesMissingValue() {
- parse("MissingPropertiesValue.xml", false, failedMissingRequiredAtt("value"));
- }
-
-
- public void testCorrectFileset() {
- parse("CorrectFileset.xml", true, shouldParse("CorrectFileset.xml"));
- }
-
- public void testFilesetMissingDir() {
- parse("MissingFilesetDir.xml", false, failedMissingRequiredAtt("todir"));
- }
-
- public void testFilesetMissingIncludes() {
- parse("MissingFilesetIncludes.xml", false, failedMissingRequiredAtt("includes"));
- }
-
- public void testFilesetMissingOptionalExcludes() {
- parse("MissingFilesetExcludes.xml", true, failedFalsePositiveRequiredAtt("excludes"));
- // no default
- }
-
- public void testFilesetMissingOptionalInWorkspace() {
- XbPackages packs = parse("MissingFilesetInWorkspace.xml", true, failedFalsePositiveRequiredAtt("inWorkspace"));
- // no default
- XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
- List l = pack.getChildren(XbFileSet.class);
- assertNotNull(l);
- assertEquals(1, l.size());
- XbFileSet fs = (XbFileSet)l.get(0);
- assertTrue(fs.isInWorkspace());
- }
-
- public void testFilesetMissingOptionalFlattened() {
- XbPackages packs = parse("MissingFilesetFlattened.xml", true, failedFalsePositiveRequiredAtt("flattened"));
- // no default
- XbPackage pack = (XbPackage)packs.getAllChildren().get(0);
- List l = pack.getChildren(XbFileSet.class);
- assertNotNull(l);
- assertEquals(1, l.size());
- XbFileSet fs = (XbFileSet)l.get(0);
- assertFalse(fs.isFlattened());
- }
-
-
- public void testCorrectAction() {
- parse("CorrectAction.xml", true, shouldParse("CorrectAction.xml"));
- }
-
- public void testActionMissingTime() {
- parse("MissingActionTime.xml", false, failedMissingRequiredAtt("time"));
- }
-
- public void testActionMissingType() {
- parse("MissingActionType.xml", false, failedMissingRequiredAtt("type"));
- }
-
-
- /*
- * Utility
- */
-
- protected XbPackages parse(String file, boolean shouldSucceed, String failMsg) {
- FileInputStream fis = null;
- XbPackages packs = null;
- try {
- fis = new FileInputStream(archiveDescriptors.append(file).toFile());
- packs = XMLBinding.unmarshal(fis, new NullProgressMonitor());
- } catch( IOException ioe ) {
- fail(ioe.getMessage());
- } catch( XbException e ) {
- if( shouldSucceed )
- fail(failMsg + " - " + e.getMessage());
- return packs;
- }
- if( !shouldSucceed )
- fail(failMsg);
- return packs;
- }
-
- protected String failedMissingRequiredAtt(String att) {
- return "File parsed while missing a required attribute: " + att;
- }
-
- protected String failedFalsePositiveRequiredAtt(String attribute) {
- return "File failed to parse even though \"" + attribute + "\" is not required";
- }
-
- protected String shouldParse(String file) {
- return file + " should parse correctly.";
- }
-}
16 years, 3 months
JBoss Tools SVN: r6726 - trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb.
by jbosstools-commits@lists.jboss.org
Author: rob.stryker(a)jboss.com
Date: 2008-03-06 14:30:44 -0500 (Thu, 06 Mar 2008)
New Revision: 6726
Modified:
trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java
Log:
XbException's message fixed
Modified: trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java
===================================================================
--- trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java 2008-03-06 19:28:18 UTC (rev 6725)
+++ trunk/core/plugins/org.jboss.ide.eclipse.archives.core/src/main/org/jboss/ide/eclipse/archives/core/model/internal/xb/XMLBinding.java 2008-03-06 19:30:44 UTC (rev 6726)
@@ -214,7 +214,7 @@
return parent;
}
public String getMessage() {
- return parent.getCause() == null ? null : parent.getCause().getMessage();
+ return parent.getCause() == null ? parent.getMessage() : parent.getCause().getMessage();
}
}
}
16 years, 3 months