Author: vrubezhny
Date: 2007-07-13 09:41:16 -0400 (Fri, 13 Jul 2007)
New Revision: 2427
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalComputer.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamExpressionResolver.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/SeamGuiPlugin.java
Log:
http://jira.jboss.org/jira/browse/EXIN-330
Prompting Computer/Processor is added to be used in JavaEditor and XML Editor content
assistants
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 2007-07-13 12:46:01
UTC (rev 2426)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/META-INF/MANIFEST.MF 2007-07-13 13:41:16
UTC (rev 2427)
@@ -16,14 +16,22 @@
org.eclipse.wst.common.modulecore,
org.eclipse.wst.common.frameworks,
org.eclipse.wst.common.project.facet.core,
- org.eclipse.jdt.core,
org.eclipse.jst.jsf.ui,
org.eclipse.wst.common.frameworks.ui,
org.jboss.tools.common,
org.jboss.tools.seam.core,
org.apache.log4j,
org.hibernate.eclipse.console,
+ org.eclipse.jdt.ui,
+ org.eclipse.jface.text,
+ org.eclipse.ui.workbench.texteditor,
+ org.eclipse.ui.editors,
+ org.hibernate.eclipse.console,
org.eclipse.jst.j2ee,
+ org.jboss.tools.common.text.ext,
+ org.eclipse.jdt.core,
+ org.jboss.tools.common.model,
+ org.eclipse.jst.j2ee,
org.eclipse.wst.common.emfworkbench.integration,
org.eclipse.jem,
org.eclipse.jem.util,
@@ -36,4 +44,9 @@
org.jboss.tools.seam.ui.internal.project.facet;x-internal:=true,
org.jboss.tools.seam.ui.widget.editor,
org.jboss.tools.seam.ui.widget.field,
- org.jboss.tools.seam.ui.wizard
+ org.jboss.tools.seam.ui.wizard,
+ org.jboss.tools.seam.ui.text.java;
+ uses:="org.eclipse.jface.text,
+ org.eclipse.jdt.ui.text.java,
+ org.eclipse.core.runtime,
+ org.eclipse.jface.text.contentassist"
Modified: trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2007-07-13 12:46:01 UTC (rev
2426)
+++ trunk/seam/plugins/org.jboss.tools.seam.ui/plugin.xml 2007-07-13 13:41:16 UTC (rev
2427)
@@ -108,55 +108,84 @@
</perspectiveExtension>
</extension>
-<extension point="org.eclipse.ui.navigator.viewer">
- <viewerContentBinding
viewerId="org.jboss.tools.seam.ui.views.SeamComponentsNavigator">
- <includes>
- <contentExtension pattern="org.jboss.tools.seam.ui.views.rootContent"
/>
- </includes>
- </viewerContentBinding>
-</extension>
+ <extension point="org.eclipse.ui.navigator.viewer">
+ <viewerContentBinding
viewerId="org.jboss.tools.seam.ui.views.SeamComponentsNavigator">
+ <includes>
+ <contentExtension pattern="org.jboss.tools.seam.ui.views.rootContent"
/>
+ </includes>
+ </viewerContentBinding>
+ </extension>
-<extension point="org.eclipse.ui.navigator.navigatorContent">
- <navigatorContent
- name="Seam Components"
- priority="highest"
- icon="icons/sample.gif"
- activeByDefault="true"
-
contentProvider="org.jboss.tools.seam.ui.views.RootContentProvider"
- labelProvider="org.jboss.tools.seam.ui.views.SeamLabelProvider"
- id="org.jboss.tools.seam.ui.views.rootContent">
- <triggerPoints>
- <or>
- <instanceof
- value="org.eclipse.core.resources.IWorkspaceRoot" />
- <instanceof
- value="org.jboss.tools.seam.core.ISeamElement" />
- </or>
- </triggerPoints>
- <possibleChildren>
- <or>
- <instanceof value="org.jboss.tools.seam.core.ISeamElement" />
- </or>
- </possibleChildren>
- <actionProvider
- class="org.jboss.tools.seam.ui.views.actions.SeamActionProvider"
- id="org.jboss.tools.seam.ui.views.actions.SeamActionProvider">
- <enablement>
- <or>
- <instanceof value="org.jboss.tools.seam.core.ISeamElement"/>
- </or>
- </enablement>
- </actionProvider>
- </navigatorContent>
-</extension>
+ <extension point="org.eclipse.ui.navigator.navigatorContent">
+ <navigatorContent
+ name="Seam Components"
+ priority="highest"
+ icon="icons/sample.gif"
+ activeByDefault="true"
+
contentProvider="org.jboss.tools.seam.ui.views.RootContentProvider"
+ labelProvider="org.jboss.tools.seam.ui.views.SeamLabelProvider"
+ id="org.jboss.tools.seam.ui.views.rootContent">
+ <triggerPoints>
+ <or>
+ <instanceof
+ value="org.eclipse.core.resources.IWorkspaceRoot" />
+ <instanceof
+ value="org.jboss.tools.seam.core.ISeamElement" />
+ </or>
+ </triggerPoints>
+ <possibleChildren>
+ <or>
+ <instanceof value="org.jboss.tools.seam.core.ISeamElement" />
+ </or>
+ </possibleChildren>
+ <actionProvider
+ class="org.jboss.tools.seam.ui.views.actions.SeamActionProvider"
+ id="org.jboss.tools.seam.ui.views.actions.SeamActionProvider">
+ <enablement>
+ <or>
+ <instanceof value="org.jboss.tools.seam.core.ISeamElement"/>
+ </or>
+ </enablement>
+ </actionProvider>
+ </navigatorContent>
+ </extension>
-<extension point="org.eclipse.core.runtime.adapters">
- <factory
-
class="org.jboss.tools.seam.ui.views.properties.SeamElementAdapterFactory"
- adaptableType="org.jboss.tools.seam.core.ISeamElement">
-
- <adapter type="org.eclipse.ui.views.properties.IPropertySource"/>
- </factory>
-</extension>
+ <extension point="org.eclipse.core.runtime.adapters">
+ <factory
+
class="org.jboss.tools.seam.ui.views.properties.SeamElementAdapterFactory"
+ adaptableType="org.jboss.tools.seam.core.ISeamElement">
+
+ <adapter type="org.eclipse.ui.views.properties.IPropertySource"/>
+ </factory>
+ </extension>
+ <extension point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
+ id="seam_el_proposals"
+ name="Seam EL Proposals">
+ <proposalCategory icon="icons/sample.gif"/>
+ </extension>
+
+ <extension point="org.eclipse.jdt.ui.javaCompletionProposalComputer"
+ id="SeamELCompletionProposalComputer"
+ name="Seam EL Completion Proposal Computer">
+ <javaCompletionProposalComputer
+ class="org.jboss.tools.seam.ui.text.java.SeamELProposalComputer"
+ categoryId="org.jboss.tools.seam.ui.seam_el_proposals"
+ activate="true">
+ <partition type="__java_string"/>
+ </javaCompletionProposalComputer>
+ </extension>
+
+ <extension
+ point="org.jboss.tools.common.text.xml.contentAssistProcessor"
+ id="org.jboss.tools.seam.ui.contentAssistProcessor"
+ name="org.jboss.tools.seam.ui.contentAssistProcessor">
+
+ <contentAssistProcessor
+ class="org.jboss.tools.seam.ui.text.java.SeamELProposalProcessor"
+ id="org.jboss.tools.seam.ui.text.java.SeamELProposalProcessor">
+ <partitiontype id="org.eclipse.wst.xml.XML_DEFAULT" />
+ </contentAssistProcessor>
+ </extension>
+
</plugin>
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamGuiPlugin.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamGuiPlugin.java 2007-07-13
12:46:01 UTC (rev 2426)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/SeamGuiPlugin.java 2007-07-13
13:41:16 UTC (rev 2427)
@@ -12,12 +12,14 @@
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.jboss.tools.common.log.BaseUIPlugin;
+import org.jboss.tools.common.log.IPluginLog;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
-public class SeamGuiPlugin extends AbstractUIPlugin {
+public class SeamGuiPlugin extends BaseUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "org.jboss.tools.seam.ui";
@@ -60,4 +62,12 @@
public static ImageDescriptor getImageDescriptor(String path) {
return imageDescriptorFromPlugin(PLUGIN_ID, path);
}
+
+ /**
+ * @return IPluginLog object
+ */
+ public static IPluginLog getPluginLog() {
+ return getDefault();
+ }
+
}
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalComputer.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalComputer.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalComputer.java 2007-07-13
13:41:16 UTC (rev 2427)
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.seam.ui.text.java;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jdt.ui.text.java.ContentAssistInvocationContext;
+import org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+
+
+public class SeamELProposalComputer implements IJavaCompletionProposalComputer {
+ /** The wrapped processor. */
+ private final SeamELProposalProcessor fProcessor= new SeamELProposalProcessor();
+
+ /**
+ * Default constructor to make it instantiatable via the extension mechanism.
+ */
+ public SeamELProposalComputer() {
+ }
+
+ /*
+ * @see
org.eclipse.jface.text.contentassist.ICompletionProposalComputer#computeCompletionProposals(org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext,
org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public List<ICompletionProposal>
computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor
monitor) {
+ return Arrays.asList(fProcessor.computeCompletionProposals(context.getViewer(),
context.getInvocationOffset()));
+ }
+
+ /*
+ * @see
org.eclipse.jface.text.contentassist.ICompletionProposalComputer#computeContextInformation(org.eclipse.jface.text.contentassist.TextContentAssistInvocationContext,
org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public List<IContextInformation>
computeContextInformation(ContentAssistInvocationContext context, IProgressMonitor
monitor) {
+ return Arrays.asList(fProcessor.computeContextInformation(context.getViewer(),
context.getInvocationOffset()));
+ }
+
+ /*
+ * @see
org.eclipse.jface.text.contentassist.ICompletionProposalComputer#getErrorMessage()
+ */
+ public String getErrorMessage() {
+ return fProcessor.getErrorMessage();
+ }
+
+ /*
+ * @see org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#sessionStarted()
+ */
+ public void sessionStarted() {
+ }
+
+ /*
+ * @see org.eclipse.jdt.ui.text.java.IJavaCompletionProposalComputer#sessionEnded()
+ */
+ public void sessionEnded() {
+ }
+}
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamELProposalProcessor.java 2007-07-13
13:41:16 UTC (rev 2427)
@@ -0,0 +1,290 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.seam.ui.text.java;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.ui.PreferenceConstants;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DocumentEvent;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IInformationControlCreator;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension3;
+import org.eclipse.jface.text.contentassist.ICompletionProposalExtension4;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.editors.text.EditorsUI;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.jboss.tools.common.text.ext.IEditorWrapper;
+import org.jboss.tools.seam.core.ISeamProject;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+
+public class SeamELProposalProcessor implements IContentAssistProcessor {
+
+ private static final ICompletionProposal[] NO_PROPOSALS= new ICompletionProposal[0];
+ private static final IContextInformation[] NO_CONTEXTS= new IContextInformation[0];
+
+ private static final class Proposal implements ICompletionProposal,
ICompletionProposalExtension, ICompletionProposalExtension2,
ICompletionProposalExtension3, ICompletionProposalExtension4 {
+
+ private final String fString;
+ private final String fPrefix;
+ private final int fOffset;
+
+ public Proposal(String string, String prefix, int offset) {
+ fString= string;
+ fPrefix= prefix;
+ fOffset= offset;
+ }
+
+ public void apply(IDocument document) {
+ apply(null, '\0', 0, fOffset);
+ }
+
+ public Point getSelection(IDocument document) {
+ return new Point(fOffset + fString.length(), 0);
+ }
+
+ public String getAdditionalProposalInfo() {
+ return null;
+ }
+
+ public String getDisplayString() {
+ return fPrefix + fString;
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+ public IContextInformation getContextInformation() {
+ return null;
+ }
+
+ public void apply(IDocument document, char trigger, int offset) {
+ try {
+ String replacement= fString.substring(offset - fOffset);
+ document.replace(offset, 0, replacement);
+ } catch (BadLocationException x) {
+ // TODO Auto-generated catch block
+ x.printStackTrace();
+ }
+ }
+
+ public boolean isValidFor(IDocument document, int offset) {
+ return validate(document, offset, null);
+ }
+
+ public char[] getTriggerCharacters() {
+ return null;
+ }
+
+ public int getContextInformationPosition() {
+ return 0;
+ }
+
+ public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
+ apply(viewer.getDocument(), trigger, offset);
+ }
+
+ public void selected(ITextViewer viewer, boolean smartToggle) {
+ }
+
+ public void unselected(ITextViewer viewer) {
+ }
+
+ public boolean validate(IDocument document, int offset, DocumentEvent event) {
+ try {
+ int prefixStart= fOffset - fPrefix.length();
+ return offset >= fOffset && offset < fOffset + fString.length()
&& document.get(prefixStart, offset - (prefixStart)).equals((fPrefix +
fString).substring(0, offset - prefixStart));
+ } catch (BadLocationException x) {
+ return false;
+ }
+ }
+
+ public IInformationControlCreator getInformationControlCreator() {
+ return null;
+ }
+
+ public CharSequence getPrefixCompletionText(IDocument document, int completionOffset)
{
+ return fPrefix + fString;
+ }
+
+ public int getPrefixCompletionStart(IDocument document, int completionOffset) {
+ return fOffset - fPrefix.length();
+ }
+
+ public boolean isAutoInsertable() {
+ return true;
+ }
+
+ }
+
+ private final SeamELCompletionEngine fEngine= new SeamELCompletionEngine();
+
+ /**
+ * Creates a new Seam EL completion proposal computer.
+ */
+ public SeamELProposalProcessor() {
+ }
+
+ /*
+ * @see
org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
int)
+ */
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset)
{
+ try {
+ ITextEditor part = getActiveEditor();
+ if (part == null)
+ return NO_PROPOSALS;
+
+ IEditorInput editorInput = part.getEditorInput();
+ if (!(editorInput instanceof IFileEditorInput))
+ return NO_PROPOSALS;
+
+ IFile file = ((IFileEditorInput)editorInput).getFile();
+ IProject project = (file == null ? null : file.getProject());
+
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
+ if (seamProject == null)
+ return NO_PROPOSALS;
+
+ String prefix= SeamELCompletionEngine.getPrefix(viewer, offset);
+ prefix = (prefix == null ? "" : prefix);
+
+ if (!checkStartPositionInEL(viewer, offset))
+ return NO_PROPOSALS;
+
+ List<String> suggestions = fEngine.getCompletions(seamProject, file,
viewer.getDocument(), prefix, offset - prefix.length());
+ List<String> uniqueSuggestions = fEngine.makeUnique(suggestions);
+
+ List<ICompletionProposal> result= new ArrayList<ICompletionProposal>();
+ for (String string : uniqueSuggestions) {
+ if (string.length() > 0)
+ result.add(createProposal(string, prefix, offset));
+ }
+
+ return (ICompletionProposal[]) result.toArray(new
ICompletionProposal[uniqueSuggestions.size()]);
+ } catch (BadLocationException x) {
+ return NO_PROPOSALS;
+ }
+ }
+
+ private ICompletionProposal createProposal(String string, String prefix, int offset) {
+ return new Proposal(string, prefix, offset);
+ }
+
+ /*
+ * @see
org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer,
int)
+ */
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset)
{
+ // no context informations for Seam EL completions
+ return NO_CONTEXTS;
+ }
+
+ private char[] autoActivChars;
+
+ /*
+ * @see
org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
+ */
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ if(autoActivChars==null) {
+ IPreferenceStore store= EditorsUI.getPreferenceStore();
+ String superDefaultChars =
store.getDefaultString(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA);
+ StringBuffer redhatDefaultChars = new StringBuffer(superDefaultChars);
+ if(superDefaultChars.indexOf("{")<0) {
+ redhatDefaultChars.append('{');
+ }
+ if(superDefaultChars.indexOf(".")<0) {
+ redhatDefaultChars.append('.');
+ }
+ autoActivChars = new char[redhatDefaultChars.length()];
+ redhatDefaultChars.getChars(0, redhatDefaultChars.length(), autoActivChars, 0);
+ store.setDefault(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA,
redhatDefaultChars.toString());
+ store.setValue(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA,
redhatDefaultChars.toString());
+ }
+ return autoActivChars;
+ }
+
+ /*
+ * @see
org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
+ */
+ public char[] getContextInformationAutoActivationCharacters() {
+ return null;
+ }
+
+ /*
+ * @see
org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
+ */
+ public IContextInformationValidator getContextInformationValidator() {
+ return null;
+ }
+
+ /*
+ * @see
org.eclipse.jface.text.contentassist.ICompletionProposalComputer#getErrorMessage()
+ */
+ public String getErrorMessage() {
+ return null; // no custom error message
+ }
+
+ private ITextEditor getActiveEditor() {
+ IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window != null) {
+ IWorkbenchPage page= window.getActivePage();
+ if (page != null) {
+ IEditorPart editor= page.getActiveEditor();
+ if (editor instanceof IEditorWrapper)
+ editor = ((IEditorWrapper) editor).getEditor();
+
+ if (editor instanceof ITextEditor)
+ return (ITextEditor) editor;
+ else
+ return (ITextEditor)editor.getAdapter(ITextEditor.class);
+ }
+ }
+ return null;
+ }
+
+ private boolean checkStartPositionInEL(ITextViewer viewer, int offset) throws
BadLocationException {
+ IDocument doc= viewer.getDocument();
+ if (doc == null || offset > doc.getLength())
+ return false;
+
+ while (--offset >= 0) {
+ if ('}' == doc.getChar(offset))
+ return false;
+
+ if ('{' == doc.getChar(offset) &&
+ (offset - 1) >= 0 &&
+ ('#' == doc.getChar(offset - 1) ||
+ '$' == doc.getChar(offset - 1))) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
Added:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamExpressionResolver.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamExpressionResolver.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/text/java/SeamExpressionResolver.java 2007-07-13
13:41:16 UTC (rev 2427)
@@ -0,0 +1,218 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.seam.ui.text.java;
+
+import java.lang.reflect.Modifier;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.jboss.tools.seam.core.IBijectedAttribute;
+import org.jboss.tools.seam.core.ISeamComponent;
+import org.jboss.tools.seam.core.ISeamContextVariable;
+import org.jboss.tools.seam.core.ISeamElement;
+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.ISeamXmlFactory;
+import org.jboss.tools.seam.core.ScopeType;
+
+public class SeamExpressionResolver {
+
+ public static List<ISeamContextVariable> resolveVariables(ISeamProject project,
ScopeType scope, String name) {
+ if (project == null || name == null) return null;
+ return (scope == null ? internalResolveVariables(project, name) :
+ internalResolveVariablesByScope(project, scope, name));
+ }
+
+ private static List<ISeamContextVariable> internalResolveVariables(ISeamProject
project, String name) {
+ List<ISeamContextVariable> resolvedVariables = new
ArrayList<ISeamContextVariable>();
+ Set<ISeamContextVariable> variables = project.getVariables();
+ for (ISeamContextVariable variable : variables) {
+ if (variable.getName().startsWith(name)) {
+ resolvedVariables.add(variable);
+ }
+ }
+ return resolvedVariables;
+ }
+
+ private static List<ISeamContextVariable>
internalResolveVariablesByScope(ISeamProject project, ScopeType scope, String name) {
+ List<ISeamContextVariable> resolvedVariables = new
ArrayList<ISeamContextVariable>();
+ Set<ISeamContextVariable> variables = project.getVariablesByScope(scope);
+ for (ISeamContextVariable variable : variables) {
+ if (variable.getName().startsWith(name)) {
+ resolvedVariables.add(variable);
+ }
+ }
+ return resolvedVariables;
+ }
+
+ public static IMember getMemberByVariable(ISeamContextVariable variable) {
+ IMember member = null;
+ if (variable instanceof ISeamComponent) {
+ ISeamComponent component = (ISeamComponent)variable;
+ ISeamJavaComponentDeclaration decl = component.getJavaDeclaration();
+ if (decl != null) {
+ member = decl.getSourceMember();
+ }
+ }
+ if (member == null && variable instanceof IBijectedAttribute) {
+ member = ((ISeamJavaSourceReference)variable).getSourceMember();
+ }
+ if (member == null && variable instanceof ISeamJavaSourceReference) {
+ member = ((ISeamJavaSourceReference)variable).getSourceMember();
+ }
+ if (member == null && variable instanceof ISeamXmlFactory) {
+ ISeamXmlFactory factory = (ISeamXmlFactory)variable;
+ String value = factory.getValue();
+ if (value != null && value.length() > 0) {
+ // TODO: Need to make sure that it's correct way to get the project and
+ // the scope from the factory
+ ISeamProject project = ((ISeamElement)factory).getSeamProject();
+// ISeamProject project = getSeamProject(factory.getResource());
+ if (project != null) {
+ List<ISeamContextVariable> resolvedValues = resolveVariables(project,
factory.getScope(), value);
+ for (ISeamContextVariable var : resolvedValues) {
+ if (var.getName().equals(value)) {
+ member = getMemberByVariable(var);
+ break;
+ }
+ }
+ }
+ }
+ }
+ return member;
+ }
+
+ public static Set<IMember> getMethods(IType type) {
+ Set<IMember> methods = new HashSet<IMember>();
+ if (type != null) {
+ try {
+ IMethod[] mthds = type.getMethods();
+ for (int i = 0; mthds != null && i < mthds.length; i++) {
+ IMethod m = mthds[i];
+ if (Modifier.isPublic(m.getFlags()) &&
+ (!m.getElementName().startsWith("get") &&
!m.getElementName().startsWith("set")) ||
+ "get".equals(m.getElementName()) ||
"set".equals(m.getElementName())) {
+ methods.add(m);
+ }
+ }
+ } catch (JavaModelException e) {
+ }
+ }
+ return methods;
+ }
+
+ public static Set<String> getMethodPresentations(IType type) {
+ Set<String> methods = new HashSet<String>();
+ if (type != null) {
+ try {
+ IMethod[] mthds = type.getMethods();
+ for (int i = 0; mthds != null && i < mthds.length; i++) {
+ IMethod m = mthds[i];
+ if (Modifier.isPublic(m.getFlags()) &&
+ (!m.getElementName().startsWith("get") &&
!m.getElementName().startsWith("set")) ||
+ "get".equals(m.getElementName()) ||
"set".equals(m.getElementName())) {
+
+ StringBuffer name = new StringBuffer(m.getElementName());
+
+ name.append('(');
+ String[] mParams = null;
+ mParams = m.getParameterNames();
+ for (int j = 0; mParams != null && j < mParams.length; j++) {
+ if (j > 0) name.append(", ");
+ name.append(mParams[j]);
+ }
+ name.append(')');
+
+ methods.add(name.toString());
+ }
+ }
+ } catch (JavaModelException e) {
+ }
+ }
+ return methods;
+ }
+
+ public static Set<IMember> getProperties(IType type) {
+ Set<IMember> properties = new HashSet<IMember>();
+ if (type != null) {
+ try {
+ IMethod[] props = type.getMethods();
+ for (int i = 0; props != null && i < props.length; i++) {
+ IMethod m = props[i];
+ if (Modifier.isPublic(m.getFlags()) &&
+ (m.getElementName().startsWith("get") &&
!"get".equals(m.getElementName())) ||
+ (m.getElementName().startsWith("set") &&
!"set".equals(m.getElementName()))) {
+ properties.add(m);
+ }
+ }
+ } catch (JavaModelException e) {
+ }
+
+ try {
+ IField[] fields = type.getFields();
+ for (int i = 0; fields != null && i < fields.length; i++) {
+ IField f = fields[i];
+ if (Modifier.isPublic(f.getFlags())) {
+ properties.add(f);
+ }
+ }
+ } catch (JavaModelException e) {
+ }
+ }
+ return properties;
+ }
+ public static Set<String> getPropertyPresentations(IType type) {
+ Set<String> properties = new
TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
+ if (type != null) {
+ try {
+ IMethod[] props = type.getMethods();
+ for (int i = 0; props != null && i < props.length; i++) {
+ IMethod m = props[i];
+ if (Modifier.isPublic(m.getFlags()) &&
+ (m.getElementName().startsWith("get") &&
!"get".equals(m.getElementName())) ||
+ (m.getElementName().startsWith("set") &&
!"set".equals(m.getElementName()))) {
+
+ StringBuffer name = new StringBuffer(m.getElementName());
+ name.delete(0, 3);
+ name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
+
+ properties.add(name.toString());
+ }
+ }
+ } catch (JavaModelException e) {
+ }
+
+ try {
+ IField[] fields = type.getFields();
+ for (int i = 0; fields != null && i < fields.length; i++) {
+ IField f = fields[i];
+ if (Modifier.isPublic(f.getFlags())) {
+ properties.add(f.getElementName());
+ }
+ }
+ } catch (JavaModelException e) {
+ }
+ }
+ return properties;
+ }
+
+}