diff options
Diffstat (limited to 'bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui')
113 files changed, 0 insertions, 16703 deletions
diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/ActionContributorJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/ActionContributorJSP.java deleted file mode 100644 index 468f0d8567..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/ActionContributorJSP.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui; - -import java.util.ResourceBundle; - -import org.eclipse.jdt.ui.actions.RefactorActionGroup; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jst.jsp.ui.internal.IActionConstantsJSP; -import org.eclipse.jst.jsp.ui.internal.IActionDefinitionIdsJSP; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.texteditor.RetargetTextEditorAction; -import org.eclipse.wst.html.ui.edit.ui.ActionContributorHTML; -import org.eclipse.wst.sse.ui.edit.util.StructuredTextEditorActionConstants; - -/** - * ActionContributorJSP - * - * This class should not be used inside multi page editor's ActionBarContributor, - * since cascaded init() call from the ActionBarContributor - * will causes exception and it leads to lose whole toolbars. - * - * Instead, use SourcePageActionContributor for source page contributor - * of multi page editor. - * - * Note that this class is still valid for single page editor. - */ -public class ActionContributorJSP extends ActionContributorHTML { - - private RetargetTextEditorAction renameElementAction = null; - private RetargetTextEditorAction moveElementAction = null; - private IMenuManager refactorMenu = null; - - private static final String[] EDITOR_IDS = {"org.eclipse.jst.jsp.ui.StructuredTextEditorJSP", "org.eclipse.wst.sse.ui.StructuredTextEditor"}; //$NON-NLS-1$ //$NON-NLS-2$ - - public ActionContributorJSP() { - super(); - - ResourceBundle bundle = JSPUIPlugin.getDefault().getResourceBundle(); - this.renameElementAction = new RetargetTextEditorAction(bundle, IActionConstantsJSP.ACTION_NAME_RENAME_ELEMENT + StructuredTextEditorActionConstants.DOT); - this.renameElementAction.setActionDefinitionId(IActionDefinitionIdsJSP.RENAME_ELEMENT); - - this.moveElementAction = new RetargetTextEditorAction(bundle, IActionConstantsJSP.ACTION_NAME_MOVE_ELEMENT + StructuredTextEditorActionConstants.DOT); - this.moveElementAction.setActionDefinitionId(IActionDefinitionIdsJSP.MOVE_ELEMENT); - - // the refactor menu, add the menu itself to add all refactor actions - this.refactorMenu = new MenuManager(JSPUIPlugin.getResourceString("%ActionContributorJSP.0"), RefactorActionGroup.MENU_ID); //$NON-NLS-1$ - refactorMenu.add(this.renameElementAction); - refactorMenu.add(this.moveElementAction); - } - - /** - * @see com.ibm.sse.editor.ui.ActionContributor#getExtensionIDs() - */ - protected String[] getExtensionIDs() { - return EDITOR_IDS; - } - - /** - * @see com.ibm.sse.editor.xml.ui.actions.ActionContributorXML#addToMenu(org.eclipse.jface.action.IMenuManager) - */ - protected void addToMenu(IMenuManager menu) { - super.addToMenu(menu); - - menu.insertAfter(IWorkbenchActionConstants.M_EDIT, this.refactorMenu); - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.xml.ui.actions.ActionContributorXML#setActiveEditor(org.eclipse.ui.IEditorPart) - */ - public void setActiveEditor(IEditorPart activeEditor) { - - super.setActiveEditor(activeEditor); - this.renameElementAction.setAction(getAction(getTextEditor(getActiveEditorPart()), IActionConstantsJSP.ACTION_NAME_RENAME_ELEMENT)); - this.moveElementAction.setAction(getAction(getTextEditor(getActiveEditorPart()), IActionConstantsJSP.ACTION_NAME_MOVE_ELEMENT)); - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.xml.ui.actions.ActionContributorXML#setViewerSpecificContributionsEnabled(boolean) - */ - public void setViewerSpecificContributionsEnabled(boolean enabled) { - - super.setViewerSpecificContributionsEnabled(enabled); - this.renameElementAction.setEnabled(enabled); - this.moveElementAction.setEnabled(enabled); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/JSPSpellCheckTarget.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/JSPSpellCheckTarget.java deleted file mode 100644 index 82ddc2406f..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/JSPSpellCheckTarget.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui; - -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.ui.XMLSpellCheckTarget; - -/** - * @deprecated - to be removed in M4 - */ - -public class JSPSpellCheckTarget extends XMLSpellCheckTarget { - - /** - * @param editor - */ - public JSPSpellCheckTarget() { - super(); - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.SpellCheckTargetImpl#isValidType(java.lang.String) - */ - protected boolean isValidType(String type) { - boolean valid = false; - if (//XMLRegionContext.UNDEFINED.equals(type) || - //XMLRegionContext.BLOCK_TEXT.equals(type) || - //XMLRegionContext.XML_CDATA_TEXT.equals(type) || - //XMLRegionContext.XML_PI_CONTENT.equals(type) || - //XMLRegionContext.XML_ELEMENT_DECL_CONTENT.equals(type) || - //XMLRegionContext.XML_ATTLIST_DECL_CONTENT.equals(type) || - //XMLJSPRegionContexts.JSP_CONTENT.equals(type) || - //XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE.equals(type) || - XMLJSPRegionContexts.JSP_COMMENT_TEXT.equals(type)) { - valid = true; - } - return valid || super.isValidType(type); - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/StructuredTextEditorJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/StructuredTextEditorJSP.java deleted file mode 100644 index 68bf6c1f77..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/StructuredTextEditorJSP.java +++ /dev/null @@ -1,139 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui; - -import java.util.ResourceBundle; - -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.GroupMarker; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.jst.jsp.ui.internal.IActionConstantsJSP; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.editor.IHelpContextIds; -import org.eclipse.jst.jsp.ui.internal.java.refactoring.JSPMoveElementAction; -import org.eclipse.jst.jsp.ui.internal.java.refactoring.JSPRenameElementAction; -import org.eclipse.jst.jsp.ui.internal.java.search.JSPFindOccurrencesAction; -import org.eclipse.swt.graphics.Point; -import org.eclipse.ui.texteditor.ITextEditorActionConstants; -import org.eclipse.wst.html.ui.edit.ui.CleanupActionHTML; -import org.eclipse.wst.html.ui.internal.search.HTMLFindOccurrencesAction; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.ui.StructuredTextEditor; -import org.eclipse.wst.sse.ui.edit.util.ActionDefinitionIds; -import org.eclipse.wst.sse.ui.edit.util.StructuredTextEditorActionConstants; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.search.FindOccurrencesActionProvider; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.ui.actions.AddBlockCommentActionXML; -import org.eclipse.wst.xml.ui.actions.RemoveBlockCommentActionXML; -import org.eclipse.wst.xml.ui.actions.ToggleCommentActionXML; - -public class StructuredTextEditorJSP extends StructuredTextEditor { - - protected void createActions() { - super.createActions(); - - ResourceBundle resourceBundle = SSEUIPlugin.getDefault().getResourceBundle(); - - Action action = new CleanupActionHTML(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT + DOT, this); - action.setActionDefinitionId(ActionDefinitionIds.CLEANUP_DOCUMENT); - setAction(StructuredTextEditorActionConstants.ACTION_NAME_CLEANUP_DOCUMENT, action); - - action = new ToggleCommentActionXML(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_TOGGLE_COMMENT + DOT, this); - action.setActionDefinitionId(ActionDefinitionIds.TOGGLE_COMMENT); - setAction(StructuredTextEditorActionConstants.ACTION_NAME_TOGGLE_COMMENT, action); - - action = new AddBlockCommentActionXML(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_ADD_BLOCK_COMMENT + DOT, this); - action.setActionDefinitionId(ActionDefinitionIds.ADD_BLOCK_COMMENT); - setAction(StructuredTextEditorActionConstants.ACTION_NAME_ADD_BLOCK_COMMENT, action); - - action = new RemoveBlockCommentActionXML(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_REMOVE_BLOCK_COMMENT + DOT, this); - action.setActionDefinitionId(ActionDefinitionIds.REMOVE_BLOCK_COMMENT); - setAction(StructuredTextEditorActionConstants.ACTION_NAME_REMOVE_BLOCK_COMMENT, action); - - FindOccurrencesActionProvider foAction = new FindOccurrencesActionProvider(resourceBundle, StructuredTextEditorActionConstants.ACTION_NAME_FIND_OCCURRENCES + DOT, this); - foAction.addAction(new HTMLFindOccurrencesAction(resourceBundle, "", this)); //$NON-NLS-1$ - foAction.addAction(new JSPFindOccurrencesAction(resourceBundle, "", this)); //$NON-NLS-1$ - foAction.setActionDefinitionId(ActionDefinitionIds.FIND_OCCURRENCES); - setAction(StructuredTextEditorActionConstants.ACTION_NAME_FIND_OCCURRENCES, foAction); - markAsSelectionDependentAction(StructuredTextEditorActionConstants.ACTION_NAME_FIND_OCCURRENCES, true); - - JSPRenameElementAction renameAction = new JSPRenameElementAction(JSPUIPlugin.getDefault().getResourceBundle(), IActionConstantsJSP.ACTION_NAME_RENAME_ELEMENT + DOT, this); - setAction(IActionConstantsJSP.ACTION_NAME_RENAME_ELEMENT, renameAction); - markAsSelectionDependentAction(IActionConstantsJSP.ACTION_NAME_RENAME_ELEMENT, true); - - JSPMoveElementAction moveAction = new JSPMoveElementAction(JSPUIPlugin.getDefault().getResourceBundle(), IActionConstantsJSP.ACTION_NAME_MOVE_ELEMENT + DOT, this); - setAction(IActionConstantsJSP.ACTION_NAME_MOVE_ELEMENT, moveAction); - markAsSelectionDependentAction(IActionConstantsJSP.ACTION_NAME_MOVE_ELEMENT, true); - } - - /** - * Uses the input's JSPTranslation to get currently selected Java - * elements. - * - * @return currently selected IJavaElements * - * @deprecated - to be refactored and made to use the editor's selection - * provider - */ - public IJavaElement[] getJavaElementsForCurrentSelection() { - - IJavaElement[] elements = new IJavaElement[0]; - // get JSP translation object for this viewer's document - XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - try { - if (xmlModel != null) { - XMLDocument xmlDoc = xmlModel.getDocument(); - - JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (adapter != null) { - JSPTranslation translation = adapter.getJSPTranslation(); - Point selected = getSelectionRange(); - elements = translation.getElementsFromJspRange(selected.x, selected.x + selected.y); - } - } - } - finally { - if (xmlModel != null) - xmlModel.releaseFromRead(); - } - return elements; - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.StructuredTextEditor#addContextMenuActions(org.eclipse.jface.action.IMenuManager) - */ - protected void addContextMenuActions(IMenuManager menu) { - - super.addContextMenuActions(menu); - - if (getSourceViewer().isEditable()) { - String label = JSPUIPlugin.getResourceString("%Refactor.label"); //$NON-NLS-1$ = "Format" - MenuManager subMenu = new MenuManager(label, "Refactor"); //$NON-NLS-1$ - addAction(subMenu, IActionConstantsJSP.ACTION_NAME_RENAME_ELEMENT); - addAction(subMenu, IActionConstantsJSP.ACTION_NAME_MOVE_ELEMENT); - subMenu.add(new GroupMarker(GROUP_NAME_ADDITIONS)); - menu.appendToGroup(ITextEditorActionConstants.GROUP_EDIT, subMenu); - } - } - - protected void initializeEditor() { - super.initializeEditor(); - setHelpContextId(IHelpContextIds.JSP_SOURCEVIEW_HELPID); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/StructuredTextViewerConfigurationJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/StructuredTextViewerConfigurationJSP.java deleted file mode 100644 index f135b11c46..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/StructuredTextViewerConfigurationJSP.java +++ /dev/null @@ -1,460 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.eclipse.jdt.ui.PreferenceConstants; -import org.eclipse.jdt.ui.text.JavaSourceViewerConfiguration; -import org.eclipse.jdt.ui.text.JavaTextTools; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.IAutoEditStrategy; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextDoubleClickStrategy; -import org.eclipse.jface.text.ITextHover; -import org.eclipse.jface.text.contentassist.ContentAssistant; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.text.contentassist.IContentAssistant; -import org.eclipse.jface.text.formatter.IContentFormatter; -import org.eclipse.jface.text.formatter.MultiPassContentFormatter; -import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; -import org.eclipse.jface.text.information.IInformationPresenter; -import org.eclipse.jface.text.information.IInformationProvider; -import org.eclipse.jface.text.information.InformationPresenter; -import org.eclipse.jface.text.reconciler.IReconciler; -import org.eclipse.jface.text.reconciler.IReconcilingStrategy; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jst.jsp.core.internal.text.rules.StructuredTextPartitionerForJSP; -import org.eclipse.jst.jsp.ui.format.FormattingStrategyJSPJava; -import org.eclipse.jst.jsp.ui.internal.autoedit.StructuredAutoEditStrategyJSP; -import org.eclipse.jst.jsp.ui.internal.contentassist.JSPContentAssistProcessor; -import org.eclipse.jst.jsp.ui.internal.contentassist.JSPJavaContentAssistProcessor; -import org.eclipse.jst.jsp.ui.internal.contentassist.NoRegionContentAssistProcessorForJSP; -import org.eclipse.jst.jsp.ui.internal.correction.CorrectionProcessorJSP; -import org.eclipse.jst.jsp.ui.internal.hyperlink.JSPJavaHyperlinkDetector; -import org.eclipse.jst.jsp.ui.internal.hyperlink.TaglibHyperlinkDetector; -import org.eclipse.jst.jsp.ui.internal.hyperlink.URIHyperlinkDetector; -import org.eclipse.jst.jsp.ui.internal.reconcile.StructuredTextReconcilingStrategyForJSP; -import org.eclipse.jst.jsp.ui.internal.taginfo.JSPJavaJavadocHoverProcessor; -import org.eclipse.jst.jsp.ui.style.LineStyleProviderForJSP; -import org.eclipse.jst.jsp.ui.style.java.LineStyleProviderForJava; -import org.eclipse.jst.jsp.ui.taginfo.JSPBestMatchHoverProcessor; -import org.eclipse.jst.jsp.ui.taginfo.JSPJavaBestMatchHoverProcessor; -import org.eclipse.jst.jsp.ui.taginfo.JSPTagInfoHoverProcessor; -import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.css.core.internal.text.rules.StructuredTextPartitionerForCSS; -import org.eclipse.wst.css.ui.contentassist.CSSContentAssistProcessor; -import org.eclipse.wst.css.ui.style.LineStyleProviderForEmbeddedCSS; -import org.eclipse.wst.html.core.format.HTMLFormatProcessorImpl; -import org.eclipse.wst.html.core.internal.text.rules.StructuredTextPartitionerForHTML; -import org.eclipse.wst.html.ui.internal.contentassist.HTMLContentAssistProcessor; -import org.eclipse.wst.html.ui.style.LineStyleProviderForHTML; -import org.eclipse.wst.html.ui.taginfo.HTMLBestMatchHoverProcessor; -import org.eclipse.wst.html.ui.taginfo.HTMLInformationProvider; -import org.eclipse.wst.html.ui.taginfo.HTMLTagInfoHoverProcessor; -import org.eclipse.wst.javascript.common.ui.contentassist.JavaScriptContentAssistProcessor; -import org.eclipse.wst.javascript.common.ui.style.LineStyleProviderForJavaScript; -import org.eclipse.wst.javascript.common.ui.taginfo.JavaScriptBestMatchHoverProcessor; -import org.eclipse.wst.javascript.common.ui.taginfo.JavaScriptInformationProvider; -import org.eclipse.wst.javascript.common.ui.taginfo.JavaScriptTagInfoHoverProcessor; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.rules.StructuredTextPartitioner; -import org.eclipse.wst.sse.ui.StructuredTextViewerConfiguration; -import org.eclipse.wst.sse.ui.format.StructuredFormattingStrategy; -import org.eclipse.wst.sse.ui.internal.reconcile.StructuredRegionProcessor; -import org.eclipse.wst.sse.ui.preferences.CommonEditorPreferenceNames; -import org.eclipse.wst.sse.ui.style.IHighlighter; -import org.eclipse.wst.sse.ui.style.LineStyleProvider; -import org.eclipse.wst.sse.ui.taginfo.AnnotationHoverProcessor; -import org.eclipse.wst.sse.ui.taginfo.ProblemAnnotationHoverProcessor; -import org.eclipse.wst.sse.ui.taginfo.TextHoverManager; -import org.eclipse.wst.sse.ui.util.EditorUtility; -import org.eclipse.wst.xml.core.text.rules.StructuredTextPartitionerForXML; -import org.eclipse.wst.xml.ui.doubleclick.XMLDoubleClickStrategy; -import org.eclipse.wst.xml.ui.internal.correction.CorrectionProcessorXML; -import org.eclipse.wst.xml.ui.reconcile.StructuredTextReconcilingStrategyForMarkup; - -public class StructuredTextViewerConfigurationJSP extends StructuredTextViewerConfiguration { - - InformationPresenter fInformationPresenter = null; - - private JavaSourceViewerConfiguration fJavaSourceViewerConfiguration; - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.StructuredTextViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer) - */ - public Map getAutoEditStrategies(ISourceViewer sourceViewer) { - Map result = super.getAutoEditStrategies(sourceViewer); - - if (result.get(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA) == null) - result.put(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA, new ArrayList(1)); - if (result.get(StructuredTextPartitionerForHTML.ST_DEFAULT_HTML) == null) - result.put(StructuredTextPartitionerForHTML.ST_DEFAULT_HTML, new ArrayList(1)); - if (result.get(StructuredTextPartitionerForHTML.ST_HTML_DECLARATION) == null) - result.put(StructuredTextPartitionerForHTML.ST_HTML_DECLARATION, new ArrayList(1)); - - List strategies = (List) result.get(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA); - // IJavaPartitions.JAVA_PARTITIONING = "___java_partitioning", but is - // internal - strategies.add(getJavaSourceViewerConfiguration().getAutoEditStrategies(sourceViewer, "___java_partitioning")[0]); - - IAutoEditStrategy autoEditStrategy = new StructuredAutoEditStrategyJSP(); - strategies = (List) result.get(StructuredTextPartitionerForHTML.ST_DEFAULT_HTML); - strategies.add(autoEditStrategy); - strategies = (List) result.get(StructuredTextPartitionerForHTML.ST_HTML_DECLARATION); - strategies.add(autoEditStrategy); - - return result; - } - - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - if (configuredContentTypes == null) { - String[] xmlTypes = StructuredTextPartitionerForXML.getConfiguredContentTypes(); - String[] htmlTypes = StructuredTextPartitionerForHTML.getConfiguredContentTypes(); - String[] jspTypes = StructuredTextPartitionerForJSP.getConfiguredContentTypes(); - configuredContentTypes = new String[2 + xmlTypes.length + htmlTypes.length + jspTypes.length]; - - configuredContentTypes[0] = StructuredTextPartitioner.ST_DEFAULT_PARTITION; - configuredContentTypes[1] = StructuredTextPartitioner.ST_UNKNOWN_PARTITION; - - int index = 0; - System.arraycopy(xmlTypes, 0, configuredContentTypes, index += 2, xmlTypes.length); - System.arraycopy(htmlTypes, 0, configuredContentTypes, index += xmlTypes.length, htmlTypes.length); - System.arraycopy(jspTypes, 0, configuredContentTypes, index += htmlTypes.length, jspTypes.length); - } - - return configuredContentTypes; - } - - public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { - IContentAssistant ca = super.getContentAssistant(sourceViewer); - - if (ca != null && ca instanceof ContentAssistant) { - ContentAssistant contentAssistant = (ContentAssistant) ca; - - IContentAssistProcessor htmlContentAssistProcessor = new HTMLContentAssistProcessor(); - IContentAssistProcessor jsContentAssistProcessor = new JavaScriptContentAssistProcessor(); - IContentAssistProcessor cssContentAssistProcessor = new CSSContentAssistProcessor(); - IContentAssistProcessor jspContentAssistProcessor = new JSPContentAssistProcessor(); - IContentAssistProcessor jspJavaContentAssistProcessor = new JSPJavaContentAssistProcessor(); - IContentAssistProcessor noRegionProcessorJsp = new NoRegionContentAssistProcessorForJSP(); - - // HTML - setContentAssistProcessor(contentAssistant, htmlContentAssistProcessor, StructuredTextPartitionerForHTML.ST_DEFAULT_HTML); - setContentAssistProcessor(contentAssistant, htmlContentAssistProcessor, StructuredTextPartitionerForHTML.ST_HTML_COMMENT); - - // HTML JavaScript - setContentAssistProcessor(contentAssistant, jsContentAssistProcessor, StructuredTextPartitionerForHTML.ST_SCRIPT); - setContentAssistProcessor(contentAssistant, jsContentAssistProcessor, StructuredTextPartitionerForHTML.ST_SCRIPT); - - // CSS - setContentAssistProcessor(contentAssistant, cssContentAssistProcessor, StructuredTextPartitionerForCSS.ST_STYLE); - setContentAssistProcessor(contentAssistant, cssContentAssistProcessor, StructuredTextPartitionerForCSS.ST_STYLE); - - // JSP - setContentAssistProcessor(contentAssistant, jspContentAssistProcessor, StructuredTextPartitioner.ST_DEFAULT_PARTITION); - setContentAssistProcessor(contentAssistant, jspContentAssistProcessor, StructuredTextPartitionerForXML.ST_DEFAULT_XML); - setContentAssistProcessor(contentAssistant, jspContentAssistProcessor, StructuredTextPartitionerForHTML.ST_DEFAULT_HTML); - setContentAssistProcessor(contentAssistant, jspContentAssistProcessor, StructuredTextPartitionerForHTML.ST_HTML_COMMENT); - setContentAssistProcessor(contentAssistant, jspContentAssistProcessor, StructuredTextPartitionerForJSP.ST_DEFAULT_JSP); - // SCRIPT region - setContentAssistProcessor(contentAssistant, jspContentAssistProcessor, StructuredTextPartitionerForHTML.ST_SCRIPT); - // JSP directives - setContentAssistProcessor(contentAssistant, jspContentAssistProcessor, StructuredTextPartitionerForJSP.ST_JSP_DIRECTIVE); - // JSP delimiters - setContentAssistProcessor(contentAssistant, jspContentAssistProcessor, StructuredTextPartitionerForJSP.ST_JSP_CONTENT_DELIMITER); - // JSP JavaScript - setContentAssistProcessor(contentAssistant, jspContentAssistProcessor, StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT); - // JSP Java - setContentAssistProcessor(contentAssistant, jspJavaContentAssistProcessor, StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA); - // unknown - setContentAssistProcessor(contentAssistant, noRegionProcessorJsp, StructuredTextPartitioner.ST_UNKNOWN_PARTITION); - // CMVC 269718 - // JSP COMMENT - setContentAssistProcessor(contentAssistant, jspContentAssistProcessor, StructuredTextPartitionerForJSP.ST_JSP_COMMENT); - } - - return ca; - } - - public IContentAssistant getCorrectionAssistant(ISourceViewer sourceViewer) { - IContentAssistant ca = super.getCorrectionAssistant(sourceViewer); - - if (ca != null && ca instanceof ContentAssistant) { - ContentAssistant correctionAssistant = (ContentAssistant) ca; - ITextEditor editor = getTextEditor(); - if (editor != null) { - IContentAssistProcessor correctionProcessor = new CorrectionProcessorXML(editor); - correctionAssistant.setContentAssistProcessor(correctionProcessor, StructuredTextPartitionerForHTML.ST_DEFAULT_HTML); - - correctionProcessor = new CorrectionProcessorJSP(editor); - correctionAssistant.setContentAssistProcessor(correctionProcessor, StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA); - } - } - - return ca; - } - - public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { - MultiPassContentFormatter formatter = new MultiPassContentFormatter(getConfiguredDocumentPartitioning(sourceViewer), StructuredTextPartitionerForXML.ST_DEFAULT_XML); - - formatter.setMasterStrategy(new StructuredFormattingStrategy(new HTMLFormatProcessorImpl())); - formatter.setSlaveStrategy(new FormattingStrategyJSPJava(), StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA); - - return formatter; - } - - public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) { - if (contentType.compareTo(StructuredTextPartitionerForHTML.ST_DEFAULT_HTML) == 0) - // HTML - return new XMLDoubleClickStrategy(); - else if (contentType.compareTo(StructuredTextPartitionerForHTML.ST_SCRIPT) == 0 || contentType.compareTo(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA) == 0 - || contentType.compareTo(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT) == 0) - // HTML JavaScript - // JSP Java or JSP JavaScript - return getJavaSourceViewerConfiguration().getDoubleClickStrategy(sourceViewer, contentType); - else if (contentType.compareTo(StructuredTextPartitionerForJSP.ST_DEFAULT_JSP) == 0) - // JSP - return new XMLDoubleClickStrategy(); - else - return super.getDoubleClickStrategy(sourceViewer, contentType); - } - - public IHighlighter getHighlighter(ISourceViewer sourceViewer) { - IHighlighter highlighter = super.getHighlighter(sourceViewer); - - if (highlighter != null) { - // HTML - LineStyleProvider htmlLineStyleProvider = new LineStyleProviderForHTML(); - highlighter.addProvider(StructuredTextPartitionerForHTML.ST_DEFAULT_HTML, htmlLineStyleProvider); - highlighter.addProvider(StructuredTextPartitionerForHTML.ST_HTML_COMMENT, htmlLineStyleProvider); - highlighter.addProvider(StructuredTextPartitionerForHTML.ST_HTML_DECLARATION, htmlLineStyleProvider); - - // HTML JavaScript - LineStyleProvider jsLineStyleProvider = new LineStyleProviderForJavaScript(); - highlighter.addProvider(StructuredTextPartitionerForHTML.ST_SCRIPT, jsLineStyleProvider); - - // CSS - LineStyleProvider cssLineStyleProvider = new LineStyleProviderForEmbeddedCSS(); - highlighter.addProvider(StructuredTextPartitionerForCSS.ST_STYLE, cssLineStyleProvider); - - // JSP - LineStyleProvider jspLineStyleProvider = new LineStyleProviderForJSP(); - highlighter.addProvider(StructuredTextPartitionerForJSP.ST_DEFAULT_JSP, jspLineStyleProvider); - highlighter.addProvider(StructuredTextPartitionerForJSP.ST_JSP_COMMENT, jspLineStyleProvider); - highlighter.addProvider(StructuredTextPartitionerForJSP.ST_JSP_DIRECTIVE, jspLineStyleProvider); - highlighter.addProvider(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_DELIMITER, jspLineStyleProvider); - - // JSP Java or JSP JavaScript - highlighter.addProvider(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA, new LineStyleProviderForJava()); - highlighter.addProvider(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT, new LineStyleProviderForJavaScript()); - } - - return highlighter; - } - - public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) { - if (fInformationPresenter == null) { - fInformationPresenter = new InformationPresenter(getInformationPresenterControlCreator(sourceViewer)); - - // HTML - IInformationProvider htmlInformationProvider = new HTMLInformationProvider(); - fInformationPresenter.setInformationProvider(htmlInformationProvider, StructuredTextPartitionerForHTML.ST_DEFAULT_HTML); - - // HTML JavaScript - IInformationProvider javascriptInformationProvider = new JavaScriptInformationProvider(); - fInformationPresenter.setInformationProvider(javascriptInformationProvider, StructuredTextPartitionerForHTML.ST_SCRIPT); - - fInformationPresenter.setSizeConstraints(60, 10, true, true); - } - return fInformationPresenter; - } - - public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) { - // html - if (contentType == StructuredTextPartitionerForHTML.ST_DEFAULT_HTML) { - TextHoverManager.TextHoverDescriptor[] hoverDescs = getTextHovers(); - int i = 0; - while (i < hoverDescs.length) { - if (hoverDescs[i].isEnabled() && EditorUtility.computeStateMask(hoverDescs[i].getModifierString()) == stateMask) { - String hoverType = hoverDescs[i].getId(); - if (TextHoverManager.COMBINATION_HOVER.equalsIgnoreCase(hoverType)) - return new HTMLBestMatchHoverProcessor(); - else if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType)) - return new ProblemAnnotationHoverProcessor(); - else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType)) - return new AnnotationHoverProcessor(); - else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) - return new HTMLTagInfoHoverProcessor(); - } - i++; - } - } else if (contentType == StructuredTextPartitionerForHTML.ST_SCRIPT) { - // HTML JavaScript - TextHoverManager.TextHoverDescriptor[] hoverDescs = getTextHovers(); - int i = 0; - while (i < hoverDescs.length) { - if (hoverDescs[i].isEnabled() && EditorUtility.computeStateMask(hoverDescs[i].getModifierString()) == stateMask) { - String hoverType = hoverDescs[i].getId(); - if (TextHoverManager.COMBINATION_HOVER.equalsIgnoreCase(hoverType)) - return new JavaScriptBestMatchHoverProcessor(); - else if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType)) - return new ProblemAnnotationHoverProcessor(); - else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType)) - return new AnnotationHoverProcessor(); - else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) - return new JavaScriptTagInfoHoverProcessor(); - } - i++; - } - } else if ((contentType == StructuredTextPartitionerForJSP.ST_DEFAULT_JSP) || (contentType == StructuredTextPartitionerForJSP.ST_JSP_DIRECTIVE)) { - // JSP - TextHoverManager.TextHoverDescriptor[] hoverDescs = getTextHovers(); - int i = 0; - while (i < hoverDescs.length) { - if (hoverDescs[i].isEnabled() && EditorUtility.computeStateMask(hoverDescs[i].getModifierString()) == stateMask) { - String hoverType = hoverDescs[i].getId(); - if (TextHoverManager.COMBINATION_HOVER.equalsIgnoreCase(hoverType)) - return new JSPBestMatchHoverProcessor(); - else if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType)) - return new ProblemAnnotationHoverProcessor(); - else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType)) - return new AnnotationHoverProcessor(); - else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) - return new JSPTagInfoHoverProcessor(); - } - i++; - } - } else if (contentType == StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA) { - // JSP Java - TextHoverManager.TextHoverDescriptor[] hoverDescs = getTextHovers(); - int i = 0; - while (i < hoverDescs.length) { - if (hoverDescs[i].isEnabled() && EditorUtility.computeStateMask(hoverDescs[i].getModifierString()) == stateMask) { - String hoverType = hoverDescs[i].getId(); - if (TextHoverManager.COMBINATION_HOVER.equalsIgnoreCase(hoverType)) { - JSPJavaBestMatchHoverProcessor hover = new JSPJavaBestMatchHoverProcessor(); - return hover; - } else if (TextHoverManager.PROBLEM_HOVER.equalsIgnoreCase(hoverType)) - return new ProblemAnnotationHoverProcessor(); - else if (TextHoverManager.ANNOTATION_HOVER.equalsIgnoreCase(hoverType)) - return new AnnotationHoverProcessor(); - else if (TextHoverManager.DOCUMENTATION_HOVER.equalsIgnoreCase(hoverType)) { - JSPJavaJavadocHoverProcessor hover = new JSPJavaJavadocHoverProcessor(); - return hover; - } - } - i++; - } - } - return super.getTextHover(sourceViewer, contentType, stateMask); - } - - public void unConfigure(ISourceViewer viewer) { - super.unConfigure(viewer); - - // InformationPresenters - if (fInformationPresenter != null) - fInformationPresenter.uninstall(); - } - - public IReconciler getReconciler(ISourceViewer sourceViewer) { - if (fReconciler != null) { - // a reconciler should always be installed or disposed of - if (!fReconciler.isInstalled()) { - fReconciler = null; - } - } - - // the first time running through, there's no model (so no pref store) - // but the reconciler still needs to be created so that its document - // gets set - if (fReconciler == null) { - // create one - fReconciler = new StructuredRegionProcessor(); - fReconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer)); - } - - boolean reconcilingEnabled = fPreferenceStore.getBoolean(CommonEditorPreferenceNames.EVALUATE_TEMPORARY_PROBLEMS); - - if (!reconcilingEnabled) - return fReconciler; - - if (fReconciler != null) { - IDocument doc = ((ITextEditor) editorPart).getDocumentProvider().getDocument(editorPart.getEditorInput()); - IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(doc); - try { - if (sModel != null) { - - IReconcilingStrategy markupStrategy = new StructuredTextReconcilingStrategyForMarkup((ITextEditor) editorPart); - IReconcilingStrategy jspStrategy = new StructuredTextReconcilingStrategyForJSP((ITextEditor) editorPart); - - fReconciler.setReconcilingStrategy(markupStrategy, StructuredTextPartitioner.ST_DEFAULT_PARTITION); - fReconciler.setReconcilingStrategy(markupStrategy, StructuredTextPartitionerForXML.ST_DEFAULT_XML); - - fReconciler.setReconcilingStrategy(jspStrategy, StructuredTextPartitionerForJSP.ST_DEFAULT_JSP); - fReconciler.setReconcilingStrategy(jspStrategy, StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA); - fReconciler.setReconcilingStrategy(jspStrategy, StructuredTextPartitionerForJSP.ST_JSP_CONTENT_DELIMITER); - fReconciler.setReconcilingStrategy(jspStrategy, StructuredTextPartitionerForJSP.ST_JSP_DIRECTIVE); - - fReconciler.setDefaultStrategy(markupStrategy); - - String contentTypeId = sModel.getContentTypeIdentifier(); - if (contentTypeId != null) - fReconciler.setValidatorStrategy(createValidatorStrategy(contentTypeId)); - - } - } finally { - if (sModel != null) - sModel.releaseFromRead(); - } - } - return fReconciler; - } - - private JavaSourceViewerConfiguration getJavaSourceViewerConfiguration() { - if (fJavaSourceViewerConfiguration == null) { - IPreferenceStore store = PreferenceConstants.getPreferenceStore(); - JavaTextTools javaTextTools = new JavaTextTools(store); - fJavaSourceViewerConfiguration = new JavaSourceViewerConfiguration(javaTextTools, getTextEditor()); - } - return fJavaSourceViewerConfiguration; - } - - /* - * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getHyperlinkDetectors(org.eclipse.jface.text.source.ISourceViewer) - * @since 3.1 - */ - public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) { - if (sourceViewer == null || !fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_HYPERLINKS_ENABLED)) - return null; - - List allDetectors = new ArrayList(0); - allDetectors.add(new JSPJavaHyperlinkDetector()); - allDetectors.add(new TaglibHyperlinkDetector()); - allDetectors.add(new URIHyperlinkDetector()); - - IHyperlinkDetector[] superDetectors = super.getHyperlinkDetectors(sourceViewer); - for (int m = 0; m < superDetectors.length; m++) { - IHyperlinkDetector detector = superDetectors[m]; - if (!allDetectors.contains(detector)) { - allDetectors.add(detector); - } - } - return (IHyperlinkDetector[]) allDetectors.toArray(new IHyperlinkDetector[0]); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/AbstractBreakpointProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/AbstractBreakpointProvider.java deleted file mode 100644 index c53da7f7a1..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/AbstractBreakpointProvider.java +++ /dev/null @@ -1,243 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.breakpointproviders; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.core.JSP12Namespace; -import org.eclipse.jst.jsp.core.contentmodel.tld.TLDElementDeclaration; -import org.eclipse.ui.IEditorInput; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNode; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.contentmodel.CMNodeWrapper; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionCollection; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.sse.ui.extensions.breakpoint.IBreakpointProvider; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * Abstract breakpoint provider class which implements breakpoint provider - * interface. - * - * This is a temporary class for JavaBreakpointProvider and - * JavaScriptBreakpointProvider, and should be refactored to separate Java and - * JavaScript parts. - */ -public abstract class AbstractBreakpointProvider implements IBreakpointProvider { - - private static final String JSP_DIRECTIVE_PAGE = "jsp:directive.page"; //$NON-NLS-1$ - private static final String[] JAVASCRIPT_LANGUAGE_KEYS = new String[]{"javascript", "javascript1.0", "javascript1.1_3", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - "javascript1.2", "javascript1.3", "javascript1.4", "javascript1.5", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - "javascript1.6", "jscript", "sashscript"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - protected static final int UNSUPPORTED = 0; - protected static final int JAVA = 1; - protected static final int JAVASCRIPT = 2; - - protected static final int END_OF_LINE = -1; - protected static final int NO_VALID_CONTENT = -2; - - protected int getValidPosition(Document doc, IDocument idoc, int lineNumber) { - if (doc == null) - return NO_VALID_CONTENT; - if (idoc == null) - return NO_VALID_CONTENT; - - int startOffset, endOffset; - try { - startOffset = idoc.getLineOffset(lineNumber - 1); - endOffset = idoc.getLineOffset(lineNumber) - 1; - - if (idoc == null) - return NO_VALID_CONTENT; - String lineText = idoc.get(startOffset, endOffset - startOffset).trim(); - - // blank lines or lines with only an open or close brace or - // scriptlet tag cannot have a breakpoint - if (lineText.equals("") || lineText.equals("{") || //$NON-NLS-2$//$NON-NLS-1$ - lineText.equals("}") || lineText.equals("<%"))//$NON-NLS-2$//$NON-NLS-1$ - return NO_VALID_CONTENT; - } - catch (BadLocationException e) { - return NO_VALID_CONTENT; - } - - IStructuredDocumentRegion flatNode = ((IStructuredDocument) idoc).getRegionAtCharacterOffset(startOffset); - // go through the node's regions looking for JSP content - // until reaching the end of the line - while (flatNode != null) { - int validPosition = getValidRegionPosition(((XMLDocument) doc).getModel(), flatNode, startOffset, endOffset); - - if (validPosition == END_OF_LINE) - return NO_VALID_CONTENT; - - if (validPosition >= 0) - return validPosition; - - flatNode = flatNode.getNext(); - } - return NO_VALID_CONTENT; - } - - /* - * Search the RegionContainer's regions looking for JSP content. - * If valid content is found, return the position >= 0 - * If no valid content is found, return NO_VALID_CONTENT. - * If a region starts after the line's endOffset, return END_OF_LINE. - */ - private static int getValidRegionPosition(IStructuredModel model, ITextRegionCollection regionContainer, int startOffset, int endOffset) { - - ITextRegionList regions = regionContainer.getRegions(); - for (int i = 0; i < regions.size(); i++) { - ITextRegion region = regions.get(i); - if (region instanceof ITextRegionCollection) { - int validPosition = getValidRegionPosition(model, (ITextRegionCollection) region, startOffset, endOffset); - if (validPosition == END_OF_LINE || validPosition >= 0) - return validPosition; - } - else { - // region must be at least partially on selected line - if (regionContainer.getEndOffset(region) > startOffset) { - - int regionStartOffset = regionContainer.getStartOffset(region); - // if region starts after line's endOffset, we're done searching - if (regionStartOffset > endOffset) - return END_OF_LINE; - - // If region is JSP content, make sure the language is Java not Javascript by - // checking the content assist adapter's type. - if (region.getType().equals(XMLJSPRegionContexts.JSP_CONTENT)) { - // DWM: this logic is not incorrect ... given changes to adapters, etc. - // but probably don't need anything here, since both Java and JavaScript - // are supported in V5. - - // nsd_TODO: verify this!!! - - // INodeNotifier notifier = (INodeNotifier)model.getNode(region.getStartOffset()); - // AdapterFactory factory = model.getFactoryRegistry().getFactoryFor(ContentAssistAdapter.class); - // if(factory instanceof HTMLContentAssistAdapterFactory) { - // INodeAdapter adapter = ((HTMLContentAssistAdapterFactory)factory).createAdapter(notifier, region); - // if(adapter != null && adapter instanceof JSPJavaContentAssistAdapter) - - if (regionStartOffset > startOffset) - return regionStartOffset; - else - return startOffset; - // } - } - // a custom tag, jsp:useBean, getproperty or setproperty statement is also a valid breakpoint location - else if (region.getType().equals(XMLRegionContext.XML_TAG_NAME) && (isCustomTagRegion(model.getIndexedRegion(regionStartOffset)) || regionContainer.getText(region).equals(JSP12Namespace.ElementName.USEBEAN) || regionContainer.getText(region).equals(JSP12Namespace.ElementName.GETPROPERTY) || regionContainer.getText(region).equals(JSP12Namespace.ElementName.SETPROPERTY))) { - - if (regionStartOffset > startOffset) - return regionStartOffset; - else - return startOffset; - } - else { - // Defect #241090, the Text Nodes inside of JSP scriptlets, expressions, and declarations are valid - // breakpoint-able locations - boolean isCodeNode = false; - IndexedRegion node = model.getIndexedRegion(regionStartOffset); - if (node != null && node instanceof Node) { - Node domNode = (Node) node; - Node root = domNode.getOwnerDocument().getDocumentElement(); - if (root != null && root.getNodeName().equals(JSP12Namespace.ElementName.ROOT) && domNode.getNodeType() == Node.TEXT_NODE && domNode.getParentNode() != null) { - String parentName = domNode.getParentNode().getNodeName(); - isCodeNode = parentName.equals(JSP12Namespace.ElementName.SCRIPTLET) || parentName.equals(JSP12Namespace.ElementName.EXPRESSION) || parentName.equals(JSP12Namespace.ElementName.DECLARATION); - } - } - if (isCodeNode) { - if (regionStartOffset > startOffset) - return regionStartOffset; - else - return startOffset; - } - } - } - } - } - return NO_VALID_CONTENT; - } - - private static boolean isCustomTagRegion(IndexedRegion node) { - - if (node instanceof Element) { - Element xmlElement = (Element) node; - ModelQuery mq = ModelQueryUtil.getModelQuery(xmlElement.getOwnerDocument()); - CMElementDeclaration decl = mq.getCMElementDeclaration(xmlElement); - if (decl instanceof CMNodeWrapper) { - CMNode cmNode = ((CMNodeWrapper) decl).getOriginNode(); - return cmNode instanceof TLDElementDeclaration; - } - } - return false; - } - - protected IResource getEditorInputResource(IEditorInput input) { - IResource resource = (IResource) input.getAdapter(IFile.class); - if (resource == null) { - resource = (IResource) input.getAdapter(IResource.class); - } - return resource; - } - - - /* - * Return the page language - */ - protected static int getPageLanguage(Document doc) { - if (doc == null) - return UNSUPPORTED; - - NodeList pageDirectives = doc.getElementsByTagName(JSP_DIRECTIVE_PAGE); - // Search for first language directive - for (int i = 0; i < pageDirectives.getLength(); i++) { - Node child = pageDirectives.item(i); - Node languageAttr = child.getAttributes().getNamedItem("language"); //$NON-NLS-1$ - if (languageAttr != null) { - String pageLanguage = languageAttr.getNodeValue(); - if (pageLanguage == null || pageLanguage.length() == 0) - return UNSUPPORTED; - pageLanguage = pageLanguage.toLowerCase(); - if (contains(JAVASCRIPT_LANGUAGE_KEYS, pageLanguage)) - return JAVASCRIPT; - else if (pageLanguage.equals("java"))//$NON-NLS-1$ - return JAVA; - else - return UNSUPPORTED; - } - } - return JAVA; // Java is default if no language directive - } - - protected static boolean contains(String[] haystack, String needle) { - for (int i = 0; i < haystack.length; i++) { - if (haystack[i].equals(needle)) { - return true; - } - } - return false; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavaBreakpointProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavaBreakpointProvider.java deleted file mode 100644 index 48140a2ca6..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavaBreakpointProvider.java +++ /dev/null @@ -1,118 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.breakpointproviders; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.debug.core.JDIDebugModel; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.wst.sse.ui.extensions.breakpoint.SourceEditingTextTools; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * A BreakpointProvider supporting server-side Java as a JSP language - */ -public class JavaBreakpointProvider extends AbstractBreakpointProvider { - - /* - * @param res - * @return String - */ - private static final String getTypeName(IResource res) { - IPath path = res.getFullPath(); - // Assume under Web Content folder if more than 2 segments - if (path.segmentCount() > 2) { - path = path.removeFirstSegments(2); - } - else { - path = path.removeFirstSegments(1); - } - String typeName = path.toString().replace(IPath.SEPARATOR, '.'); - if (res.getFileExtension() != null) { - typeName = typeName.substring(0, typeName.lastIndexOf('.')); - } - return typeName; - } - - - /* (non-Javadoc) - * @see com.ibm.sse.editor.extensions.BreakpointProvider#canAddBreakpoint(org.w3c.dom.Document, org.eclipse.jface.text.IDocument, org.eclipse.ui.IEditorInput, org.w3c.dom.Node, int, int) - */ - public boolean canAddBreakpoint(Document doc, IDocument idoc, IEditorInput input, Node node, int lineNumber, int offset) { - IResource res = input instanceof IFileEditorInput ? ((IFileEditorInput) input).getFile() : null; - - return res != null && !isBreakpointExist(res, lineNumber) && isValidPosition(doc, idoc, lineNumber) && (getPageLanguage(doc) == JAVA); - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.extensions.breakpoint.IBreakpointProvider#addBreakpoint(org.w3c.dom.Document, org.eclipse.jface.text.IDocument, org.eclipse.ui.IEditorInput, org.w3c.dom.Node, int, int) - */ - public IStatus addBreakpoint(Document doc, IDocument idoc, IEditorInput input, Node node, int lineNumber, int offset) throws CoreException { - int pos = getValidPosition(doc, idoc, lineNumber); - if (pos != NO_VALID_CONTENT) { - IResource res = getEditorInputResource(input); - if (res != null) { - String typeName = getTypeName(res); - try { - JDIDebugModel.createLineBreakpoint(res, typeName, lineNumber, pos, pos, 0, true, null); - } - catch(CoreException e) { - return e.getStatus(); - } - } - } - return new Status(IStatus.OK, JSPUIPlugin.ID, IStatus.OK, JSPUIPlugin.getResourceString("%OK"), null); //$NON-NLS-1$ - } - - /* - * @param res - * @param lineNumber - * @return boolean - */ - private boolean isBreakpointExist(IResource res, int lineNumber) { - try { - return JDIDebugModel.lineBreakpointExists(getTypeName(res), lineNumber) != null; - } - catch (CoreException e) { - return false; - } - } - - /* - * @param doc - * @param idoc - * @param lineNumber - * @return boolean - */ - private boolean isValidPosition(Document doc, IDocument idoc, int lineNumber) { - return getValidPosition(doc, idoc, lineNumber) != NO_VALID_CONTENT; - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.extensions.BreakpointProvider#setSourceEditingTextTools(com.ibm.sse.editor.extensions.SourceEditingTextTools) - */ - public void setSourceEditingTextTools(SourceEditingTextTools util) { - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.extensions.BreakpointProvider#getResource(org.eclipse.ui.IStorageEditorInput) - */ - public IResource getResource(IEditorInput input) { - return getEditorInputResource(input); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavaScriptBreakpointProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavaScriptBreakpointProvider.java deleted file mode 100644 index 3c2899e816..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavaScriptBreakpointProvider.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.breakpointproviders; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.IBreakpointManager; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ui.IEditorInput; -import org.eclipse.wst.sse.ui.extensions.breakpoint.SourceEditingTextTools; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * A IBreakpointProvider supporting server-side JavaScript as a JSP language - * - */ -public class JavaScriptBreakpointProvider extends AbstractBreakpointProvider { - public boolean canAddBreakpoint(Document doc, IDocument idoc, IEditorInput input, Node node, int lineNumber, int offset) { - IResource res = getEditorInputResource(input); - return res != null && !isBreakpointExist(res, lineNumber) && isValidPosition(doc, idoc, lineNumber) && (getPageLanguage(doc) != JAVA); - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.extensions.breakpoint.IBreakpointProvider#addBreakpoint(org.w3c.dom.Document, org.eclipse.jface.text.IDocument, org.eclipse.ui.IEditorInput, org.w3c.dom.Node, int, int) - */ - public IStatus addBreakpoint(Document doc, IDocument idoc, IEditorInput input, Node node, int lineNumber, int offset) { - int pos = getValidPosition(doc, idoc, lineNumber); - if (pos != NO_VALID_CONTENT && canAddBreakpoint(doc, idoc, input, node, lineNumber, offset)) { - IResource res = getEditorInputResource(input); - if (res != null) { -// try { - new JavascriptLineBreakpoint(res, lineNumber, pos, pos); -// } -// catch(CoreException e) { -// return new Status(IStatus.ERROR, JSPUIPlugin.ID, IStatus.ERROR, "Problem adding Java breakpoint", e); -// } - } - } - return new Status(IStatus.OK, JSPUIPlugin.ID, IStatus.OK, JSPUIPlugin.getResourceString("%OK"), null); //$NON-NLS-1$ - } - - /* - * @param res - * @param lineNumber - * @return boolean - */ - private boolean isBreakpointExist(IResource res, int lineNumber) { - IBreakpointManager manager = DebugPlugin.getDefault().getBreakpointManager(); - IBreakpoint[] breakpoints = manager.getBreakpoints(); - for (int i = 0; i < breakpoints.length; i++) { - if (!(breakpoints[i] instanceof JavascriptLineBreakpoint)) - continue; - JavascriptLineBreakpoint breakpoint = (JavascriptLineBreakpoint) breakpoints[i]; - try { - if (breakpoint.getResource().equals(res) && breakpoint.getLineNumber() == lineNumber) { - return true; - } - } - catch (CoreException e) { - return true; - } - } - return false; - } - - /* - * @param doc - * @param idoc - * @param lineNumber - * @return boolean - */ - private boolean isValidPosition(Document doc, IDocument idoc, int lineNumber) { - return getValidPosition(doc, idoc, lineNumber) != NO_VALID_CONTENT; - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.extensions.IBreakpointProvider#setSourceEditingTextTools(com.ibm.sse.editor.extensions.SourceEditingTextTools) - */ - public void setSourceEditingTextTools(SourceEditingTextTools util) { - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.extensions.IBreakpointProvider#getResource(org.eclipse.ui.IStorageEditorInput) - */ - public IResource getResource(IEditorInput input) { - return getEditorInputResource(input); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavaStratumBreakpointProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavaStratumBreakpointProvider.java deleted file mode 100644 index 7a3e9e69cd..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavaStratumBreakpointProvider.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.breakpointproviders; - -import java.util.HashMap; -import java.util.Map; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IExecutableExtension; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.jdt.debug.core.JDIDebugModel; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jst.jsp.core.internal.text.rules.StructuredTextPartitionerForJSP; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IStorageEditorInput; -import org.eclipse.wst.sse.ui.StructuredResourceMarkerAnnotationModel; -import org.eclipse.wst.sse.ui.extensions.breakpoint.IBreakpointProvider; -import org.eclipse.wst.sse.ui.extensions.breakpoint.SourceEditingTextTools; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * A IBreakpointProvider supporting JSP breakpoints for a Non-Java Language - * Source JSP page - */ -public class JavaStratumBreakpointProvider implements IBreakpointProvider, IExecutableExtension { - private String fClassPattern = null; //$NON-NLS-1$ - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.extensions.breakpoint.IBreakpointProvider#addBreakpoint(org.w3c.dom.Document, - * org.eclipse.jface.text.IDocument, org.eclipse.ui.IEditorInput, - * org.w3c.dom.Node, int, int) - */ - public IStatus addBreakpoint(Document doc, IDocument idoc, IEditorInput input, Node node, int editorLineNumber, int offset) throws CoreException { - // check if there is a valid position to set breakpoint - int pos = getValidPosition(idoc, editorLineNumber); - IStatus status = null; - if (pos >= 0) { - //SSE C3 behavior - // JDIDebugModel.createStratumBreakpoint(res, "JSP", - // getTypeName(res), null, "*_jsp", lineNumber, -1, -1, 0, true, - // null); //$NON-NLS-1$ //$NON-NLS-2$ - //Java Family Example 3.0 - // JDIDebugModel.createStratumBreakpoint(resource, null, - // resource.getName(), null, null, lineNumber, -1, -1, 0, true, - // null); - IResource res = getResourceFromInput(input); - if (res != null) { - IBreakpoint point = JDIDebugModel.createStratumBreakpoint(res, "JSP", res.getName(), null, getClassPattern(), editorLineNumber, pos, pos, 0, true, null); //$NON-NLS-1$ //$NON-NLS-2$ - if (point == null) { - status = new Status(IStatus.ERROR, JSPUIPlugin.ID, IStatus.ERROR, "unsupported input type", null); //$NON-NLS-1$ - } - } - else if (input instanceof IStorageEditorInput) { - // For non-resources, use the workspace root and a coordinated - // attribute that is used to - // prevent unwanted (breakpoint) markers from being loaded - // into the editors. - res = ResourcesPlugin.getWorkspace().getRoot(); - String id = input.getName(); - if (input instanceof IStorageEditorInput && ((IStorageEditorInput) input).getStorage() != null) { - id = ((IStorageEditorInput) input).getStorage().getFullPath().toString(); - } - Map attributes = new HashMap(); - attributes.put(StructuredResourceMarkerAnnotationModel.SECONDARY_ID_KEY, id); - IBreakpoint point = JDIDebugModel.createStratumBreakpoint(res, "JSP", input.getName(), null, getClassPattern(), editorLineNumber, pos, pos, 0, true, attributes); //$NON-NLS-1$ //$NON-NLS-2$ - if (point == null) { - status = new Status(IStatus.ERROR, JSPUIPlugin.ID, IStatus.ERROR, "unsupported input type", null); //$NON-NLS-1$ - } - } - } - if (status == null) { - status = new Status(IStatus.OK, JSPUIPlugin.ID, IStatus.OK, JSPUIPlugin.getResourceString("%OK"), null); //$NON-NLS-1$ - } - return status; - } - - private String getClassPattern() { - return fClassPattern; - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.extensions.breakpoint.IBreakpointProvider#getResource(org.eclipse.ui.IStorageEditorInput) - */ - public IResource getResource(IEditorInput input) { - return getResourceFromInput(input); - } - - private IResource getResourceFromInput(IEditorInput input) { - IResource resource = (IResource) input.getAdapter(IFile.class); - if (resource == null) { - resource = (IResource) input.getAdapter(IResource.class); - } - return resource; - } - - /** - * Finds a valid position somewhere on lineNumber in document, idoc, where - * a breakpoint can be set and returns that position. -1 is returned if a - * position could not be found. - * - * @param idoc - * @param editorLineNumber - * @return position to set breakpoint or -1 if no position could be found - */ - private int getValidPosition(IDocument idoc, int editorLineNumber) { - int result = -1; - if (idoc != null) { - - int startOffset = 0; - int endOffset = 0; - try { - IRegion line = idoc.getLineInformation(editorLineNumber - 1); - startOffset = line.getOffset(); - endOffset = Math.max(line.getOffset(), line.getOffset() + line.getLength()); - - String lineText = idoc.get(startOffset, endOffset - startOffset).trim(); - - // blank lines or lines with only an open or close brace or - // scriptlet tag cannot have a breakpoint - if (lineText.equals("") || lineText.equals("{") || //$NON-NLS-2$//$NON-NLS-1$ - lineText.equals("}") || lineText.equals("<%"))//$NON-NLS-2$//$NON-NLS-1$ - { - result = -1; - } - else { - // get all partitions for current line - ITypedRegion[] partitions = null; - - partitions = idoc.computePartitioning(startOffset, endOffset - startOffset); - - - for (int i = 0; i < partitions.length; ++i) { - String type = partitions[i].getType(); - // if found jsp java content, jsp directive tags, - // custom - // tags, - // return that position - if (type == StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA || type == StructuredTextPartitionerForJSP.ST_JSP_DIRECTIVE) { - result = partitions[i].getOffset(); - } - } - } - } - catch (BadLocationException e) { - result = -1; - } - } - - return result; - } - - /** - * @see org.eclipse.core.runtime.IExecutableExtension#setInitializationData(org.eclipse.core.runtime.IConfigurationElement, - * java.lang.String, java.lang.Object) - */ - public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { - if (data != null) { - if (data instanceof String && data.toString().length() > 0) { - fClassPattern = (String) data; - } - } - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.extensions.breakpoint.IBreakpointProvider#setSourceEditingTextTools(com.ibm.sse.editor.extensions.breakpoint.SourceEditingTextTools) - */ - public void setSourceEditingTextTools(SourceEditingTextTools util) { - // not used - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavascriptLineBreakpoint.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavascriptLineBreakpoint.java deleted file mode 100644 index c58efb31c9..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/breakpointproviders/JavascriptLineBreakpoint.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on Jul 20, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.jst.jsp.ui.breakpointproviders; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; - -/** - * @author davidw - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class JavascriptLineBreakpoint { - - /** - * @param res - * @param lineNumber - * @param pos - * @param pos1 - */ - public JavascriptLineBreakpoint(IResource res, int lineNumber, int pos, int pos1) { - - // TODO Auto-generated constructor stub - } - - /** - * - */ - public JavascriptLineBreakpoint() { - super(); - // TODO Auto-generated constructor stub - } - - /** - * - */ - public IResource getResource() throws CoreException { - // TODO Auto-generated method stub - return null; - } - - /** - * @return - */ - public int getLineNumber() { - // TODO Auto-generated method stub - return 0; - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/contentassist/BeanInfoProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/contentassist/BeanInfoProvider.java deleted file mode 100644 index 9ce6caa1c7..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/contentassist/BeanInfoProvider.java +++ /dev/null @@ -1,444 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.contentassist; - -import java.beans.Introspector; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.QualifiedName; -import org.eclipse.jdt.core.Flags; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.ITypeHierarchy; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jst.jsp.ui.internal.Logger; - -/** - * Navigates the IJavaProject classpath (incl. source) on a given resource and infers bean properties - * given a fully qualified beanname. Bean properties can be retrieved using: - * <code>getRuntimeProperties(IResource baseResource, String typeName)</code> - * - * @author pavery - */ -public class BeanInfoProvider implements IBeanInfoProvider { - - public class JavaPropertyDescriptor implements IJavaPropertyDescriptor { - String fType = null; - String fName = null; - boolean fReadable = true; - boolean fWritable = true; - - public JavaPropertyDescriptor(String name, String type, boolean readable, boolean writable) { - fName = name; - fType = type; - fReadable = readable; - fWritable = writable; - } - - public String getDeclaredType() { - return fType; - } - - public String getDisplayName() { - return fName; - } - - public String getName() { - return fName; - } - - public boolean getReadable() { - return fReadable; - } - - public boolean getWriteable() { - return fWritable; - } - } - - // looks up encoded type (see Class.getName), and gives you a displayable string - private HashMap fEncodedTypeMap = null; - // to avoid repeat properties from showing up - private HashSet fRepeatMethods = null; - - public BeanInfoProvider() { - fRepeatMethods = new HashSet(); - } - - /** - * Returns the inferred properties of a bean based on the project from the baseResource, - * and the fully qualified name of the bean. - * - * @param baseResource the base resource where the bean is being used - * @param typeName the <i>fully qualified</i> type name (eg. javax.swing.JButton) of the bean - */ - public IJavaPropertyDescriptor[] getRuntimeProperties(IResource baseResource, String typeName) { - IJavaProject javaProject = JavaCore.create(baseResource.getProject()); - QualifiedName typeQualifiedName = getTypeQualifiedName(typeName); - List getMethodResults = new ArrayList(); - List isMethodResults = new ArrayList(); - List setMethodResults = new ArrayList(); - List descriptorResults = new ArrayList(); - try { - IType type = javaProject.findType(typeQualifiedName.getQualifier() + "." + typeQualifiedName.getLocalName()); //$NON-NLS-1$ - // type must exist - if(type != null) { - ITypeHierarchy hierarchy = type.newTypeHierarchy(null); - IType[] supers = hierarchy.getAllSuperclasses(type); - - IMethod[] methods = type.getMethods(); - // iterate the bean's methods - for (int i = 0; i < methods.length; i++) - acceptMethod(getMethodResults, isMethodResults, setMethodResults, methods[i]); - // the bean hierarchy's methods - for (int i = 0; i < supers.length; i++) { - methods = supers[i].getMethods(); - for (int j = 0; j < methods.length; j++) - acceptMethod(getMethodResults, isMethodResults, setMethodResults, methods[j]); - } - adaptMethodsToPropertyDescriptors(getMethodResults, isMethodResults, setMethodResults, descriptorResults); - } - } - catch (JavaModelException jmex) { - Logger.logException("Problem navigating JavaProject in BeanInfoProvider", jmex); //$NON-NLS-1$ - } - - IJavaPropertyDescriptor[] finalResults = new IJavaPropertyDescriptor[descriptorResults.size()]; - System.arraycopy(descriptorResults.toArray(), 0, finalResults, 0, descriptorResults.size()); - return finalResults; - } - - /** - * Retrieves the necessary information from method declaration lists, creates and fills a list of JavaPropertyDescriptors. - * @param getMethods - * @param isMethods - * @param setMethods - * @param descriptorResults - */ - private void adaptMethodsToPropertyDescriptors(List getMethods, List isMethods, List setMethods, List descriptors) throws JavaModelException { - List readable = new ArrayList(); - HashMap types = new HashMap(); - - // iterate through get* and is* methods, updating 'readable' list and 'types' map - filterGetMethods(getMethods, readable, types); - filterIsMethods(isMethods, readable, types); - - // iterate set* methods, checking overlap w/ readable - Iterator it = setMethods.iterator(); - IMethod temp = null; - String name = ""; //$NON-NLS-1$ - String type = ""; //$NON-NLS-1$ - String[] encodedParams = null; - String returnType = ""; //$NON-NLS-1$ - String param0 = ""; //$NON-NLS-1$ - - while (it.hasNext()) { - temp = (IMethod) it.next(); - name = createPropertyNameFromMethod(temp); - // invalid naming convention - if (name == null) - continue; - - returnType = getDecodedTypeName(temp.getReturnType()); - // setter should have no return type - if (!returnType.equals("void")) //$NON-NLS-1$ - continue; - - // need to get type from parameter - encodedParams = temp.getParameterTypes(); - if (encodedParams != null && encodedParams.length > 0) { - if (encodedParams.length > 1) { - // multiple params - param0 = getDecodedTypeName(encodedParams[0]); - if (!param0.equals("int")) //$NON-NLS-1$ - // not a valid indexed property - continue; - else - type = getDecodedTypeName(encodedParams[1]); - } - else { - // one param, regular setter - if (isArray(encodedParams[0])) - type = getDecodedTypeName(encodedParams[0]); - } - } - - if (readable.contains(name)) { - // writable and readable - if (!fRepeatMethods.contains(name)) { - descriptors.add(new JavaPropertyDescriptor(name, (String) types.get(name), true, true)); - readable.remove(name); - fRepeatMethods.add(name); - } - } - else { - // wasn't readable, just writable - String[] params = temp.getParameterTypes(); - // can't be setProperty if no parameters - if (!(params.length > 0)) - continue; - if (!fRepeatMethods.contains(name)) { - type = getDecodedTypeName(params[0]); - descriptors.add(new JavaPropertyDescriptor(name, type, false, true)); - fRepeatMethods.add(name); - } - } - } - // add leftover from readable, get* and is* methods (readable = true, writable = false) - it = readable.iterator(); - while (it.hasNext()) { - name = (String) it.next(); - if (!fRepeatMethods.contains(name)) { - descriptors.add(new JavaPropertyDescriptor(name, (String) types.get(name), true, false)); - fRepeatMethods.add(name); - } - } - } - - private void filterGetMethods(List getMethods, List readable, HashMap types) throws JavaModelException { - IMethod temp; - String name; - String encodedReturnType; - String returnType; - Iterator it = getMethods.iterator(); - String[] encodedParams; - String paramType; - // iterate get* methods - while (it.hasNext()) { - temp = (IMethod) it.next(); - name = createPropertyNameFromMethod(temp); - // invalid bean naming convention - if (name == null) - continue; - - encodedReturnType = temp.getReturnType(); - returnType = getDecodedTypeName(encodedReturnType); - - // can't get be a getProperty if returns void - if (returnType.equals("void")) //$NON-NLS-1$ - continue; - - // check params in case it's indexed propety - encodedParams = temp.getParameterTypes(); - if (encodedParams != null && encodedParams.length == 1) { - paramType = getDecodedTypeName(encodedParams[0]); - // syntax is > Type getter(int); - if (!paramType.equals("int")) { //$NON-NLS-1$ - //it's not an indexed property - continue; - } - else { - // it is indexed, prop type is an ARRAY - returnType += "[]"; //$NON-NLS-1$ - } - } - - readable.add(name); - types.put(name, returnType); - } - - } - - private void filterIsMethods(List isMethodResults, List readable, HashMap types) throws JavaModelException { - IMethod temp; - String name; - String encodedReturnType; - String returnType; - String[] encodedParams; - String paramType; - // iterate is* methods - Iterator it = isMethodResults.iterator(); - while (it.hasNext()) { - temp = (IMethod) it.next(); - name = createPropertyNameFromMethod(temp); - // invalid bean naming convention - if (name == null) - continue; - encodedReturnType = temp.getReturnType(); - returnType = getDecodedTypeName(encodedReturnType); - - // isProperty only valid for boolean - if (!returnType.equals("boolean")) //$NON-NLS-1$ - continue; - - // check params in case it's indexed propety - encodedParams = temp.getParameterTypes(); - if (encodedParams != null && encodedParams.length == 1) { - paramType = getDecodedTypeName(encodedParams[0]); - // syntax is > Type getter(int); - if (!paramType.equals("int")) { //$NON-NLS-1$ - //it's not a valid indexed property - continue; - } - } - - readable.add(name); - types.put(name, returnType); - } - } - - /** - * Pass in a get*|set*|is* method and it will return an inferred property name using <code>Introspector.decapitalize(String)</code> - * @param temp - * @return an inferred property name based on the IMethod name, null if the name is not valid according to bean spec - */ - private String createPropertyNameFromMethod(IMethod temp) { - String name = temp.getElementName(); - if (name.startsWith("is")) //$NON-NLS-1$ - name = Introspector.decapitalize(name.substring(2)); - else - // must be get or set - name = Introspector.decapitalize(name.substring(3)); - return name; - } - - /** - * Initial filtering of methods. Checks prefix if it's valid length. If the prefix is "get" the method name - * is placed in the getMethodResults List. If the prefix is "is", the name is added to the isMethodResults list. If the - * prefix is "set", it's added to the setMethodResultsList. - * - * @param getMethodResults - * @param isMethodResults - * @param setMethodResults - * @param method - */ - private void acceptMethod(List getMethodResults, List isMethodResults, List setMethodResults, IMethod method) throws JavaModelException { - if (!fRepeatMethods.contains(method.getElementName())) { - fRepeatMethods.add(method.getElementName()); - int flags = method.getFlags(); - String methodName = method.getElementName(); - if (Flags.isPublic(flags)) { - if (methodName.length() > 3 && methodName.startsWith("get")) //$NON-NLS-1$ - getMethodResults.add(method); - else if (methodName.length() > 2 && methodName.startsWith("is")) //$NON-NLS-1$ - isMethodResults.add(method); - else if (methodName.length() > 3 && methodName.startsWith("set")) //$NON-NLS-1$ - setMethodResults.add(method); - } - } - } - - /** - * @param typeName - * @return a Qualified name with the package as the qualifier, and class name as LocalName - */ - private QualifiedName getTypeQualifiedName(String typeName) { - StringTokenizer st = new StringTokenizer(typeName, ".", false); //$NON-NLS-1$ - int length = st.countTokens(); - int count = 0; - StringBuffer root = new StringBuffer(); - while (count++ < length - 1) { - root.append(st.nextToken()); - if (count < length - 1) - root.append('.'); - } - return new QualifiedName(root.toString(), st.nextToken()); - } - - /** - * Checks if encodedTypeName is an array - * @param encodedTypeName - * @return true if encodedTypeName is an array, false otherwise. - */ - private boolean isArray(String encodedTypeName) { - if (encodedTypeName != null && encodedTypeName.length() > 0) { - if (encodedTypeName.charAt(0) == '[') - return true; - } - return false; - } - - /** - * Returns the decoded (displayable) name fo the type. - * Either a primitive type (int, long, float...) Object (String) - * @param type - * @return decoded name for the encoded string - */ - private String getDecodedTypeName(String encoded) { - HashMap map = getEncodedTypeMap(); - - StringBuffer decoded = new StringBuffer(); - char BRACKET = '['; - String BRACKETS = "[]"; //$NON-NLS-1$ - char identifier = ' '; - int last = 0; - // count brackets - while (encoded.indexOf(BRACKET, last) != -1) { - last++; - } - identifier = encoded.charAt(last); - Object primitiveType = map.get(String.valueOf(identifier)); - // L > binary type name, Q > source type name - if (identifier == 'L' || identifier == 'Q') { - // handle object - String classname = encoded.substring(last + 1, encoded.length() - 1); - decoded.append(classname); - } - else if (primitiveType != null) { - // handle primitive type (from IField.getSignature()) - decoded.append((String) primitiveType); - } - else { - // handle primitive type (from Class.getName()) - decoded.append(encoded); - } - // handle arrays - if (last > 0) { - for (int i = 0; i < last; i++) { - decoded.append(BRACKETS); - } - } - return decoded.toString(); - } - - /** - * from Class.getName() javadoc - * also see Signature in jdt.core api - *<pre> - * B byte - * C char - * D double - * F float - * I int - * J long - * Lclassname; class or interface - * Qsourcename; source - * S short - * Z boolean - * V void - *</pre> - * - * @return the "encoding letter" to "type" map. - */ - private HashMap getEncodedTypeMap() { - if (fEncodedTypeMap == null) { - fEncodedTypeMap = new HashMap(); - fEncodedTypeMap.put("B", "byte"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("C", "char"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("D", "double"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("F", "float"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("I", "int"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("J", "long"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("S", "short"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("Z", "boolean"); //$NON-NLS-1$ //$NON-NLS-2$ - fEncodedTypeMap.put("V", "void"); //$NON-NLS-1$ //$NON-NLS-2$ - } - return fEncodedTypeMap; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/contentassist/IBeanInfoProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/contentassist/IBeanInfoProvider.java deleted file mode 100644 index 17d73d0663..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/contentassist/IBeanInfoProvider.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.contentassist; - -import org.eclipse.core.resources.IResource; - -public interface IBeanInfoProvider { - IJavaPropertyDescriptor[] getRuntimeProperties(IResource baseResource, String typeName); -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/contentassist/IJavaPropertyDescriptor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/contentassist/IJavaPropertyDescriptor.java deleted file mode 100644 index 0339443a10..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/contentassist/IJavaPropertyDescriptor.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.contentassist; - -public interface IJavaPropertyDescriptor { - - String getDeclaredType(); - - String getDisplayName(); - - String getName(); - - boolean getReadable(); - - boolean getWriteable(); -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/extensions/JSPSourceEditingTextTools.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/extensions/JSPSourceEditingTextTools.java deleted file mode 100644 index 6a802b3016..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/extensions/JSPSourceEditingTextTools.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.extensions; - - - -import org.eclipse.jst.jsp.core.JSP11Namespace; -import org.eclipse.jst.jsp.core.JSP12Namespace; -import org.eclipse.jst.jsp.core.PageDirectiveAdapter; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.ui.extensions.XMLSourceEditingTextTools; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * Implements SourceEditingTextTools interface - */ -public class JSPSourceEditingTextTools extends XMLSourceEditingTextTools { - - public String getPageLanguage(Node node) { - String language = null; - Document doc = null; - if (node.getNodeType() == Node.DOCUMENT_NODE) { - doc = (Document) node; - } - else { - doc = node.getOwnerDocument(); - } - if (doc != null) { - if (doc instanceof XMLDocument) { - PageDirectiveAdapter adapter = (PageDirectiveAdapter) ((XMLDocument) doc).getAdapterFor(PageDirectiveAdapter.class); - if (adapter != null) - language = adapter.getLanguage(); - } - else { - // iterate through all of the page directives - NodeList pageDirectives = doc.getElementsByTagName(JSP12Namespace.ElementName.DIRECTIVE_PAGE); - for (int i = 0; i < pageDirectives.getLength(); i++) { - Element pageDirective = (Element) pageDirectives.item(i); - String langValue = pageDirective.getAttribute(JSP11Namespace.ATTR_NAME_LANGUAGE); - // last one to declare a language wins - if (langValue != null) - language = langValue; - } - } - } - // if no language was specified anywhere, assume Java - if (language == null) - language = JSP11Namespace.ATTR_VALUE_JAVA; - return language; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/format/FormattingStrategyJSPJava.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/format/FormattingStrategyJSPJava.java deleted file mode 100644 index ece8c79bcd..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/format/FormattingStrategyJSPJava.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.format; - -import java.util.LinkedList; -import java.util.Map; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.core.ToolFactory; -import org.eclipse.jdt.core.formatter.CodeFormatter; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.TypedPosition; -import org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy; -import org.eclipse.jface.text.formatter.FormattingContextProperties; -import org.eclipse.jface.text.formatter.IFormattingContext; -import org.eclipse.jst.jsp.core.internal.Logger; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationUtil; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.TextEdit; - - -public class FormattingStrategyJSPJava extends ContextBasedFormattingStrategy { - - /** Documents to be formatted by this strategy */ - private final LinkedList fDocuments = new LinkedList(); - /** Partitions to be formatted by this strategy */ - private final LinkedList fPartitions = new LinkedList(); - JSPTranslation translation = null; - - /** - * Creates a new java formatting strategy. - */ - public FormattingStrategyJSPJava() { - super(); - } - - /* - * @see org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy#format() - */ - public void format() { - super.format(); - - final IDocument document = (IDocument) fDocuments.removeFirst(); - final TypedPosition partition = (TypedPosition) fPartitions.removeFirst(); - - if (document != null && partition != null) { - try { - - JSPTranslationUtil translationUtil = new JSPTranslationUtil(document); - ICompilationUnit cu = translationUtil.getCompilationUnit(); - if (cu != null) { - String cuSource = cu.getSource(); - TextEdit textEdit = formatString(CodeFormatter.K_COMPILATION_UNIT, cuSource, 0, TextUtilities.getDefaultLineDelimiter(document), getPreferences()); - - TextEdit jspEdit = translationUtil.getTranslation().getJspEdit(textEdit); - if (jspEdit != null && jspEdit.hasChildren()) - jspEdit.apply(document); - } - - } - catch (MalformedTreeException exception) { - Logger.logException(exception); - } - catch (BadLocationException exception) { - // Can only happen on concurrent document modification - log - // and bail out - Logger.logException(exception); - } - catch (JavaModelException exception) { - Logger.logException(exception); - } - } - } - - /* - * @see org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy#formatterStarts(org.eclipse.jface.text.formatter.IFormattingContext) - */ - public void formatterStarts(final IFormattingContext context) { - super.formatterStarts(context); - - fPartitions.addLast(context.getProperty(FormattingContextProperties.CONTEXT_PARTITION)); - fDocuments.addLast(context.getProperty(FormattingContextProperties.CONTEXT_MEDIUM)); - } - - /* - * @see org.eclipse.jface.text.formatter.ContextBasedFormattingStrategy#formatterStops() - */ - public void formatterStops() { - super.formatterStops(); - - fPartitions.clear(); - fDocuments.clear(); - } - - public TextEdit formatString(int kind, String string, int indentationLevel, String lineSeparator, Map options) { - return ToolFactory.createCodeFormatter(options).format(kind, string, 0, string.length(), indentationLevel, lineSeparator); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/IActionConstantsJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/IActionConstantsJSP.java deleted file mode 100644 index a400780e48..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/IActionConstantsJSP.java +++ /dev/null @@ -1,19 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal; - -/** - * @author pavery - */ -public interface IActionConstantsJSP { - public final static String ACTION_NAME_RENAME_ELEMENT = "RenameElement"; //$NON-NLS-1$ - public final static String ACTION_NAME_MOVE_ELEMENT = "MoveElement"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/IActionDefinitionIdsJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/IActionDefinitionIdsJSP.java deleted file mode 100644 index f90607e7b2..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/IActionDefinitionIdsJSP.java +++ /dev/null @@ -1,21 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal; - -import org.eclipse.jdt.ui.actions.IJavaEditorActionDefinitionIds; - -/** - * @author pavery - */ -public interface IActionDefinitionIdsJSP { - public final static String RENAME_ELEMENT = IJavaEditorActionDefinitionIds.RENAME_ELEMENT; - public final static String MOVE_ELEMENT = IJavaEditorActionDefinitionIds.MOVE_ELEMENT; -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPlugin.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPlugin.java deleted file mode 100644 index beec9cee43..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPlugin.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal; - -import java.io.IOException; -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.templates.ContextTypeRegistry; -import org.eclipse.jface.text.templates.persistence.TemplateStore; -import org.eclipse.jst.jsp.ui.templates.TemplateContextTypeJSP; -import org.eclipse.jst.jsp.ui.templates.TemplateContextTypeJSPAttribute; -import org.eclipse.jst.jsp.ui.templates.TemplateContextTypeJSPAttributeValue; -import org.eclipse.jst.jsp.ui.templates.TemplateContextTypeJSPTag; -import org.eclipse.ui.editors.text.templates.ContributionContextTypeRegistry; -import org.eclipse.ui.editors.text.templates.ContributionTemplateStore; -import org.eclipse.ui.plugin.AbstractUIPlugin; -import org.eclipse.wst.sse.ui.preferences.CommonEditorPreferenceNames; -import org.eclipse.wst.sse.ui.registry.AdapterFactoryRegistry; -import org.eclipse.wst.sse.ui.registry.AdapterFactoryRegistryImpl; -import org.eclipse.wst.sse.ui.registry.embedded.EmbeddedAdapterFactoryRegistryImpl; - -/** - * The main plugin class to be used in the desktop. - */ -public class JSPUIPlugin extends AbstractUIPlugin { - public final static String ID = "org.eclipse.jst.jsp.ui"; //$NON-NLS-1$ - - protected static JSPUIPlugin instance = null; - //Resource bundle. - private ResourceBundle resourceBundle; - private static final String KEY_PREFIX = "%"; //$NON-NLS-1$ - private static final String KEY_DOUBLE_PREFIX = "%%"; //$NON-NLS-1$ - - /** - * The template store for the jsp editor. - */ - private TemplateStore fTemplateStore; - - /** - * The template context type registry for the jsp editor. - */ - private ContextTypeRegistry fContextTypeRegistry; - - public JSPUIPlugin() { - super(); - instance = this; - } - - public static JSPUIPlugin getDefault() { - return instance; - } - - public synchronized static JSPUIPlugin getInstance() { - return instance; - } - - public AdapterFactoryRegistry getAdapterFactoryRegistry() { - return AdapterFactoryRegistryImpl.getInstance(); - - } - - public AdapterFactoryRegistry getEmbeddedAdapterFactoryRegistry() { - return EmbeddedAdapterFactoryRegistryImpl.getInstance(); - - } - - /** - * @deprecated using JSPUIPreferenceInitializer instead - */ - protected void initializeDefaultJSPPreferences(IPreferenceStore store) { -// -// String ctId = IContentTypeIdentifier.ContentTypeID_JSP; -// // setting the same as HTML -// store.setDefault(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.CONTENT_ASSIST_SUPPORTED, ctId), true); -// store.setDefault(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.AUTO_PROPOSE, ctId), true); -// store.setDefault(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.AUTO_PROPOSE_CODE, ctId), CommonEditorPreferenceNames.LT); -// -// store.setDefault(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.EDITOR_VALIDATION_METHOD, ctId), CommonEditorPreferenceNames.EDITOR_VALIDATION_WORKBENCH_DEFAULT); //$NON-NLS-1$ -// store.setDefault(PreferenceKeyGenerator.generateKey(CommonEditorPreferenceNames.EDITOR_USE_INFERRED_GRAMMAR, ctId), true); -// -// // JSP Style Preferences -// String NOBACKGROUNDBOLD = " | null | false"; //$NON-NLS-1$ -// String styleValue = ColorHelper.getColorString(127, 0, 127) + NOBACKGROUNDBOLD; -// store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.TAG_ATTRIBUTE_NAME, ctId), styleValue); -// -// styleValue = ColorHelper.getColorString(42, 0, 255) + NOBACKGROUNDBOLD; -// store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, ctId), styleValue); -// -// styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ -// store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS, ctId), styleValue); // specified value is black; leaving as widget default -// -// styleValue = ColorHelper.getColorString(63, 95, 191) + NOBACKGROUNDBOLD; -// store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.COMMENT_BORDER, ctId), styleValue); -// store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.COMMENT_TEXT, ctId), styleValue); -// -// styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; -// store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.TAG_BORDER, ctId), styleValue); -// -// styleValue = ColorHelper.getColorString(63, 127, 127) + NOBACKGROUNDBOLD; -// store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsXML.TAG_NAME, ctId), styleValue); -// -// styleValue = ColorHelper.getColorString(191, 95, 63) + NOBACKGROUNDBOLD; -// store.setDefault(PreferenceKeyGenerator.generateKey(IStyleConstantsHTML.SCRIPT_AREA_BORDER, ctId), styleValue); - } - - /** - * Returns the template store for the jsp editor templates. - * - * @return the template store for the jsp editor templates - */ - public TemplateStore getTemplateStore() { - if (fTemplateStore == null) { - fTemplateStore= new ContributionTemplateStore(getTemplateContextRegistry(), getPreferenceStore(), CommonEditorPreferenceNames.TEMPLATES_KEY); - - try { - fTemplateStore.load(); - } catch (IOException e) { - Logger.logException(e); - } - } - return fTemplateStore; - } - - /** - * Returns the template context type registry for the jsp plugin. - * - * @return the template context type registry for the jsp plugin - */ - public ContextTypeRegistry getTemplateContextRegistry() { - if (fContextTypeRegistry == null) { - fContextTypeRegistry= new ContributionContextTypeRegistry(); - - fContextTypeRegistry.addContextType(new TemplateContextTypeJSP()); - fContextTypeRegistry.addContextType(new TemplateContextTypeJSPTag()); - fContextTypeRegistry.addContextType(new TemplateContextTypeJSPAttribute()); - fContextTypeRegistry.addContextType(new TemplateContextTypeJSPAttributeValue()); - } - - return fContextTypeRegistry; - } - - /** - * Returns the string from the plugin's resource bundle, - * or 'key' if not found. - */ - public static String getResourceString(String value) { - String s = value.trim(); - if (!s.startsWith(KEY_PREFIX, 0)) - return s; - if (s.startsWith(KEY_DOUBLE_PREFIX, 0)) - return s.substring(1); - - int ix = s.indexOf(' '); - String key = ix == -1 ? s : s.substring(0, ix); - - ResourceBundle bundle = getDefault().getResourceBundle(); - try { - return (bundle != null) ? bundle.getString(key.substring(1)) : key; - } catch (MissingResourceException e) { - return key; - } - } - - public static String getResourceString(String key, Object[] args) { - - try { - return MessageFormat.format(getResourceString(key), args); - } catch (IllegalArgumentException e) { - return getResourceString(key); - } - - } - - /** - * Returns the plugin's resource bundle, - */ - public ResourceBundle getResourceBundle() { - try { - if (resourceBundle == null) - resourceBundle = ResourceBundle.getBundle("org.eclipse.jst.jsp.ui.internal.JSPUIPluginResources"); - } catch (MissingResourceException x) { - resourceBundle = null; - } - return resourceBundle; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties deleted file mode 100644 index 3b54f9cc1f..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/JSPUIPluginResources.properties +++ /dev/null @@ -1,40 +0,0 @@ -############################################################################### -# Copyright (c) 2004 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are 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: -# IBM Corporation - initial API and implementation -############################################################################### -## The following line is a sample JSP document. Please translate only the following parts: -## Use below tags ONLY for JSP 1.1 -## Welcome! -## Use below tags ONLY for JSP 1.2 -## Welcome! -Sample_JSP_doc=<%@ page \n\tlanguage=\"java\" \n\tcontentType=\"text/html; charset=ISO-8859-1\"\n%>\n<jsp:include flush=\"true\" page=\"titleBar.jsp\"/>\n\n<%-- Use below tags ONLY for JSP 1.1 --%>\n<%\n\tSystem.out.println(\"Welcome!\");\n%>\n<%-- Use below tags ONLY for JSP 1.2 --%>\n<jsp:scriptlet>\n\tSystem.out.println(\"Welcome!\");\n</jsp:scriptlet> -JSP_Delimiters_UI_=JSP Delimiters -Refactor.label=R&efactor -RenameElement.label=Re&name -MoveElement.label=Mo&ve -# -OK=OK -JSP_changes=JSP changes -ActionContributorJSP.0=Refa&ctor -JSPRenameElementAction.0=Editor selection does not resolve to a renamable Java element -JSPMoveElementAction.0=Editor selection does not resolve to movable Java elements -BasicRefactorSearchRequestor.0=JSP Rename -BasicRefactorSearchRequestor.1=in file: {0} line: {1} -BasicRefactorSearchRequestor.2=Move Type ''{0}'' to package ''{1}'' -BasicRefactorSearchRequestor.3=Rename Method ''{0}'' to ''{1}'' -BasicRefactorSearchRequestor.4=Rename Type ''{0}'' to ''{1}'' -BasicRefactorSearchRequestor.5=Rename Package ''{0}'' to ''{1}'' -JSPSearchUIConfiguration.0=JSP Search - 1 Match -JSPSearchUIConfiguration.1=JSP Search - {0} Matches -JSPJavaOpenOnJSP.0=Open -JSPJavaOpenOnJSP.1=Select or enter the element to open: -TemplateContextTypeJSPAttribute.0=JSP Attributes -TemplateContextTypeJSPAttributeValue.0=JSP Attribute Values -TemplateContextTypeJSP.0=All JSP -TemplateContextTypeJSPTag.0=JSP Tags diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/Logger.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/Logger.java deleted file mode 100644 index a4373ab077..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/Logger.java +++ /dev/null @@ -1,144 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal; - -import java.util.StringTokenizer; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.Status; -import org.osgi.framework.Bundle; - -/** - * Small convenience class to log messages to plugin's log file and also, if desired, - * the console. This class should only be used by classes in this plugin. Other - * plugins should make their own copy, with appropriate ID. - */ -public class Logger { - private static final String PLUGIN_ID = "org.eclipse.jst.jsp.ui"; //$NON-NLS-1$ - - private static final String TRACEFILTER_LOCATION = "/debug/tracefilter"; //$NON-NLS-1$ - - public static final int OK = IStatus.OK; // 0 - public static final int INFO = IStatus.INFO; // 1 - public static final int WARNING = IStatus.WARNING; // 2 - public static final int ERROR = IStatus.ERROR; // 4 - - public static final int OK_DEBUG = 200 + OK; - public static final int INFO_DEBUG = 200 + INFO; - public static final int WARNING_DEBUG = 200 + WARNING; - public static final int ERROR_DEBUG = 200 + ERROR; - - /** - * Adds message to log. - * @param level severity level of the message (OK, INFO, WARNING, ERROR, OK_DEBUG, INFO_DEBUG, WARNING_DEBUG, ERROR_DEBUG) - * @param message text to add to the log - * @param exception exception thrown - */ - protected static void _log(int level, String message, Throwable exception) { - if (level == OK_DEBUG || level == INFO_DEBUG || level == WARNING_DEBUG || level == ERROR_DEBUG) { - if (!isDebugging()) - return; - } - - int severity = IStatus.OK; - switch (level) { - case INFO_DEBUG : - case INFO : - severity = IStatus.INFO; - break; - case WARNING_DEBUG : - case WARNING : - severity = IStatus.WARNING; - break; - case ERROR_DEBUG : - case ERROR : - severity = IStatus.ERROR; - } - message = (message != null) ? message : "null"; //$NON-NLS-1$ - Status statusObj = new Status(severity, PLUGIN_ID, severity, message, exception); - Bundle bundle = Platform.getBundle(PLUGIN_ID); - if (bundle != null) - Platform.getLog(bundle).log(statusObj); - } - - /** - * Prints message to log if category matches /debug/tracefilter option. - * @param message text to print - * @param category category of the message, to be compared with /debug/tracefilter - */ - protected static void _trace(String category, String message, Throwable exception) { - if (isTracing(category)) { - message = (message != null) ? message : "null"; //$NON-NLS-1$ - Status statusObj = new Status(IStatus.OK, PLUGIN_ID, IStatus.OK, message, exception); - Bundle bundle = Platform.getBundle(PLUGIN_ID); - if (bundle != null) - Platform.getLog(bundle).log(statusObj); - } - } - - /** - * @return true if the platform is debugging - */ - public static boolean isDebugging() { - return Platform.inDebugMode(); - } - - /** - * Determines if currently tracing a category - * @param category - * @return true if tracing category, false otherwise - */ - public static boolean isTracing(String category) { - if (!isDebugging()) - return false; - - String traceFilter = Platform.getDebugOption(PLUGIN_ID + TRACEFILTER_LOCATION); - if (traceFilter != null) { - StringTokenizer tokenizer = new StringTokenizer(traceFilter, ","); //$NON-NLS-1$ - while (tokenizer.hasMoreTokens()) { - String cat = tokenizer.nextToken().trim(); - if (category.equals(cat)) { - return true; - } - } - } - return false; - } - - public static void log(int level, String message) { - _log(level, message, null); - } - - public static void log(int level, String message, Throwable exception) { - _log(level, message, exception); - } - - public static void logException(String message, Throwable exception) { - _log(ERROR, message, exception); - } - - public static void logException(Throwable exception) { - _log(ERROR, exception.getMessage(), exception); - } - - public static void traceException(String category, String message, Throwable exception) { - _trace(category, message, exception); - } - - public static void traceException(String category, Throwable exception) { - _trace(category, exception.getMessage(), exception); - } - - public static void trace(String category, String message) { - _trace(category, message, null); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/autoedit/StructuredAutoEditStrategyJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/autoedit/StructuredAutoEditStrategyJSP.java deleted file mode 100644 index 85b3b3fb46..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/autoedit/StructuredAutoEditStrategyJSP.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.autoedit; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentCommand; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.ui.StructuredDocumentCommand; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.ui.internal.autoedit.StructuredAutoEditStrategyXML; - -public class StructuredAutoEditStrategyJSP extends StructuredAutoEditStrategyXML { - public void customizeDocumentCommand(IDocument document, DocumentCommand command) { - StructuredDocumentCommand structuredDocumentCommand = (StructuredDocumentCommand) command; - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(document); - - if (model != null) { - if (structuredDocumentCommand.text != null) { - if (structuredDocumentCommand.text.equals("%")) { //$NON-NLS-1$ - XMLNode node = (XMLNode) model.getIndexedRegion(structuredDocumentCommand.offset); - try { - if (prefixedWith(document, structuredDocumentCommand.offset, "<") && !node.getSource().endsWith("%>")) { //$NON-NLS-1$ //$NON-NLS-2$ - structuredDocumentCommand.doit = false; - structuredDocumentCommand.addCommand(structuredDocumentCommand.offset, 0, " %>", null); //$NON-NLS-1$ - } - } - catch (BadLocationException e) { - Logger.logException(e); - } - - } - else - super.customizeDocumentCommand(document, structuredDocumentCommand); - } - } - } - finally { - if (model != null) - model.releaseFromRead(); - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProcessor.java deleted file mode 100644 index 79c410b286..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionProcessor.java +++ /dev/null @@ -1,306 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import java.util.HashMap; -import java.util.Iterator; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.ui.IReleasable; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.contentassist.IResourceDependentProcessor; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; - -/** - * @author pavery - */ -public class JSPCompletionProcessor implements IContentAssistProcessor, IReleasable, IResourceDependentProcessor { - // for debugging - private static final boolean DEBUG; - static { - String value= Platform.getDebugOption("org.eclipse.jst.jsp.core/debug/jsptranslation"); //$NON-NLS-1$ - DEBUG= value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - - private static final String JDT_CORE_PLUGIN_ID = "org.eclipse.jdt.core"; //$NON-NLS-1$ - - protected int fJspSourcePosition, fJavaPosition; - protected IResource fResource; - protected JSPCompletionRequestor fCollector; - protected String fErrorMessage = null; - protected StructuredTextViewer fViewer = null; - private JSPTranslationAdapter fTranslationAdapter = null; - - public JSPCompletionProcessor(IResource resource) { - fResource = resource; - } - - /** - * Returns a list of completion proposals based on the - * specified location within the document that corresponds - * to the current cursor position within the text viewer. - * - * @param viewer the viewer whose document is used to compute the proposals - * @param documentPosition an offset within the document for which completions should be computed - * @return an array of completion proposals or <code>null</code> if no proposals are possible - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int pos) { - initialize(pos); - try { - if (viewer instanceof StructuredTextViewer) - fViewer = (StructuredTextViewer) viewer; - - XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(fViewer.getDocument()); - XMLDocument xmlDoc = xmlModel.getDocument(); - xmlModel.releaseFromRead(); - if (fTranslationAdapter == null) - fTranslationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (fTranslationAdapter != null) { - - JSPTranslation translation = fTranslationAdapter.getJSPTranslation(); - fJavaPosition = translation.getJavaOffset(getDocumentPosition()); - - fCollector.setCodeAssistOffset(fJavaPosition); - fCollector.setJavaToJSPOffset(fJspSourcePosition - fJavaPosition); - fCollector.setCursorInExpression(cursorInExpression()); - - - if (DEBUG) - System.out.println(debug(translation)); - - try { - - ICompilationUnit cu = translation.getCompilationUnit(); - fCollector.setCompilationUnit(cu); - - // can't get java proposals w/out a compilation unit - if (cu == null) - return new ICompletionProposal[0]; - - synchronized (cu) { - cu.codeComplete(fJavaPosition, fCollector, null); - } - } - catch (CoreException coreEx) { - // a possible Java Model Exception due to not being a Web (Java) Project - coreEx.printStackTrace(); - } - } - } - catch (Exception exc) { - exc.printStackTrace(); - // throw out exceptions on code assist. - } - - ICompletionProposal[] results = fCollector.getResults(); - if (results == null || results.length < 1) - fErrorMessage = SSEUIPlugin.getResourceString("%Java_Content_Assist_is_not_UI_"); //$NON-NLS-1$ = "Java Content Assist is not available for the current cursor location" - - return results; - } - - /** - * For debugging translation mapping only. - * @param translation - */ - private String debug(JSPTranslation translation) { - StringBuffer debugString = new StringBuffer(); - HashMap jsp2java = translation.getJsp2JavaMap(); - String javaText = translation.getJavaText(); - String jspText = fViewer.getDocument().get(); - debugString.append("[jsp2JavaMap in JSPCompletionProcessor]\r\n"); //$NON-NLS-1$ - debugString.append("jsp cursor position >> " + fViewer.getTextWidget().getCaretOffset() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$ - Iterator it = jsp2java.keySet().iterator(); - while (it.hasNext()) { - try { - Position jspPos = (Position) it.next(); - Position javaPos = (Position) jsp2java.get(jspPos); - debugString.append("jsp > " + jspPos.offset + ":" + jspPos.length + ":" + jspText.substring(jspPos.offset, jspPos.offset + jspPos.length) + ":\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - debugString.append("java > " + javaPos.offset + ":" + javaPos.length + ":" + javaText.substring(javaPos.offset, javaPos.offset + javaPos.length) + ":\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - debugString.append("-------------------------------------------------\n"); //$NON-NLS-1$ - } - catch (Exception e) { - // eat exceptions, it's only for debug - } - } - return debugString.toString(); - } - - /** - * @return whether the source cursor is in an expression - */ - private boolean cursorInExpression() { - boolean inExpression = false; - IStructuredDocumentRegion sdRegion = null; - XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(fViewer.getDocument()); - XMLNode xmlNode = null; - xmlModel.releaseFromRead(); - xmlNode = (XMLNode) xmlModel.getIndexedRegion(fJspSourcePosition); - if(xmlNode != null) { - XMLNode parent = (XMLNode)xmlNode.getParentNode(); - if(parent != null) { - sdRegion = parent.getFirstStructuredDocumentRegion(); - inExpression = sdRegion != null && (sdRegion.getType() == XMLJSPRegionContexts.JSP_EXPRESSION_OPEN || sdRegion.getType() == XMLJSPRegionContexts.JSP_SCRIPTLET_OPEN); - } - } - return inExpression; - } - - /** - * Returns information about possible contexts based on the - * specified location within the document that corresponds - * to the current cursor position within the text viewer. - * - * @param viewer the viewer whose document is used to compute the possible contexts - * @param documentPosition an offset within the document for which context information should be computed - * @return an array of context information objects or <code>null</code> if no context could be found - */ - public org.eclipse.jface.text.contentassist.IContextInformation[] computeContextInformation(org.eclipse.jface.text.ITextViewer viewer, int documentOffset) { - return null; - } - - /** - * Returns a string of characters which when pressed should - * automatically display content-assist proposals. - * - * @return string of characters - */ - public java.lang.String getAutoProposalInvocationCharacters() { - return null; - } - - /** - * Returns a string of characters which when pressed should - * automatically display a content-assist tip. - * - * @return string of characters - */ - public java.lang.String getAutoTipInvocationCharacters() { - return null; - } - - /** - * Returns the characters which when entered by the user should - * automatically trigger the presentation of possible completions. - * - * @return the auto activation characters for completion proposal or <code>null</code> - * if no auto activation is desired - */ - public char[] getCompletionProposalAutoActivationCharacters() { - return null; - } - - /** - * Returns the characters which when entered by the user should - * automatically trigger the presentation of context information. - * - * @return the auto activation characters for presenting context information - * or <code>null</code> if no auto activation is desired - */ - public char[] getContextInformationAutoActivationCharacters() { - return null; - } - - /** - * Returns a validator used to determine when displayed context information - * should be dismissed. May only return <code>null</code> if the processor is - * incapable of computing context information. - * - * @return a context information validator, or <code>null</code> if the processor - * is incapable of computing context information - */ - public org.eclipse.jface.text.contentassist.IContextInformationValidator getContextInformationValidator() { - return null; - } - - protected int getDocumentPosition() { - return fJspSourcePosition; - } - - public String getErrorMessage() { - // TODO: -// if (fCollector.getErrorMessage() != null && fCollector.getErrorMessage().length() > 0) -// return fCollector.getErrorMessage(); - return fErrorMessage; - } - - /** - * Return the Java project for the to create completions within - */ - protected IJavaProject getJavaProject() { - if (fResource == null) - return null; - IProject proj = (fResource.getType() == IResource.PROJECT) ? (IProject) fResource : fResource.getProject(); - IJavaProject javaProj = JavaCore.create(proj); - return javaProj; - } - - /** - * Initialize the code assist processor. - */ - protected void initialize(int pos) { - initializeJavaPlugins(); - - // fCollector = new JSPResultCollector(); - fCollector = new JSPCompletionRequestor(); - fJspSourcePosition = pos; - fErrorMessage = null; - } - - /** - * Initialize the Java Plugins that the JSP processor requires. - */ - protected void initializeJavaPlugins() { - try { - Bundle bundle = Platform.getBundle(JDT_CORE_PLUGIN_ID); - bundle.start(); - } - catch (BundleException exc) { - Logger.logException("Could not initialize the JDT Plugins", exc);//$NON-NLS-1$ - } - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.IReleasable#release() - */ - public void release() { - fTranslationAdapter = null; - } - - /* - * @see com.ibm.sse.editor.contentassist.IResourceDependent#initialize(org.eclipse.core.resources.IResource) - */ - public void initialize(IResource resource) { - fResource = resource; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionRequestor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionRequestor.java deleted file mode 100644 index 02ea17d552..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPCompletionRequestor.java +++ /dev/null @@ -1,744 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jdt.core.CompletionProposal; -import org.eclipse.jdt.core.CompletionRequestor; -import org.eclipse.jdt.core.Flags; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.Signature; -import org.eclipse.jdt.core.compiler.CharOperation; -import org.eclipse.jdt.ui.JavaElementImageDescriptor; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ContextInformation; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jst.jsp.core.internal.java.JSP2ServletNameUtil; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; - -/** - * Most "accept" methods copied from JDT ResultCollector. - * - * @author pavery - */ -public class JSPCompletionRequestor extends CompletionRequestor { - - // for debugging - private static final boolean DEBUG; - static { - String value = Platform.getDebugOption("org.eclipse.jst.jsp.ui/debug/jspcontentassist"); //$NON-NLS-1$ - DEBUG = value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - - private final static char[] METHOD_WITH_ARGUMENTS_TRIGGERS = new char[] {'(', '-', ' ' }; - private final static char[] METHOD_TRIGGERS = new char[] { ';', ',', '.','\t', '[', ' ' }; - private final static char[] TYPE_TRIGGERS = new char[] { '.', '\t', '[','(', ' ' }; - private final static char[] VAR_TRIGGER = new char[] { '\t', ' ', '=',';', '.' }; - - // private IJavaProject fJavaProject; - - // set when imports can be added - private ICompilationUnit fCompilationUnit; - - private int fCodeAssistOffset; - - // private int fContextOffset; - - protected ITextViewer fTextViewer; - - private List fFields = new ArrayList(); - - private List fKeywords = new ArrayList(); - - private List fLabels = new ArrayList(); - - private List fMethods = new ArrayList(); - - private List fModifiers = new ArrayList(); - - private List fPackages = new ArrayList(); - - private List fTypes = new ArrayList(); - - private List fVariables = new ArrayList(); - - private boolean fCursorInExpression = false; - - private int fJavaToJSPOffset; - - private String fJspName; - - private String fMangledName; - - public boolean isCursorInExpression() { - return fCursorInExpression; - } - - /** - * @param doFilter - * The doFilter to set. - */ - public void setCursorInExpression(boolean inExpression) { - fCursorInExpression = inExpression; - } - - /** - * @return Returns the fJavaToJSPOffset. - */ - public int getJavaToJSPOffset() { - return fJavaToJSPOffset; - } - - /** - * @param javaToJSPOffset - * The fJavaToJSPOffset to set. - */ - public void setJavaToJSPOffset(int javaToJSPOffset) { - fJavaToJSPOffset = javaToJSPOffset; - } - - /** - * Copied logic from CompletionRequestorWrapper - * - * @see org.eclipse.jdt.core.CompletionRequestor#accept(org.eclipse.jdt.core.CompletionProposal) - */ - public void accept(CompletionProposal proposal) { - - switch (proposal.getKind()) { - - case CompletionProposal.KEYWORD: - acceptKeyword(proposal.getName(), proposal.getReplaceStart(), proposal.getReplaceEnd(), proposal.getRelevance()); - break; - case CompletionProposal.PACKAGE_REF: - acceptPackage(proposal.getDeclarationSignature(), proposal.getCompletion(), proposal.getReplaceStart(), proposal.getReplaceEnd(), proposal.getRelevance()); - - break; - case CompletionProposal.TYPE_REF: - if ((proposal.getFlags() & Flags.AccEnum) != 0) { - // does not exist for old requestor - } else if ((proposal.getFlags() & Flags.AccInterface) != 0) { - acceptInterface(proposal.getDeclarationSignature(), Signature.getSignatureSimpleName(proposal.getSignature()), proposal.getCompletion(), proposal.getFlags() & ~Flags.AccInterface, - proposal.getReplaceStart(), proposal.getReplaceEnd(), proposal.getRelevance()); - - } else { - acceptClass(proposal.getDeclarationSignature(), Signature.getSignatureSimpleName(proposal.getSignature()), proposal.getCompletion(), proposal.getFlags(), proposal.getReplaceStart(), - proposal.getReplaceEnd(), proposal.getRelevance()); - } - break; - case CompletionProposal.FIELD_REF: - acceptField(Signature.getSignatureQualifier(proposal.getDeclarationSignature()), Signature.getSignatureSimpleName(proposal.getDeclarationSignature()), proposal.getName(), Signature - .getSignatureQualifier(proposal.getSignature()), Signature.getSignatureSimpleName(proposal.getSignature()), proposal.getCompletion(), proposal.getFlags(), proposal - .getReplaceStart(), proposal.getReplaceEnd(), proposal.getRelevance()); - - break; - case CompletionProposal.METHOD_REF: - acceptMethod(Signature.getSignatureQualifier(proposal.getDeclarationSignature()), Signature.getSignatureSimpleName(proposal.getDeclarationSignature()), proposal.getName(), - getParameterPackages(proposal.getSignature()), getParameterTypes(proposal.getSignature()), proposal.findParameterNames(null) == null ? CharOperation.NO_CHAR_CHAR : proposal - .findParameterNames(null), Signature.getSignatureQualifier(Signature.getReturnType(proposal.getSignature())), Signature.getSignatureSimpleName(Signature - .getReturnType(proposal.getSignature())), proposal.getCompletion(), proposal.getFlags(), proposal.getReplaceStart(), proposal.getReplaceEnd(), proposal.getRelevance()); - - break; - case CompletionProposal.METHOD_DECLARATION: - acceptMethodDeclaration(Signature.getSignatureQualifier(proposal.getDeclarationSignature()), Signature.getSignatureSimpleName(proposal.getDeclarationSignature()), proposal.getName(), - getParameterPackages(proposal.getSignature()), getParameterTypes(proposal.getSignature()), proposal.findParameterNames(null) == null ? CharOperation.NO_CHAR_CHAR : proposal - .findParameterNames(null), Signature.getSignatureQualifier(Signature.getReturnType(proposal.getSignature())), Signature.getSignatureSimpleName(Signature - .getReturnType(proposal.getSignature())), proposal.getCompletion(), proposal.getFlags(), proposal.getReplaceStart(), proposal.getReplaceEnd(), proposal.getRelevance()); - - break; - case CompletionProposal.ANONYMOUS_CLASS_DECLARATION: - acceptAnonymousType(Signature.getSignatureQualifier(proposal.getDeclarationSignature()), Signature.getSignatureSimpleName(proposal.getDeclarationSignature()), - getParameterPackages(proposal.getSignature()), getParameterTypes(proposal.getSignature()), proposal.findParameterNames(null) == null ? CharOperation.NO_CHAR_CHAR : proposal - .findParameterNames(null), proposal.getCompletion(), proposal.getFlags(), proposal.getReplaceStart(), proposal.getReplaceEnd(), proposal.getRelevance()); - - break; - case CompletionProposal.LABEL_REF: - acceptLabel(proposal.getCompletion(), proposal.getReplaceStart(), proposal.getReplaceEnd(), proposal.getRelevance()); - break; - case CompletionProposal.LOCAL_VARIABLE_REF: - acceptLocalVariable(proposal.getCompletion(), Signature.getSignatureQualifier(proposal.getSignature()), Signature.getSignatureSimpleName(proposal.getSignature()), proposal.getFlags(), - proposal.getReplaceStart(), proposal.getReplaceEnd(), proposal.getRelevance()); - - break; - case CompletionProposal.VARIABLE_DECLARATION: - acceptLocalVariable(proposal.getCompletion(), Signature.getSignatureQualifier(proposal.getSignature()), Signature.getSignatureSimpleName(proposal.getSignature()), proposal.getFlags(), - proposal.getReplaceStart(), proposal.getReplaceEnd(), proposal.getRelevance()); - - break; - case CompletionProposal.POTENTIAL_METHOD_DECLARATION: - acceptPotentialMethodDeclaration(Signature.getSignatureQualifier(proposal.getDeclarationSignature()), Signature.getSignatureSimpleName(proposal.getDeclarationSignature()), proposal - .getName(), proposal.getReplaceStart(), proposal.getReplaceEnd(), proposal.getRelevance()); - - break; - } - } - - private void acceptPotentialMethodDeclaration(char[] declaringTypePackageName, char[] declaringTypeName, char[] selector, int completionStart, int completionEnd, int relevance) { - if (DEBUG) - System.out.println("TODO: implement acceptPotentialMethodDeclaration"); - // if (fCompilationUnit == null) { - // return; - // } - // String prefix= new String(selector); - // - // try { - // IJavaElement element= - // getCompilationUnit().getElementAt(getCodeAssistOffset()); - // if (element != null) { - // IType type= (IType) element.getAncestor(IJavaElement.TYPE); - // if (type != null) { - // GetterSetterCompletionProposal.evaluateProposals(type, prefix, - // completionStart, completionEnd - completionStart, relevance + 100, - // fSuggestedMethodNames, fMethods); - // MethodCompletionProposal.evaluateProposals(type, prefix, - // completionStart, completionEnd - completionStart, relevance + 99, - // fSuggestedMethodNames, fMethods); - // } - // } - // } catch (CoreException e) { - // - // } - } - - private void acceptLocalVariable(char[] name, char[] typePackageName, char[] typeName, int modifiers, int start, int end, int relevance) { - - String completionString = new String(name); - int offset = start + getJavaToJSPOffset(); - int length = end - start; - Image image = JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.LOCAL_VARIABLE_OBJ); - - StringBuffer buf = new StringBuffer(); - buf.append(name); - if (typeName != null) { - buf.append(" "); //$NON-NLS-1$ - buf.append(fixupTypeName(typeName)); - } - String displayString = buf.toString(); - - CustomCompletionProposal proposal = new CustomCompletionProposal(completionString, offset, length, completionString.length(), image, displayString, null, null, relevance); - proposal.setTriggerCharacters(VAR_TRIGGER); - fVariables.add(proposal); - } - - private void acceptLabel(char[] completion, int replaceStart, int replaceEnd, int relevance) { - if (DEBUG) - System.out.println("implement acceptLabel"); - } - - private void acceptAnonymousType(char[] signatureQualifier, char[] signatureSimpleName, char[][] parameterPackages, char[][] parameterTypes, char[][] cs, char[] completion, int flags, - int replaceStart, int replaceEnd, int relevance) { - if (DEBUG) - System.out.println("implement acceptAnonymousType"); - } - - private void acceptMethodDeclaration(char[] declaringTypePackageName, char[] declaringTypeName, char[] name, char[][] parameterPackageNames, char[][] parameterTypeNames, char[][] parameterNames, - char[] returnTypePackageName, char[] returnTypeName, char[] completionName, int modifiers, int start, int end, int relevance) { - - if (!isCursorInExpression()) - return; - - StringBuffer displayString = getMethodDisplayString(null, name, parameterTypeNames, parameterNames, returnTypeName); - displayString.append(" - "); //$NON-NLS-1$ - displayString.append("Override method in '" + new String(declaringTypeName) + "'"); - - StringBuffer typeName = new StringBuffer(); - if (declaringTypePackageName.length > 0) { - typeName.append(declaringTypePackageName); - typeName.append('.'); - } - typeName.append(declaringTypeName); - - String[] paramTypes = new String[parameterTypeNames.length]; - for (int i = 0; i < parameterTypeNames.length; i++) { - paramTypes[i] = Signature.createTypeSignature(parameterTypeNames[i], true); - } - - // JavaCompletionProposal proposal= new - // OverrideCompletionProposal(fJavaProject, fCompilationUnit, - // typeName.toString(), new String(name), paramTypes, start, - // getLength(start, end), displayString.toString(), new - // String(completionName)); - // proposal.setImage(getImage(getMemberDescriptor(modifiers))); - // proposal.setProposalInfo(new ProposalInfo(fJavaProject, - // declaringTypePackageName, declaringTypeName, name, - // parameterPackageNames, parameterTypeNames, returnTypeName.length == - // 0)); - - String completionString = new String(completionName); - int offset = start + getJavaToJSPOffset(); - int length = end - start; - Image image = createMethodImage(modifiers); - - CustomCompletionProposal proposal = new CustomCompletionProposal(completionString, offset, length, completionString.length(), image, displayString.toString(), null, null, relevance + 100); - // proposal.setRelevance(relevance + 100); - fMethods.add(proposal); - // fSuggestedMethodNames.add(new String(name)); - } - - private void acceptMethod(char[] declaringTypePackageName, char[] declaringTypeName, char[] name, char[][] parameterPackageNames, char[][] parameterTypeNames, char[][] parameterNames, - char[] returnTypePackageName, char[] returnTypeName, char[] completionName, int modifiers, int start, int end, int relevance) { - - if (completionName == null) - return; - - if (!isCursorInExpression()) - return; - - // if (TypeFilter.isFiltered(declaringTypePackageName, - // declaringTypeName)) { - // return; - // } - - String completionString = new String(completionName); - String displayString = getMethodDisplayString(declaringTypeName, name, parameterTypeNames, parameterNames, returnTypeName).toString(); - int offset = start + getJavaToJSPOffset(); - int length = end - start; - Image image = createMethodImage(modifiers); - - boolean hasOpeningBracket = completionName.length == 0 || (completionName.length > 0 && completionName[completionName.length - 1] == ')'); - ContextInformation contextInformation = null; - if (hasOpeningBracket && parameterTypeNames.length > 0) { - contextInformation = new ContextInformation(image, displayString, getParameterSignature(parameterTypeNames, parameterNames)); - -// int position = (completionName.length == 0) ? fContextOffset : -1; - //contextInformation.setContextInformationPosition(position); - } - boolean userMustCompleteParameters = (contextInformation != null && completionName.length > 0); - char[] triggers = userMustCompleteParameters ? METHOD_WITH_ARGUMENTS_TRIGGERS : METHOD_TRIGGERS; - int cursorPosition = completionString.length(); - if (userMustCompleteParameters) { - // set the cursor before the closing bracket - //proposal.setCursorPosition(completionName.length - 1); - cursorPosition--; - } - - CustomCompletionProposal proposal = new CustomCompletionProposal(completionString, offset, length, cursorPosition, image, displayString, contextInformation, null, relevance); - proposal.setTriggerCharacters(triggers); - - - -// boolean isConstructor= returnTypeName == null ? true : -// returnTypeName.length == 0; -// proposal.setProposalInfo(new ProposalInfo(fJavaProject, -// declaringTypePackageName, declaringTypeName, name, -// parameterPackageNames, parameterTypeNames, isConstructor)); - - fMethods.add(proposal); - } - - private StringBuffer getMethodDisplayString(char[] declaringTypeName, char[] name, char[][] parameterTypeNames, char[][] parameterNames, char[] returnTypeName) { - StringBuffer nameBuffer = new StringBuffer(); - nameBuffer.append(name); - nameBuffer.append('('); - if (parameterTypeNames != null && parameterTypeNames.length > 0) { - nameBuffer.append(getParameterSignature(parameterTypeNames, parameterNames)); - } - nameBuffer.append(')'); - if (returnTypeName != null && returnTypeName.length > 0) { - nameBuffer.append(" "); //$NON-NLS-1$ - nameBuffer.append(returnTypeName); - } - // if declaring type is mangled, unmangle - if (declaringTypeName != null && declaringTypeName.length > 0) { - nameBuffer.append(" - "); //$NON-NLS-1$ - nameBuffer.append(fixupTypeName(declaringTypeName)); - } - return nameBuffer; - } - - protected String getParameterSignature(char[][] parameterTypeNames, char[][] parameterNames) { - StringBuffer buf = new StringBuffer(); - if (parameterTypeNames != null) { - for (int i = 0; i < parameterTypeNames.length; i++) { - if (i > 0) { - buf.append(','); - buf.append(' '); - } - buf.append(parameterTypeNames[i]); - if (parameterNames != null && parameterNames[i] != null) { - buf.append(' '); - buf.append(parameterNames[i]); - } - } - } - return buf.toString(); - } - - /** - * @param flags - * @return - */ - private Image createMethodImage(int flags) { - ImageDescriptor imageDescriptor = null; - if ((flags & Flags.AccDefault) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.DEFAULT_CO); - } else if ((flags & Flags.AccPrivate) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.PRIVATE_CO); - } else if ((flags & Flags.AccProtected) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.PROTECTED_CO); - } else if ((flags & Flags.AccPublic) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.PUBLIC_CO); - } else { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.PUBLIC_CO); - } - Image image = JSPEditorPluginImageHelper.getInstance().getImage(decorateImage(imageDescriptor, flags)); - return image; - } - - private ImageDescriptor decorateImage(ImageDescriptor base, int modifiers) { - - int adornments = 0; - if (Flags.isDeprecated(modifiers)) - adornments = adornments | JavaElementImageDescriptor.DEPRECATED; - if (Flags.isStatic(modifiers)) - adornments = adornments | JavaElementImageDescriptor.STATIC; - - JavaElementImageDescriptor javaDescriptor = new JavaElementImageDescriptor(base, adornments, new Point(16, 16)); - - return javaDescriptor; - } - - private void acceptField(char[] declaringTypePackageName, char[] declaringTypeName, char[] name, char[] typePackageName, char[] typeName, char[] completionName, int modifiers, int start, int end, - int relevance) { - - // if (TypeFilter.isFiltered(declaringTypePackageName, - // declaringTypeName)) { - // return; - // } - - String completionNameString = new String(completionName); - int offset = start + getJavaToJSPOffset(); - int length = end - start; - - Image image = createFieldImage(modifiers); - - StringBuffer nameBuffer = new StringBuffer(); - nameBuffer.append(name); - if (typeName.length > 0) { - nameBuffer.append(" "); //$NON-NLS-1$ - nameBuffer.append(typeName); - } - // also fix up name if it's the servlet class - // (since it's that ugly mangled string) - if (declaringTypeName != null && declaringTypeName.length > 0) { - nameBuffer.append(" - "); //$NON-NLS-1$ - nameBuffer.append(fixupTypeName(declaringTypeName)); - } - - // JavaCompletionProposal proposal= createCompletion(start, end, new - // String(completionName), descriptor, nameBuffer.toString(), - // relevance); - CustomCompletionProposal proposal = new CustomCompletionProposal(completionNameString, offset, length, completionNameString.length(), image, nameBuffer.toString(), null, null, relevance); - proposal.setTriggerCharacters(VAR_TRIGGER); - fFields.add(proposal); - // proposal.setProposalInfo(new ProposalInfo(fJavaProject, - // declaringTypePackageName, declaringTypeName, name)); - - } - - /** - * @param flags - * @return - */ - private Image createFieldImage(int flags) { - ImageDescriptor imageDescriptor = null; - if ((flags & Flags.AccDefault) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.FIELD_DEFAULT_OBJ); - } else if ((flags & Flags.AccPrivate) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.FIELD_PRIVATE_OBJ); - } else if ((flags & Flags.AccProtected) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.FIELD_PROTECTED_OBJ); - } else if ((flags & Flags.AccPublic) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.FIELD_PUBLIC_OBJ); - } else { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.FIELD_DEFAULT_OBJ); - } - Image image = JSPEditorPluginImageHelper.getInstance().getImage(decorateImage(imageDescriptor, flags)); - return image; - } - - protected void acceptClass(char[] packageName, char[] typeName, char[] completionName, int modifiers, int start, int end, int relevance) { - - // if (TypeFilter.isFiltered(packageName, typeName)) { - // return; - // } - - // ProposalInfo info= new ProposalInfo(fJavaProject, packageName, - // typeName); - - int offset = start + getJavaToJSPOffset(); - int length = end - start; - Image image = createClassImage(modifiers); - - String completionNameString = new String(completionName); - - String containerNameString = new String(packageName); - String typeNameString = fixupTypeName(typeName); - if (typeNameString == getJspName()) - return; - // containername can be null - String fullName = concatenateName(containerNameString, typeNameString); - - String simpleName = Signature.getSimpleName(fullName); - StringBuffer buf = new StringBuffer(simpleName); - String typeQualifier = Signature.getQualifier(fullName); - if (typeQualifier.length() > 0) { - buf.append(" - "); //$NON-NLS-1$ - buf.append(fixupTypeName(typeQualifier)); - } - String name = buf.toString(); - - // ICompilationUnit cu= null; - // if (containerNameString != null && fCompilationUnit != null) { - // if (completionNameString.equals(fullName)) { - // cu= fCompilationUnit; - // } - // } - - //CustomCompletionProposal proposal = new CustomCompletionProposal(completionNameString, offset, length, completionNameString.length(), image, name, null, null, relevance); - JavaTypeCompletionProposal proposal = new JavaTypeCompletionProposal(completionNameString, offset, length, fullName, image, typeNameString, typeQualifier, relevance, true); - proposal.setTriggerCharacters(TYPE_TRIGGERS); - fTypes.add(proposal); - - // JavaCompletionProposal proposal= new - // JavaTypeCompletionProposal(completion, cu, start, getLength(start, - // end), getImage(descriptor), name, relevance, typeName, - // containerName); - // proposal.setProposalInfo(proposalInfo); - // fTypes.add(createTypeCompletion(start, end, new - // String(completionName), descriptor, new String(typeName), new - // String(packageName), info, relevance)); - } - - /** - * @param modifiers - */ - private Image createClassImage(int modifiers) { - - ImageDescriptor descriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.IMG_OBJ_CLASS_OBJ); - if ((modifiers & Flags.AccDefault) != 0) { - descriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.INNERCLASS_DEFAULT_OBJ); - } else if ((modifiers & Flags.AccPrivate) != 0) { - descriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.INNERCLASS_PRIVATE_OBJ); - } else if ((modifiers & Flags.AccProtected) != 0) { - descriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.INNERCLASS_PROTECTED_OBJ); - } else if ((modifiers & Flags.AccPublic) != 0) { - descriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.IMG_OBJ_CLASS_OBJ); - } else { - descriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.INNERCLASS_DEFAULT_OBJ); - } - Image image = JSPEditorPluginImageHelper.getInstance().getImage(decorateImage(descriptor, modifiers)); - return image; - } - - /** - * Concatenates two names. Uses a dot for separation. Both strings can be - * empty or <code>null</code>. - */ - public String concatenateName(String name1, String name2) { - StringBuffer buf = new StringBuffer(); - if (name1 != null && name1.length() > 0) { - buf.append(name1); - } - if (name2 != null && name2.length() > 0) { - if (buf.length() > 0) { - buf.append('.'); - } - buf.append(name2); - } - return buf.toString(); - } - - protected void acceptInterface(char[] packageName, char[] typeName, char[] completionName, int modifiers, int start, int end, int relevance) { - // if (TypeFilter.isFiltered(packageName, typeName)) { - // return; - // } - - String completionNameString = new String(completionName); - - int offset = start + getJavaToJSPOffset(); - int length = end - start; - Image image = createInterfaceImage(modifiers); - - String containerNameString = new String(packageName); - String typeNameString = fixupTypeName(new String(typeName)); - if (typeNameString == getJspName()) - return; - - // container name can be null - String fullName = concatenateName(containerNameString, typeNameString); - - StringBuffer buf = new StringBuffer(Signature.getSimpleName(fullName)); - String typeQualifier = Signature.getQualifier(fullName); - if (typeQualifier.length() > 0) { - buf.append(" - "); //$NON-NLS-1$ - buf.append(fixupTypeName(typeQualifier)); - } - String name = buf.toString(); - - CustomCompletionProposal proposal = new CustomCompletionProposal(completionNameString, offset, length, completionNameString.length(), image, name, null, null, relevance); - fTypes.add(proposal); - // ProposalInfo info= new ProposalInfo(fJavaProject, packageName, - // typeName); - // fTypes.add(createTypeCompletion(start, end, new - // String(completionName), descriptor, new String(typeName), new - // String(packageName), info, relevance)); - } - - /** - * @param modifiers - * @return - */ - private Image createInterfaceImage(int modifiers) { - ImageDescriptor imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.INNERINTERFACE_PUBLIC_OBJ); - if ((modifiers & Flags.AccDefault) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.INNERINTERFACE_DEFAULT_OBJ); - } else if ((modifiers & Flags.AccPrivate) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.INNERINTERFACE_PRIVATE_OBJ); - } else if ((modifiers & Flags.AccProtected) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.INNERINTERFACE_PROTECTED_OBJ); - } else if ((modifiers & Flags.AccPublic) != 0) { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.INNERINTERFACE_PUBLIC_OBJ); - } else { - imageDescriptor = JSPEditorPluginImageHelper.getInstance().getImageDescriptor(JSPEditorPluginImages.INNERINTERFACE_DEFAULT_OBJ); - } - Image image = JSPEditorPluginImageHelper.getInstance().getImage(decorateImage(imageDescriptor, modifiers)); - return image; - } - - private void acceptPackage(char[] packageName, char[] completionName, int start, int end, int relevance) { -// if (TypeFilter.isFiltered(new String(packageName))) { -// return; -// } - - String packageNameString = new String(packageName); - String completionNameString = new String(completionName); - - int offset = start + getJavaToJSPOffset(); - int length = end - start; - - Image image = JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.PACKAGE_OBJ); - CustomCompletionProposal proposal = new CustomCompletionProposal(packageNameString, offset, length, packageNameString.length(), image, completionNameString, null, null, relevance); - - fPackages.add(proposal); - } - - private void acceptKeyword(char[] name, int replaceStart, int replaceEnd, int relevance) { - if(DEBUG) - System.out.println("TODO: implement accept keyword"); - } - - private char[][] getParameterPackages(char[] methodSignature) { - char[][] parameterQualifiedTypes = Signature.getParameterTypes(methodSignature); - int length = parameterQualifiedTypes == null ? 0 : parameterQualifiedTypes.length; - char[][] parameterPackages = new char[length][]; - for (int i = 0; i < length; i++) { - parameterPackages[i] = Signature.getSignatureQualifier(parameterQualifiedTypes[i]); - } - - return parameterPackages; - } - - private char[][] getParameterTypes(char[] methodSignature) { - char[][] parameterQualifiedTypes = Signature.getParameterTypes(methodSignature); - int length = parameterQualifiedTypes == null ? 0 : parameterQualifiedTypes.length; - char[][] parameterPackages = new char[length][]; - for (int i = 0; i < length; i++) { - parameterPackages[i] = Signature.getSignatureSimpleName(parameterQualifiedTypes[i]); - } - - return parameterPackages; - } - - public ICompletionProposal[] getResults() { - - // TODO: eventually do better custom sorting here.. - List results = new ArrayList(); - results.addAll(fFields); - results.addAll(fKeywords); - results.addAll(fLabels); - results.addAll(fMethods); - results.addAll(fModifiers); - results.addAll(fPackages); - results.addAll(fTypes); - results.addAll(fVariables); - return (ICompletionProposal[]) results.toArray(new ICompletionProposal[results.size()]); - } - - /** - * @param compilationUnit - * The fCompilationUnit to set. - */ - public void setCompilationUnit(ICompilationUnit compilationUnit) { - fCompilationUnit = compilationUnit; - - // set some names for fixing up mangled name - // in proposals later - String cuName = getCompilationUnit().getPath().lastSegment(); - setMangledName(cuName.substring(0, cuName.lastIndexOf('.'))); - - String unmangled = JSP2ServletNameUtil.unmangle(cuName); - setJspName(unmangled.substring(unmangled.lastIndexOf('/') + 1)); - } - - /** - * @return Returns the fCompilationUnit. - */ - public ICompilationUnit getCompilationUnit() { - return fCompilationUnit; - } - - private String fixupTypeName(char[] typeNameChars) { - String typeName = new String(typeNameChars); - return fixupTypeName(typeName); - } - - /** - * Changes mangled type name to the name of the jsp file Or if it's an inner - * type, returns the name of the inner type (minus the mangled parent type - * name) - * - * @param typeNameChars - * @return - */ - private String fixupTypeName(String typeName) { - String mangledName = getMangledName(); - // can be null if no CU was ever set - if(mangledName != null) { - if (typeName.equals(mangledName)) - return getJspName(); - else if (typeName.startsWith(mangledName)) - return typeName.substring(typeName.lastIndexOf('.')+1); - } - return typeName; - } - - private String getMangledName() { - return fMangledName; - } - - private void setMangledName(String mangledName) { - fMangledName = mangledName; - } - - private String getJspName() { - return fJspName; - } - - private void setJspName(String jspName) { - fJspName = jspName; - } - - public int getCodeAssistOffset() { - return fCodeAssistOffset; - } - - public void setCodeAssistOffset(int offset) { - fCodeAssistOffset = offset; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPContentAssistProcessor.java deleted file mode 100644 index 72e4e81cf6..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPContentAssistProcessor.java +++ /dev/null @@ -1,1264 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Vector; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; -import org.eclipse.jst.jsp.core.JSP11Namespace; -import org.eclipse.jst.jsp.core.JSP12Namespace; -import org.eclipse.jst.jsp.core.PageDirectiveAdapter; -import org.eclipse.jst.jsp.core.contenttype.ContentTypeIdForJSP; -import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibController; -import org.eclipse.jst.jsp.core.internal.contentmodel.tld.TLDCMDocumentManager; -import org.eclipse.jst.jsp.core.internal.document.PageDirectiveAdapterFactory; -import org.eclipse.jst.jsp.core.internal.text.rules.StructuredTextPartitionerForJSP; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.wst.common.contentmodel.CMDocument; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQueryAction; -import org.eclipse.wst.css.ui.contentassist.CSSContentAssistProcessor; -import org.eclipse.wst.html.core.HTMLCMProperties; -import org.eclipse.wst.html.core.contentmodel.HTMLCMDocumentFactory; -import org.eclipse.wst.html.core.contentmodel.HTMLElementDeclaration; -import org.eclipse.wst.html.core.contentmodel.JSPCMDocument; -import org.eclipse.wst.html.core.internal.text.rules.StructuredTextPartitionerForHTML; -import org.eclipse.wst.html.ui.internal.contentassist.HTMLContentAssistProcessor; -import org.eclipse.wst.javascript.common.ui.contentassist.JavaScriptContentAssistProcessor; -import org.eclipse.wst.sse.core.IModelManager; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.contentmodel.CMDocType; -import org.eclipse.wst.sse.core.contentmodel.CMDocumentTracker; -import org.eclipse.wst.sse.core.contentmodel.CMNodeWrapper; -import org.eclipse.wst.sse.core.modelquery.ModelQueryAdapter; -import org.eclipse.wst.sse.core.parser.BlockMarker; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.sse.core.text.rules.StructuredTextPartitioner; -import org.eclipse.wst.sse.core.util.StringUtils; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.contentassist.IRelevanceCompletionProposal; -import org.eclipse.wst.sse.ui.contentassist.IResourceDependentProcessor; -import org.eclipse.wst.sse.ui.edit.util.SharedEditorPluginImageHelper; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceConstants; -import org.eclipse.wst.sse.ui.preferences.CommonEditorPreferenceNames; -import org.eclipse.wst.sse.ui.registry.AdapterFactoryProvider; -import org.eclipse.wst.sse.ui.registry.AdapterFactoryRegistry; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.internal.parser.XMLSourceParser; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.core.text.rules.StructuredTextPartitionerForXML; -import org.eclipse.wst.xml.ui.contentassist.AbstractContentAssistProcessor; -import org.eclipse.wst.xml.ui.contentassist.AbstractTemplateCompletionProcessor; -import org.eclipse.wst.xml.ui.contentassist.ContentAssistRequest; -import org.eclipse.wst.xml.ui.contentassist.NonValidatingModelQueryAction; -import org.eclipse.wst.xml.ui.contentassist.ProposalComparator; -import org.eclipse.wst.xml.ui.contentassist.XMLContentAssistProcessor; -import org.eclipse.wst.xml.ui.contentassist.XMLContentAssistUtilities; -import org.eclipse.wst.xml.ui.contentassist.XMLRelevanceConstants; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeIds; -import org.eclipse.wst.xml.ui.util.SharedXMLEditorPluginImageHelper; -import org.w3c.dom.Attr; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * Adds proposals not normally covered by the generic behavior with the - * content model - */ -public class JSPContentAssistProcessor extends AbstractContentAssistProcessor implements IResourceDependentProcessor { - - protected int depthCount = 0; - protected ITextViewer fViewer = null; - protected boolean useEmbeddedResults = true; - protected boolean isInternalAdapter = false; - protected HashMap fNameToProcessorMap = null; - protected HashMap fPartitionToProcessorMap = null; - private final ICompletionProposal[] EMPTY_PROPOSAL_SET = new ICompletionProposal[0]; - protected IResource fResource = null; - protected AbstractTemplateCompletionProcessor fTemplateProcessor = null; - - public JSPContentAssistProcessor() { - super(); - initNameToProcessorMap(); - initPartitionToProcessorMap(); - } - - /** - * init map for extra content assist processors (useBean, - * get/setProperty). points [tagname > processor] - */ - protected void initNameToProcessorMap() { - fNameToProcessorMap = new HashMap(); - JSPPropertyContentAssistProcessor jspPropertyCAP = new JSPPropertyContentAssistProcessor(); - fNameToProcessorMap.put(JSP11Namespace.ElementName.SETPROPERTY, jspPropertyCAP); - fNameToProcessorMap.put(JSP11Namespace.ElementName.GETPROPERTY, jspPropertyCAP); - fNameToProcessorMap.put(JSP11Namespace.ElementName.USEBEAN, new JSPUseBeanContentAssistProcessor()); - } - - /** - * int map that points [partition > processor]. This takes place of - * embedded adapters for now. - */ - protected void initPartitionToProcessorMap() { - fPartitionToProcessorMap = new HashMap(); - HTMLContentAssistProcessor htmlProcessor = new HTMLContentAssistProcessor(); - JSPJavaContentAssistProcessor jspJavaProcessor = new JSPJavaContentAssistProcessor(); - XMLContentAssistProcessor xmlProcessor = new XMLContentAssistProcessor(); - JavaScriptContentAssistProcessor javascriptProcessor = new JavaScriptContentAssistProcessor(); - - fPartitionToProcessorMap.put(StructuredTextPartitionerForHTML.ST_DEFAULT_HTML, htmlProcessor); - fPartitionToProcessorMap.put(StructuredTextPartitionerForXML.ST_DEFAULT_XML, xmlProcessor); - fPartitionToProcessorMap.put(StructuredTextPartitioner.ST_DEFAULT_PARTITION, htmlProcessor); - fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_DEFAULT_JSP, jspJavaProcessor); - fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_JSP_DIRECTIVE, xmlProcessor); - fPartitionToProcessorMap.put(StructuredTextPartitionerForHTML.ST_HTML_COMMENT, htmlProcessor); - fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT, javascriptProcessor); - fPartitionToProcessorMap.put(StructuredTextPartitionerForHTML.ST_SCRIPT, javascriptProcessor); // default - // to - // javascript - // for - // all - // script - } - - protected void addCommentProposal(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addDocTypeProposal(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addEmptyDocumentProposals(ContentAssistRequest contentAssistRequest) { - super.addEmptyDocumentProposals(contentAssistRequest); - addTagInsertionProposals(contentAssistRequest, 0); - } - - protected void addEndTagNameProposals(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addPCDATAProposal(String nodeName, ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addStartDocumentProposals(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addTagCloseProposals(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addXMLProposal(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addEndTagProposals(ContentAssistRequest contentAssistRequest) { - // do nothing - } - - protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) { - // CMVC 261162 (248603) - // macros for JSP attribute values weren't showing up - addTemplates(contentAssistRequest, TemplateContextTypeIds.ATTRIBUTE); - - // specific fix for CMVC 274033 - // no attribute proposals for <jsp:useBean /> - String nodeName = contentAssistRequest.getNode().getNodeName(); - if (nodeName.indexOf(':') != -1) { //$NON-NLS-1$ - super.addAttributeNameProposals(contentAssistRequest); - } - } - - /** - * add proposals for tags in attribute values - */ - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - XMLNode node = (XMLNode) contentAssistRequest.getNode(); - // CMVC 248603 - // macros for JSP attribute values weren't showing up - addTemplates(contentAssistRequest, TemplateContextTypeIds.ATTRIBUTEVALUE); - - // add JSP extra proposals from JSPBeanInfoContentAssistProcessor - // JSPPropertyContentAssistProcessor - - // 2.1 - // get results from JSPUseBean and JSPProperty here - // (look up processor in a map based on node name) - JSPDummyContentAssistProcessor extraProcessor = (JSPDummyContentAssistProcessor) fNameToProcessorMap.get(node.getNodeName()); - if (extraProcessor != null && contentAssistRequest != null) { - extraProcessor.initialize(fResource); - extraProcessor.addAttributeValueProposals(contentAssistRequest); - } - - ModelQuery mq = ModelQueryUtil.getModelQuery(node.getOwnerDocument()); - if (mq != null) { - CMDocument doc = mq.getCorrespondingCMDocument(node); - // this shouldn't have to have the prefix coded in - if (doc instanceof JSPCMDocument || doc instanceof CMNodeWrapper || node.getNodeName().startsWith("jsp:")) //$NON-NLS-1$ - return; - } - - // Find the attribute name for which this position should have a value - IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion(); - ITextRegionList openRegions = open.getRegions(); - int i = openRegions.indexOf(contentAssistRequest.getRegion()); - if (i < 0) - return; - ITextRegion nameRegion = null; - while (i >= 0) { - nameRegion = openRegions.get(i--); - if (nameRegion.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) - break; - } - - String attributeName = null; - if (nameRegion != null) - attributeName = open.getText(nameRegion); - String currentValue = null; - if (attributeName != null) - currentValue = node.getAttributes().getNamedItem(attributeName).getNodeValue(); - - // on an empty value, add all the JSP and taglib tags - if ((contentAssistRequest.getRegion().getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_EQUALS && contentAssistRequest.getReplacementLength() == 0) || (contentAssistRequest.getRegion().getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE && (currentValue == null || currentValue.length() == 0))) { - List rejectElements = new ArrayList(); - rejectElements.add(JSP12Namespace.ElementName.SCRIPTLET); - rejectElements.add(JSP12Namespace.ElementName.EXPRESSION); - rejectElements.add(JSP12Namespace.ElementName.DECLARATION); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_PAGE); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB); - rejectElements.add(JSP12Namespace.ElementName.FALLBACK); - rejectElements.add(JSP12Namespace.ElementName.USEBEAN); - rejectElements.add(JSP12Namespace.ElementName.SETPROPERTY); - rejectElements.add(JSP12Namespace.ElementName.FORWARD); - rejectElements.add(JSP12Namespace.ElementName.PLUGIN); - rejectElements.add(JSP12Namespace.ElementName.FALLBACK); - rejectElements.add(JSP12Namespace.ElementName.PARAMS); - - List additionalElements = getAdditionalChildren(new ArrayList(), node, -1); - for (i = 0; i < additionalElements.size(); i++) { - CMElementDeclaration ed = (CMElementDeclaration) additionalElements.get(i); - if (rejectElements.contains(ed.getNodeName())) - continue; - String tagname = getContentGenerator().getRequiredName(node, ed); - StringBuffer contents = new StringBuffer("\""); //$NON-NLS-1$ - getContentGenerator().generateTag(node, ed, contents); - contents.append('"'); - CustomCompletionProposal proposal = new CustomCompletionProposal(contents.toString(), contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), contents.length(), SharedEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_TAG_GENERIC), tagname, null, null, XMLRelevanceConstants.R_JSP_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - - addTemplates(contentAssistRequest, TemplateContextTypeIds.TAG); - addTemplates(contentAssistRequest, TemplateContextTypeIds.ALL); - } - } - - else if (contentAssistRequest.getRegion().getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - try { - // Create a new model for Content Assist to operate on. This - // will simulate - // a full Document and then adjust the offset numbers in the - // list of results. - IStructuredModel internalModel = null; - IModelManager mmanager = StructuredModelManager.getModelManager(); - internalModel = mmanager.createUnManagedStructuredModelFor(ContentTypeIdForJSP.ContentTypeID_JSP); - XMLNode xmlNode = null; - XMLModel xmlOuterModel = null; - if (contentAssistRequest.getNode() instanceof XMLNode) { - xmlNode = (XMLNode) contentAssistRequest.getNode(); - xmlOuterModel = xmlNode.getModel(); - internalModel.setResolver(xmlOuterModel.getResolver()); - internalModel.setBaseLocation(xmlOuterModel.getBaseLocation()); - } - String contents = StringUtils.strip(contentAssistRequest.getText()); - if (xmlNode != null && contents != null) { - int additionalShifts = 0; - // Be sure that custom tags from taglibs also show up - // by - // adding taglib declarations to the internal model. - TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(xmlOuterModel.getStructuredDocument()); - if (mgr != null) { - List trackers = mgr.getCMDocumentTrackers(contentAssistRequest.getReplacementBeginPosition()); - if (trackers != null) { - for (i = 0; i < trackers.size(); i++) { - CMDocumentTracker tracker = (CMDocumentTracker) trackers.get(i); - String declaration = tracker.getStructuredDocumentRegion().getText(); - if (declaration != null) { - contents = declaration + contents; - additionalShifts += declaration.length(); - } - } - } - } - // Also copy any jsp:useBean tags so that - // jsp:[gs]etProperty will function - Document doc = null; - if (contentAssistRequest.getNode().getNodeType() == Node.DOCUMENT_NODE) - doc = (Document) node; - else - doc = node.getOwnerDocument(); - NodeList useBeans = doc.getElementsByTagName(JSP12Namespace.ElementName.USEBEAN); - for (int k = 0; k < useBeans.getLength(); k++) { - XMLNode useBean = (XMLNode) useBeans.item(k); - if (useBean.getStartOffset() < contentAssistRequest.getReplacementBeginPosition()) { - StringBuffer useBeanText = new StringBuffer("<jsp:useBean"); //$NON-NLS-1$ - for (int j = 0; j < useBean.getAttributes().getLength(); j++) { - Attr attr = (Attr) useBean.getAttributes().item(j); - useBeanText.append(' '); - useBeanText.append(attr.getName()); - useBeanText.append("=\""); //$NON-NLS-1$ - useBeanText.append(attr.getValue()); - useBeanText.append('"'); - } - useBeanText.append("/>"); //$NON-NLS-1$ - additionalShifts += useBeanText.length(); - contents = useBeanText.toString() + contents; - } - } - internalModel.getStructuredDocument().set(contents); - int internalOffset = 0; - boolean quoted = false; - // if quoted, use position inside and shift by one - if (contentAssistRequest.getMatchString().length() > 0 && (contentAssistRequest.getMatchString().charAt(0) == '\'' || contentAssistRequest.getMatchString().charAt(0) == '"')) { - internalOffset = contentAssistRequest.getMatchString().length() - 1 + additionalShifts; - quoted = true; - } - // if unquoted, use position inside - else if (contentAssistRequest.getMatchString().length() > 0 && contentAssistRequest.getMatchString().charAt(0) == '<') - internalOffset = contentAssistRequest.getMatchString().length() + additionalShifts; - else - internalOffset = contentAssistRequest.getReplacementBeginPosition() - contentAssistRequest.getStartOffset() + additionalShifts; - depthCount++; - IndexedRegion internalNode = null; - int tmpOffset = internalOffset; - while (internalNode == null && tmpOffset >= 0) - internalNode = internalModel.getIndexedRegion(tmpOffset--); - - if (internalModel.getFactoryRegistry() != null) { - // set up the internal model - if (internalModel.getFactoryRegistry().getFactoryFor(PageDirectiveAdapter.class) == null) { - internalModel.getFactoryRegistry().addFactory(new PageDirectiveAdapterFactory()); - } - PageDirectiveAdapter outerEmbeddedTypeAdapter = (PageDirectiveAdapter) xmlOuterModel.getDocument().getAdapterFor(PageDirectiveAdapter.class); - PageDirectiveAdapter internalEmbeddedTypeAdapter = (PageDirectiveAdapter) ((INodeNotifier) ((Node) internalNode).getOwnerDocument()).getAdapterFor(PageDirectiveAdapter.class); - internalEmbeddedTypeAdapter.setEmbeddedType(outerEmbeddedTypeAdapter.getEmbeddedType()); - } - - AdapterFactoryRegistry adapterRegistry = JSPUIPlugin.getDefault().getAdapterFactoryRegistry(); - Iterator adapterList = adapterRegistry.getAdapterFactories(); - // And all those appropriate for this particular type - // of content - while (adapterList.hasNext()) { - try { - AdapterFactoryProvider provider = (AdapterFactoryProvider) adapterList.next(); - if (provider.isFor(internalModel.getModelHandler())) { - provider.addAdapterFactories(internalModel); - } - } - catch (Exception e) { - Logger.logException(e); - } - } - - // the internal adapter does all the real work of - // using the JSP content model to form proposals - // TODO : Nitin and Phil, please take a look - //// ContentAssistAdapter internalAdapter = - // (ContentAssistAdapter) ((INodeNotifier) - // internalNode).getAdapterFor(ContentAssistAdapter.class); - ICompletionProposal[] results = null; - //// if (internalAdapter != null) { - //// internalAdapter.initialize(resource); - //// if(internalAdapter instanceof - // JSPContentAssistProcessor) - //// - // ((JSPContentAssistProcessor)internalAdapter).isInternalAdapter - // = true; - //// results = - // internalAdapter.computeCompletionProposals(fViewer, - // internalOffset, internalNode); - //// } - //// // results = computeCompletionProposals(null, - // internalOffset, internalNode); - depthCount--; - if (results != null) { - for (i = 0; i < results.length; i++) { - contentAssistRequest.addProposal(new CustomCompletionProposal(((CustomCompletionProposal) results[i]).getReplacementString(), ((CustomCompletionProposal) results[i]).getReplacementOffset() - additionalShifts + contentAssistRequest.getStartOffset() + (quoted ? 1 : 0), ((CustomCompletionProposal) results[i]).getReplacementLength(), ((CustomCompletionProposal) results[i]).getCursorPosition(), results[i].getImage(), results[i].getDisplayString(), ((CustomCompletionProposal) results[i]).getContextInformation(), ((CustomCompletionProposal) results[i]).getAdditionalProposalInfo(), (results[i] instanceof IRelevanceCompletionProposal) ? ((IRelevanceCompletionProposal) results[i]).getRelevance() : IRelevanceConstants.R_NONE)); - } - } - } - } - catch (Exception e) { - Logger.logException("Error in embedded JSP Content Assist", e); //$NON-NLS-1$ - } - } - - - } - - private List getAdditionalChildren(List elementDecls, Node node, int childIndex) { - if (node instanceof XMLNode) { - // find the location of the intended insertion as it will give us - // the - // correct offset for checking position dependent CMDocuments - int textInsertionOffset = 0; - NodeList children = node.getChildNodes(); - if (children.getLength() >= childIndex && childIndex >= 0) { - Node nodeAlreadyAtIndex = children.item(childIndex); - if (nodeAlreadyAtIndex instanceof XMLNode) - textInsertionOffset = ((XMLNode) nodeAlreadyAtIndex).getEndOffset(); - } - else { - textInsertionOffset = ((XMLNode) node).getStartOffset(); - } - TLDCMDocumentManager mgr = TaglibController.getTLDCMDocumentManager(((XMLNode) node).getStructuredDocument()); - if (mgr != null) { - List moreCMDocuments = mgr.getCMDocumentTrackers(textInsertionOffset); - if (moreCMDocuments != null) { - for (int i = 0; i < moreCMDocuments.size(); i++) { - CMDocument doc = (CMDocument) moreCMDocuments.get(i); - CMNamedNodeMap elements = doc.getElements(); - if (elements != null) { - for (int j = 0; j < elements.getLength(); j++) { - CMElementDeclaration ed = (CMElementDeclaration) elements.item(j); - elementDecls.add(ed); - } - } - } - } - } - - // get position dependent CMDocuments and insert their tags as - // proposals - - ModelQueryAdapter mqAdapter = null; - if (node.getNodeType() == Node.DOCUMENT_NODE) - mqAdapter = (ModelQueryAdapter) ((XMLNode) node).getAdapterFor(ModelQueryAdapter.class); - else - mqAdapter = (ModelQueryAdapter) ((XMLNode) node.getOwnerDocument()).getAdapterFor(ModelQueryAdapter.class); - - if (mqAdapter != null) { - CMDocument doc = mqAdapter.getModelQuery().getCorrespondingCMDocument(node); - // this shouldn't have to have the prefix coded in - if (!(doc != null && (doc instanceof JSPCMDocument || doc instanceof CMNodeWrapper || node.getNodeName().startsWith("jsp:")))) { //$NON-NLS-1$ - // get jsp namespace elements and insert their contents - CMDocument JCMDoc = HTMLCMDocumentFactory.getCMDocument(CMDocType.JSP11_DOC_TYPE); - CMNamedNodeMap jspelements = JCMDoc.getElements(); - - if (jspelements != null) { - List rejectElements = new ArrayList(); - - // determine if the document is in XML form - Document domDoc = null; - if (node.getNodeType() == Node.DOCUMENT_NODE) - domDoc = (Document) node; - else - domDoc = node.getOwnerDocument(); - // Show XML tag forms of JSP markers if jsp:root is - // the document element OR it's HTML but - // isn't really in the text. - // If the document isn't strictly XML, pull out the - // XML tag forms - if (!isXMLFormat(domDoc)) { - rejectElements.add(JSP12Namespace.ElementName.SCRIPTLET); - rejectElements.add(JSP12Namespace.ElementName.EXPRESSION); - rejectElements.add(JSP12Namespace.ElementName.DECLARATION); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_INCLUDE); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_PAGE); - rejectElements.add(JSP12Namespace.ElementName.TEXT); - } - // always exclude jsp:directive.taglib - if (isInternalAdapter) { - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB); - rejectElements.add(JSP12Namespace.ElementName.DIRECTIVE_TAGLIB); - rejectElements.add(JSP12Namespace.ElementName.FALLBACK); - rejectElements.add(JSP12Namespace.ElementName.USEBEAN); - rejectElements.add(JSP12Namespace.ElementName.SETPROPERTY); - rejectElements.add(JSP12Namespace.ElementName.FORWARD); - rejectElements.add(JSP12Namespace.ElementName.PLUGIN); - rejectElements.add(JSP12Namespace.ElementName.FALLBACK); - rejectElements.add(JSP12Namespace.ElementName.PARAMS); - } - - // don't show jsp:root if a document element already - // exists - Element docElement = domDoc.getDocumentElement(); - if (docElement != null && ((docElement.getNodeName().equals("jsp:root")) || ((((XMLNode) docElement).getStartStructuredDocumentRegion() != null || ((XMLNode) docElement).getEndStructuredDocumentRegion() != null)))) //$NON-NLS-1$ - rejectElements.add(JSP12Namespace.ElementName.ROOT); - - for (int j = 0; j < jspelements.getLength(); j++) { - CMElementDeclaration ed = (CMElementDeclaration) jspelements.item(j); - if (rejectElements.contains(ed.getNodeName())) - continue; - else - elementDecls.add(ed); - } - } - } - } - } - return elementDecls; - } - - protected List getAvailableChildrenAtIndex(Element parent, int index) { - List list = new ArrayList(); - List additionalElements = getAdditionalChildren(new ArrayList(), parent, index); - for (int i = 0; i < additionalElements.size(); i++) { - ModelQueryAction insertAction = new NonValidatingModelQueryAction((CMElementDeclaration) additionalElements.get(i), ModelQueryAction.INSERT, 0, parent.getChildNodes().getLength(), null); - list.add(insertAction); - } - - // add allowed children of implicit tags that don't already exist - NodeList children = parent.getChildNodes(); - List childNames = new ArrayList(); - if (children != null) { - for (int i = 0; i < children.getLength(); i++) { - Node child = children.item(i); - if (child.getNodeType() == Node.ELEMENT_NODE) - childNames.add(child.getNodeName().toLowerCase()); - } - } - List allActions = new ArrayList(); - Iterator iterator = list.iterator(); - ModelQuery modelQuery = ModelQueryUtil.getModelQuery(parent.getOwnerDocument()); - while (iterator.hasNext()) { - ModelQueryAction action = (ModelQueryAction) iterator.next(); - allActions.add(action); - if (action.getCMNode() instanceof HTMLElementDeclaration) { - HTMLElementDeclaration ed = (HTMLElementDeclaration) action.getCMNode(); - String ommission = (String) ed.getProperty(HTMLCMProperties.OMIT_TYPE); - if (!childNames.contains(ed.getNodeName().toLowerCase()) && ((ommission != null) && (ommission.equals(HTMLCMProperties.Values.OMIT_BOTH)))) { - List implicitValidActions = new ArrayList(); - modelQuery.getInsertActions(parent, ed, 0, ModelQuery.INCLUDE_CHILD_NODES, ModelQuery.VALIDITY_NONE, implicitValidActions); - if (implicitValidActions != null) { - Iterator implicitValidActionsIterator = implicitValidActions.iterator(); - while (implicitValidActionsIterator.hasNext()) { - ModelQueryAction insertAction = new NonValidatingModelQueryAction(((ModelQueryAction) implicitValidActionsIterator.next()).getCMNode(), ModelQueryAction.INSERT, 0, parent.getChildNodes().getLength(), null); - allActions.add(insertAction); - } - } - } - } - } - return allActions; - } - - protected List getAvailableRootChildren(Document document, int childIndex) { - List list = new ArrayList(); - if (!isXMLFormat(document)) - getAdditionalChildren(list, document, childIndex); - return list; - } - - protected void init() { - super.init(); - } - - public void setErrorMessage(String errorMessage) { - if (depthCount == 0) - fErrorMessage = errorMessage; - } - - /** - * This method is acting as a "catch all" for pulling together content - * assist proposals from different Processors when document partitioning - * alone couldn't determine definitively what content assist should show - * up at that particular position in the document - * - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(ITextViewer, - * int) - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentPosition) { - IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion((StructuredTextViewer) viewer, documentPosition); - fViewer = viewer; - ICompletionProposal[] jspResults = EMPTY_PROPOSAL_SET; - ICompletionProposal[] embeddedResults = EMPTY_PROPOSAL_SET; - - // check the actual partition type - String partitionType = getPartitionType((StructuredTextViewer) viewer, documentPosition); - IStructuredModel sModel = StructuredModelManager.getModelManager().getExistingModelForRead(viewer.getDocument()); - IStructuredDocument structuredDocument = sModel.getStructuredDocument(); - sModel.releaseFromRead(); - - IStructuredDocumentRegion fn = structuredDocument.getRegionAtCharacterOffset(documentPosition); - - ////////////////////////////////////////////////////////////////////////////// - // ANOTHER WORKAROUND UNTIL PARTITIONING TAKES CARE OF THIS - // check for xml-jsp tags... - // CMVC 243657 - if (partitionType == StructuredTextPartitionerForJSP.ST_JSP_DIRECTIVE && fn != null) { - IStructuredDocumentRegion possibleXMLJSP = ((fn.getType() == XMLRegionContext.XML_CONTENT) && fn.getPrevious() != null) ? fn.getPrevious() : fn; - ITextRegionList regions = possibleXMLJSP.getRegions(); - if (regions.size() > 1) { - // check bounds cases - ITextRegion xmlOpenOrClose = regions.get(0); - if (xmlOpenOrClose.getType() == XMLRegionContext.XML_TAG_OPEN && documentPosition == possibleXMLJSP.getStartOffset()) { - // do regular jsp content assist - } - else if (xmlOpenOrClose.getType() == XMLRegionContext.XML_END_TAG_OPEN && documentPosition > possibleXMLJSP.getStartOffset()) { - // do regular jsp content assist - } - else { - // possible xml-jsp - ITextRegion nameRegion = regions.get(1); - String name = possibleXMLJSP.getText(nameRegion); - if (name.equals("jsp:scriptlet") || name.equals("jsp:expression") || name.equals("jsp:declaration")) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - } - } - - ////////////////////////////////////////////////////////////////////////////// - // ** THIS IS A TEMP FIX UNTIL PARTITIONING TAKES CARE OF THIS... - // CMVC 241882 - // check for XML-JSP in a <script> region - if (partitionType == StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT || partitionType == StructuredTextPartitionerForHTML.ST_SCRIPT) { - //fn should be block text - IStructuredDocumentRegion decodedSDRegion = decodeScriptBlock(fn.getFullText()); - //System.out.println("decoded > " + - // blockOfText.substring(decodedSDRegion.getStartOffset(), - // decodedSDRegion.getEndOffset())); - if (decodedSDRegion != null) { - IStructuredDocumentRegion sdr = decodedSDRegion; - while (sdr != null) { - //System.out.println("sdr " + sdr.getType()); - //System.out.println("sdr > " + - // blockOfText.substring(sdr.getStartOffset(), - // sdr.getEndOffset())); - if (sdr.getType() == XMLJSPRegionContexts.JSP_CONTENT) { - if (documentPosition >= fn.getStartOffset() + sdr.getStartOffset() && documentPosition <= fn.getStartOffset() + sdr.getEndOffset()) { - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - else if (sdr.getType() == XMLRegionContext.XML_TAG_NAME) { - if (documentPosition > fn.getStartOffset() + sdr.getStartOffset() && documentPosition < fn.getStartOffset() + sdr.getEndOffset()) { - return EMPTY_PROPOSAL_SET; - } - else if (documentPosition == fn.getStartOffset() + sdr.getEndOffset() && sdr.getNext() != null && sdr.getNext().getType() == XMLJSPRegionContexts.JSP_CONTENT) { - // the end of an open tag <script> - // <jsp:scriptlet>| blah </jsp:scriptlet> - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - else if (documentPosition == fn.getStartOffset() + sdr.getStartOffset() && sdr.getPrevious() != null && sdr.getPrevious().getType() == XMLRegionContext.XML_TAG_NAME) { - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - sdr = sdr.getNext(); - } - } - } - /////////////////////////////////////////////////////////////////////////// - - // check special JSP delimiter cases - if (fn != null && partitionType == StructuredTextPartitionerForJSP.ST_JSP_CONTENT_DELIMITER) { - IStructuredDocumentRegion fnDelim = fn; - - // if it's a nested JSP region, need to get the correct - // StructuredDocumentRegion - // not sure why this check was there... - //if (fnDelim.getType() == XMLRegionContext.BLOCK_TEXT) { - Iterator blockRegions = fnDelim.getRegions().iterator(); - ITextRegion temp = null; - ITextRegionContainer trc; - while (blockRegions.hasNext()) { - temp = (ITextRegion) blockRegions.next(); - // we hit a nested - if (temp instanceof ITextRegionContainer) { - trc = (ITextRegionContainer) temp; - // it's in this region - if (documentPosition >= trc.getStartOffset() && documentPosition < trc.getEndOffset()) { - Iterator nestedJSPRegions = trc.getRegions().iterator(); - while (nestedJSPRegions.hasNext()) { - temp = (ITextRegion) nestedJSPRegions.next(); - if (XMLContentAssistUtilities.isJSPOpenDelimiter(temp.getType()) && documentPosition == trc.getStartOffset(temp)) { - // HTML content assist - // we actually want content assist for the - // previous type of region, - // well get those proposals from the embedded - // adapter - if (documentPosition > 0) { - partitionType = getPartitionType((StructuredTextViewer) viewer, documentPosition - 1); - break; - } - } - else if (XMLContentAssistUtilities.isJSPCloseDelimiter(temp.getType()) && documentPosition == trc.getStartOffset(temp)) { - // JSP content assist - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - } - } - //} - } - - // take care of XML-JSP delimter cases - if (XMLContentAssistUtilities.isXMLJSPDelimiter(fnDelim)) { - // since it's a delimiter, we know it's a ITextRegionContainer - ITextRegion firstRegion = fnDelim.getRegions().get(0); - if (fnDelim.getStartOffset() == documentPosition && (firstRegion.getType() == XMLRegionContext.XML_TAG_OPEN)) { - // |<jsp:scriptlet> </jsp:scriptlet> - // (pa) commented out so that we get regular behavior JSP - // macros etc... - //return getHTMLCompletionProposals(viewer, - // documentPosition); - } - else if (fnDelim.getStartOffset() == documentPosition && (firstRegion.getType() == XMLRegionContext.XML_END_TAG_OPEN)) { - // <jsp:scriptlet> |</jsp:scriptlet> - // check previous partition type to see if it's JAVASCRIPT - // if it is, we're just gonna let the embedded JAVASCRIPT - // adapter get the proposals - if (documentPosition > 0) { - String checkType = getPartitionType((StructuredTextViewer) viewer, documentPosition - 1); - if (checkType != StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT) { // this - // check - // is - // failing - // for - // XML-JSP - // (region - // is - // not - // javascript...) - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - else { - partitionType = StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT; - } - } - } - else if ((firstRegion.getType() == XMLRegionContext.XML_TAG_OPEN) && documentPosition >= fnDelim.getEndOffset()) { - // anything else inbetween - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - else if (XMLContentAssistUtilities.isJSPDelimiter(fnDelim)) { - // the delimiter <%, <%=, <%!, ... - if (XMLContentAssistUtilities.isJSPCloseDelimiter(fnDelim)) { - if (documentPosition == fnDelim.getStartOffset()) { - // check previous partition type to see if it's - // JAVASCRIPT - // if it is, we're just gonna let the embedded - // JAVASCRIPT adapter get the proposals - if (documentPosition > 0) { - String checkType = getPartitionType((StructuredTextViewer) viewer, documentPosition - 1); - if (checkType != StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT) { - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - else { - partitionType = StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT; - } - } - } - } - else if (XMLContentAssistUtilities.isJSPOpenDelimiter(fnDelim)) { - // if it's the first position of open delimiter - // use embedded HTML results - if (documentPosition == fnDelim.getStartOffset()) { - embeddedResults = getHTMLCompletionProposals(viewer, documentPosition); - } - else if (documentPosition == fnDelim.getEndOffset()) { - // it's at the EOF <%| - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - } - } - - // need to check if it's JSP region inside of CDATA w/ no region - // <![CDATA[ <%|%> ]]> - // or a comment region - // <!-- <% |%> --> - if (fn != null && (fn.getType() == XMLRegionContext.XML_CDATA_TEXT || fn.getType() == XMLRegionContext.XML_COMMENT_TEXT)) { - if (fn instanceof ITextRegionContainer) { - Object[] cdataRegions = fn.getRegions().toArray(); - ITextRegion r = null; - ITextRegion jspRegion = null; - for (int i = 0; i < cdataRegions.length; i++) { - r = (ITextRegion) cdataRegions[i]; - if (r instanceof ITextRegionContainer) { - // CDATA embedded container, or comment container - Object[] jspRegions = ((ITextRegionContainer) r).getRegions().toArray(); - for (int j = 0; j < jspRegions.length; j++) { - jspRegion = (ITextRegion) jspRegions[j]; - if (jspRegion.getType() == XMLJSPRegionContexts.JSP_CLOSE) { - if (sdRegion.getStartOffset(jspRegion) == documentPosition) - return getJSPJavaCompletionProposals(viewer, documentPosition); - } - } - } - } - - } - } - - // check if it's in an attribute value, if so, don't add CDATA - // proposal - ITextRegion attrContainer = (fn != null) ? fn.getRegionAtCharacterOffset(documentPosition) : null; - if (attrContainer != null && attrContainer instanceof ITextRegionContainer) { - if (attrContainer.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - // test location of the cursor - // return null if it's in the middle of an open/close - // delimeter - Iterator attrRegions = ((ITextRegionContainer) attrContainer).getRegions().iterator(); - ITextRegion testRegion = null; - while (attrRegions.hasNext()) { - testRegion = (ITextRegion) attrRegions.next(); - // need to check for other valid attribute regions - if (XMLContentAssistUtilities.isJSPOpenDelimiter(testRegion.getType())) { - if (!(((ITextRegionContainer) attrContainer).getEndOffset(testRegion) <= documentPosition)) - return EMPTY_PROPOSAL_SET; - } - else if (XMLContentAssistUtilities.isJSPCloseDelimiter(testRegion.getType())) { - if (!(((ITextRegionContainer) attrContainer).getStartOffset(testRegion) >= documentPosition)) - return EMPTY_PROPOSAL_SET; - } - } - // TODO: handle non-Java code such as nested tags - if (testRegion.getType().equals(XMLJSPRegionContexts.JSP_CONTENT)) - return getJSPJavaCompletionProposals(viewer, documentPosition); - else - return EMPTY_PROPOSAL_SET; - } - } - - IContentAssistProcessor p = (IContentAssistProcessor) fPartitionToProcessorMap.get(partitionType); - if (p != null) { - embeddedResults = p.computeCompletionProposals(viewer, documentPosition); - // get bean methods, objects, and constants if there are any... - if (partitionType == StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT || partitionType == StructuredTextPartitionerForHTML.ST_SCRIPT) { - ICompletionProposal[] beanResults = getJSPJavaBeanProposals(viewer, documentPosition); - if (beanResults != null && beanResults.length > 0) { - ICompletionProposal[] added = new ICompletionProposal[beanResults.length + embeddedResults.length]; - System.arraycopy(beanResults, 0, added, 0, beanResults.length); - System.arraycopy(embeddedResults, 0, added, beanResults.length, embeddedResults.length); - embeddedResults = added; - } - } - } - else { - // the partition type is probably not mapped - } - - // fix for CMVC 253000 - if (!(p instanceof JavaScriptContentAssistProcessor || p instanceof CSSContentAssistProcessor)) { - super.macroContexts.clear(); - jspResults = super.computeCompletionProposals(viewer, documentPosition); - } - if (useEmbeddedResults) { - if (embeddedResults != null && embeddedResults.length > 0) { - List results = new ArrayList(); - for (int i = 0; i < embeddedResults.length; i++) - results.add(embeddedResults[i]); - if (jspResults != null) { - for (int i = 0; i < jspResults.length; i++) - results.add(jspResults[i]); - } - jspResults = new ICompletionProposal[results.size()]; - Collections.sort(results, new ProposalComparator()); - for (int i = 0; i < results.size(); i++) - jspResults[i] = (ICompletionProposal) results.get(i); - - } - } - if (jspResults == null) - jspResults = EMPTY_PROPOSAL_SET; - setErrorMessage(jspResults.length == 0 ? UNKNOWN_CONTEXT : null); - - // CMVC 269718 - // check for |<%-- --%> first position of jsp comment - if (partitionType == StructuredTextPartitionerForJSP.ST_JSP_COMMENT) { - if (sdRegion.getStartOffset() == documentPosition) { - ICompletionProposal[] htmlResults = getHTMLCompletionProposals(viewer, documentPosition); - jspResults = merge(jspResults, htmlResults); - } - } - return jspResults; - } - - /** - * Adds 2 arrays of ICompletionProposals and sorts them with a - * ProposalComparator. - * - * @param jspResults - * @param htmlResults - * @return - */ - private ICompletionProposal[] merge(ICompletionProposal[] jspResults, ICompletionProposal[] htmlResults) { - List results = new ArrayList(); - List jsps = Arrays.asList(jspResults); - List htmls = Arrays.asList(htmlResults); - - results.addAll(jsps); - results.addAll(htmls); - - Collections.sort(results, new ProposalComparator()); - return (ICompletionProposal[]) results.toArray(new ICompletionProposal[results.size()]); - } - - /* - * This method will return JSPJava Proposals that are relevant to any java - * beans that in scope at the documentPosition - * - * TODO (pa) are taglib vars getting filtered? - * - * @param viewer @param documentPosition @return ICompletionProposal[] - */ - private ICompletionProposal[] getJSPJavaBeanProposals(ITextViewer viewer, int documentPosition) { - ICompletionProposal[] regularJSPResults = getJSPJavaCompletionProposals(viewer, documentPosition); - Vector filteredProposals = new Vector(); - ICompletionProposal[] finalResults = EMPTY_PROPOSAL_SET; - for (int i = 0; i < regularJSPResults.length; i++) { - ICompletionProposal test = regularJSPResults[i]; - - System.out.println("proposal > " + test.getDisplayString()); - System.out.println("relevance > " + ((CustomCompletionProposal) test).getRelevance()); - - if (isRelevanceAllowed(((CustomCompletionProposal) test).getRelevance())) { - filteredProposals.add(test); - } - } - if (filteredProposals.size() > 0) { - finalResults = new ICompletionProposal[filteredProposals.size()]; - Iterator it = filteredProposals.iterator(); - int j = 0; - while (it.hasNext()) { - finalResults[j++] = (ICompletionProposal) it.next(); - } - } - return finalResults; - } - - // These are the only things I'm allowing for use bean if the language is - // JAVASCRIPT - // I'm filtering based on JavaContentAssistProposal relevance - // - // 485 > method that belongs to the bean - // 486 > bean object - // 386 > bean CONSTANT - private boolean isRelevanceAllowed(int relevance) { - return (relevance == 485 || relevance == 486 || relevance == 326); - } - - - /** - * - * @param viewer - * @param documentPosition - * @return ICompletionProposal[] - */ - private ICompletionProposal[] getHTMLCompletionProposals(ITextViewer viewer, int documentPosition) { - - IContentAssistProcessor p = (IContentAssistProcessor) fPartitionToProcessorMap.get(StructuredTextPartitionerForHTML.ST_DEFAULT_HTML); - return p.computeCompletionProposals(viewer, documentPosition); - } - - /** - * - * @param viewer - * @param documentPosition - * @return ICompletionProposal[] - */ - protected ICompletionProposal[] getJSPJavaCompletionProposals(ITextViewer viewer, int documentPosition) { - JSPJavaContentAssistProcessor p = (JSPJavaContentAssistProcessor) fPartitionToProcessorMap.get(StructuredTextPartitionerForJSP.ST_DEFAULT_JSP); - p.initialize(fResource); - return p.computeCompletionProposals(viewer, documentPosition); - } - - /** - * @param viewer - * @param documentPosition - * @return String - */ - protected String getPartitionType(StructuredTextViewer viewer, int documentPosition) { - String partitionType = null; - try { - partitionType = TextUtilities.getContentType(viewer.getDocument(), IStructuredDocument.DEFAULT_STRUCTURED_PARTITIONING, viewer.modelOffset2WidgetOffset(documentPosition), false); - } - catch (BadLocationException e) { - partitionType = IDocument.DEFAULT_CONTENT_TYPE; - } - return partitionType; - } - - /* - * ** TEMP WORKAROUND FOR CMVC 241882 Takes a String and blocks out - * jsp:scriptlet, jsp:expression, and jsp:declaration @param blockText - * @return - */ - private IStructuredDocumentRegion decodeScriptBlock(String blockText) { - XMLSourceParser parser = new XMLSourceParser(); - // use JSP_CONTENT for region type - parser.addBlockMarker(new BlockMarker("jsp:scriptlet", null, XMLJSPRegionContexts.JSP_CONTENT, false, false)); //$NON-NLS-1$ - parser.addBlockMarker(new BlockMarker("jsp:expression", null, XMLJSPRegionContexts.JSP_CONTENT, false, false)); //$NON-NLS-1$ - parser.addBlockMarker(new BlockMarker("jsp:declaration", null, XMLJSPRegionContexts.JSP_CONTENT, false, false)); //$NON-NLS-1$ - parser.reset(blockText); - return parser.getDocumentRegions(); - } - - /* - * @see ContentAssistAdapter#computeContextInformation(ITextViewer, int, - * IndexedRegion) - */ - public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset, IndexedRegion indexedNode) { - return super.computeContextInformation(viewer, documentOffset); - } - - /* - * @see ContentAssistAdapter#getContextInformationAutoActivationCharacters() - */ - public char[] getContextInformationAutoActivationCharacters() { - return super.getContextInformationAutoActivationCharacters(); - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getCompletionProposalAutoActivationCharacters() - */ - public char[] getCompletionProposalAutoActivationCharacters() { - // CMVC 260546 - // return from HTML preference, - // since we know that we are inhereiting the preference for auto - // activation from HTML -// AbstractUIPlugin htmlPlugin = (AbstractUIPlugin) Platform.getPlugin(HTMLEditorPlugin.ID); - IPreferenceStore store = JSPUIPlugin.getDefault().getPreferenceStore(); - String key = CommonEditorPreferenceNames.AUTO_PROPOSE_CODE; - - String chars = store.getString(key); - return (chars != null) ? chars.toCharArray() : new char[0]; - } - - /* - * @see ContentAssistAdapter#getContextInformationValidator() - */ - public IContextInformationValidator getContextInformationValidator() { - return super.getContextInformationValidator(); - } - - /* - * @see ContentAssistAdapter#initialize(IResource) - */ - public void initialize(IResource resourceToInit) { - fResource = resourceToInit; - if (fNameToProcessorMap != null) { - - if(fNameToProcessorMap.isEmpty()) - initNameToProcessorMap(); - - // init some embedded processors - JSPUseBeanContentAssistProcessor useBeanProcessor = (JSPUseBeanContentAssistProcessor) fNameToProcessorMap.get(JSP11Namespace.ElementName.USEBEAN); - JSPPropertyContentAssistProcessor propProcessor = (JSPPropertyContentAssistProcessor) fNameToProcessorMap.get(JSP11Namespace.ElementName.SETPROPERTY); - useBeanProcessor.initialize(resourceToInit); - propProcessor.initialize(resourceToInit); - } - if(fPartitionToProcessorMap != null) { - if(fPartitionToProcessorMap.isEmpty()) - initPartitionToProcessorMap(); - } - } - - protected boolean isXMLFormat(Document doc) { - if (doc == null) - return false; - Element docElement = doc.getDocumentElement(); - return docElement != null && ((docElement.getNodeName().equals("jsp:root")) || ((((XMLNode) docElement).getStartStructuredDocumentRegion() == null && ((XMLNode) docElement).getEndStructuredDocumentRegion() == null))); //$NON-NLS-1$ - } - - /* - * @see ContentAssistAdapter#release() - */ - public void release() { - super.release(); - // release *ContentAssistProcessors in maps - // CMVC 254023 - releasePartitionToProcessorMap(); - releaseNameToProcessorMap(); - } - - protected void releasePartitionToProcessorMap() { - releaseMap(fPartitionToProcessorMap); - } - - protected void releaseNameToProcessorMap() { - releaseMap(fNameToProcessorMap); - } - - protected void releaseMap(HashMap map) { - if (map != null) { - if (!map.isEmpty()) { - Iterator it = map.keySet().iterator(); - Object key = null; - while (it.hasNext()) { - key = it.next(); - // TODO (pa) need to make sure processors w/ release() - // implement releasable - if (map.get(key) instanceof AbstractContentAssistProcessor) { - ((AbstractContentAssistProcessor) map.get(key)).release(); - } - } - } - map.clear(); - map = null; - } - } - - /** - * @see AbstractContentAssistProcessor#computeCompletionProposals(int, - * String, ITextRegion, XMLNode, XMLNode) - */ - protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode treeNode, XMLNode xmlnode) { - - ContentAssistRequest request = super.computeCompletionProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - IStructuredDocumentRegion sdRegion = ContentAssistUtils.getStructuredDocumentRegion((StructuredTextViewer) fTextViewer, documentPosition); - - Document doc = null; - if (xmlnode != null) { - if (xmlnode.getNodeType() == Node.DOCUMENT_NODE) - doc = (Document) xmlnode; - else - doc = xmlnode.getOwnerDocument(); - } - String[] directiveNames = {"page", "include", "taglib"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - // suggest JSP Expression inside of XML comments - if (completionRegion.getType() == XMLRegionContext.XML_COMMENT_TEXT && !isXMLFormat(doc)) { - if (request == null) - request = newContentAssistRequest(treeNode, xmlnode, sdRegion, completionRegion, documentPosition, 0, ""); //$NON-NLS-1$ - request.addProposal(new CustomCompletionProposal("<%= %>", documentPosition, 0, 4, SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_TAG_MACRO), "jsp:expression", null, "<%= %>", XMLRelevanceConstants.R_JSP)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - } - // handle proposals in and around JSP_DIRECTIVE_OPEN and - // JSP_DIRECTIVE_NAME - else if ((completionRegion.getType() == XMLJSPRegionContexts.JSP_DIRECTIVE_OPEN && documentPosition >= sdRegion.getTextEndOffset(completionRegion)) || (completionRegion.getType() == XMLJSPRegionContexts.JSP_DIRECTIVE_NAME && documentPosition <= sdRegion.getTextEndOffset(completionRegion))) { - if (completionRegion.getType() == XMLJSPRegionContexts.JSP_DIRECTIVE_OPEN) { - if (request == null) - request = newContentAssistRequest(xmlnode, xmlnode, sdRegion, completionRegion, documentPosition, 0, matchString); - Iterator regions = sdRegion.getRegions().iterator(); - String nameString = null; - int begin = request.getReplacementBeginPosition(); - int length = request.getReplacementLength(); - while (regions.hasNext()) { - ITextRegion region = (ITextRegion) regions.next(); - if (region.getType() == XMLJSPRegionContexts.JSP_DIRECTIVE_NAME) { - nameString = sdRegion.getText(region); - begin = sdRegion.getStartOffset(region); - length = region.getTextLength(); - break; - } - } - if (nameString == null) - nameString = ""; //$NON-NLS-1$ - for (int i = 0; i < directiveNames.length; i++) { - if (directiveNames[i].startsWith(nameString) || documentPosition <= begin) - request.addProposal(new CustomCompletionProposal(directiveNames[i], begin, length, directiveNames[i].length(), SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP)); - } - } - else { // by default, JSP_DIRECTIVE_NAME - if (request == null) - request = newContentAssistRequest(xmlnode, xmlnode, sdRegion, completionRegion, sdRegion.getStartOffset(completionRegion), completionRegion.getTextLength(), matchString); - for (int i = 0; i < directiveNames.length; i++) { - if (directiveNames[i].startsWith(matchString)) - request.addProposal(new CustomCompletionProposal(directiveNames[i], request.getReplacementBeginPosition(), request.getReplacementLength(), directiveNames[i].length(), SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP)); - } - } - } - else if ((completionRegion.getType() == XMLJSPRegionContexts.JSP_DIRECTIVE_NAME && documentPosition > sdRegion.getTextEndOffset(completionRegion)) || (completionRegion.getType() == XMLJSPRegionContexts.JSP_DIRECTIVE_CLOSE && documentPosition <= sdRegion.getStartOffset(completionRegion))) { - if (request == null) - request = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - super.addTagCloseProposals(request); - // CMVC 274033, this is being added for all <jsp:* tags - // in addAttributeNameProposals(contentAssistRequest) - //super.addAttributeNameProposals(request); - } - // no name?: <%@ %> - else if (completionRegion.getType() == XMLJSPRegionContexts.JSP_DIRECTIVE_CLOSE && documentPosition <= sdRegion.getStartOffset(completionRegion)) { - if (request != null) - request = computeAttributeProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - Iterator regions = sdRegion.getRegions().iterator(); - String nameString = null; - while (regions.hasNext()) { - ITextRegion region = (ITextRegion) regions.next(); - if (region.getType() == XMLJSPRegionContexts.JSP_DIRECTIVE_NAME) { - nameString = sdRegion.getText(region); - break; - } - } - if (nameString == null) { - for (int i = 0; i < directiveNames.length; i++) { - request.addProposal(new CustomCompletionProposal(directiveNames[i], request.getReplacementBeginPosition(), request.getReplacementLength(), directiveNames[i].length(), SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_TAG_GENERIC), directiveNames[i], null, null, XMLRelevanceConstants.R_JSP)); - } - } - } - return request; - } - - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.xml.contentassist.AbstractContentAssistProcessor#getTemplateCompletionProcessor() - */ - protected AbstractTemplateCompletionProcessor getTemplateCompletionProcessor() { - if (fTemplateProcessor == null) { - fTemplateProcessor = new JSPTemplateCompletionProcessor(); - } - return fTemplateProcessor; - } - - /** - * @see com.ibm.sed.contentassist.old.xml.AbstractContentAssistProcessor#addEntityProposals(ContentAssistRequest, - * int, ITextRegion, XMLNode) - */ - protected void addEntityProposals(ContentAssistRequest contentAssistRequest, int documentPosition, ITextRegion completionRegion, XMLNode treeNode) { - } - - /** - * @see com.ibm.sed.contentassist.old.xml.AbstractContentAssistProcessor#addTagInsertionProposals(ContentAssistRequest, - * int) - */ - protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition) { - super.addTagInsertionProposals(contentAssistRequest, childPosition); - if (isInternalAdapter) - useEmbeddedResults = false; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPDummyContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPDummyContentAssistProcessor.java deleted file mode 100644 index 4b2f9be710..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPDummyContentAssistProcessor.java +++ /dev/null @@ -1,489 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - - - -import java.util.List; -import java.util.Properties; -import java.util.Vector; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; -import org.eclipse.wst.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMContent; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.CMNamedNodeMap; -import org.eclipse.wst.common.contentmodel.CMNode; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.ui.contentassist.IResourceDependentProcessor; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.ui.contentassist.AbstractContentAssistProcessor; -import org.eclipse.wst.xml.ui.contentassist.ContentAssistRequest; -import org.eclipse.wst.xml.ui.contentassist.XMLContentModelGenerator; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * @author pavery - * - * This class is a "null" version of AbstractContentAssistProcessor - */ -public class JSPDummyContentAssistProcessor extends AbstractContentAssistProcessor implements IResourceDependentProcessor { - - IResource fResource = null; - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addAttributeNameProposals(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest) - */ - protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest) { - super.addAttributeNameProposals(contentAssistRequest); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addAttributeValueProposals(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest) - */ - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - super.addAttributeValueProposals(contentAssistRequest); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addCommentProposal(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest) - */ - protected void addCommentProposal(ContentAssistRequest contentAssistRequest) { - super.addCommentProposal(contentAssistRequest); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addContent(java.util.List, org.eclipse.wst.common.contentmodel.CMContent) - */ - protected void addContent(List contentList, CMContent content) { - super.addContent(contentList, content); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addDocTypeProposal(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest) - */ - protected void addDocTypeProposal(ContentAssistRequest contentAssistRequest) { - super.addDocTypeProposal(contentAssistRequest); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addEmptyDocumentProposals(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest) - */ - protected void addEmptyDocumentProposals(ContentAssistRequest contentAssistRequest) { - super.addEmptyDocumentProposals(contentAssistRequest); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addEndTagNameProposals(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest) - */ - protected void addEndTagNameProposals(ContentAssistRequest contentAssistRequest) { - super.addEndTagNameProposals(contentAssistRequest); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addEndTagProposals(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest) - */ - protected void addEndTagProposals(ContentAssistRequest contentAssistRequest) { - super.addEndTagProposals(contentAssistRequest); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addEntityProposals(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest, int, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode) - */ - protected void addEntityProposals(ContentAssistRequest contentAssistRequest, int documentPosition, ITextRegion completionRegion, XMLNode treeNode) { - super.addEntityProposals(contentAssistRequest, documentPosition, completionRegion, treeNode); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addEntityProposals(java.util.Vector, java.util.Properties, java.lang.String, int, com.ibm.sed.structuredDocument.ITextRegion) - */ - protected void addEntityProposals(Vector proposals, Properties map, String key, int nodeOffset, IStructuredDocumentRegion parent, ITextRegion completionRegion) { - super.addEntityProposals(proposals, map, key, nodeOffset, parent, completionRegion); - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.xml.contentassist.AbstractContentAssistProcessor#addTemplates(com.ibm.sse.editor.xml.contentassist.ContentAssistRequest, java.lang.String) - */ - protected void addTemplates(ContentAssistRequest contentAssistRequest, String context) { - super.addTemplates(contentAssistRequest, context); - } - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addPCDATAProposal(java.lang.String, com.ibm.sed.structured.contentassist.xml.ContentAssistRequest) - */ - protected void addPCDATAProposal(String nodeName, ContentAssistRequest contentAssistRequest) { - super.addPCDATAProposal(nodeName, contentAssistRequest); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addStartDocumentProposals(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest) - */ - protected void addStartDocumentProposals(ContentAssistRequest contentAssistRequest) { - super.addStartDocumentProposals(contentAssistRequest); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addTagCloseProposals(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest) - */ - protected void addTagCloseProposals(ContentAssistRequest contentAssistRequest) { - super.addTagCloseProposals(contentAssistRequest); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addTagInsertionProposals(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest, int) - */ - protected void addTagInsertionProposals(ContentAssistRequest contentAssistRequest, int childPosition) { - super.addTagInsertionProposals(contentAssistRequest, childPosition); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addTagNameProposals(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest, int) - */ - protected void addTagNameProposals(ContentAssistRequest contentAssistRequest, int childPosition) { - super.addTagNameProposals(contentAssistRequest, childPosition); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#addXMLProposal(com.ibm.sed.structured.contentassist.xml.ContentAssistRequest) - */ - protected void addXMLProposal(ContentAssistRequest contentAssistRequest) { - super.addXMLProposal(contentAssistRequest); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#attributeInList(com.ibm.sed.model.xml.XMLNode, org.w3c.dom.Node, org.eclipse.wst.common.contentmodel.CMNode) - */ - protected boolean attributeInList(XMLNode node, Node parent, CMNode cmnode) { - return super.attributeInList(node, parent, cmnode); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#beginsWith(java.lang.String, java.lang.String) - */ - protected boolean beginsWith(String aString, String prefix) { - return super.beginsWith(aString, prefix); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#computeAttributeProposals(int, java.lang.String, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode, com.ibm.sed.model.xml.XMLNode) - */ - protected ContentAssistRequest computeAttributeProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode node) { - return super.computeAttributeProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#computeAttributeValueProposals(int, java.lang.String, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode, com.ibm.sed.model.xml.XMLNode) - */ - protected ContentAssistRequest computeAttributeValueProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode node) { - return super.computeAttributeValueProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#computeCompletionProposals(int, java.lang.String, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode, com.ibm.sed.model.xml.XMLNode) - */ - protected ContentAssistRequest computeCompletionProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode treeNode, XMLNode xmlnode) { - return super.computeCompletionProposals(documentPosition, matchString, completionRegion, treeNode, xmlnode); - } - - /** - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int) - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { - return super.computeCompletionProposals(viewer, documentOffset); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#computeContentProposals(int, java.lang.String, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode, com.ibm.sed.model.xml.XMLNode) - */ - protected ContentAssistRequest computeContentProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode node) { - return super.computeContentProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - /** - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int) - */ - public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) { - return super.computeContextInformation(viewer, documentOffset); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#computeEndTagOpenProposals(int, java.lang.String, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode, com.ibm.sed.model.xml.XMLNode) - */ - protected ContentAssistRequest computeEndTagOpenProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode node) { - return super.computeEndTagOpenProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#computeEntityReferenceProposals(int, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode) - */ - protected ICompletionProposal[] computeEntityReferenceProposals(int documentPosition, ITextRegion completionRegion, XMLNode treeNode) { - return super.computeEntityReferenceProposals(documentPosition, completionRegion, treeNode); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#computeEqualsProposals(int, java.lang.String, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode, com.ibm.sed.model.xml.XMLNode) - */ - protected ContentAssistRequest computeEqualsProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode node) { - return super.computeEqualsProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#computeStartDocumentProposals(int, java.lang.String, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode, com.ibm.sed.model.xml.XMLNode) - */ - protected ContentAssistRequest computeStartDocumentProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode node) { - return super.computeStartDocumentProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#computeTagCloseProposals(int, java.lang.String, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode, com.ibm.sed.model.xml.XMLNode) - */ - protected ContentAssistRequest computeTagCloseProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode node) { - return super.computeTagCloseProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#computeTagNameProposals(int, java.lang.String, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode, com.ibm.sed.model.xml.XMLNode) - */ - protected ContentAssistRequest computeTagNameProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode node) { - return super.computeTagNameProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#computeTagOpenProposals(int, java.lang.String, com.ibm.sed.structuredDocument.ITextRegion, com.ibm.sed.model.xml.XMLNode, com.ibm.sed.model.xml.XMLNode) - */ - protected ContentAssistRequest computeTagOpenProposals(int documentPosition, String matchString, ITextRegion completionRegion, XMLNode nodeAtOffset, XMLNode node) { - return super.computeTagOpenProposals(documentPosition, matchString, completionRegion, nodeAtOffset, node); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getAdditionalInfo(org.eclipse.wst.common.contentmodel.CMNode, org.eclipse.wst.common.contentmodel.CMNode) - */ - protected String getAdditionalInfo(CMNode parentOrOwner, CMNode cmnode) { - return super.getAdditionalInfo(parentOrOwner, cmnode); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getAvailableChildrenAtIndex(org.w3c.dom.Element, int) - */ - protected List getAvailableChildrenAtIndex(Element parent, int index) { - return super.getAvailableChildrenAtIndex(parent, index); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getAvailableRootChildren(org.w3c.dom.Document, int) - */ - protected List getAvailableRootChildren(Document document, int childIndex) { - return super.getAvailableRootChildren(document, childIndex); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getCMElementDeclaration(org.w3c.dom.Node) - */ - protected CMElementDeclaration getCMElementDeclaration(Node node) { - return super.getCMElementDeclaration(node); - } - - /** - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() - */ - public char[] getCompletionProposalAutoActivationCharacters() { - return super.getCompletionProposalAutoActivationCharacters(); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getCompletionRegion(int, com.ibm.sed.structuredDocument.core.IStructuredDocumentRegion) - */ - protected ITextRegion getCompletionRegion(int offset, IStructuredDocumentRegion flatNode) { - return super.getCompletionRegion(offset, flatNode); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getCompletionRegion(int, org.w3c.dom.Node) - */ - protected ITextRegion getCompletionRegion(int documentPosition, Node domnode) { - return super.getCompletionRegion(documentPosition, domnode); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getContentGenerator() - */ - public XMLContentModelGenerator getContentGenerator() { - return super.getContentGenerator(); - } - - /** - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters() - */ - public char[] getContextInformationAutoActivationCharacters() { - return super.getContextInformationAutoActivationCharacters(); - } - - /** - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator() - */ - public IContextInformationValidator getContextInformationValidator() { - return super.getContextInformationValidator(); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getElementPosition(org.w3c.dom.Node) - */ - protected int getElementPosition(Node child) { - return super.getElementPosition(child); - } - - /** - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage() - */ - public String getErrorMessage() { - return super.getErrorMessage(); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getMatchString(com.ibm.sed.structuredDocument.ITextRegion, int) - */ - protected String getMatchString(IStructuredDocumentRegion parent, ITextRegion aRegion, int offset) { - return super.getMatchString(parent, aRegion, offset); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getNameRegion(com.ibm.sed.structuredDocument.IStructuredDocumentRegion) - */ - protected ITextRegion getNameRegion(IStructuredDocumentRegion flatNode) { - return super.getNameRegion(flatNode); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getPossibleDataTypeValues(org.w3c.dom.Node, org.eclipse.wst.common.contentmodel.CMAttributeDeclaration) - */ - protected List getPossibleDataTypeValues(Node node, CMAttributeDeclaration ad) { - return super.getPossibleDataTypeValues(node, ad); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getRequiredName(org.w3c.dom.Node, org.eclipse.wst.common.contentmodel.CMNode) - */ - protected String getRequiredName(Node parentOrOwner, CMNode cmnode) { - return super.getRequiredName(parentOrOwner, cmnode); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getRequiredText(org.w3c.dom.Node, org.eclipse.wst.common.contentmodel.CMAttributeDeclaration) - */ - protected String getRequiredText(Node parentOrOwner, CMAttributeDeclaration attrDecl) { - return super.getRequiredText(parentOrOwner, attrDecl); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getRequiredText(org.w3c.dom.Node, org.eclipse.wst.common.contentmodel.CMElementDeclaration) - */ - protected String getRequiredText(Node parentOrOwner, CMElementDeclaration elementDecl) { - return super.getRequiredText(parentOrOwner, elementDecl); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#getValidCMNodes(int, int, java.util.List) - */ - protected List getValidCMNodes(int childPosition, int kindOfAction, List modelQueryActions) { - return super.getValidCMNodes(childPosition, kindOfAction, modelQueryActions); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#init() - */ - protected void init() { - super.init(); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#initialize(org.eclipse.core.resources.IResource) - */ - public void initialize(IResource iResource) { - fResource = iResource; - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#isCloseRegion(com.ibm.sed.structuredDocument.ITextRegion) - */ - protected boolean isCloseRegion(ITextRegion region) { - return super.isCloseRegion(region); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#isNameRegion(com.ibm.sed.structuredDocument.ITextRegion) - */ - protected boolean isNameRegion(ITextRegion region) { - return super.isNameRegion(region); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#isQuote(java.lang.String) - */ - protected boolean isQuote(String string) { - return super.isQuote(string); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#mapToProperties(org.eclipse.wst.common.contentmodel.CMNamedNodeMap) - */ - protected Properties mapToProperties(CMNamedNodeMap map) { - return super.mapToProperties(map); - } - - // /** - // * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#newContentAssistRequest(org.w3c.dom.Node, org.w3c.dom.Node, com.ibm.sed.structuredDocument.ITextRegion, int, int, java.lang.String) - // */ - // protected ContentAssistRequest newContentAssistRequest(Node node, Node possibleParent, ITextRegion completionRegion, int begin, int length, String filter) { - // return super.newContentAssistRequest(node, possibleParent, completionRegion, begin, length, filter); - // } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#release() - */ - public void release() { - super.release(); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#setErrorMessage(java.lang.String, java.lang.String, java.lang.String) - */ - protected void setErrorMessage(String errorMessage, String prepend, String append) { - super.setErrorMessage(errorMessage, prepend, append); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#setErrorMessage(java.lang.String, java.lang.String) - */ - protected void setErrorMessage(String errorMessage, String append) { - super.setErrorMessage(errorMessage, append); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#setErrorMessage(java.lang.String) - */ - public void setErrorMessage(String errorMessage) { - super.setErrorMessage(errorMessage); - } - - /** - * @see com.ibm.sed.structured.contentassist.xml.AbstractContentAssistProcessor#stringsEqual(java.lang.String, java.lang.String) - */ - protected boolean stringsEqual(String a, String b) { - return super.stringsEqual(a, b); - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPJavaContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPJavaContentAssistProcessor.java deleted file mode 100644 index 228c937498..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPJavaContentAssistProcessor.java +++ /dev/null @@ -1,332 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.text.IDocumentPartitioner; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; -import org.eclipse.jst.jsp.core.internal.text.rules.StructuredTextPartitionerForJSP; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.sse.ui.IReleasable; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.contentassist.IResourceDependentProcessor; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.contentassist.ContentAssistUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.ui.contentassist.XMLRelevanceConstants; -import org.eclipse.wst.xml.ui.util.SharedXMLEditorPluginImageHelper; - -public class JSPJavaContentAssistProcessor implements IContentAssistProcessor, IResourceDependentProcessor, IReleasable { - protected IResource fResource; - protected char completionProposalAutoActivationCharacters[] = new char[]{'.'}; - protected char contextInformationAutoActivationCharacters[] = null; - protected static final String UNKNOWN_CONTEXT = SSEUIPlugin.getResourceString("%Content_Assist_not_availab_UI_"); //$NON-NLS-1$ = "Content Assist not available at the current location " - protected String fErrorMessage = null; - private JSPCompletionProcessor fJspCompletionProcessor = null; - - public JSPJavaContentAssistProcessor() { - super(); - } - - public JSPJavaContentAssistProcessor(IResource file) { - super(); - fResource = file; - } - - public static void main(String[] args) { - JSPJavaContentAssistProcessor instance = new JSPJavaContentAssistProcessor(); - // unit test for 'reverse' function - instance._unitTest0(); - instance._unitTestNormal1(); - instance._unitTestNormal2(); - instance._unitTestNormal3(); - instance._unitTestNormal4(); - instance._unitTestNormal5(); - } - - private void _printList(Object[] list) { - for (int i = 0; i < list.length; i++) { - System.out.print(list[i] + " "); //$NON-NLS-1$ - } - System.out.println(); - - } - - private void _unitTest0() { - Object[] listOfObjects = new Object[0]; - _printList(listOfObjects); - reverse(listOfObjects); - _printList(listOfObjects); - } - - private void _unitTestNormal1() { - Object[] listOfObjects = new Object[1]; - listOfObjects[0] = "one"; //$NON-NLS-1$ - _printList(listOfObjects); - reverse(listOfObjects); - _printList(listOfObjects); - } - - private void _unitTestNormal2() { - Object[] listOfObjects = new Object[2]; - listOfObjects[0] = "one"; //$NON-NLS-1$ - listOfObjects[1] = "two"; //$NON-NLS-1$ - _printList(listOfObjects); - reverse(listOfObjects); - _printList(listOfObjects); - } - - private void _unitTestNormal3() { - Object[] listOfObjects = new Object[3]; - listOfObjects[0] = "one"; //$NON-NLS-1$ - listOfObjects[1] = "two"; //$NON-NLS-1$ - listOfObjects[2] = "three"; //$NON-NLS-1$ - _printList(listOfObjects); - reverse(listOfObjects); - _printList(listOfObjects); - } - - private void _unitTestNormal4() { - Object[] listOfObjects = new Object[4]; - listOfObjects[0] = "one"; //$NON-NLS-1$ - listOfObjects[1] = "two"; //$NON-NLS-1$ - listOfObjects[2] = "three"; //$NON-NLS-1$ - listOfObjects[3] = "four"; //$NON-NLS-1$ - _printList(listOfObjects); - reverse(listOfObjects); - _printList(listOfObjects); - } - - private void _unitTestNormal5() { - Object[] listOfObjects = new Object[5]; - listOfObjects[0] = "one"; //$NON-NLS-1$ - listOfObjects[1] = "two"; //$NON-NLS-1$ - listOfObjects[2] = "three"; //$NON-NLS-1$ - listOfObjects[3] = "four"; //$NON-NLS-1$ - listOfObjects[4] = "five"; //$NON-NLS-1$ - _printList(listOfObjects); - reverse(listOfObjects); - _printList(listOfObjects); - } - - /** - * Return a list of proposed code completions based on the - * specified location within the document that corresponds - * to the current cursor position within the text-editor control. - * - * @param documentPosition a location within the document - * @return an array of code-assist items - */ - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentPosition) { - - IndexedRegion treeNode = ContentAssistUtils.getNodeAt((StructuredTextViewer) viewer, documentPosition); - - // get results from JSP completion processor - fJspCompletionProcessor = getJspCompletionProcessor(); - ICompletionProposal[] results = fJspCompletionProcessor.computeCompletionProposals(viewer, documentPosition); - fErrorMessage = fJspCompletionProcessor.getErrorMessage(); - if (results.length == 0 && (fErrorMessage == null || fErrorMessage.length() == 0)) { - fErrorMessage = UNKNOWN_CONTEXT; - } - - XMLNode xNode = null; - IStructuredDocumentRegion flat = null; - if (treeNode instanceof XMLNode) { - xNode = (XMLNode) treeNode; - flat = xNode.getFirstStructuredDocumentRegion(); - if (flat != null && flat.getType() == XMLJSPRegionContexts.JSP_CONTENT) { - flat = flat.getPrevious(); - } - } - - // this is in case it's a <%@, it will be a region container... - ITextRegion openRegion = null; - if (flat != null && flat instanceof ITextRegionContainer) { - ITextRegionList v = ((ITextRegionContainer) flat).getRegions(); - if (v.size() > 0) - openRegion = v.get(0); - } - - // ADD CDATA PROPOSAL IF IT'S AN XML-JSP TAG - if (flat != null && flat.getType() != XMLJSPRegionContexts.JSP_SCRIPTLET_OPEN && flat.getType() != XMLJSPRegionContexts.JSP_DECLARATION_OPEN && flat.getType() != XMLJSPRegionContexts.JSP_EXPRESSION_OPEN && flat.getType() != XMLRegionContext.BLOCK_TEXT && (openRegion != null && openRegion.getType() != XMLJSPRegionContexts.JSP_DIRECTIVE_OPEN) && !inAttributeRegion(flat, documentPosition)) { - - // determine if cursor is before or after selected range - int adjustedDocPosition = documentPosition; - int realCaretPosition = viewer.getTextWidget().getCaretOffset(); - int selectionLength = viewer.getSelectedRange().y; - if (documentPosition > realCaretPosition) { - adjustedDocPosition -= selectionLength; - } - - CustomCompletionProposal cdataProposal = createCDATAProposal(adjustedDocPosition, selectionLength); - ICompletionProposal[] newResults = new ICompletionProposal[results.length + 1]; - System.arraycopy(results, 0, newResults, 0, results.length); - newResults[results.length] = cdataProposal; - results = newResults; - } - - // (pa) ** this is code in progress... - // add ending %> proposal for non closed JSP tags - // String tagText = flat.getText(); - // // TODO need a much better compare (using constants?) - // if(tagText.equals("<%") || tagText.equals("<%=") || tagText.equals("<%!")); - // { - // ICompletionProposal testah = ContentAssistUtils.computeJSPEndTagProposal(viewer,documentPosition, treeNode, "<%" , SharedXMLEditorPluginImageHelper.IMG_OBJ_TAG_GENERIC); - // if(testah != null) - // { - // ICompletionProposal[] newResults = new ICompletionProposal[results.length + 1]; - // System.arraycopy( results, 0, newResults, 0, results.length); - // newResults[results.length] = testah; - // results = newResults; - // } - // } - - reverse(results); // so variables show up first - return results; - } - - // reverses an array of objects - public void reverse(Object[] array) { - Object temp = null; - //DMW: 8/16/2002 this was <=, but was thrown out of bounds occasionally - for (int i = 0; i < (array.length / 2); i++) { - temp = array[i]; - array[i] = array[(array.length - 1) - i]; - array[(array.length - 1) - i] = temp; - } - } - - private CustomCompletionProposal createCDATAProposal(int adjustedDocPosition, int selectionLength) { - return new CustomCompletionProposal("<![CDATA[]]>", //$NON-NLS-1$ - adjustedDocPosition, selectionLength, // should be the selection length - 9, SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_CDATASECTION), - "CDATA Section", //$NON-NLS-1$ - null, null, XMLRelevanceConstants.R_CDATA); - } - - private boolean inAttributeRegion(IStructuredDocumentRegion flat, int documentPosition) { - ITextRegion attrContainer = flat.getRegionAtCharacterOffset(documentPosition); - if (attrContainer != null && attrContainer instanceof ITextRegionContainer) { - if (attrContainer.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - return true; - } - } - return false; - } - - /** - * Returns the characters which when entered by the user should - * automatically trigger the presentation of possible completions. - * - * @return the auto activation characters for completion proposal or <code>null</code> - * if no auto activation is desired - */ - public char[] getCompletionProposalAutoActivationCharacters() { - return completionProposalAutoActivationCharacters; - } - - /** - * Returns the characters which when entered by the user should - * automatically trigger the presentation of context information. - * - * @return the auto activation characters for presenting context information - * or <code>null</code> if no auto activation is desired - */ - public char[] getContextInformationAutoActivationCharacters() { - return contextInformationAutoActivationCharacters; - } - - /** - * Return the reason why computeProposals was not able to find any completions. - * - * @return an error message - * or null if no error occurred - */ - public String getErrorMessage() { - return fErrorMessage; - } - - /** - * @see ContentAssistAdapter#release() - */ - public void release() { - if (fJspCompletionProcessor != null) { - fJspCompletionProcessor.release(); - fJspCompletionProcessor = null; - } - fResource = null; - } - - /** - * @see ContentAssistAdapter#initialize(IResource) - */ - public void initialize(IResource resource) { - fResource = resource; - getJspCompletionProcessor().initialize(resource); - } - - /** - * - */ - private JSPCompletionProcessor getJspCompletionProcessor() { - if (fJspCompletionProcessor == null) { - fJspCompletionProcessor = new JSPCompletionProcessor(fResource); - fJspCompletionProcessor.initialize(fResource); - } - return fJspCompletionProcessor; - } - - /** - * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int) - */ - public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) { - List results = new ArrayList(); - // need to compute context info here, if it's JSP, call java computer - IDocumentPartitioner dp = viewer.getDocument().getDocumentPartitioner(); - String type = dp.getPartition(documentOffset).getType(); - if (type == StructuredTextPartitionerForJSP.ST_DEFAULT_JSP || type == StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA) { - // get context info from completion results... - ICompletionProposal[] proposals = computeCompletionProposals(viewer, documentOffset); - for (int i = 0; i < proposals.length; i++) { - IContextInformation ci = proposals[i].getContextInformation(); - if (ci != null) - results.add(ci); - } - } - return (IContextInformation[]) results.toArray(new IContextInformation[results.size()]); - } - - /** - * Returns a validator used to determine when displayed context information - * should be dismissed. May only return <code>null</code> if the processor is - * incapable of computing context information. - * - * @return a context information validator, or <code>null</code> if the processor - * is incapable of computing context information - */ - public IContextInformationValidator getContextInformationValidator() { - return new JavaParameterListValidator(); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPPropertyContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPPropertyContentAssistProcessor.java deleted file mode 100644 index 1aea12ded8..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPPropertyContentAssistProcessor.java +++ /dev/null @@ -1,227 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - - - -import org.eclipse.core.resources.IResource; -import org.eclipse.jst.jsp.core.JSP11Namespace; -import org.eclipse.jst.jsp.ui.contentassist.BeanInfoProvider; -import org.eclipse.jst.jsp.ui.contentassist.IBeanInfoProvider; -import org.eclipse.jst.jsp.ui.contentassist.IJavaPropertyDescriptor; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.sse.core.util.StringUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.ui.contentassist.ContentAssistRequest; -import org.eclipse.wst.xml.ui.contentassist.XMLRelevanceConstants; -import org.eclipse.wst.xml.ui.util.SharedXMLEditorPluginImageHelper; -import org.w3c.dom.Element; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * This class computes attribute value completion proposals for <jsp:[gs]etProperty> tags. - * - */ -public class JSPPropertyContentAssistProcessor extends JSPDummyContentAssistProcessor { - - IBeanInfoProvider provider = null; - protected IResource resource = null; - - public JSPPropertyContentAssistProcessor() { - super(); - } - - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - XMLNode node = (XMLNode) contentAssistRequest.getNode(); - - // Find the attribute name for which this position should have a value - IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion(); - ITextRegionList openRegions = open.getRegions(); - int i = openRegions.indexOf(contentAssistRequest.getRegion()); - if (i < 0) - return; - - // get the attribute in question (first attr name to the left of the cursor) - ITextRegion attrNameRegion = null; - String attributeName = null; - while (i >= 0) { - attrNameRegion = openRegions.get(i--); - if (attrNameRegion.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) - break; - } - if (attrNameRegion != null) - attributeName = open.getText(attrNameRegion); - - // determine get or set - ITextRegion tagNameRegion = null; - boolean isGetProperty = true; - for (int j = 0; j < openRegions.size(); j++) { - tagNameRegion = openRegions.get(j); - if (tagNameRegion.getType() == XMLRegionContext.XML_TAG_NAME && open.getText(tagNameRegion).trim().equals("jsp:setProperty")) { //$NON-NLS-1$ - isGetProperty = false; - break; - } - } - - String currentValue = null; - if (contentAssistRequest.getRegion().getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) - currentValue = contentAssistRequest.getText(); - else - currentValue = ""; //$NON-NLS-1$ - String matchString = null; - // fixups since the matchString computations don't care if there are quotes around the value - if (currentValue.length() > StringUtils.strip(currentValue).length() && (currentValue.startsWith("\"") || currentValue.startsWith("'")) && contentAssistRequest.getMatchString().length() > 0) //$NON-NLS-1$ //$NON-NLS-2$ - matchString = currentValue.substring(1, contentAssistRequest.getMatchString().length()); - else - matchString = currentValue.substring(0, contentAssistRequest.getMatchString().length()); - - // for now we ignore complicated values such as jsp embedded in an attribute - boolean existingComplicatedValue = contentAssistRequest.getRegion() != null && contentAssistRequest.getRegion() instanceof ITextRegionContainer; - if (existingComplicatedValue) { - contentAssistRequest.getProposals().clear(); - contentAssistRequest.getMacros().clear(); - } - else { - if (attributeName.equals(JSP11Namespace.ATTR_NAME_NAME)) { - addBeanNameProposals(contentAssistRequest, node, matchString); - } - else if (attributeName.equals(JSP11Namespace.ATTR_NAME_PROPERTY)) { - addBeanPropertyProposals(contentAssistRequest, node, isGetProperty, matchString); - } - } - } - - private void addBeanPropertyProposals(ContentAssistRequest contentAssistRequest, XMLNode node, boolean isGetProperty, String matchString) { - // assumes that the node is the [gs]etProperty tag - String useBeanName = ((Element) node).getAttribute(JSP11Namespace.ATTR_NAME_NAME); - // properties can only be provided if a class/type/beanName has been declared - if (useBeanName != null && useBeanName.length() > 0) { - NodeList useBeans = node.getOwnerDocument().getElementsByTagName(JSP11Namespace.ElementName.USEBEAN); - if (useBeans != null) { - String typeName = null; - for (int j = 0; j < useBeans.getLength(); j++) { - if (useBeans.item(j).getNodeType() != Node.ELEMENT_NODE) - continue; - Element useBean = (Element) useBeans.item(j); - if (useBean instanceof IndexedRegion && ((IndexedRegion) useBean).getStartOffset() < node.getStartOffset()) { - if (useBean.getAttribute(JSP11Namespace.ATTR_NAME_ID).equals(useBeanName)) { - typeName = useBean.getAttribute(JSP11Namespace.ATTR_NAME_CLASS); - if (typeName == null || typeName.length() < 1) { - typeName = useBean.getAttribute(JSP11Namespace.ATTR_NAME_TYPE); - } - if (typeName == null || typeName.length() < 1) { - typeName = useBean.getAttribute(JSP11Namespace.ATTR_NAME_BEAN_NAME); - } - } - } - } - if (typeName != null && typeName.length() > 0) { - // find the class/type/beanName definition and obtain the list of properties - BeanInfoProvider provider = new BeanInfoProvider(); - IJavaPropertyDescriptor[] descriptors = provider.getRuntimeProperties(resource, typeName); - CustomCompletionProposal proposal = null; - String displayString = ""; //$NON-NLS-1$ - for (int j = 0; j < descriptors.length; j++) { - IJavaPropertyDescriptor pd = descriptors[j]; - // check whether it's get or set kinda property - if (pd.getReadable() && isGetProperty || pd.getWriteable() && !isGetProperty) { - // filter attr value name - if (matchString.length() == 0 || pd.getName().toLowerCase().startsWith(matchString.toLowerCase())) { - displayString = pd.getDisplayName(); - if (pd.getDeclaredType() != null && pd.getDeclaredType().length() > 0) - displayString += " - " + pd.getDeclaredType(); //$NON-NLS-1$ - proposal = new CustomCompletionProposal("\"" + pd.getName() + "\"", //$NON-NLS-1$ //$NON-NLS-2$ - contentAssistRequest.getReplacementBeginPosition(), contentAssistRequest.getReplacementLength(), pd.getName().length() + 2, SharedXMLEditorPluginImageHelper.getImage(SharedXMLEditorPluginImageHelper.IMG_OBJ_ATTRIBUTE), - displayString, null, pd.getDeclaredType(), XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - } - } - } - } - } - } - } - - private void addBeanNameProposals(ContentAssistRequest contentAssistRequest, XMLNode node, String matchString) { - // will not catch useBeans specified using other than actual DOM Nodes - NodeList useBeans = node.getOwnerDocument().getElementsByTagName(JSP11Namespace.ElementName.USEBEAN); - if (useBeans != null) { - String id = ""; //$NON-NLS-1$ - String displayString = null; - String classOrType = null; - String imageName = JSPEditorPluginImages.IMG_OBJ_CLASS_OBJ; - for (int j = 0; j < useBeans.getLength(); j++) { - if (useBeans.item(j).getNodeType() != Node.ELEMENT_NODE) - continue; - Element useBean = (Element) useBeans.item(j); - if (useBean instanceof IndexedRegion && ((IndexedRegion) useBean).getStartOffset() < node.getStartOffset()) { - id = StringUtils.strip(useBean.getAttribute(JSP11Namespace.ATTR_NAME_ID)); - displayString = null; - classOrType = null; - imageName = JSPEditorPluginImages.IMG_OBJ_CLASS_OBJ; - // set the Image based on whether the class, type, or beanName attribute is present - classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_CLASS); - if (classOrType == null || classOrType.length() < 1) { - classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_TYPE); - imageName = JSPEditorPluginImages.IMG_OBJ_PUBLIC; - } - if (classOrType == null || classOrType.length() < 1) { - classOrType = useBean.getAttribute(JSP11Namespace.ATTR_NAME_BEAN_NAME); - imageName = JSPEditorPluginImages.IMG_OBJ_PUBLIC; - } - if (classOrType != null && classOrType.length() > 0) - displayString = id + " - " + classOrType; //$NON-NLS-1$ - else - displayString = id; - - // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=2341 - if(id != null) { - // filter - if (matchString.length() == 0 || id.startsWith(matchString)) { - CustomCompletionProposal proposal = new CustomCompletionProposal("\"" + id + "\"", //$NON-NLS-1$ //$NON-NLS-2$ - contentAssistRequest.getReplacementBeginPosition(), - contentAssistRequest.getReplacementLength(), - id.length() + 2, - JSPEditorPluginImageHelper.getInstance().getImage(imageName), - displayString, - null, - null, - XMLRelevanceConstants.R_XML_ATTRIBUTE_VALUE); - contentAssistRequest.addProposal(proposal); - } - } - } - } - } - } - - public void release() { - resource = null; - provider = null; - } - - /** - * @see com.ibm.sed.structured.contentassist.IContentAssistProcessor#initialize(org.eclipse.core.resources.IResource) - */ - public void initialize(IResource iResource) { - this.resource = iResource; - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPResultCollector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPResultCollector.java deleted file mode 100644 index d1b2d4045d..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPResultCollector.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import java.util.Arrays; - -import org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal; -import org.eclipse.jdt.internal.ui.text.java.ResultCollector; - -/** - * - * @author pavery - * @deprecated getting rid of JDT internal. Use JSPCompletionRequestor - */ -public class JSPResultCollector extends ResultCollector { - - int fJavaToJSPOffset; - boolean doFilter = false; - - char[] translatorInternalIgnoreClass = "JspWriter".toCharArray(); //$NON-NLS-1$ - char[] translatorInternalIgnorePackage = "javax.servlet.jsp".toCharArray(); //$NON-NLS-1$ - String translatorInternalIgnoreMethodstarter = "print"; //$NON-NLS-1$ - - public int getJavaToJSPOffset() { - return fJavaToJSPOffset; - } - - /** - * @param newJavaToJSPOffset int - */ - public void setJavaToJSPOffset(int newJavaToJSPOffset) { - fJavaToJSPOffset = newJavaToJSPOffset; - } - - public JavaCompletionProposal[] getResults() { - JavaCompletionProposal[] javaDocumentResults = super.getResults(); - for (int i = 0; i < javaDocumentResults.length; i++) - javaDocumentResults[i].setReplacementOffset(javaDocumentResults[i].getReplacementOffset() + fJavaToJSPOffset); - return javaDocumentResults; - } - - /** - * @see org.eclipse.jdt.core.ICompletionRequestor#acceptMethod(char[], char[], char[], char[][], char[][], char[][], char[], char[], char[], int, int, int, int) - */ - public void acceptMethod(char[] declaringTypePackageName, char[] declaringTypeName, char[] selector, char[][] parameterPackageNames, char[][] parameterTypeNames, char[][] parameterNames, char[] returnTypePackageName, char[] returnTypeName, char[] completionName, int modifiers, int completionStart, int completionEnd, int relevance) { - // if this method is the exact package and type name and starts with the same method name, don't suggest it - if (!doFilter || !(Arrays.equals(translatorInternalIgnorePackage, declaringTypePackageName) && Arrays.equals(translatorInternalIgnoreClass, declaringTypeName) && selector != null && new String(selector).startsWith(translatorInternalIgnoreMethodstarter))) { - //super.acceptMethod(declaringTypePackageName, declaringTypeName, selector, parameterPackageNames, parameterTypeNames, parameterNames, returnTypePackageName, returnTypeName, completionName, modifiers, completionStart, completionEnd, relevance); - } - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTemplateCompletionProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTemplateCompletionProcessor.java deleted file mode 100644 index 9ef3dc0a11..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPTemplateCompletionProcessor.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import org.eclipse.jface.text.templates.ContextTypeRegistry; -import org.eclipse.jface.text.templates.Template; -import org.eclipse.jface.text.templates.persistence.TemplateStore; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImages; -import org.eclipse.jst.jsp.ui.templates.TemplateContextTypeJSP; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.xml.ui.contentassist.AbstractTemplateCompletionProcessor; - -/** - * Completion processor for JSP Templates - */ -public class JSPTemplateCompletionProcessor extends AbstractTemplateCompletionProcessor { - - /* (non-Javadoc) - * @see com.ibm.sse.editor.xml.contentassist.AbstractTemplateCompletionProcessor#getTemplateStore() - */ - protected TemplateStore getTemplateStore() { - return getJSPEditorPlugin().getTemplateStore(); - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.xml.contentassist.AbstractTemplateCompletionProcessor#getTemplateContextRegistry() - */ - protected ContextTypeRegistry getTemplateContextRegistry() { - return getJSPEditorPlugin().getTemplateContextRegistry(); - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.xml.contentassist.AbstractTemplateCompletionProcessor#getContextTypeId() - */ - protected String getContextTypeId() { - // turn the context type id into content type specific - return TemplateContextTypeJSP.generateContextTypeId(super.getContextTypeId()); - } - - /** - * Returns the JSPUIPlugin - * @return JSPUIPlugin - */ - private JSPUIPlugin getJSPEditorPlugin() { - return JSPUIPlugin.getDefault(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.text.templates.TemplateCompletionProcessor#getImage(org.eclipse.jface.text.templates.Template) - */ - protected Image getImage(Template template) { - // just return the same image for now - return JSPEditorPluginImageHelper.getInstance().getImage(JSPEditorPluginImages.IMG_OBJ_TAG_JSP); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPUseBeanContentAssistProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPUseBeanContentAssistProcessor.java deleted file mode 100644 index 6a9bcf6d7a..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JSPUseBeanContentAssistProcessor.java +++ /dev/null @@ -1,125 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - - - -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jst.jsp.core.JSP11Namespace; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionContainer; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.sse.core.util.StringUtils; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.ui.contentassist.ContentAssistRequest; - -public class JSPUseBeanContentAssistProcessor extends JSPDummyContentAssistProcessor { - - public JSPUseBeanContentAssistProcessor() { - super(); - } - - protected void addAttributeValueProposals(ContentAssistRequest contentAssistRequest) { - - XMLNode node = (XMLNode) contentAssistRequest.getNode(); - - // Find the attribute name for which this position should have a value - IStructuredDocumentRegion open = node.getFirstStructuredDocumentRegion(); - ITextRegionList openRegions = open.getRegions(); - int i = openRegions.indexOf(contentAssistRequest.getRegion()); - if (i < 0) - return; - ITextRegion nameRegion = null; - while (i >= 0) { - nameRegion = openRegions.get(i--); - if (nameRegion.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) - break; - } - - String attributeName = null; - if (nameRegion != null) - attributeName = open.getText(nameRegion); - - String currentValue = null; - if (contentAssistRequest.getRegion().getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) - currentValue = contentAssistRequest.getText(); - else - currentValue = ""; //$NON-NLS-1$ - String matchString = null; - // fixups - int start = contentAssistRequest.getReplacementBeginPosition(); - int length = contentAssistRequest.getReplacementLength(); - if (currentValue.length() > StringUtils.strip(currentValue).length() - && (currentValue.startsWith("\"") || currentValue.startsWith("'")) //$NON-NLS-1$ //$NON-NLS-2$ - && contentAssistRequest.getMatchString().length() > 0) { - matchString = currentValue.substring(1, contentAssistRequest.getMatchString().length()); - start++; - length = matchString.length(); - } - else - matchString = currentValue.substring(0, contentAssistRequest.getMatchString().length()); - boolean existingComplicatedValue = contentAssistRequest.getRegion() != null && contentAssistRequest.getRegion() instanceof ITextRegionContainer; - if (existingComplicatedValue) { - contentAssistRequest.getProposals().clear(); - contentAssistRequest.getMacros().clear(); - } - else { - if (attributeName.equals(JSP11Namespace.ATTR_NAME_CLASS)) { - ICompletionProposal[] classProposals = JavaTypeFinder.getClassProposals(fResource, start, length); - if (classProposals != null) { - for (int j = 0; j < classProposals.length; j++) { - JavaTypeCompletionProposal proposal = (JavaTypeCompletionProposal) classProposals[j]; - if (matchString.length() == 0 || proposal.getQualifiedName().toLowerCase().startsWith(matchString.toLowerCase()) || proposal.getShortName().toLowerCase().startsWith(matchString.toLowerCase())) - contentAssistRequest.addProposal(proposal); - } - } - } - else if (attributeName.equals(JSP11Namespace.ATTR_NAME_TYPE)) { - ICompletionProposal[] typeProposals = JavaTypeFinder.getTypeProposals(fResource, start, length); - if (typeProposals != null) { - for (int j = 0; j < typeProposals.length; j++) { - JavaTypeCompletionProposal proposal = (JavaTypeCompletionProposal) typeProposals[j]; - if (matchString.length() == 0 || proposal.getQualifiedName().toLowerCase().startsWith(matchString.toLowerCase()) || proposal.getShortName().toLowerCase().startsWith(matchString.toLowerCase())) - contentAssistRequest.addProposal(proposal); - } - } - } - else if (attributeName.equals(JSP11Namespace.ATTR_NAME_BEAN_NAME)) { - ICompletionProposal[] beanNameProposals = JavaTypeFinder.getBeanProposals(fResource, start, length); - if (beanNameProposals != null) { - for (int j = 0; j < beanNameProposals.length; j++) { - if (beanNameProposals[j] instanceof CustomCompletionProposal) { - JavaTypeCompletionProposal proposal = (JavaTypeCompletionProposal) beanNameProposals[j]; - if (matchString.length() == 0 || proposal.getDisplayString().toLowerCase().startsWith(matchString.toLowerCase())) - contentAssistRequest.addProposal(proposal); - } - else if (beanNameProposals[j] instanceof JavaTypeCompletionProposal) { - JavaTypeCompletionProposal proposal = (JavaTypeCompletionProposal) beanNameProposals[j]; - if (matchString.length() == 0 || proposal.getQualifiedName().toLowerCase().startsWith(matchString.toLowerCase()) || proposal.getShortName().toLowerCase().startsWith(matchString.toLowerCase())) - contentAssistRequest.addProposal(proposal); - } - } - } - } - } - } - - /** - * @see com.ibm.sed.structured.contentassist.IContentAssistProcessorExtension#release() - */ - public void release() { - fResource = null; - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaParameterListValidator.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaParameterListValidator.java deleted file mode 100644 index 07f0182677..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaParameterListValidator.java +++ /dev/null @@ -1,222 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.TextPresentation; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.contentassist.IContextInformationPresenter; -import org.eclipse.jface.text.contentassist.IContextInformationValidator; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyleRange; - - -/** - * - * @author pavery - */ -public class JavaParameterListValidator implements IContextInformationValidator, IContextInformationPresenter { - - private int fPosition; - private ITextViewer fViewer; - private IContextInformation fInformation; - - private int fCurrentParameter; - - - - public JavaParameterListValidator() { - } - - /** - * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int) - * @see IContextInformationPresenter#install(IContextInformation, ITextViewer, int) - */ - public void install(IContextInformation info, ITextViewer viewer, int documentPosition) { - fPosition= documentPosition; - fViewer= viewer; - fInformation= info; - - fCurrentParameter= -1; - } - - private int getCommentEnd(IDocument d, int pos, int end) throws BadLocationException { - while (pos < end) { - char curr= d.getChar(pos); - pos++; - if (curr == '*') { - if (pos < end && d.getChar(pos) == '/') { - return pos + 1; - } - } - } - return end; - } - - private int getStringEnd(IDocument d, int pos, int end, char ch) throws BadLocationException { - while (pos < end) { - char curr= d.getChar(pos); - pos++; - if (curr == '\\') { - // ignore escaped characters - pos++; - } else if (curr == ch) { - return pos; - } - } - return end; - } - - private int getCharCount(IDocument document, int start, int end, char increment, char decrement, boolean considerNesting) throws BadLocationException { - - Assert.isTrue((increment != 0 || decrement != 0) && increment != decrement); - - int nestingLevel= 0; - int charCount= 0; - while (start < end) { - char curr= document.getChar(start++); - switch (curr) { - case '/': - if (start < end) { - char next= document.getChar(start); - if (next == '*') { - // a comment starts, advance to the comment end - start= getCommentEnd(document, start + 1, end); - } else if (next == '/') { - // '//'-comment: nothing to do anymore on this line - start= end; - } - } - break; - case '*': - if (start < end) { - char next= document.getChar(start); - if (next == '/') { - // we have been in a comment: forget what we read before - charCount= 0; - ++ start; - } - } - break; - case '"': - case '\'': - start= getStringEnd(document, start, end, curr); - break; - default: - - if (considerNesting) { - - if ('(' == curr) - ++ nestingLevel; - else if (')' == curr) - -- nestingLevel; - - if (nestingLevel != 0) - break; - } - - if (increment != 0) { - if (curr == increment) - ++ charCount; - } - - if (decrement != 0) { - if (curr == decrement) - -- charCount; - } - } - } - - return charCount; - } - - /** - * @see IContextInformationValidator#isContextInformationValid(int) - */ - public boolean isContextInformationValid(int position) { - - try { - if (position < fPosition) - return false; - - IDocument document= fViewer.getDocument(); - IRegion line= document.getLineInformationOfOffset(fPosition); - - if (position < line.getOffset() || position >= document.getLength()) - return false; - - return (getCharCount(document, fPosition, position, '(', ')', false) >= 0); - - } catch (BadLocationException x) { - return false; - } - } - - /** - * @see IContextInformationPresenter#updatePresentation(int, TextPresentation) - */ - public boolean updatePresentation(int position, TextPresentation presentation) { - - int currentParameter= -1; - - try { - currentParameter= getCharCount(fViewer.getDocument(), fPosition, position, ',', (char) 0, true); - } catch (BadLocationException x) { - return false; - } - - if (fCurrentParameter != -1) { - if (currentParameter == fCurrentParameter) - return false; - } - - presentation.clear(); - fCurrentParameter= currentParameter; - - String s= fInformation.getInformationDisplayString(); - int start= 0; - int occurrences= 0; - while (occurrences < fCurrentParameter) { - int found= s.indexOf(',', start); - if (found == -1) - break; - start= found + 1; - ++ occurrences; - } - - if (occurrences < fCurrentParameter) { - presentation.addStyleRange(new StyleRange(0, s.length(), null, null, SWT.NORMAL)); - return true; - } - - if (start == -1) - start= 0; - - int end= s.indexOf(',', start); - if (end == -1) - end= s.length(); - - if (start > 0) - presentation.addStyleRange(new StyleRange(0, start, null, null, SWT.NORMAL)); - - if (end > start) - presentation.addStyleRange(new StyleRange(start, end - start, null, null, SWT.BOLD)); - - if (end < s.length()) - presentation.addStyleRange(new StyleRange(end, s.length() - end, null, null, SWT.NORMAL)); - - return true; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeCompletionProposal.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeCompletionProposal.java deleted file mode 100644 index 7d5db175a9..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeCompletionProposal.java +++ /dev/null @@ -1,307 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - - - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jst.jsp.core.JSP11Namespace; -import org.eclipse.jst.jsp.core.JSP12Namespace; -import org.eclipse.swt.graphics.Image; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.sse.core.util.StringUtils; -import org.eclipse.wst.sse.ui.contentassist.IRelevanceCompletionProposal; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; - -/** - * An implementation of ICompletionProposal whose values can be - * read after creation. - */ -public class JavaTypeCompletionProposal extends CustomCompletionProposal implements IRelevanceCompletionProposal { - - private int fCursorPosition = 0; - private String fLocalDisplayString; - private String fShortName; - private String fQualifiedName; - private String fContainerName; - - public JavaTypeCompletionProposal(String replacementString, int replacementOffset, int replacementLength, String qualifiedName, Image image, String typeName, String containerName, int relevence, boolean updateReplacementLengthOnValidate) { - super(replacementString, replacementOffset, replacementLength, qualifiedName.length() + 2, image, - (containerName != null && containerName.length() > 0) ? typeName + " - " + containerName : typeName, null, null, relevence, true); //$NON-NLS-1$ - // CMVC 243817, superclass was comparing incorrect display string in validate method... - //super(replacementString, replacementOffset, replacementLength, image, (containerName != null && containerName.length() > 0)? typeName + " - " + containerName:typeName/*qualifiedName*/, relevence); - fShortName = typeName; - fQualifiedName = qualifiedName; - fContainerName = containerName; - fCursorPosition = fQualifiedName.length() + 2; - //fProposalInfo = proposalInfo; - if (containerName != null && containerName.length() > 0) - fLocalDisplayString = typeName + " - " + containerName; //$NON-NLS-1$ - else - fLocalDisplayString = typeName; - } - - public String getDisplayString() { - return fLocalDisplayString; - } - - public int getCursorPosition() { - return fCursorPosition; - } - - public void setCursorPosition(int cursorPosition) { - super.setCursorPosition(cursorPosition); - fCursorPosition = cursorPosition; - } - - public String getQualifiedName() { - return fQualifiedName; - } - - public String getAdditionalProposalInfo() { - // String info = super.getAdditionalProposalInfo(); - // if (info == null || info.length() == 0 && fProposalInfo != null) - // return fProposalInfo.getInfo(); - // return info; - return null; // unexplained NPE - } - - public String getShortName() { - return fShortName; - } - - protected String getImport(IStructuredDocumentRegion flatNode) { - ITextRegionList regions = flatNode.getRegions(); - String importSpec = null; - boolean isImport = false; - for (int i = 0; i < regions.size(); i++) { - ITextRegion region = regions.get(i); - if (region.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) { - if (flatNode.getText(region).equals(JSP11Namespace.ATTR_NAME_IMPORT)) { - isImport = true; - } - else { - isImport = false; - } - } - else if (isImport && region.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - importSpec = flatNode.getText(region); - } - } - return importSpec; - } - - /** - * Add an import page directive for the current type name - */ - protected int applyImport(IStructuredDocument model) { - // if the type is in the default package or java.lang, skip it - if (fContainerName == null || fContainerName.length() == 0 || fContainerName.equals("java.lang")) //$NON-NLS-1$ - return 0; - // collect page directives and store their import values - List imports = new ArrayList(); - IStructuredDocumentRegion node = model.getFirstStructuredDocumentRegion(); - - // use the last position of a page directive as a hint as to where to add - // a new one - int hint = 0; - // watch for jsp:root so that we use the right XML/JSP format for the directive - boolean useXML = false; - - while (node != null) { - // Can't just look for all StructuredDocumentRegions starting with JSP_DIRECTIVE_OPEN - // since the XML form is required, too - ITextRegionList regions = node.getRegions(); - if (regions.size() > 1) { - ITextRegion name = regions.get(1); - // verify that this is a JSP directive - if (name.getType() == XMLJSPRegionContexts.JSP_DIRECTIVE_NAME) { - // verify that this is a *page* directive - if (node.getText(name).equals(JSP11Namespace.ATTR_NAME_PAGE) || node.getText(name).equals(JSP12Namespace.ElementName.DIRECTIVE_PAGE)) { - if (node.getEndOffset() < getReplacementOffset()) - hint = node.getEndOffset(); - String importSpec = getImport(node); - if (importSpec != null) { - imports.add(importSpec); - } - } - } - else { - // if this is a jsp:root tag, use the XML form - useXML = useXML || name.getType() == XMLJSPRegionContexts.JSP_ROOT_TAG_NAME; - } - } - node = node.getNext(); - } - - // evaluate requirements for a "new" import directive - boolean needsImport = !importHandles(fQualifiedName, imports); - int adjustmentLength = 0; - // insert "new" import directive - if (needsImport) { - String directive = null; - - // vary the XML behavior - if (useXML) { - directive = "<jsp:directive.page import=\"" + fQualifiedName + "\"/>"; //$NON-NLS-1$ //$NON-NLS-2$ - } - else { - directive = "<%@ page import=\"" + fQualifiedName + "\" %>"; //$NON-NLS-1$ //$NON-NLS-2$ - } - - try { - IRegion line = model.getLineInformationOfOffset(hint); - boolean prependNewLine = line.getOffset() + line.getLength() == hint; - boolean appendNewLine = hint == 0; - if (prependNewLine) - directive = model.getLineDelimiter() + directive; - if (appendNewLine) - directive = directive + model.getLineDelimiter(); - adjustmentLength = directive.length(); - } - catch (BadLocationException e) { - } - - try { - model.replace(hint, 0, directive); - - } - catch (BadLocationException e) { - // Not that we should ever get a BLE, but if so, our - // replacement offset from the Content Assist call should - // work - try { - model.replace(getReplacementOffset(), 0, directive); - adjustmentLength = directive.length(); - } - catch (BadLocationException e2) { - // now what? - } - } - } - return adjustmentLength; - } - - /** - * See if the import specification is a wildcard import, and if so, that - * it applies to the given type. - */ - protected boolean isWildcardMatch(String importSpec, String type) { - int specLength = importSpec.length(); - if (importSpec.endsWith("*") && specLength > 2 && type.length() >= specLength) { //$NON-NLS-1$ - // pull out the package name including the final '.' - String container = importSpec.substring(0, specLength - 1); - // verify that the type is in the container's hierarchy and that - // there are no other package separators afterwards - if (type.startsWith(container) && type.indexOf('.', specLength - 1) < 0) { - // container matches - return true; - } - } - return false; - } - - protected boolean importHandles(String type, List listOfImports) { - Iterator imports = listOfImports.iterator(); - while (imports.hasNext()) { - String importSpec = StringUtils.strip(imports.next().toString()); - if (importSpec.equals(type) || isWildcardMatch(importSpec, type)) - return true; - } - return false; - } - - public void apply(IDocument document, char trigger, int offset) { - // If we have a parsed IStructuredDocument, insert the short name instead of the - // fully qualified name and a import page directive if - // needed. Do the import first so the cursor goes to the right location - // and we don't surprise the user. - - boolean addShortForm = false; //document instanceof IStructuredDocument && fContainerName != null && fContainerName.length() > 0; - if (addShortForm) { - setReplacementString('"' + fShortName + '"'); - int importLength = applyImport((IStructuredDocument) document); - setReplacementOffset(getReplacementOffset() + importLength); - } - - setCursorPosition(getReplacementString().length()); - super.apply(document, trigger, offset); - - } - - /* - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension1#apply(org.eclipse.jface.text.ITextViewer, char, int, int) - */ - public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { - // CMVC 243815 - // (pa) this is overridden to get around replacement length modification - // which is done in the super (since eclipse 2.1) - apply(viewer.getDocument(), trigger, offset); - } - - /** - * borrowed from JavaCompletionProposal - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent) - */ -// public boolean validate(IDocument document, int offset, DocumentEvent event) { -// if (offset < getReplacementOffset()) -// return false; -// boolean validated = startsWith(document, offset, getDisplayString()); -// return validated; -// } - - // code is borrowed from JavaCompletionProposal - protected boolean startsWith(IDocument document, int offset, String word) { - int wordLength = word == null ? 0 : word.length(); - if (offset > getReplacementOffset() + wordLength) - return false; - - try { - int length = offset - getReplacementOffset(); - // CMVC 243817 - // slightly modified to be a little more flexible for attribute value string matching.. - String start = StringUtils.stripQuotes(document.get(getReplacementOffset(), length)); - return word.toLowerCase().startsWith(start.toLowerCase()) || fQualifiedName.toLowerCase().startsWith(start.toLowerCase()); - //return word.substring(0, length).equalsIgnoreCase(start); - } - catch (BadLocationException x) { - } - - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent) - // */ - // public boolean validate(IDocument document, int offset, org.eclipse.jface.text.DocumentEvent event) { - // return super.validate(document, offset, event); - // } - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal#selected(org.eclipse.jface.text.ITextViewer, boolean) - */ - public void selected(ITextViewer viewer, boolean smartToggle) { - // (pa) we currently don't use smart toggle... - super.selected(viewer, false); - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeFinder.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeFinder.java deleted file mode 100644 index 73b25741c7..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeFinder.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - - - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.Flags; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.search.IJavaSearchConstants; -import org.eclipse.jdt.core.search.IJavaSearchScope; -import org.eclipse.jdt.core.search.ITypeNameRequestor; -import org.eclipse.jdt.core.search.SearchEngine; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.wst.sse.ui.internal.contentassist.CustomCompletionProposal; -import org.eclipse.wst.sse.ui.internal.contentassist.IRelevanceConstants; -import org.eclipse.wst.xml.uriresolver.util.URIHelper; - -/** - * - */ -public class JavaTypeFinder { - // COPIED TO REMOVE INTERNAL DEPENDENCY FOR NOW... - // org.eclipse.jdt.internal.codeassist.R_DEFAULT - static int R_DEFAULT = 0; - - protected static class JavaTypeNameRequestor implements ITypeNameRequestor { - - private JavaTypeResultCollector collector = null; - private StringBuffer s = null; - private boolean allowInterfaces = true; - - public JavaTypeNameRequestor(boolean allowInterfaces) { - super(); - this.allowInterfaces = allowInterfaces; - collector = new JavaTypeResultCollector(allowInterfaces); - s = new StringBuffer(); - } - - private char[] getCompletionName(char[] packageName, char[][] enclosingTypeNames, char[] simpleTypeName) { - s.delete(0, s.length()); - if (packageName != null && packageName.length > 0) { - s.append(packageName); - s.append('.'); - } - if (enclosingTypeNames != null) { - for (int i = 0; i < enclosingTypeNames.length; i++) { - if (enclosingTypeNames[i].length > 0) { - s.append(enclosingTypeNames[i]); - s.append('.'); - } - } - } - s.append(simpleTypeName); - return s.toString().toCharArray(); - } - - public void acceptClass(char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { - // forbid inner classes as they don't work [yet] - if (enclosingTypeNames == null || enclosingTypeNames.length == 0) - collector.acceptClass(packageName, simpleTypeName, getCompletionName(packageName, enclosingTypeNames, simpleTypeName), Flags.AccPublic, 0, 0, R_DEFAULT); - } - - public void acceptInterface(char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path) { - // forbid inner classes as they don't work [yet] - if (this.allowInterfaces && (enclosingTypeNames == null || enclosingTypeNames.length == 0)) - collector.acceptInterface(packageName, simpleTypeName, getCompletionName(packageName, enclosingTypeNames, simpleTypeName), Flags.AccPublic, 0, 0, R_DEFAULT); - } - - public JavaTypeResultCollector getCollector() { - return collector; - } - } - - public static ICompletionProposal[] getBeanProposals(IResource resource, int replacementStart, int replacementLength) { - ICompletionProposal[] typeProposals = getTypeProposals(resource, replacementStart, replacementLength); - ICompletionProposal[] serialProposals = getSerializedProposals(resource, replacementStart, replacementLength); - ICompletionProposal[] beanProposals = new ICompletionProposal[typeProposals.length + serialProposals.length]; - - int i; - for (i = 0; i < serialProposals.length; i++) { - beanProposals[i] = serialProposals[i]; - } - for (i = serialProposals.length; i < serialProposals.length + typeProposals.length; i++) { - beanProposals[i] = typeProposals[i - serialProposals.length]; - } - return beanProposals; - } - - private static void getMembers(IContainer container, List membersList) { - try { - IResource[] members = container.members(true); - if (members != null) { - for (int i = 0; i < members.length; i++) { - if (members[i].getType() == IResource.FILE) - membersList.add(members[i]); - else if (members[i].getType() == IResource.FOLDER) - getMembers((IContainer) members[i], membersList); - } - } - } - catch (CoreException e) { - // do nothing - } - } - - protected static ICompletionProposal[] getSerializedProposals(IResource resource, int replacementStart, int replacementLength) { - List names = new ArrayList(); - List resources = new ArrayList(); - getMembers(resource.getProject(), resources); - IResource memberResource = null; - for (int i = 0; i < resources.size(); i++) { - memberResource = (IResource) resources.get(i); - if (memberResource.getType() == IResource.FILE && memberResource.getName().endsWith(".ser")) { //$NON-NLS-1$ - String path = URIHelper.normalize(memberResource.getFullPath().toString(), resource.getFullPath().toString(), resource.getProject().getFullPath().toString()); - if (path != null) { - names.add(new CustomCompletionProposal("\"" + path + "\"", //$NON-NLS-1$ //$NON-NLS-2$ - replacementStart, replacementLength, path.length() + 2, null, path, null, null, IRelevanceConstants.R_NONE)); - } - } - } - return (ICompletionProposal[]) names.toArray(new ICompletionProposal[names.size()]); - } - - protected static ICompletionProposal[] findTypeProposals(IResource resource, int replacementStart, int replacementLength, boolean allowInterfaces) { - - JavaTypeNameRequestor requestor = new JavaTypeNameRequestor(allowInterfaces); - requestor.getCollector().setReplacementStart(replacementStart); - requestor.getCollector().setReplacementLength(replacementLength); - - try { - IJavaElement[] elements = new IJavaElement[]{getJavaProject(resource)}; - IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements); - new SearchEngine().searchAllTypeNames(ResourcesPlugin.getWorkspace(), null, null, IJavaSearchConstants.PATTERN_MATCH, IJavaSearchConstants.CASE_INSENSITIVE, IJavaSearchConstants.TYPE, scope, requestor, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, null); - } - catch (CoreException exc) { - Logger.logException(exc); - } - catch (Exception exc) { // JavaModel - Logger.logException(exc); - } - return requestor.getCollector().getResults(); - } - - public static ICompletionProposal[] getClassProposals(IResource resource, int replacementStart, int replacementLength) { - return findTypeProposals(resource, replacementStart, replacementLength, false); - } - - public static ICompletionProposal[] getTypeProposals(IResource resource, int replacementStart, int replacementLength) { - return findTypeProposals(resource, replacementStart, replacementLength, true); - } - - public static IJavaProject getJavaProject(IResource resource) { - IProject proj = resource.getProject(); - IJavaProject javaProject = JavaCore.create(proj); - return javaProject; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeResultCollector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeResultCollector.java deleted file mode 100644 index 3e1bb997d6..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/JavaTypeResultCollector.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jst.jsp.ui.internal.editor.JSPEditorPluginImageHelper; -import org.eclipse.swt.graphics.Image; - - - -public class JavaTypeResultCollector extends JSPCompletionRequestor { - - protected final boolean fShowClasses = true; - protected boolean fShowInterfaces = true; - - protected int fReplacementStart = 0; - protected int fReplacementLength = 0; - -// protected ImageDescriptorRegistry fRegistry = JavaPlugin.getImageDescriptorRegistry(); - - public JavaTypeResultCollector() { - super(); - } - - public JavaTypeResultCollector(boolean showInterfaces) { - super(); - fShowInterfaces = showInterfaces; - } - - protected boolean getShowClasses() { - return fShowClasses; - } - - protected void setShowClasses(boolean showClasses) { - } - - protected boolean getShowInterfaces() { - return fShowInterfaces; - } - - protected void setShowInterfaces(boolean showInterfaces) { - fShowInterfaces = showInterfaces; - } - - public int getReplacementLength() { - return fReplacementLength; - } - - public void setReplacementLength(int replacementLength) { - fReplacementLength = replacementLength; - } - - public int getReplacementStart() { - return fReplacementStart; - } - - public void setReplacementStart(int replacementStart) { - fReplacementStart = replacementStart; - } - - /** - * @see org.eclipse.jdt.core.ICompletionRequestor#acceptClass(char[], - * char[], char[], int, int, int, int) - */ - public void acceptClass(char[] packageName, char[] className, char[] completionName, int modifiers, int completionStart, int completionEnd, int relevance) { - if (fShowClasses) { - completionStart = getReplacementStart(); - completionEnd = completionStart + getReplacementLength(); - super.acceptClass(packageName, className, completionName, modifiers, completionStart, completionEnd, relevance); - } - } - - /** - * @see org.eclipse.jdt.core.ICompletionRequestor#acceptInterface(char[], char[], char[], int, - * int, int, int) - */ - public void acceptInterface(char[] packageName, char[] interfaceName, char[] completionName, int modifiers, int completionStart, int completionEnd, int relevance) { - if (fShowInterfaces) { - completionStart = getReplacementStart(); - completionEnd = completionStart + getReplacementLength(); - super.acceptInterface(packageName, interfaceName, completionName, modifiers, completionStart, completionEnd, relevance); - } - } - - protected JavaTypeCompletionProposal createTypeCompletion(int start, int end, String completion, ImageDescriptor descriptor, String typeName, String containerName, int relevance) { - String qualifiedName = null; - if (containerName != null && containerName.length() > 0) - qualifiedName = containerName + "." + typeName; //$NON-NLS-1$ - else - qualifiedName = typeName; - Image image = null; - if (descriptor != null) - image = JSPEditorPluginImageHelper.getInstance().getImage(descriptor); - return new JavaTypeCompletionProposal("\"" + qualifiedName + "\"", fReplacementStart, fReplacementLength, qualifiedName, image, typeName, containerName, relevance, true); //$NON-NLS-1$ //$NON-NLS-2$ - // return super.createTypeCompletion(start, end, completion, - // descriptor, typeName, containerName, proposalInfo, relevance); - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/NoRegionContentAssistProcessorForJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/NoRegionContentAssistProcessorForJSP.java deleted file mode 100644 index e43b47f98e..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/contentassist/NoRegionContentAssistProcessorForJSP.java +++ /dev/null @@ -1,103 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.contentassist; - -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.IContentAssistProcessor; -import org.eclipse.jst.jsp.core.JSP11Namespace; -import org.eclipse.jst.jsp.core.internal.text.rules.StructuredTextPartitionerForJSP; -import org.eclipse.wst.html.core.internal.text.rules.StructuredTextPartitionerForHTML; -import org.eclipse.wst.html.ui.internal.contentassist.NoRegionContentAssistProcessorForHTML; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.rules.StructuredTextPartitioner; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.text.rules.StructuredTextPartitionerForXML; - -/** - * - * @author pavery - */ -public class NoRegionContentAssistProcessorForJSP extends NoRegionContentAssistProcessorForHTML { - - private String[] fJSPContexts = null; - - public NoRegionContentAssistProcessorForJSP() { - super(); - initJSPContexts(); - } - - /* - * @see org.eclipse.wst.html.ui.internal.contentassist.NoRegionContentAssistProcessorForHTML#initPartitionToProcessorMap() - */ - protected void initPartitionToProcessorMap() { - super.initPartitionToProcessorMap(); - IContentAssistProcessor jspContentAssistProcessor = new JSPContentAssistProcessor(); - // JSP - fPartitionToProcessorMap.put(StructuredTextPartitioner.ST_DEFAULT_PARTITION, jspContentAssistProcessor); - fPartitionToProcessorMap.put(StructuredTextPartitionerForXML.ST_DEFAULT_XML, jspContentAssistProcessor); - fPartitionToProcessorMap.put(StructuredTextPartitionerForHTML.ST_DEFAULT_HTML, jspContentAssistProcessor); - fPartitionToProcessorMap.put(StructuredTextPartitionerForHTML.ST_HTML_COMMENT, jspContentAssistProcessor); - fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_DEFAULT_JSP, jspContentAssistProcessor); - // JSP directives - fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_JSP_DIRECTIVE, jspContentAssistProcessor); - // JSP delimiters - fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_DELIMITER, jspContentAssistProcessor); - // JSP JavaScript - fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVASCRIPT, jspContentAssistProcessor); - - IContentAssistProcessor jspJavaContentAssistProcessor = new JSPJavaContentAssistProcessor(); - // JSP Java - fPartitionToProcessorMap.put(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA, jspJavaContentAssistProcessor); - } - - /* - * @see com.ibm.sse.editor.xml.contentassist.NoRegionContentAssistProcessor#initNameToProcessorMap() - */ - protected void initNameToProcessorMap() { - super.initNameToProcessorMap(); - JSPPropertyContentAssistProcessor jspPropertyCAP = new JSPPropertyContentAssistProcessor(); - fNameToProcessorMap.put(JSP11Namespace.ElementName.SETPROPERTY, jspPropertyCAP); - fNameToProcessorMap.put(JSP11Namespace.ElementName.GETPROPERTY, jspPropertyCAP); - fNameToProcessorMap.put(JSP11Namespace.ElementName.USEBEAN, new JSPUseBeanContentAssistProcessor()); - } - - private void initJSPContexts() { - fJSPContexts = new String[]{XMLJSPRegionContexts.JSP_CLOSE, XMLJSPRegionContexts.JSP_CONTENT, XMLJSPRegionContexts.JSP_DECLARATION_OPEN, XMLJSPRegionContexts.JSP_EXPRESSION_OPEN, XMLJSPRegionContexts.JSP_SCRIPTLET_OPEN}; - } - - /** - * Quick check to see if context (String) should map to JSPContentAssistProcessor. - * @param context - * @return if it's a JSP Region (for which we need JSP Content assist) - */ - private boolean isJSPRegion(IStructuredDocumentRegion sdRegion) { - String context = sdRegion.getType(); - for (int i = 0; i < fJSPContexts.length; i++) { - if (context == fJSPContexts[i]) - return true; - } - return false; - } - - /* - * @see com.ibm.sse.editor.xml.contentassist.NoRegionContentAssistProcessor#guessContentAssistProcessor(org.eclipse.jface.text.ITextViewer, int) - */ - protected IContentAssistProcessor guessContentAssistProcessor(ITextViewer viewer, int documentOffset) { - IContentAssistProcessor p = super.guessContentAssistProcessor(viewer, documentOffset); - if (p == null) { - IStructuredDocumentRegion sdRegion = ((IStructuredDocument) viewer.getDocument()).getRegionAtCharacterOffset(documentOffset); - if (isJSPRegion(sdRegion)) - p = (IContentAssistProcessor) fPartitionToProcessorMap.get(StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA); - } - return p; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/ASTRewriteCorrectionProposalJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/ASTRewriteCorrectionProposalJSP.java deleted file mode 100644 index c35b662b34..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/ASTRewriteCorrectionProposalJSP.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.correction; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; -import org.eclipse.jdt.internal.ui.text.correction.ASTRewriteCorrectionProposal; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationUtil; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.DocumentChange; -import org.eclipse.ltk.core.refactoring.TextChange; -import org.eclipse.swt.graphics.Image; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.TextEdit; - -public class ASTRewriteCorrectionProposalJSP extends ASTRewriteCorrectionProposal { - - public ASTRewriteCorrectionProposalJSP(String name, ICompilationUnit cu, ASTRewrite rewrite, int relevance, Image image) { - super(name, cu, rewrite, relevance, image); - } - - public void apply(IDocument document) { - Change change = getChange(); - if (change instanceof DocumentChange) { - try { - getPreviewContent(); - JSPTranslationUtil translationUtil = new JSPTranslationUtil(document); - TextEdit textEdit = ((TextChange) change).getEdit(); - TextEdit translatedTextEdit = translationUtil.translateTextEdit(textEdit); - if (translatedTextEdit != null) - translatedTextEdit.apply(document); - } - catch (MalformedTreeException e) { - Logger.logException(e); - } - catch (BadLocationException e) { - Logger.logException(e); - } - catch (CoreException e) { - Logger.logException(e); - } - } - else - super.apply(document); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/CorrectionProcessorJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/CorrectionProcessorJSP.java deleted file mode 100644 index 0e3b6b96c8..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/CorrectionProcessorJSP.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.correction; - -import java.util.ArrayList; -import java.util.Iterator; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.compiler.IProblem; -import org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation; -import org.eclipse.jdt.internal.ui.text.correction.AssistContext; -import org.eclipse.jdt.internal.ui.text.correction.ProblemLocation; -import org.eclipse.jdt.internal.ui.text.correction.QuickFixProcessor; -import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; -import org.eclipse.jdt.ui.text.java.IProblemLocation; -import org.eclipse.jdt.ui.text.java.IQuickAssistProcessor; -import org.eclipse.jdt.ui.text.java.IQuickFixProcessor; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.contentassist.ICompletionProposal; -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.exceptions.SourceEditingRuntimeException; -import org.eclipse.wst.sse.ui.StructuredTextViewer; -import org.eclipse.wst.sse.ui.internal.correction.StructuredCorrectionProcessor; -import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; - -public class CorrectionProcessorJSP extends StructuredCorrectionProcessor { - protected IQuickFixProcessor fQuickFixProcessor; - protected IQuickAssistProcessor fQuickAssistProcessor; - - public CorrectionProcessorJSP(ITextEditor editor) { - super(editor); - } - - protected IQuickFixProcessor getQuickFixProcessorJSP() { - if (fQuickFixProcessor == null) - fQuickFixProcessor = new QuickFixProcessor(); - - return fQuickFixProcessor; - } - - protected IQuickAssistProcessor getQuickAssistProcessorJSP() { - if (fQuickAssistProcessor == null) - fQuickAssistProcessor = new QuickAssistProcessorJSP(); - - return fQuickAssistProcessor; - } - - protected void addQuickFixProposals(StructuredTextViewer viewer, ArrayList proposals, int documentOffset) { - ArrayList problems = new ArrayList(); - Iterator iter = fAnnotationModel.getAnnotationIterator(); - while (iter.hasNext()) { - Annotation annotation = (Annotation) iter.next(); - Position pos = fAnnotationModel.getPosition(annotation); - if (documentOffset >= pos.offset && documentOffset <= pos.offset + pos.length) { - IQuickFixProcessor processor = getQuickFixProcessorJSP(); - - XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(viewer.getDocument()); - XMLDocument xmlDoc = xmlModel.getDocument(); - xmlModel.releaseFromRead(); - JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (translationAdapter != null) { - JSPTranslation translation = translationAdapter.getJSPTranslation(); - - ICompilationUnit cu = translation.getCompilationUnit(); - int problemID = -1; - if (annotation instanceof TemporaryAnnotation) { - problemID = ((TemporaryAnnotation) annotation).getProblemID(); - if (problemID != -1) { - IJavaAnnotation javaAnnotation = new ProblemAnnotation((IProblem) ((TemporaryAnnotation) annotation).getAdditionalFixInfo(), cu); - problems.add(new ProblemLocation(translation.getJavaOffset(pos.offset), pos.getLength(), javaAnnotation)); - } - } - - int length = viewer != null ? viewer.getSelectedRange().y : 0; - AssistContext context = new AssistContext(cu, translation.getJavaOffset(documentOffset), length); - - if (processor != null && processor.hasCorrections(cu, problemID)) { - try { - IProblemLocation[] problemLocations = (IProblemLocation[]) problems.toArray(new IProblemLocation[problems.size()]); - IJavaCompletionProposal[] res = ((QuickFixProcessor) processor).getCorrections(context, problemLocations); - if (res != null) { - for (int k = 0; k < res.length; k++) { - //proposals.add(res[k]); - } - } - } - catch (CoreException e) { - throw new SourceEditingRuntimeException(); - } - } - } - } - } - } - - protected void addQuickAssistProposals(StructuredTextViewer viewer, ArrayList proposals, int documentOffset) { - try { - IQuickAssistProcessor processor = getQuickAssistProcessorJSP(); - - XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(viewer.getDocument()); - XMLDocument xmlDoc = xmlModel.getDocument(); - xmlModel.releaseFromRead(); - JSPTranslationAdapter translationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (translationAdapter != null) { - JSPTranslation translation = translationAdapter.getJSPTranslation(); - ICompilationUnit cu = translation.getCompilationUnit(); - - if (cu != null) { - synchronized(cu) { - if (processor instanceof QuickAssistProcessorJSP) - ((QuickAssistProcessorJSP) processor).setJSPDocument(viewer.getDocument()); - - int length = viewer != null ? viewer.getSelectedRange().y : 0; - AssistContext context = new AssistContext(cu, translation.getJavaOffset(documentOffset), length); - - if (processor != null) { - ICompletionProposal[] res = processor.getAssists(context, null); - if (res != null) { - for (int k = 0; k < res.length; k++) { - proposals.add(res[k]); - } - } - } - } - } - } - } - catch (Exception e) { - throw new SourceEditingRuntimeException(); - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/LocalRenameQuickAssistProposalJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/LocalRenameQuickAssistProposalJSP.java deleted file mode 100644 index 6c1894d791..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/LocalRenameQuickAssistProposalJSP.java +++ /dev/null @@ -1,212 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.correction; - -import java.util.Arrays; -import java.util.Comparator; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.CompilationUnit; -import org.eclipse.jdt.core.dom.SimpleName; -import org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder; -import org.eclipse.jdt.internal.corext.dom.NodeFinder; -import org.eclipse.jdt.internal.ui.JavaPlugin; -import org.eclipse.jdt.internal.ui.JavaPluginImages; -import org.eclipse.jdt.internal.ui.text.correction.CorrectionMessages; -import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2; -import org.eclipse.jface.text.contentassist.IContextInformation; -import org.eclipse.jface.text.link.LinkedModeModel; -import org.eclipse.jface.text.link.LinkedModeUI; -import org.eclipse.jface.text.link.LinkedPosition; -import org.eclipse.jface.text.link.LinkedPositionGroup; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationUtil; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.ui.texteditor.link.EditorLinkedModeUI; -import org.eclipse.wst.sse.ui.StructuredTextViewer; - -/** - * This is a copy of - * org.eclipse.jdt.internal.ui.text.correction.LinkedNamesAssistProposal with - * the following modifications: - * - set viewer redraw to true before apply to work around a repaint problem - * - translate AST element offsets to JSP document offsets - */ -public class LocalRenameQuickAssistProposalJSP implements IJavaCompletionProposal, ICompletionProposalExtension2 { - private SimpleName fNode; - private IRegion fSelectedRegion; // initialized by apply() - private ICompilationUnit fCompilationUnit; - - public LocalRenameQuickAssistProposalJSP(ICompilationUnit cu, SimpleName node) { - fNode = node; - fCompilationUnit = cu; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, - * char, int, int) - */ - public void apply(ITextViewer viewer, char trigger, int stateMask, final int offset) { - try { - // get full ast - CompilationUnit root = JavaPlugin.getDefault().getASTProvider().getAST(fCompilationUnit, true, null); - - ASTNode nameNode = NodeFinder.perform(root, fNode.getStartPosition(), fNode.getLength()); - final int pos = fNode.getStartPosition(); - - ASTNode[] sameNodes; - if (nameNode instanceof SimpleName) { - sameNodes = LinkedNodeFinder.findByNode(root, (SimpleName) nameNode); - } - else { - sameNodes = new ASTNode[]{nameNode}; - } - - // sort for iteration order, starting with the node @ offset - Arrays.sort(sameNodes, new Comparator() { - - public int compare(Object o1, Object o2) { - return rank((ASTNode) o1) - rank((ASTNode) o2); - } - - /** - * Returns the absolute rank of an <code>ASTNode</code>. - * Nodes preceding <code>offset</code> are ranked last. - * - * @param node - * the node to compute the rank for - * @return the rank of the node with respect to the invocation - * offset - */ - private int rank(ASTNode node) { - int relativeRank = node.getStartPosition() + node.getLength() - pos; - if (relativeRank < 0) - return Integer.MAX_VALUE + relativeRank; - else - return relativeRank; - } - - }); - - // TODO CompletionProposalPopup#insertProposal() calls - // IRewriteTarget.beginCompoundChange() - // which disables redraw in ITextViewer. Workaround for now. - ((StructuredTextViewer) viewer).setRedraw(true); - - IDocument document = viewer.getDocument(); - LinkedPositionGroup group = new LinkedPositionGroup(); - JSPTranslationUtil translationUtil = new JSPTranslationUtil(document); - for (int i = 0; i < sameNodes.length; i++) { - ASTNode elem = sameNodes[i]; - group.addPosition(new LinkedPosition(document, translationUtil.getTranslation().getJspOffset(elem.getStartPosition()), elem.getLength(), i)); - } - - LinkedModeModel linkedModeModel = new LinkedModeModel(); - linkedModeModel.addGroup(group); - linkedModeModel.forceInstall(); - - LinkedModeUI ui= new EditorLinkedModeUI(linkedModeModel, viewer); - ui.setExitPosition(viewer, offset, 0, LinkedPositionGroup.NO_STOP); - ui.enter(); - - fSelectedRegion = ui.getSelectedRegion(); - } - catch (BadLocationException e) { - JavaPlugin.log(e); - } - } - - /* - * @see ICompletionProposal#apply(IDocument) - */ - public void apply(IDocument document) { - // can't do anything - } - - /* - * @see ICompletionProposal#getSelection(IDocument) - */ - public Point getSelection(IDocument document) { - return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength()); - } - - /* - * @see ICompletionProposal#getAdditionalProposalInfo() - */ - public String getAdditionalProposalInfo() { - return CorrectionMessages.getString("LinkedNamesAssistProposal.proposalinfo"); //$NON-NLS-1$ - } - - /* - * @see ICompletionProposal#getDisplayString() - */ - public String getDisplayString() { - return CorrectionMessages.getString("LinkedNamesAssistProposal.description"); //$NON-NLS-1$ - } - - /* - * @see ICompletionProposal#getImage() - */ - public Image getImage() { - return JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL); - } - - /* - * @see ICompletionProposal#getContextInformation() - */ - public IContextInformation getContextInformation() { - return null; - } - - /* - * @see IJavaCompletionProposal#getRelevance() - */ - public int getRelevance() { - return 1; - } - - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, - * boolean) - */ - public void selected(ITextViewer textViewer, boolean smartToggle) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#unselected(org.eclipse.jface.text.ITextViewer) - */ - public void unselected(ITextViewer textViewer) { - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, - * int, org.eclipse.jface.text.DocumentEvent) - */ - public boolean validate(IDocument document, int offset, DocumentEvent event) { - return false; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/ProblemAnnotation.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/ProblemAnnotation.java deleted file mode 100644 index ad88bce42a..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/ProblemAnnotation.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.correction; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.compiler.IProblem; -import org.eclipse.jdt.internal.ui.JavaPluginImages; -import org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation; -import org.eclipse.jdt.internal.ui.javaeditor.JavaMarkerAnnotation; -import org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor; -import org.eclipse.jdt.ui.PreferenceConstants; -import org.eclipse.jface.text.source.Annotation; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; - -public class ProblemAnnotation extends Annotation implements IJavaAnnotation { - private static Image fgQuickFixImage; - private static Image fgQuickFixErrorImage; - private static boolean fgQuickFixImagesInitialized = false; - - private ICompilationUnit fCompilationUnit; - private List fOverlaids; - private IProblem fProblem; - private Image fImage; - private boolean fQuickFixImagesInitialized = false; - - public ProblemAnnotation(IProblem problem, ICompilationUnit cu) { - - fProblem = problem; - fCompilationUnit = cu; - - - - if (IProblem.Task == fProblem.getID()) { - setType(JavaMarkerAnnotation.TASK_ANNOTATION_TYPE); - //fLayer = TASK_LAYER; - } - else if (fProblem.isWarning()) { - setType(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE); - //fLayer = WARNING_LAYER; - } - else if (fProblem.isError()) { - setType(JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE); - //fLayer = ERROR_LAYER; - } - else { - setType(JavaMarkerAnnotation.INFO_ANNOTATION_TYPE); - //fLayer = INFO_LAYER; - } - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#hasOverlay() - */ - public boolean hasOverlay() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay() - */ - public IJavaAnnotation getOverlay() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlaidIterator() - */ - public Iterator getOverlaidIterator() { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#addOverlaid(org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation) - */ - public void addOverlaid(IJavaAnnotation annotation) { - if (fOverlaids == null) - fOverlaids = new ArrayList(1); - fOverlaids.add(annotation); - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#removeOverlaid(org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation) - */ - public void removeOverlaid(IJavaAnnotation annotation) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#isProblem() - */ - public boolean isProblem() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit() - */ - public ICompilationUnit getCompilationUnit() { - return fCompilationUnit; - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getArguments() - */ - public String[] getArguments() { - return isProblem() ? fProblem.getArguments() : null; - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getId() - */ - public int getId() { - return fProblem.getID(); - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getImage(org.eclipse.swt.widgets.Display) - */ - public Image getImage(Display display) { - initializeImages(); - return fImage; - } - - private void initializeImages() { - // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936 - if (!fQuickFixImagesInitialized) { - if (isProblem() && indicateQuixFixableProblems() && JavaCorrectionProcessor.hasCorrections(this)) { // no light bulb for tasks - if (!fgQuickFixImagesInitialized) { - fgQuickFixImage = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM); - fgQuickFixErrorImage = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR); - fgQuickFixImagesInitialized = true; - } - if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(getType())) - fImage = fgQuickFixErrorImage; - else - fImage = fgQuickFixImage; - } - fQuickFixImagesInitialized = true; - } - } - - private boolean indicateQuixFixableProblems() { - return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/QuickAssistProcessorJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/QuickAssistProcessorJSP.java deleted file mode 100644 index bc0da52e98..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/correction/QuickAssistProcessorJSP.java +++ /dev/null @@ -1,859 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.correction; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.compiler.IProblem; -import org.eclipse.jdt.core.dom.AST; -import org.eclipse.jdt.core.dom.ASTNode; -import org.eclipse.jdt.core.dom.AnonymousClassDeclaration; -import org.eclipse.jdt.core.dom.Assignment; -import org.eclipse.jdt.core.dom.Block; -import org.eclipse.jdt.core.dom.BodyDeclaration; -import org.eclipse.jdt.core.dom.CastExpression; -import org.eclipse.jdt.core.dom.CatchClause; -import org.eclipse.jdt.core.dom.ChildListPropertyDescriptor; -import org.eclipse.jdt.core.dom.ConditionalExpression; -import org.eclipse.jdt.core.dom.DoStatement; -import org.eclipse.jdt.core.dom.Expression; -import org.eclipse.jdt.core.dom.ExpressionStatement; -import org.eclipse.jdt.core.dom.ForStatement; -import org.eclipse.jdt.core.dom.IBinding; -import org.eclipse.jdt.core.dom.ITypeBinding; -import org.eclipse.jdt.core.dom.IVariableBinding; -import org.eclipse.jdt.core.dom.IfStatement; -import org.eclipse.jdt.core.dom.InfixExpression; -import org.eclipse.jdt.core.dom.MethodDeclaration; -import org.eclipse.jdt.core.dom.MethodInvocation; -import org.eclipse.jdt.core.dom.Modifier; -import org.eclipse.jdt.core.dom.Name; -import org.eclipse.jdt.core.dom.ParenthesizedExpression; -import org.eclipse.jdt.core.dom.SimpleName; -import org.eclipse.jdt.core.dom.SimpleType; -import org.eclipse.jdt.core.dom.SingleVariableDeclaration; -import org.eclipse.jdt.core.dom.Statement; -import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor; -import org.eclipse.jdt.core.dom.ThisExpression; -import org.eclipse.jdt.core.dom.TryStatement; -import org.eclipse.jdt.core.dom.Type; -import org.eclipse.jdt.core.dom.TypeDeclaration; -import org.eclipse.jdt.core.dom.VariableDeclarationExpression; -import org.eclipse.jdt.core.dom.VariableDeclarationFragment; -import org.eclipse.jdt.core.dom.VariableDeclarationStatement; -import org.eclipse.jdt.core.dom.WhileStatement; -import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; -import org.eclipse.jdt.core.dom.rewrite.ListRewrite; -import org.eclipse.jdt.internal.corext.dom.Bindings; -import org.eclipse.jdt.internal.corext.dom.LinkedNodeFinder; -import org.eclipse.jdt.internal.corext.dom.NodeFinder; -import org.eclipse.jdt.internal.ui.JavaPluginImages; -import org.eclipse.jdt.internal.ui.text.correction.ASTResolving; -import org.eclipse.jdt.internal.ui.text.correction.AssignToVariableAssistProposal; -import org.eclipse.jdt.internal.ui.text.correction.CorrectionMessages; -import org.eclipse.jdt.internal.ui.text.correction.LinkedCorrectionProposal; -import org.eclipse.jdt.ui.text.java.IInvocationContext; -import org.eclipse.jdt.ui.text.java.IJavaCompletionProposal; -import org.eclipse.jdt.ui.text.java.IProblemLocation; -import org.eclipse.jdt.ui.text.java.IQuickAssistProcessor; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationUtil; -import org.eclipse.swt.graphics.Image; - -/** - * This is a copy of - * org.eclipse.jdt.internal.ui.text.correction.QuickAssistProcessor with the - * following modifications: - replaced LocalRenameQuickAssistProposal with - * LocalRenameQuickAssistProposalJSP - replace ASTRewriteCorrectionProposal - * with ASTRewriteCorrectionProposalJSP - */ -public class QuickAssistProcessorJSP implements IQuickAssistProcessor { - private IDocument fDocument; - - public void setJSPDocument(IDocument document) { - fDocument = document; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.ui.text.correction.IAssistProcessor#hasAssists(org.eclipse.jdt.internal.ui.text.correction.IAssistContext) - */ - public boolean hasAssists(IInvocationContext context) throws CoreException { - ASTNode coveringNode = getCoveringNode(context); - if (coveringNode != null) { - return getCatchClauseToThrowsProposals(context, coveringNode, null) || getRenameLocalProposals(context, coveringNode, null, null) || getAssignToVariableProposals(context, coveringNode, null) || getUnWrapProposals(context, coveringNode, null) || getAssignParamToFieldProposals(context, coveringNode, null) || getJoinVariableProposals(context, coveringNode, null) || getAddFinallyProposals(context, coveringNode, null) || getAddElseProposals(context, coveringNode, null) || getSplitVariableProposals(context, coveringNode, null) || getAddBlockProposals(context, coveringNode, null) || getInvertEqualsProposal(context, coveringNode, null); - } - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.internal.ui.text.correction.IAssistProcessor#getAssists(org.eclipse.jdt.internal.ui.text.correction.IAssistContext, - * org.eclipse.jdt.internal.ui.text.correction.IProblemLocation[]) - */ - public IJavaCompletionProposal[] getAssists(IInvocationContext context, IProblemLocation[] locations) throws CoreException { - ASTNode coveringNode = getCoveringNode(context); - if (coveringNode != null) { - ArrayList resultingCollections = new ArrayList(); - // quick assists that show up also if there is an error/warning - getRenameLocalProposals(context, coveringNode, locations, resultingCollections); - - if (noErrorsAtLocation(locations)) { - getCatchClauseToThrowsProposals(context, coveringNode, resultingCollections); - getAssignToVariableProposals(context, coveringNode, resultingCollections); - getAssignParamToFieldProposals(context, coveringNode, resultingCollections); - getUnWrapProposals(context, coveringNode, resultingCollections); - getSplitVariableProposals(context, coveringNode, resultingCollections); - getJoinVariableProposals(context, coveringNode, resultingCollections); - getAddFinallyProposals(context, coveringNode, resultingCollections); - getAddElseProposals(context, coveringNode, resultingCollections); - getAddBlockProposals(context, coveringNode, resultingCollections); - getInvertEqualsProposal(context, coveringNode, resultingCollections); - } - return (IJavaCompletionProposal[]) resultingCollections.toArray(new IJavaCompletionProposal[resultingCollections.size()]); - } - return null; - } - - private boolean noErrorsAtLocation(IProblemLocation[] locations) { - if (locations != null) { - for (int i = 0; i < locations.length; i++) { - if (locations[i].isError()) { - return false; - } - } - } - return true; - } - - private boolean getJoinVariableProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { - ASTNode parent = node.getParent(); - if (!(parent instanceof VariableDeclarationFragment)) { - return false; - } - VariableDeclarationFragment fragment = (VariableDeclarationFragment) parent; - - IVariableBinding binding = fragment.resolveBinding(); - if (fragment.getInitializer() != null || binding == null || binding.isField()) { - return false; - } - - if (!(fragment.getParent() instanceof VariableDeclarationStatement)) { - return false; - } - VariableDeclarationStatement statement = (VariableDeclarationStatement) fragment.getParent(); - - SimpleName[] names = LinkedNodeFinder.findByBinding(statement.getParent(), binding); - if (names.length <= 1 || names[0] != fragment.getName()) { - return false; - } - - SimpleName firstAccess = names[1]; - if (!(firstAccess.getParent() instanceof Assignment)) { - return false; - } - Assignment assignment = (Assignment) firstAccess.getParent(); - if (assignment.getLeftHandSide() != firstAccess) { - return false; - } - - ASTNode assignParent = assignment.getParent(); - if (!(assignParent instanceof ExpressionStatement || assignParent instanceof ForStatement && ((ForStatement) assignParent).initializers().contains(assignment))) { - return false; - } - - if (resultingCollections == null) { - return true; - } - - AST ast = statement.getAST(); - ASTRewrite rewrite = ASTRewrite.create(ast); - - String label = CorrectionMessages.getString("QuickAssistProcessor.joindeclaration.description"); //$NON-NLS-1$ - Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL); - LinkedCorrectionProposal proposal = new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, 1, image); - - Expression placeholder = (Expression) rewrite.createMoveTarget(assignment.getRightHandSide()); - rewrite.set(fragment, VariableDeclarationFragment.INITIALIZER_PROPERTY, placeholder, null); - - if (assignParent instanceof ExpressionStatement) { - int statementParent = assignParent.getParent().getNodeType(); - if (statementParent == ASTNode.IF_STATEMENT || statementParent == ASTNode.WHILE_STATEMENT || statementParent == ASTNode.DO_STATEMENT || statementParent == ASTNode.FOR_STATEMENT) { - - Block block = ast.newBlock(); - rewrite.replace(assignParent, block, null); - } - else { - rewrite.remove(assignParent, null); - } - } - else { - rewrite.remove(assignment, null); - } - - proposal.setEndPosition(rewrite.track(fragment.getName())); - resultingCollections.add(proposal); - return true; - - } - - private boolean getSplitVariableProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { - ASTNode parent = node.getParent(); - if (!(parent instanceof VariableDeclarationFragment)) { - return false; - } - VariableDeclarationFragment fragment = (VariableDeclarationFragment) parent; - - if (fragment.getInitializer() == null) { - return false; - } - - Statement statement; - ASTNode fragParent = fragment.getParent(); - if (fragParent instanceof VariableDeclarationStatement) { - statement = (VariableDeclarationStatement) fragParent; - } - else if (fragParent instanceof VariableDeclarationExpression) { - statement = (Statement) fragParent.getParent(); - } - else { - return false; - } - // statement is ForStatement or VariableDeclarationStatement - - ASTNode statementParent = statement.getParent(); - StructuralPropertyDescriptor property = statement.getLocationInParent(); - if (!property.isChildListProperty()) { - return false; - } - - List list = (List) statementParent.getStructuralProperty(property); - - if (resultingCollections == null) { - return true; - } - - AST ast = statement.getAST(); - ASTRewrite rewrite = ASTRewrite.create(ast); - - String label = CorrectionMessages.getString("QuickAssistProcessor.splitdeclaration.description"); //$NON-NLS-1$ - Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_LOCAL); - ASTRewriteCorrectionProposalJSP proposal = new ASTRewriteCorrectionProposalJSP(label, context.getCompilationUnit(), rewrite, 1, image); - - Statement newStatement; - int insertIndex = list.indexOf(statement); - - Expression placeholder = (Expression) rewrite.createMoveTarget(fragment.getInitializer()); - Assignment assignment = ast.newAssignment(); - assignment.setRightHandSide(placeholder); - assignment.setLeftHandSide(ast.newSimpleName(fragment.getName().getIdentifier())); - - if (statement instanceof VariableDeclarationStatement) { - newStatement = ast.newExpressionStatement(assignment); - insertIndex += 1; // add after declaration - - int modifiers = ((VariableDeclarationStatement) statement).getModifiers(); - if (Modifier.isFinal(modifiers)) { - rewrite.set(statement, VariableDeclarationStatement.MODIFIERS_PROPERTY, new Integer(modifiers & ~Modifier.FINAL), null); - } - } - else { - rewrite.replace(fragment.getParent(), assignment, null); - VariableDeclarationFragment newFrag = ast.newVariableDeclarationFragment(); - newFrag.setName(ast.newSimpleName(fragment.getName().getIdentifier())); - newFrag.setExtraDimensions(fragment.getExtraDimensions()); - - VariableDeclarationExpression oldVarDecl = (VariableDeclarationExpression) fragParent; - - VariableDeclarationStatement newVarDec = ast.newVariableDeclarationStatement(newFrag); - newVarDec.setType((Type) ASTNode.copySubtree(ast, oldVarDecl.getType())); - newVarDec.setModifiers(oldVarDecl.getModifiers() & ~Modifier.FINAL); - newStatement = newVarDec; - } - - ListRewrite listRewriter = rewrite.getListRewrite(statementParent, (ChildListPropertyDescriptor) property); - listRewriter.insertAt(newStatement, insertIndex, null); - - resultingCollections.add(proposal); - return true; - } - - private ASTNode getCoveringNode(IInvocationContext context) { - NodeFinder finder = new NodeFinder(context.getSelectionOffset(), context.getSelectionLength()); - context.getASTRoot().accept(finder); - return finder.getCoveringNode(); - } - - - private boolean getAssignToVariableProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { - Statement statement = ASTResolving.findParentStatement(node); - if (!(statement instanceof ExpressionStatement)) { - return false; - } - ExpressionStatement expressionStatement = (ExpressionStatement) statement; - - Expression expression = expressionStatement.getExpression(); - if (expression.getNodeType() == ASTNode.ASSIGNMENT) { - return false; // too confusing and not helpful - } - - ITypeBinding typeBinding = expression.resolveTypeBinding(); - typeBinding = Bindings.normalizeTypeBinding(typeBinding); - if (typeBinding == null) { - return false; - } - if (resultingCollections == null) { - return true; - } - - ICompilationUnit cu = context.getCompilationUnit(); - - AssignToVariableAssistProposal localProposal = new AssignToVariableAssistProposal(cu, AssignToVariableAssistProposal.LOCAL, expressionStatement, typeBinding, 2); - resultingCollections.add(localProposal); - - ASTNode type = ASTResolving.findParentType(expression); - if (type != null) { - AssignToVariableAssistProposal fieldProposal = new AssignToVariableAssistProposal(cu, AssignToVariableAssistProposal.FIELD, expressionStatement, typeBinding, 1); - resultingCollections.add(fieldProposal); - } - return false; - - } - - private boolean getAssignParamToFieldProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { - ASTNode parent = node.getParent(); - if (!(parent instanceof SingleVariableDeclaration) || !(parent.getParent() instanceof MethodDeclaration)) { - return false; - } - SingleVariableDeclaration paramDecl = (SingleVariableDeclaration) parent; - IVariableBinding binding = paramDecl.resolveBinding(); - - MethodDeclaration methodDecl = (MethodDeclaration) parent.getParent(); - if (binding == null || methodDecl.getBody() == null) { - return false; - } - ITypeBinding typeBinding = binding.getType(); - if (typeBinding == null) { - return false; - } - - if (resultingCollections != null) { - AssignToVariableAssistProposal fieldProposal = new AssignToVariableAssistProposal(context.getCompilationUnit(), paramDecl, typeBinding, 1); - resultingCollections.add(fieldProposal); - } - return true; - } - - private boolean getAddFinallyProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { - TryStatement tryStatement = ASTResolving.findParentTryStatement(node); - if (tryStatement == null || tryStatement.getFinally() != null) { - return false; - } - Statement statement = ASTResolving.findParentStatement(node); - if (tryStatement != statement && tryStatement.getBody() != statement) { - return false; // an node inside a catch or finally block - } - - if (resultingCollections == null) { - return true; - } - - AST ast = tryStatement.getAST(); - ASTRewrite rewrite = ASTRewrite.create(ast); - Block finallyBody = ast.newBlock(); - - rewrite.set(tryStatement, TryStatement.FINALLY_PROPERTY, finallyBody, null); - - String label = CorrectionMessages.getString("QuickAssistProcessor.addfinallyblock.description"); //$NON-NLS-1$ - Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD); - ASTRewriteCorrectionProposalJSP proposal = new ASTRewriteCorrectionProposalJSP(label, context.getCompilationUnit(), rewrite, 1, image); - resultingCollections.add(proposal); - return true; - } - - private boolean getAddElseProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { - Statement statement = ASTResolving.findParentStatement(node); - if (!(statement instanceof IfStatement)) { - return false; - } - IfStatement ifStatement = (IfStatement) statement; - if (ifStatement.getElseStatement() != null) { - return false; - } - - if (resultingCollections == null) { - return true; - } - - AST ast = statement.getAST(); - ASTRewrite rewrite = ASTRewrite.create(ast); - Block body = ast.newBlock(); - - rewrite.set(ifStatement, IfStatement.ELSE_STATEMENT_PROPERTY, body, null); - - String label = CorrectionMessages.getString("QuickAssistProcessor.addelseblock.description"); //$NON-NLS-1$ - Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_ADD); - ASTRewriteCorrectionProposalJSP proposal = new ASTRewriteCorrectionProposalJSP(label, context.getCompilationUnit(), rewrite, 1, image); - resultingCollections.add(proposal); - return true; - } - - public static boolean getCatchClauseToThrowsProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { - CatchClause catchClause = (CatchClause) ASTResolving.findAncestor(node, ASTNode.CATCH_CLAUSE); - if (catchClause == null) { - return false; - } - - Statement statement = ASTResolving.findParentStatement(node); - if (statement != catchClause.getParent() && statement != catchClause.getBody()) { - return false; // selection is in a statement inside the body - } - - Type type = catchClause.getException().getType(); - if (!type.isSimpleType()) { - return false; - } - - BodyDeclaration bodyDeclaration = ASTResolving.findParentBodyDeclaration(catchClause); - if (!(bodyDeclaration instanceof MethodDeclaration)) { - return false; - } - - if (resultingCollections == null) { - return true; - } - - AST ast = bodyDeclaration.getAST(); - MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration; - { - ASTRewrite rewrite = ASTRewrite.create(ast); - - removeCatchBlock(rewrite, methodDeclaration, catchClause); - - ITypeBinding binding = type.resolveBinding(); - if (binding == null || isNotYetThrown(binding, methodDeclaration.thrownExceptions())) { - Name name = ((SimpleType) type).getName(); - Name newName = (Name) ASTNode.copySubtree(catchClause.getAST(), name); - - ListRewrite listRewriter = rewrite.getListRewrite(methodDeclaration, MethodDeclaration.THROWN_EXCEPTIONS_PROPERTY); - listRewriter.insertLast(newName, null); - } - - String label = CorrectionMessages.getString("QuickAssistProcessor.catchclausetothrows.description"); //$NON-NLS-1$ - Image image = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); - ASTRewriteCorrectionProposalJSP proposal = new ASTRewriteCorrectionProposalJSP(label, context.getCompilationUnit(), rewrite, 4, image); - resultingCollections.add(proposal); - } - { - ASTRewrite rewrite = ASTRewrite.create(ast); - - removeCatchBlock(rewrite, methodDeclaration, catchClause); - String label = CorrectionMessages.getString("QuickAssistProcessor.removecatchclause.description"); //$NON-NLS-1$ - Image image = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); - ASTRewriteCorrectionProposalJSP proposal = new ASTRewriteCorrectionProposalJSP(label, context.getCompilationUnit(), rewrite, 5, image); - resultingCollections.add(proposal); - } - - return true; - } - - private static void removeCatchBlock(ASTRewrite rewrite, MethodDeclaration methodDeclaration, CatchClause catchClause) { - TryStatement tryStatement = (TryStatement) catchClause.getParent(); - if (tryStatement.catchClauses().size() > 1 || tryStatement.getFinally() != null) { - rewrite.remove(catchClause, null); - } - else { - Block block = tryStatement.getBody(); - List statements = block.statements(); - if (statements.size() > 0) { - ListRewrite listRewrite = rewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY); - ASTNode first = (ASTNode) statements.get(0); - ASTNode last = (ASTNode) statements.get(statements.size() - 1); - ASTNode placeholder = listRewrite.createCopyTarget(first, last); - rewrite.replace(tryStatement, placeholder, null); - } - else { - rewrite.remove(tryStatement, null); - } - } - } - - private static boolean isNotYetThrown(ITypeBinding binding, List thrownExcpetions) { - for (int i = 0; i < thrownExcpetions.size(); i++) { - Name name = (Name) thrownExcpetions.get(i); - ITypeBinding elem = (ITypeBinding) name.resolveBinding(); - if (elem != null) { - if (Bindings.isSuperType(elem, binding)) { // existing - // exception is - // base class of - // new - return false; - } - } - } - return true; - } - - - private boolean getRenameLocalProposals(IInvocationContext context, ASTNode node, IProblemLocation[] locations, Collection resultingCollections) { - if (!(node instanceof SimpleName)) { - return false; - } - SimpleName name = (SimpleName) node; - IBinding binding = name.resolveBinding(); - if (binding != null && binding.getKind() == IBinding.PACKAGE) { - return false; - } - - if (locations != null) { - for (int i = 0; i < locations.length; i++) { - switch (locations[i].getProblemId()) { - case IProblem.LocalVariableHidingLocalVariable : - case IProblem.LocalVariableHidingField : - case IProblem.FieldHidingLocalVariable : - case IProblem.FieldHidingField : - case IProblem.ArgumentHidingLocalVariable : - case IProblem.ArgumentHidingField : - return false; - } - } - } - - if (resultingCollections == null) { - return true; - } - - LocalRenameQuickAssistProposalJSP proposal = new LocalRenameQuickAssistProposalJSP(context.getCompilationUnit(), name); - resultingCollections.add(proposal); - return true; - } - - private ASTNode getCopyOfInner(ASTRewrite rewrite, ASTNode statement) { - if (statement.getNodeType() == ASTNode.BLOCK) { - Block block = (Block) statement; - List innerStatements = block.statements(); - int nStatements = innerStatements.size(); - if (nStatements == 1) { - return rewrite.createCopyTarget(((ASTNode) innerStatements.get(0))); - } - else if (nStatements > 1) { - ListRewrite listRewrite = rewrite.getListRewrite(block, Block.STATEMENTS_PROPERTY); - ASTNode first = (ASTNode) innerStatements.get(0); - ASTNode last = (ASTNode) innerStatements.get(nStatements - 1); - return listRewrite.createCopyTarget(first, last); - } - return null; - } - else { - return rewrite.createCopyTarget(statement); - } - } - - - private boolean getUnWrapProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { - ASTNode outer = node; - - Block block = null; - if (outer.getNodeType() == ASTNode.BLOCK) { - block = (Block) outer; - outer = block.getParent(); - } - - ASTNode body = null; - String label = null; - if (outer instanceof IfStatement) { - IfStatement ifStatement = (IfStatement) outer; - Statement elseBlock = ifStatement.getElseStatement(); - if (elseBlock == null || ((elseBlock instanceof Block) && ((Block) elseBlock).statements().isEmpty())) { - body = ifStatement.getThenStatement(); - } - label = CorrectionMessages.getString("QuickAssistProcessor.unwrap.ifstatement"); //$NON-NLS-1$ - } - else if (outer instanceof WhileStatement) { - body = ((WhileStatement) outer).getBody(); - label = CorrectionMessages.getString("QuickAssistProcessor.unwrap.whilestatement"); //$NON-NLS-1$ - } - else if (outer instanceof ForStatement) { - body = ((ForStatement) outer).getBody(); - label = CorrectionMessages.getString("QuickAssistProcessor.unwrap.forstatement"); //$NON-NLS-1$ - } - else if (outer instanceof DoStatement) { - body = ((DoStatement) outer).getBody(); - label = CorrectionMessages.getString("QuickAssistProcessor.unwrap.dostatement"); //$NON-NLS-1$ - } - else if (outer instanceof TryStatement) { - TryStatement tryStatement = (TryStatement) outer; - if (tryStatement.catchClauses().isEmpty()) { - body = tryStatement.getBody(); - } - label = CorrectionMessages.getString("QuickAssistProcessor.unwrap.trystatement"); //$NON-NLS-1$ - } - else if (outer instanceof AnonymousClassDeclaration) { - List decls = ((AnonymousClassDeclaration) outer).bodyDeclarations(); - for (int i = 0; i < decls.size(); i++) { - ASTNode elem = (ASTNode) decls.get(i); - if (elem instanceof MethodDeclaration) { - Block curr = ((MethodDeclaration) elem).getBody(); - if (curr != null && !curr.statements().isEmpty()) { - if (body != null) { - return false; - } - body = curr; - } - } - else if (elem instanceof TypeDeclaration) { - return false; - } - } - label = CorrectionMessages.getString("QuickAssistProcessor.unwrap.anonymous"); //$NON-NLS-1$ - outer = ASTResolving.findParentStatement(outer); - } - else if (outer instanceof Block) { - // -> a block in a block - body = block; - outer = block; - label = CorrectionMessages.getString("QuickAssistProcessor.unwrap.block"); //$NON-NLS-1$ - } - else if (outer instanceof ParenthesizedExpression) { - ParenthesizedExpression expression = (ParenthesizedExpression) outer; - body = expression.getExpression(); - label = CorrectionMessages.getString("QuickAssistProcessor.unwrap.parenthesis"); //$NON-NLS-1$ - } - else if (outer instanceof MethodInvocation) { - MethodInvocation invocation = (MethodInvocation) outer; - if (invocation.arguments().size() == 1) { - body = (ASTNode) invocation.arguments().get(0); - if (invocation.getParent().getNodeType() == ASTNode.EXPRESSION_STATEMENT) { - int kind = body.getNodeType(); - if (kind != ASTNode.ASSIGNMENT && kind != ASTNode.PREFIX_EXPRESSION && kind != ASTNode.POSTFIX_EXPRESSION && kind != ASTNode.METHOD_INVOCATION && kind != ASTNode.SUPER_METHOD_INVOCATION) { - body = null; - } - } - label = CorrectionMessages.getString("QuickAssistProcessor.unwrap.methodinvocation"); //$NON-NLS-1$ - } - } - if (body == null) { - return false; - } - ASTRewrite rewrite = ASTRewrite.create(outer.getAST()); - ASTNode inner = getCopyOfInner(rewrite, body); - if (inner == null) { - return false; - } - if (resultingCollections == null) { - return true; - } - - JSPTranslationUtil translationUtil = new JSPTranslationUtil(fDocument); - if (!translationUtil.getTranslation().javaSpansMultipleJspPartitions(outer.getStartPosition(), outer.getLength())) { - rewrite.replace(outer, inner, null); - Image image = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_EXCEPTION); - ASTRewriteCorrectionProposalJSP proposal = new ASTRewriteCorrectionProposalJSP(label, context.getCompilationUnit(), rewrite, 1, image); - resultingCollections.add(proposal); - return true; - } - else - return false; - } - - private static boolean isControlStatementWithBlock(ASTNode node) { - switch (node.getNodeType()) { - case ASTNode.IF_STATEMENT : - case ASTNode.WHILE_STATEMENT : - case ASTNode.FOR_STATEMENT : - case ASTNode.DO_STATEMENT : - return true; - default : - return false; - } - } - - - private boolean getAddBlockProposals(IInvocationContext context, ASTNode node, Collection resultingCollections) { - Statement statement = ASTResolving.findParentStatement(node); - if (statement == null) { - return false; - } - - if (!isControlStatementWithBlock(statement)) { - if (!isControlStatementWithBlock(statement.getParent())) { - return false; - } - int statementStart = statement.getStartPosition(); - int statementEnd = statementStart + statement.getLength(); - - int offset = context.getSelectionOffset(); - int length = context.getSelectionLength(); - if (length == 0) { - if (offset != statementEnd) { // cursor at end - return false; - } - } - else { - if (offset > statementStart || offset + length < statementEnd) { // statement - // selected - return false; - } - } - statement = (Statement) statement.getParent(); - } - - StructuralPropertyDescriptor childProperty = null; - ASTNode child = null; - switch (statement.getNodeType()) { - case ASTNode.IF_STATEMENT : - int selectionStart = context.getSelectionOffset(); - int selectionEnd = context.getSelectionOffset() + context.getSelectionLength(); - ASTNode then = ((IfStatement) statement).getThenStatement(); - if (selectionEnd <= then.getStartPosition() + then.getLength()) { - if (!(then instanceof Block)) { - childProperty = IfStatement.THEN_STATEMENT_PROPERTY; - child = then; - } - } - else if (selectionStart >= then.getStartPosition() + then.getLength()) { - ASTNode elseStatement = ((IfStatement) statement).getElseStatement(); - if (!(elseStatement instanceof Block)) { - childProperty = IfStatement.ELSE_STATEMENT_PROPERTY; - child = elseStatement; - } - } - break; - case ASTNode.WHILE_STATEMENT : - ASTNode whileBody = ((WhileStatement) statement).getBody(); - if (!(whileBody instanceof Block)) { - childProperty = WhileStatement.BODY_PROPERTY; - child = whileBody; - } - break; - case ASTNode.FOR_STATEMENT : - ASTNode forBody = ((ForStatement) statement).getBody(); - if (!(forBody instanceof Block)) { - childProperty = ForStatement.BODY_PROPERTY; - child = forBody; - } - break; - case ASTNode.DO_STATEMENT : - ASTNode doBody = ((DoStatement) statement).getBody(); - if (!(doBody instanceof Block)) { - childProperty = DoStatement.BODY_PROPERTY; - child = doBody; - } - break; - default : - } - if (child == null) { - return false; - } - - if (resultingCollections == null) { - return true; - } - AST ast = statement.getAST(); - ASTRewrite rewrite = ASTRewrite.create(ast); - - ASTNode childPlaceholder = rewrite.createMoveTarget(child); - Block replacingBody = ast.newBlock(); - replacingBody.statements().add(childPlaceholder); - rewrite.set(statement, childProperty, replacingBody, null); - - String label; - if (childProperty == IfStatement.THEN_STATEMENT_PROPERTY) { - label = CorrectionMessages.getString("QuickAssistProcessor.replacethenwithblock.description");//$NON-NLS-1$ - } - else if (childProperty == IfStatement.ELSE_STATEMENT_PROPERTY) { - label = CorrectionMessages.getString("QuickAssistProcessor.replaceelsewithblock.description");//$NON-NLS-1$ - } - else { - label = CorrectionMessages.getString("QuickAssistProcessor.replacebodywithblock.description");//$NON-NLS-1$ - } - - Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); - LinkedCorrectionProposal proposal = new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, 10, image); - proposal.setEndPosition(rewrite.track(child)); - resultingCollections.add(proposal); - return true; - } - - private boolean getInvertEqualsProposal(IInvocationContext context, ASTNode node, Collection resultingCollections) { - ASTNode parent = node.getParent(); - if (!(parent instanceof MethodInvocation)) { - return false; - } - MethodInvocation method = (MethodInvocation) parent; - if (!"equals".equals(method.getName().getIdentifier())) { //$NON-NLS-1$ - return false; - } - List arguments = method.arguments(); - if (arguments.size() != 1) { //overloaded equals w/ more than 1 arg - return false; - } - Expression right = (Expression) arguments.get(0); - ITypeBinding binding = right.resolveTypeBinding(); - if (!(binding.isClass() || binding.isInterface())) { //overloaded - // equals w/ - // non-class/interface - // arg or null - return false; - } - Expression left = method.getExpression(); - - AST ast = method.getAST(); - ASTRewrite rewrite; - if (left == null) { // equals(x) -> x.equals(this) - rewrite = ASTRewrite.create(ast); - MethodInvocation replacement = ast.newMethodInvocation(); - replacement.setName((SimpleName) rewrite.createCopyTarget(method.getName())); - replacement.arguments().add(ast.newThisExpression()); - replacement.setExpression((Expression) rewrite.createCopyTarget(right)); - rewrite.replace(method, replacement, null); - } - else if (right instanceof ThisExpression) { // x.equals(this) -> - // equals(x) - rewrite = ASTRewrite.create(ast); - MethodInvocation replacement = rewrite.getAST().newMethodInvocation(); - replacement.setName((SimpleName) rewrite.createCopyTarget(method.getName())); - replacement.arguments().add(rewrite.createCopyTarget(left)); - rewrite.replace(method, replacement, null); - } - else { - rewrite = ASTRewrite.create(ast); - if (left instanceof ParenthesizedExpression) { - Expression ex = ((ParenthesizedExpression) left).getExpression(); - rewrite.replace(right, rewrite.createCopyTarget(ex), null); - } - else { - rewrite.replace(right, rewrite.createCopyTarget(left), null); - } - if ((right instanceof CastExpression) || (right instanceof Assignment) || (right instanceof ConditionalExpression) || (right instanceof InfixExpression)) { - ParenthesizedExpression paren = rewrite.getAST().newParenthesizedExpression(); - paren.setExpression((Expression) rewrite.createCopyTarget(right)); - rewrite.replace(left, paren, null); - } - else { - rewrite.replace(left, rewrite.createCopyTarget(right), null); - } - } - - String label = CorrectionMessages.getString("QuickAssistProcessor.invertequals.description"); //$NON-NLS-1$ - Image image = JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE); - - LinkedCorrectionProposal proposal = new LinkedCorrectionProposal(label, context.getCompilationUnit(), rewrite, 1, image); - resultingCollections.add(proposal); - return true; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/editor/IHelpContextIds.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/editor/IHelpContextIds.java deleted file mode 100644 index ddb387125c..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/editor/IHelpContextIds.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.editor; - -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; - -/** - * Help context ids for the JSP Source Editor. - * <p> - * This interface contains constants only; it is not intended to be implemented. - * </p> - * - */ -public interface IHelpContextIds { - // org.eclipse.jst.jsp.ui. - public static final String PREFIX = JSPUIPlugin.ID + "."; //$NON-NLS-1$ - - // JSP Source page editor - public static final String JSP_SOURCEVIEW_HELPID = PREFIX + "ejsp0000"; //$NON-NLS-1$ - - // JSP Files Preference page - public static final String JSP_PREFWEBX_FILES_HELPID = PREFIX + "webx0050"; //$NON-NLS-1$ - // JSP Styles Preference page - public static final String JSP_PREFWEBX_STYLES_HELPID = PREFIX + "webx0051"; //$NON-NLS-1$ - // JSP Templates Preference page - public static final String JSP_PREFWEBX_TEMPLATES_HELPID = PREFIX + "webx0052"; //$NON-NLS-1$ - - // JSP Fragment Property Page - public static final String JSP_FRAGMENT_HELPID = PREFIX + "jspf1000"; //$NON-NLS-1$ - - // JSP Source Editor Context Menu - // Refactor Rename TODO infopop needed - // Refactor Move TODO infopop needed -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/editor/JSPEditorPluginImageHelper.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/editor/JSPEditorPluginImageHelper.java deleted file mode 100644 index b659b9b301..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/editor/JSPEditorPluginImageHelper.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.editor; - -import java.util.HashMap; - -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.swt.graphics.Image; -import org.eclipse.ui.plugin.AbstractUIPlugin; - - -/** - * Helper class to handle images provided by this plug-in. - * - * NOTE: For internal use only. For images used externally, please use the - * Shared***ImageHelper class instead. - * - * @author amywu - */ -public class JSPEditorPluginImageHelper { - private final String PLUGINID = JSPUIPlugin.ID; - private static JSPEditorPluginImageHelper instance = null; - - // save a descriptor for each image - private HashMap fImageDescRegistry = null; - - /** - * Gets the instance. - * - * @return Returns a JSPEditorPluginImageHelper - */ - public synchronized static JSPEditorPluginImageHelper getInstance() { - if (instance == null) - instance = new JSPEditorPluginImageHelper(); - return instance; - } - - /** - * Retrieves the image associated with resource from the image registry. - * If the image cannot be retrieved, attempt to find and load the image at - * the location specified in resource. - * - * @param resource - * the image to retrieve - * @return Image the image associated with resource or null if one could - * not be found - */ - public Image getImage(String resource) { - Image image = getImageRegistry().get(resource); - if (image == null) { - // create an image - image = createImage(resource); - } - return image; - } - - /** - * Retrieves the Image associated with ImageDescriptor from the image - * descriptor registry. If the Image cannot be retrieved, it is created - * from the ImageDescriptor - * - * @param resource - * the image descriptor to retrieve - * @return Image the associated with the ImageDescriptor or - * the default "missing" image descriptor if one could not be - * found - */ - public Image getImage(ImageDescriptor descriptor) { - if (descriptor == null) - descriptor= ImageDescriptor.getMissingImageDescriptor(); - - Image result= (Image)getImageDescriptorRegistry().get(descriptor); - if (result != null) - return result; - - result= descriptor.createImage(); - if (result != null) - getImageDescriptorRegistry().put(descriptor, result); - return result; - } - - /** - * Retrieves the image descriptor associated with resource from the image - * descriptor registry. If the image descriptor cannot be retrieved, - * attempt to find and load the image descriptor at the location specified - * in resource. - * - * @param resource - * the image descriptor to retrieve - * @return ImageDescriptor the image descriptor assocated with resource or - * the default "missing" image descriptor if one could not be - * found - */ - public ImageDescriptor getImageDescriptor(String resource) { - ImageDescriptor imageDescriptor = null; - Object o = getImageDescriptorRegistry().get(resource); - if (o == null) { - //create a descriptor - imageDescriptor = createImageDescriptor(resource); - } - else { - imageDescriptor = (ImageDescriptor) o; - } - return imageDescriptor; - } - - /** - * Returns the image descriptor registry for this plugin. - * - * @return HashMap - image descriptor registry for this plugin - */ - private HashMap getImageDescriptorRegistry() { - if (fImageDescRegistry == null) - fImageDescRegistry = new HashMap(); - return fImageDescRegistry; - } - - /** - * Returns the image registry for this plugin. - * - * @return ImageRegistry - image registry for this plugin - */ - private ImageRegistry getImageRegistry() { - return JFaceResources.getImageRegistry(); - } - - /** - * Creates an image from the given resource and adds the image to the - * image registry. - * - * @param resource - * @return Image - */ - private Image createImage(String resource) { - ImageDescriptor desc = getImageDescriptor(resource); - Image image = null; - - if (desc != null) { - image = desc.createImage(); - // dont add the missing image descriptor image to the image registry - if (!desc.equals(ImageDescriptor.getMissingImageDescriptor())) - getImageRegistry().put(resource, image); - } - return image; - } - - /** - * Creates an image descriptor from the given imageFilePath and adds the - * image descriptor to the image descriptor registry. If an image - * descriptor could not be created, the default "missing" image descriptor - * is returned but not added to the image descriptor registry. - * - * @param imageFilePath - * @return ImageDescriptor image descriptor for imageFilePath or default - * "missing" image descriptor if resource could not be found - */ - private ImageDescriptor createImageDescriptor(String imageFilePath) { - ImageDescriptor imageDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(PLUGINID, imageFilePath); - if (imageDescriptor != null) { - getImageDescriptorRegistry().put(imageFilePath, imageDescriptor); - } - else { - imageDescriptor = ImageDescriptor.getMissingImageDescriptor(); - } - - return imageDescriptor; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/editor/JSPEditorPluginImages.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/editor/JSPEditorPluginImages.java deleted file mode 100644 index ab3aa1fbf7..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/editor/JSPEditorPluginImages.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.editor; - -/** - * Bundle of most images used by the JSP Editor plug-in. - */ -public class JSPEditorPluginImages { - public static final String IMG_OBJ_CLASS_OBJ = "icons/full/obj16/class_obj.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_TAG_JSP = "icons/full/obj16/tag-jsp.gif"; //$NON-NLS-1$ - public static final String IMG_OBJ_PUBLIC = "icons/full/obj16/public.gif"; //$NON-NLS-1$ - - public static final String FIELD_PROTECTED_OBJ = "icons/full/obj16/field_protected_obj.gif"; //$NON-NLS-1$ - public static final String FIELD_PUBLIC_OBJ = "icons/full/obj16/field_public_obj.gif"; //$NON-NLS-1$ - public static final String FIELD_DEFAULT_OBJ= "icons/full/obj16/field_default_obj.gif"; //$NON-NLS-1$ - public static final String FIELD_PRIVATE_OBJ = "icons/full/obj16/field_private_obj.gif"; //$NON-NLS-1$ - - public static final String DEFAULT_CO = "icons/full/obj16/default_co.gif"; //$NON-NLS-1$ - public static final String PROTECTED_CO = "icons/full/obj16/protected_co.gif"; //$NON-NLS-1$ - public static final String PUBLIC_CO = "icons/full/obj16/public_co.gif"; //$NON-NLS-1$ - public static final String PRIVATE_CO = "icons/full/obj16/private_co.gif"; //$NON-NLS-1$ - - public static final String INNERCLASS_DEFAULT_OBJ= "icons/full/obj16/innerclass_default_obj.gif"; //$NON-NLS-1$ - public static final String INNERCLASS_PRIVATE_OBJ = "icons/full/obj16/innerclass_private_obj.gif"; //$NON-NLS-1$ - public static final String INNERCLASS_PROTECTED_OBJ = "icons/full/obj16/innerclass_protected_obj.gif"; //$NON-NLS-1$ - public static final String INNERCLASS_PUBLIC_OBJ = "icons/full/obj16/innerclass_public_obj.gif"; //$NON-NLS-1$ - - public static final String INNERINTERFACE_DEFAULT_OBJ = "icons/full/obj16/innerinterface_default_obj.gif"; //$NON-NLS-1$ - public static final String INNERINTERFACE_PRIVATE_OBJ = "icons/full/obj16/innerinterface_private_obj.gif"; //$NON-NLS-1$ - public static final String INNERINTERFACE_PROTECTED_OBJ = "icons/full/obj16/innerinterface_protected_obj.gif"; //$NON-NLS-1$ - public static final String INNERINTERFACE_PUBLIC_OBJ = "icons/full/obj16/innerinterface_public_obj.gif"; //$NON-NLS-1$ - - public static final String PACKAGE_OBJ = "icons/full/obj16/package_obj.gif"; //$NON-NLS-1$ - - public static final String LOCAL_VARIABLE_OBJ = "icons/full/obj16/localvariable_obj.gif"; //$NON-NLS-1$ -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/ExternalFileEditorInput.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/ExternalFileEditorInput.java deleted file mode 100644 index ccb07340ee..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/ExternalFileEditorInput.java +++ /dev/null @@ -1,146 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.hyperlink; - -import java.io.File; - -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IPersistableElement; -import org.eclipse.ui.editors.text.ILocationProvider; -import org.eclipse.ui.model.IWorkbenchAdapter; - -/** - * EditorInput for external files. Copied from - * org.eclipse.ui.internal.editors.text.JavaFileEditorInput - */ -class ExternalFileEditorInput implements IEditorInput, ILocationProvider { - // copies of this class exist in: - // org.eclipse.wst.xml.ui.internal.hyperlink - // org.eclipse.wst.html.ui.internal.hyperlink - // org.eclipse.jst.jsp.ui.internal.hyperlink - - /** - * The workbench adapter which simply provides the label. - * - * @since 3.1 - */ - private class WorkbenchAdapter implements IWorkbenchAdapter { - /* - * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(java.lang.Object) - */ - public Object[] getChildren(Object o) { - return null; - } - - /* - * @see org.eclipse.ui.model.IWorkbenchAdapter#getImageDescriptor(java.lang.Object) - */ - public ImageDescriptor getImageDescriptor(Object object) { - return null; - } - - /* - * @see org.eclipse.ui.model.IWorkbenchAdapter#getLabel(java.lang.Object) - */ - public String getLabel(Object o) { - return ((ExternalFileEditorInput) o).getName(); - } - - /* - * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(java.lang.Object) - */ - public Object getParent(Object o) { - return null; - } - } - - private File fFile; - private WorkbenchAdapter fWorkbenchAdapter = new WorkbenchAdapter(); - - public ExternalFileEditorInput(File file) { - super(); - fFile = file; - fWorkbenchAdapter = new WorkbenchAdapter(); - } - - /* - * @see org.eclipse.ui.IEditorInput#exists() - */ - public boolean exists() { - return fFile.exists(); - } - - /* - * @see org.eclipse.ui.IEditorInput#getImageDescriptor() - */ - public ImageDescriptor getImageDescriptor() { - return null; - } - - /* - * @see org.eclipse.ui.IEditorInput#getName() - */ - public String getName() { - return fFile.getName(); - } - - /* - * @see org.eclipse.ui.IEditorInput#getPersistable() - */ - public IPersistableElement getPersistable() { - return null; - } - - /* - * @see org.eclipse.ui.IEditorInput#getToolTipText() - */ - public String getToolTipText() { - return fFile.getAbsolutePath(); - } - - /* - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class adapter) { - if (ILocationProvider.class.equals(adapter)) - return this; - if (IWorkbenchAdapter.class.equals(adapter)) - return fWorkbenchAdapter; - return Platform.getAdapterManager().getAdapter(this, adapter); - } - - /* - * @see org.eclipse.ui.editors.text.ILocationProvider#getPath(java.lang.Object) - */ - public IPath getPath(Object element) { - if (element instanceof ExternalFileEditorInput) { - ExternalFileEditorInput input = (ExternalFileEditorInput) element; - return Path.fromOSString(input.fFile.getAbsolutePath()); - } - return null; - } - - /* - * @see java.lang.Object#equals(java.lang.Object) - */ - public boolean equals(Object o) { - if (o == this) - return true; - - if (o instanceof ExternalFileEditorInput) { - ExternalFileEditorInput input = (ExternalFileEditorInput) o; - return fFile.equals(input.fFile); - } - - return false; - } - - /* - * @see java.lang.Object#hashCode() - */ - public int hashCode() { - return fFile.hashCode(); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/ExternalFileHyperlink.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/ExternalFileHyperlink.java deleted file mode 100644 index 61d6be1f81..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/ExternalFileHyperlink.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.hyperlink; - -import java.io.File; - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; - -/** - * Hyperlink for external files. - */ -class ExternalFileHyperlink implements IHyperlink { - // copies of this class exist in: - // org.eclipse.wst.xml.ui.internal.hyperlink - // org.eclipse.wst.html.ui.internal.hyperlink - // org.eclipse.jst.jsp.ui.internal.hyperlink - - private IRegion fHyperlinkRegion; - private File fHyperlinkFile; - - public ExternalFileHyperlink(IRegion region, File file) { - fHyperlinkFile = file; - fHyperlinkRegion = region; - } - - public IRegion getHyperlinkRegion() { - return fHyperlinkRegion; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel() - */ - public String getTypeLabel() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText() - */ - public String getHyperlinkText() { - // TODO Auto-generated method stub - return null; - } - - public void open() { - if (fHyperlinkFile != null) { - IEditorInput input = new ExternalFileEditorInput(fHyperlinkFile); - IEditorDescriptor descriptor; - try { - descriptor = IDE.getEditorDescriptor(input.getName()); - if (descriptor != null) { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IDE.openEditor(page, input, descriptor.getId(), true); - } - } - catch (PartInitException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/JSPJavaHyperlink.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/JSPJavaHyperlink.java deleted file mode 100644 index 539f95951c..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/JSPJavaHyperlink.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.hyperlink; - -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.ui.IEditorPart; - -/** - * Hyperlink for JSP Java elements - */ -class JSPJavaHyperlink implements IHyperlink { - private IRegion fRegion; - private IJavaElement fElement; - - public JSPJavaHyperlink(IRegion region, IJavaElement element) { - fRegion = region; - fElement = element; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkRegion() - */ - public IRegion getHyperlinkRegion() { - return fRegion; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel() - */ - public String getTypeLabel() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText() - */ - public String getHyperlinkText() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#open() - */ - public void open() { - try { - IEditorPart editor = JavaUI.openInEditor(fElement); - if (editor != null) { - JavaUI.revealInEditor(editor, fElement); - } - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/JSPJavaHyperlinkDetector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/JSPJavaHyperlinkDetector.java deleted file mode 100644 index f7a963c065..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/JSPJavaHyperlinkDetector.java +++ /dev/null @@ -1,237 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.hyperlink; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IField; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.ILocalVariable; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.ISourceRange; -import org.eclipse.jdt.core.ISourceReference; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; - -/** - * Detects hyperlinks in JSP Java content - */ -public class JSPJavaHyperlinkDetector implements IHyperlinkDetector { - - private IHyperlink createHyperlink(IJavaElement element, IRegion region, IDocument document) { - IHyperlink link = null; - if (region != null) { - // open local variable in the JSP file... - if (element instanceof ISourceReference) { - IFile file = null; - int jspOffset = 0; - IStructuredModel sModel = null; - - // try to locate the file in the workspace - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (sModel != null) { - String uriString = sModel.getResolver().getFileBaseLocation(); - file = getFile(uriString); - } - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - - // get Java range, translate coordinate to JSP - - try { - ISourceRange range = null; - IJSPTranslation jspTranslation = getJSPTranslation(document); - if (jspTranslation != null) { - // link to local variable definitions - if (element instanceof ILocalVariable) { - range = ((ILocalVariable) element).getNameRange(); - } - // linking to fields of the same compilation unit - else if (element.getElementType() == IJavaElement.FIELD) { - Object cu = ((IField) element).getCompilationUnit(); - if (cu != null && cu.equals(jspTranslation.getCompilationUnit())) - range = ((ISourceReference) element).getSourceRange(); - } - // linking to methods of the same compilation unit - else if (element.getElementType() == IJavaElement.METHOD) { - Object cu = ((IMethod) element).getCompilationUnit(); - if (cu != null && cu.equals(jspTranslation.getCompilationUnit())) - range = ((ISourceReference) element).getSourceRange(); - } - } - - if (range != null && file != null && file.exists()) { - jspOffset = jspTranslation.getJspOffset(range.getOffset()); - if (jspOffset >= 0) { - link = new WorkspaceFileHyperlink(region, file, new Region(jspOffset, range.getLength())); - } - } - } - catch (JavaModelException jme) { - Logger.log(Logger.WARNING_DEBUG, jme.getMessage(), jme); - } - } - if (link == null) { - link = new JSPJavaHyperlink(region, element); - } - } - return link; - } - - /* - * (non-Javadoc) - * - * @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) { - List hyperlinks = new ArrayList(0); - - if (region != null && textViewer != null) { - IDocument document = textViewer.getDocument(); - - // check and make sure this is a valid Java type - JSPTranslation jspTranslation = getJSPTranslation(document); - if (jspTranslation != null) { - // check if we are in JSP Java content - int javaOffset = jspTranslation.getJavaOffset(region.getOffset()); - if (javaOffset > -1) { - // check that we are not in indirect Java content (like - // included files) - if (!jspTranslation.isIndirect(javaOffset)) { - // get Java elements - IJavaElement[] elements = jspTranslation.getElementsFromJspRange(region.getOffset(), region.getOffset() + region.getLength()); - if (elements != null && elements.length > 0) { - // create a JSPJavaHyperlink for each Java element - for (int i = 0; i < elements.length; ++i) { - IJavaElement element = elements[i]; - - // find hyperlink range for Java element - IRegion hyperlinkRegion = selectWord(document, region.getOffset()); - IHyperlink link = createHyperlink(element, hyperlinkRegion, document); - if (link != null) { - hyperlinks.add(link); - } - } - } - } - } - } - } - - if (hyperlinks.size() == 0) - return null; - return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[0]); - } - - /** - * Returns an IFile from the given uri if possible, null if cannot find - * file from uri. - * - * @param fileString - * file system path - * @return returns IFile if fileString exists in the workspace - */ - private IFile getFile(String fileString) { - IFile file = null; - - if (fileString != null) { - IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(fileString)); - for (int i = 0; i < files.length && file == null; i++) - if (files[i].exists()) - file = files[i]; - } - - return file; - } - /** - * Get JSP translation object - * - * @return JSPTranslation if one exists, null otherwise - */ - private JSPTranslation getJSPTranslation(IDocument document) { - JSPTranslation translation = null; - - XMLModel xmlModel = null; - try { - xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (xmlModel != null) { - XMLDocument xmlDoc = xmlModel.getDocument(); - JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (adapter != null) { - translation = adapter.getJSPTranslation(); - } - } - } - finally { - if (xmlModel != null) - xmlModel.releaseFromRead(); - } - return translation; - } - - /** - * Java always selects word when defining region - * - * @param document - * @param anchor - * @return IRegion - */ - private IRegion selectWord(IDocument document, int anchor) { - - try { - int offset = anchor; - char c; - - while (offset >= 0) { - c = document.getChar(offset); - if (!Character.isJavaIdentifierPart(c)) - break; - --offset; - } - - int start = offset; - - offset = anchor; - int length = document.getLength(); - - while (offset < length) { - c = document.getChar(offset); - if (!Character.isJavaIdentifierPart(c)) - break; - ++offset; - } - - int end = offset; - - if (start == end) - return new Region(start, 0); - - return new Region(start + 1, end - start - 1); - - } - catch (BadLocationException x) { - return null; - } - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/TaglibHyperlinkDetector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/TaglibHyperlinkDetector.java deleted file mode 100644 index fe8e5ab557..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/TaglibHyperlinkDetector.java +++ /dev/null @@ -1,223 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.hyperlink; - -import java.io.File; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.TextUtilities; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; -import org.eclipse.jface.text.hyperlink.URLHyperlink; -import org.eclipse.jst.jsp.core.JSP11Namespace; -import org.eclipse.jst.jsp.core.internal.contentmodel.ITaglibRecord; -import org.eclipse.jst.jsp.core.internal.contentmodel.TLDRecord; -import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibIndex; -import org.eclipse.jst.jsp.core.internal.text.rules.StructuredTextPartitionerForJSP; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.sse.core.util.StringUtils; -import org.eclipse.wst.xml.core.document.XMLAttr; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -/** - * Detects hyperlinks for taglibs. - */ -public class TaglibHyperlinkDetector implements IHyperlinkDetector { - private final String HTTP_PROTOCOL = "http://";//$NON-NLS-1$ - - public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { - IHyperlink hyperlink = null; - - if (textViewer != null && region != null) { - IDocument doc = textViewer.getDocument(); - if (doc != null) { - try { - // check if jsp tag/directive first - ITypedRegion partition = TextUtilities.getPartition(doc, IStructuredDocument.DEFAULT_STRUCTURED_PARTITIONING, region.getOffset(), false); - if (partition != null && partition.getType() == StructuredTextPartitionerForJSP.ST_JSP_DIRECTIVE) { - // check if jsp taglib directive - Node currentNode = getCurrentNode(doc, region.getOffset()); - if (currentNode != null && currentNode.getNodeType() == Node.ELEMENT_NODE && JSP11Namespace.ElementName.DIRECTIVE_TAGLIB.equalsIgnoreCase(currentNode.getNodeName())) { - // get the uri attribute - Attr taglibNode = ((Element) currentNode).getAttributeNode(JSP11Namespace.ATTR_NAME_URI); - ITaglibRecord reference = TaglibIndex.resolve(getBaseLocationForTaglib(doc), taglibNode.getValue(), false); - if (reference != null) { - // handle taglibs - switch (reference.getRecordType()) { - case (ITaglibRecord.TLD) : { - TLDRecord record = (TLDRecord) reference; - String uriString = record.getLocation().toString(); - IRegion hyperlinkRegion = getHyperlinkRegion(taglibNode); - hyperlink = createHyperlink(uriString, hyperlinkRegion, doc, taglibNode); - } - break; - case (ITaglibRecord.JAR) : - case (ITaglibRecord.URL) : { - IRegion hyperlinkRegion = getHyperlinkRegion(taglibNode); - hyperlink = new TaglibJarUriHyperlink(hyperlinkRegion, reference); - } - } - } - } - } - } - catch (BadLocationException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } - if (hyperlink != null) - return new IHyperlink[]{hyperlink}; - return null; - } - - /** - * Get the base location from the current model (if within workspace, - * location is relative to workspace, otherwise, file system path) - */ - private String getBaseLocationForTaglib(IDocument document) { - String baseLoc = null; - - // get the base location from the current model - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (sModel != null) { - baseLoc = sModel.getBaseLocation(); - } - } - finally { - if (sModel != null) { - sModel.releaseFromRead(); - } - } - return baseLoc; - } - - // the below methods were copied from URIHyperlinkDetector - - private IRegion getHyperlinkRegion(Node node) { - IRegion hyperRegion = null; - - if (node != null) { - short nodeType = node.getNodeType(); - if (nodeType == Node.DOCUMENT_TYPE_NODE) { - // handle doc type node - XMLNode docNode = (XMLNode) node; - hyperRegion = new Region(docNode.getStartOffset(), docNode.getEndOffset() - docNode.getStartOffset()); - } - else if (nodeType == Node.ATTRIBUTE_NODE) { - // handle attribute nodes - XMLAttr att = (XMLAttr) node; - // do not include quotes in attribute value region - int regOffset = att.getValueRegionStartOffset(); - int regLength = att.getValueRegion().getTextLength(); - String attValue = att.getValueRegionText(); - if (StringUtils.isQuoted(attValue)) { - regOffset = ++regOffset; - regLength = regLength - 2; - } - hyperRegion = new Region(regOffset, regLength); - } - } - return hyperRegion; - } - - /** - * Returns an IFile from the given uri if possible, null if cannot find - * file from uri. - * - * @param fileString - * file system path - * @return returns IFile if fileString exists in the workspace - */ - private IFile getFile(String fileString) { - IFile file = null; - - if (fileString != null) { - IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(fileString)); - for (int i = 0; i < files.length && file == null; i++) - if (files[i].exists()) - file = files[i]; - } - - return file; - } - - /** - * Create the appropriate hyperlink - * - * @param uriString - * @param hyperlinkRegion - * @return IHyperlink - */ - private IHyperlink createHyperlink(String uriString, IRegion hyperlinkRegion, IDocument document, Node node) { - IHyperlink link = null; - - if (uriString != null) { - String temp = uriString.toLowerCase(); - if (temp.startsWith(HTTP_PROTOCOL)) { - // this is a URLHyperlink since this is a web address - link = new URLHyperlink(hyperlinkRegion, uriString); - } - - // try to locate the file in the workspace - IFile file = getFile(uriString); - if (file != null && file.exists()) { - // this is a WorkspaceFileHyperlink since file exists in - // workspace - link = new WorkspaceFileHyperlink(hyperlinkRegion, file); - } - else { - // this is an ExternalFileHyperlink since file does not exist - // in workspace - File externalFile = new File(uriString); - link = new ExternalFileHyperlink(hyperlinkRegion, externalFile); - } - } - - return link; - } - - /** - * Returns the node the cursor is currently on in the document. null if no - * node is selected - * - * @param offset - * @return Node either element, doctype, text, or null - */ - private Node getCurrentNode(IDocument document, int offset) { - // get the current node at the offset (returns either: element, - // doctype, text) - IndexedRegion inode = null; - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document); - inode = sModel.getIndexedRegion(offset); - if (inode == null) - inode = sModel.getIndexedRegion(offset - 1); - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - - if (inode instanceof Node) { - return (Node) inode; - } - return null; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/TaglibJarHyperlink.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/TaglibJarHyperlink.java deleted file mode 100644 index f612725d8a..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/TaglibJarHyperlink.java +++ /dev/null @@ -1,114 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.hyperlink; - -import java.io.File; -import java.io.InputStream; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; - -/** - * Hyperlink for taglib files in jars. - */ -class TaglibJarHyperlink implements IHyperlink { - static class ZipStorage implements IStorage { - File fFile = null; - String fEntryName = null; - - ZipStorage(File file, String entryName) { - fFile = file; - fEntryName = entryName; - } - - public InputStream getContents() throws CoreException { - InputStream stream = null; - try { - ZipFile file = new ZipFile(fFile); - ZipEntry entry = file.getEntry(fEntryName); - stream = file.getInputStream(entry); - } - catch (Exception e) { - throw new CoreException(new Status(IStatus.ERROR, JSPUIPlugin.getDefault().getBundle().getSymbolicName(), IStatus.ERROR, getFullPath().toString(), e)); - } - return stream; - } - - public IPath getFullPath() { - return new Path(fFile.getAbsolutePath() + IPath.SEPARATOR + fEntryName); - } - - public String getName() { - return fEntryName; - } - - public boolean isReadOnly() { - return true; - } - - public Object getAdapter(Class adapter) { - return null; - } - } - - private IRegion fRegion; - private IPath fZipFilePath; - - public TaglibJarHyperlink(IRegion region, IPath zipFilePath) { - fRegion = region; - fZipFilePath = zipFilePath; - } - - public IRegion getHyperlinkRegion() { - return fRegion; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel() - */ - public String getTypeLabel() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText() - */ - public String getHyperlinkText() { - // TODO Auto-generated method stub - return null; - } - - public void open() { - IEditorInput input = new URLFileHyperlink.StorageEditorInput(new ZipStorage(fZipFilePath.toFile(), "META-INF/taglib.tld")); - IEditorDescriptor descriptor; - try { - descriptor = IDE.getEditorDescriptor(input.getName()); - if (descriptor != null) { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IDE.openEditor(page, input, descriptor.getId(), true); - } - } - catch (PartInitException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/TaglibJarUriHyperlink.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/TaglibJarUriHyperlink.java deleted file mode 100644 index aab8f408f3..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/TaglibJarUriHyperlink.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.hyperlink; - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.jst.jsp.core.internal.contentmodel.ITaglibRecord; -import org.eclipse.jst.jsp.core.internal.contentmodel.JarRecord; -import org.eclipse.jst.jsp.core.internal.contentmodel.URLRecord; - -/** - * Hyperlink for taglib files in jars or specified by urls. - */ -class TaglibJarUriHyperlink implements IHyperlink { - private IRegion fRegion; - private ITaglibRecord fTaglibRecord; - private IHyperlink fHyperlink; - - public TaglibJarUriHyperlink(IRegion region, ITaglibRecord record) { - fRegion = region; - fTaglibRecord = record; - } - - private IHyperlink getHyperlink() { - if (fHyperlink == null && fTaglibRecord != null) { - switch (fTaglibRecord.getRecordType()) { - case (ITaglibRecord.JAR) : { - JarRecord record = (JarRecord) fTaglibRecord; - fHyperlink = new TaglibJarHyperlink(fRegion, record.getLocation()); - } - break; - case (ITaglibRecord.URL) : { - URLRecord record = (URLRecord) fTaglibRecord; - fHyperlink = new URLFileHyperlink(fRegion, record.getURL()); - } - } - } - return fHyperlink; - } - - public IRegion getHyperlinkRegion() { - IRegion region = null; - - IHyperlink link = getHyperlink(); - if (link != null) { - region = link.getHyperlinkRegion(); - } - return region; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel() - */ - public String getTypeLabel() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText() - */ - public String getHyperlinkText() { - // TODO Auto-generated method stub - return null; - } - - public void open() { - IHyperlink link = getHyperlink(); - if (link != null) { - link.open(); - } - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/URIHyperlinkDetector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/URIHyperlinkDetector.java deleted file mode 100644 index 4f4ac76db9..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/URIHyperlinkDetector.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.hyperlink; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.wst.common.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.util.StringUtils; -import org.eclipse.wst.sse.core.util.URIResolver; -import org.w3c.dom.Attr; -import org.w3c.dom.Node; - -/** - * Detects hyperlinks in tags. Includes detection in DOCTYPE and attribute - * values. Resolves references to schemas, dtds, href, file, src, etc using the - * Web Project Resolver. - * - */ -public class URIHyperlinkDetector extends XMLHyperlinkDetector { - // copies of this class exist in: - // org.eclipse.wst.html.ui.internal.hyperlink - // org.eclipse.jst.jsp.ui.internal.hyperlink - - private final String SCHEMA_LOCATION = "schemaLocation"; //$NON-NLS-1$ - private final String XMLNS = "xmlns"; //$NON-NLS-1$ - private final String XSI_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$ - - protected String getURIString(Node node, IDocument document) { - if (isXMLHandled(node)) - return super.getURIString(node, document); - - String resolvedURI = null; - if (node.getNodeType() == Node.ATTRIBUTE_NODE) { - // handle attribute node - Attr attrNode = (Attr) node; - String attrValue = attrNode.getValue(); - attrValue = StringUtils.strip(attrValue); - - if (attrValue != null && attrValue.length() > 0) { - // currently using model's URI resolver until a better resolver is - // extended to common extensible URI resolver - // future_TODO: should use the new common extensible URI resolver - // when - // clients start implementing it - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (sModel != null) { - URIResolver resolver = sModel.getResolver(); - resolvedURI = resolver != null ? resolver.getLocationByURI(attrValue, true) : attrValue; - } - } - catch (Exception e) { - Logger.logException(e); - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - } - } - return resolvedURI; - } - - /** - * Check if this is an xml-related node (schema location, doctype). - * @param node - * @return - */ - private boolean isXMLHandled(Node node) { - short nodeType = node.getNodeType(); - if (nodeType == Node.DOCUMENT_TYPE_NODE) { - return true; - } else if (nodeType == Node.ATTRIBUTE_NODE) { - Attr attrNode = (Attr) node; - String attrName = attrNode.getName(); - - // handle schemaLocation attribute - String prefix = DOMNamespaceHelper.getPrefix(attrName); - String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attrName); - if ((XMLNS.equals(prefix)) || (XMLNS.equals(unprefixedName))) { - return true; - } else if ((XSI_NAMESPACE_URI.equals(DOMNamespaceHelper.getNamespaceURI(attrNode))) && (SCHEMA_LOCATION.equals(unprefixedName))) { - return true; - } - } - return false; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/URLFileHyperlink.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/URLFileHyperlink.java deleted file mode 100644 index 092f6bdeca..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/URLFileHyperlink.java +++ /dev/null @@ -1,161 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.hyperlink; - -import java.io.InputStream; -import java.net.URL; - -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IPersistableElement; -import org.eclipse.ui.IStorageEditorInput; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; - -/** - * Hyperlink for URLs (opens in read-only mode) - */ -class URLFileHyperlink implements IHyperlink { - // copies of this class exist in: - // org.eclipse.wst.xml.ui.internal.hyperlink - // org.eclipse.wst.html.ui.internal.hyperlink - // org.eclipse.jst.jsp.ui.internal.hyperlink - - static class StorageEditorInput implements IStorageEditorInput { - IStorage fStorage = null; - - StorageEditorInput(IStorage storage) { - fStorage = storage; - } - - public IStorage getStorage() throws CoreException { - return fStorage; - } - - public boolean exists() { - return fStorage != null; - } - - public ImageDescriptor getImageDescriptor() { - return null; - } - - public String getName() { - return fStorage.getName(); - } - - public IPersistableElement getPersistable() { - return null; - } - - public String getToolTipText() { - return fStorage.getFullPath().toString(); - } - - public Object getAdapter(Class adapter) { - return null; - } - } - - static class URLStorage implements IStorage { - URL fURL = null; - - URLStorage(URL url) { - fURL = url; - } - - public InputStream getContents() throws CoreException { - InputStream stream = null; - try { - stream = fURL.openStream(); - } - catch (Exception e) { - throw new CoreException(new Status(IStatus.ERROR, JSPUIPlugin.getDefault().getBundle().getSymbolicName(), IStatus.ERROR, fURL.toString(), e)); - } - return stream; - } - - public IPath getFullPath() { - return new Path(fURL.toString()); - } - - public String getName() { - return new Path(fURL.getFile()).lastSegment(); - } - - public boolean isReadOnly() { - return true; - } - - public Object getAdapter(Class adapter) { - return null; - } - - } - - private IRegion fRegion; - private URL fURL; - - public URLFileHyperlink(IRegion region, URL url) { - fRegion = region; - fURL = url; - } - - public IRegion getHyperlinkRegion() { - return fRegion; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel() - */ - public String getTypeLabel() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText() - */ - public String getHyperlinkText() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#open() - */ - public void open() { - if (fURL != null) { - IEditorInput input = new StorageEditorInput(new URLStorage(fURL)); - IEditorDescriptor descriptor; - try { - descriptor = IDE.getEditorDescriptor(input.getName()); - if (descriptor != null) { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IDE.openEditor(page, input, descriptor.getId(), true); - } - } - catch (PartInitException e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } - -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/WorkspaceFileHyperlink.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/WorkspaceFileHyperlink.java deleted file mode 100644 index 66c1725193..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/WorkspaceFileHyperlink.java +++ /dev/null @@ -1,79 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.hyperlink; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.jst.jsp.ui.internal.Logger; - -/** - * Hyperlink for files within the workspace. (As long as there is an IFile, - * this can be used) Opens the default editor for the file. - */ -class WorkspaceFileHyperlink implements IHyperlink { - // copies of this class exist in: - // org.eclipse.wst.xml.ui.internal.hyperlink - // org.eclipse.wst.html.ui.internal.hyperlink - // org.eclipse.jst.jsp.ui.internal.hyperlink - - private IRegion fRegion; - private IFile fFile; - private IRegion fHighlightRange; - - public WorkspaceFileHyperlink(IRegion region, IFile file) { - fRegion = region; - fFile = file; - } - - public WorkspaceFileHyperlink(IRegion region, IFile file, IRegion range) { - fRegion = region; - fFile = file; - fHighlightRange = range; - } - - public IRegion getHyperlinkRegion() { - return fRegion; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getTypeLabel() - */ - public String getTypeLabel() { - // TODO Auto-generated method stub - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.hyperlink.IHyperlink#getHyperlinkText() - */ - public String getHyperlinkText() { - // TODO Auto-generated method stub - return null; - } - - public void open() { - if (fFile != null && fFile.exists()) { - try { - IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); - IEditorPart editor = IDE.openEditor(page, fFile, true); - // highlight range in editor if possible - if (fHighlightRange != null && editor instanceof ITextEditor) { - ((ITextEditor) editor).setHighlightRange(fHighlightRange.getOffset(), fHighlightRange.getLength(), true); - } - } - catch (PartInitException pie) { - Logger.log(Logger.WARNING_DEBUG, pie.getMessage(), pie); - } - } - } - -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/XMLHyperlinkDetector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/XMLHyperlinkDetector.java deleted file mode 100644 index 98ccf1d6bc..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/hyperlink/XMLHyperlinkDetector.java +++ /dev/null @@ -1,467 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.hyperlink; - -import java.io.File; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.text.hyperlink.IHyperlink; -import org.eclipse.jface.text.hyperlink.IHyperlinkDetector; -import org.eclipse.jface.text.hyperlink.URLHyperlink; -import org.eclipse.wst.common.contentmodel.CMAttributeDeclaration; -import org.eclipse.wst.common.contentmodel.CMDataType; -import org.eclipse.wst.common.contentmodel.CMElementDeclaration; -import org.eclipse.wst.common.contentmodel.modelquery.ModelQuery; -import org.eclipse.wst.common.contentmodel.util.DOMNamespaceHelper; -import org.eclipse.wst.common.uriresolver.URIResolverPlugin; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.util.StringUtils; -import org.eclipse.wst.xml.core.document.XMLAttr; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.modelquery.ModelQueryUtil; -import org.w3c.dom.Attr; -import org.w3c.dom.DocumentType; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * Detects hyperlinks in XML tags. Includes detection in DOCTYPE and attribute - * values. Resolves references to schemas, dtds, etc using the Common URI - * Resolver. - * - */ -class XMLHyperlinkDetector implements IHyperlinkDetector { - // copies of this class exist in: - // org.eclipse.wst.xml.ui.internal.hyperlink - // org.eclipse.wst.html.ui.internal.hyperlink - // org.eclipse.jst.jsp.ui.internal.hyperlink - - private final String NO_NAMESPACE_SCHEMA_LOCATION = "noNamespaceSchemaLocation"; //$NON-NLS-1$ - private final String SCHEMA_LOCATION = "schemaLocation"; //$NON-NLS-1$ - private final String XMLNS = "xmlns"; //$NON-NLS-1$ - private final String XSI_NAMESPACE_URI = "http://www.w3.org/2001/XMLSchema-instance"; //$NON-NLS-1$ - private final String HTTP_PROTOCOL = "http://";//$NON-NLS-1$ - - public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { - // for now, only capable of creating 1 hyperlink - List hyperlinks = new ArrayList(0); - - if (region != null && textViewer != null) { - IDocument document = textViewer.getDocument(); - Node currentNode = getCurrentNode(document, region.getOffset()); - if (currentNode != null) { - String uriString = null; - if (currentNode.getNodeType() == Node.DOCUMENT_TYPE_NODE) { - // doctype nodes - uriString = getURIString(currentNode, document); - } - else if (currentNode.getNodeType() == Node.ELEMENT_NODE) { - // element nodes - Attr currentAttr = getCurrentAttrNode(currentNode, region.getOffset()); - if (currentAttr != null) { - // try to find link for current attribute - // resolve attribute value - uriString = getURIString(currentAttr, document); - // verify validity of uri string - if (!isValidURI(uriString)) - // reset current attribute - currentAttr = null; - } - if (currentAttr == null) { - // try to find a linkable attribute within element - currentAttr = getLinkableAttr((Element) currentNode); - if (currentAttr != null) { - uriString = getURIString(currentAttr, document); - } - } - currentNode = currentAttr; - } - // try to create hyperlink from information gathered - if (uriString != null && currentNode != null && isValidURI(uriString)) { - IRegion hyperlinkRegion = getHyperlinkRegion(currentNode); - IHyperlink hyperlink = createHyperlink(uriString, hyperlinkRegion, document, currentNode); - if (hyperlink != null) { - hyperlinks.add(hyperlink); - } - } - } - } - if (hyperlinks.size() == 0) - return null; - return (IHyperlink[]) hyperlinks.toArray(new IHyperlink[0]); - } - - /** - * Create the appropriate hyperlink - * - * @param uriString - * @param hyperlinkRegion - * @return IHyperlink - */ - private IHyperlink createHyperlink(String uriString, IRegion hyperlinkRegion, IDocument document, Node node) { - IHyperlink link = null; - - if (uriString != null) { - String temp = uriString.toLowerCase(); - if (temp.startsWith(HTTP_PROTOCOL)) { - // this is a URLHyperlink since this is a web address - link = new URLHyperlink(hyperlinkRegion, uriString); - } - else { - // try to locate the file in the workspace - IFile file = getFile(uriString); - if (file != null && file.exists()) { - // this is a WorkspaceFileHyperlink since file exists in - // workspace - link = new WorkspaceFileHyperlink(hyperlinkRegion, file); - } - else { - // this is an ExternalFileHyperlink since file does not - // exist - // in workspace - File externalFile = new File(uriString); - link = new ExternalFileHyperlink(hyperlinkRegion, externalFile); - } - } - } - - return link; - } - - private IRegion getHyperlinkRegion(Node node) { - IRegion hyperRegion = null; - - if (node != null) { - short nodeType = node.getNodeType(); - if (nodeType == Node.DOCUMENT_TYPE_NODE) { - // handle doc type node - XMLNode docNode = (XMLNode) node; - hyperRegion = new Region(docNode.getStartOffset(), docNode.getEndOffset() - docNode.getStartOffset()); - } - else if (nodeType == Node.ATTRIBUTE_NODE) { - // handle attribute nodes - XMLAttr att = (XMLAttr) node; - // do not include quotes in attribute value region - int regOffset = att.getValueRegionStartOffset(); - int regLength = att.getValueRegion().getTextLength(); - String attValue = att.getValueRegionText(); - if (StringUtils.isQuoted(attValue)) { - regOffset = ++regOffset; - regLength = regLength - 2; - } - hyperRegion = new Region(regOffset, regLength); - } - } - return hyperRegion; - } - - /** - * Returns the URI string - * - * @param node - - * assumes not null - */ - protected String getURIString(Node node, IDocument document) { - String resolvedURI = null; - // need the base location, publicId, and systemId for URIResolver - String baseLoc = null; - String publicId = null; - String systemId = null; - - short nodeType = node.getNodeType(); - // handle doc type node - if (nodeType == Node.DOCUMENT_TYPE_NODE) { - baseLoc = getBaseLocation(document); - publicId = ((DocumentType) node).getPublicId(); - systemId = ((DocumentType) node).getSystemId(); - } - else if (nodeType == Node.ATTRIBUTE_NODE) { - // handle attribute node - Attr attrNode = (Attr) node; - baseLoc = getBaseLocation(document); - String attrName = attrNode.getName(); - String attrValue = attrNode.getValue(); - attrValue = StringUtils.strip(attrValue); - - // handle schemaLocation attribute - String prefix = DOMNamespaceHelper.getPrefix(attrName); - String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attrName); - if ((XMLNS.equals(prefix)) || (XMLNS.equals(unprefixedName))) { - publicId = attrValue; - systemId = getLocationHint(attrNode.getOwnerElement(), publicId); - } - else if ((XSI_NAMESPACE_URI.equals(DOMNamespaceHelper.getNamespaceURI(attrNode))) && (SCHEMA_LOCATION.equals(unprefixedName))) { - // for now just use the first pair - // need to look into being more precise - StringTokenizer st = new StringTokenizer(attrValue); - publicId = st.hasMoreTokens() ? st.nextToken() : null; - systemId = st.hasMoreTokens() ? st.nextToken() : null; - // else check if xmlns publicId = value - } - else { - systemId = attrValue; - } - } - - resolvedURI = resolveURI(baseLoc, publicId, systemId); - return resolvedURI; - } - - /** - * Returns an IFile from the given uri if possible, null if cannot find - * file from uri. - * - * @param fileString - * file system path - * @return returns IFile if fileString exists in the workspace - */ - private IFile getFile(String fileString) { - IFile file = null; - - if (fileString != null) { - IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(new Path(fileString)); - for (int i = 0; i < files.length && file == null; i++) - if (files[i].exists()) - file = files[i]; - } - - return file; - } - - /** - * Checks to see if the given attribute is openable. Attribute is openable - * if it is a namespace declaration attribute or if the attribute value is - * of type URI. - * - * @param attr - * cannot be null - * @param cmElement - * CMElementDeclaration associated with the attribute (can be - * null) - * @return true if this attribute is "openOn-able" false otherwise - */ - private boolean isLinkableAttr(Attr attr, CMElementDeclaration cmElement) { - String attrName = attr.getName(); - String prefix = DOMNamespaceHelper.getPrefix(attrName); - String unprefixedName = DOMNamespaceHelper.getUnprefixedName(attrName); - // determine if attribute is namespace declaration - if ((XMLNS.equals(prefix)) || (XMLNS.equals(unprefixedName))) - return true; - - // determine if attribute contains schema location - if ((XSI_NAMESPACE_URI.equals(DOMNamespaceHelper.getNamespaceURI(attr))) && ((SCHEMA_LOCATION.equals(unprefixedName)) || (NO_NAMESPACE_SCHEMA_LOCATION.equals(unprefixedName)))) - return true; - - // determine if attribute value is of type URI - if (cmElement != null) { - CMAttributeDeclaration attrDecl = (CMAttributeDeclaration) cmElement.getAttributes().getNamedItem(attrName); - if ((attrDecl != null) && (attrDecl.getAttrType() != null) && (CMDataType.URI.equals(attrDecl.getAttrType().getDataTypeName()))) { - return true; - } - } - return false; - } - - /** - * Attempts to find an attribute within element that is openable. - * - * @param element - - * cannot be null - * @return Attr attribute that can be used for open on, null if no - * attribute could be found - */ - private Attr getLinkableAttr(Element element) { - CMElementDeclaration ed = getCMElementDeclaration(element); - // get the list of attributes for this node - NamedNodeMap attrs = element.getAttributes(); - for (int i = 0; i < attrs.getLength(); ++i) { - // check if this attribute is "openOn-able" - Attr att = (Attr) attrs.item(i); - if (isLinkableAttr(att, ed)) { - return att; - } - } - return null; - } - - /** - * Get the CMElementDeclaration for an element - * - * @param element - * @return CMElementDeclaration - */ - private CMElementDeclaration getCMElementDeclaration(Element element) { - CMElementDeclaration ed = null; - - ModelQuery mq = ModelQueryUtil.getModelQuery(element.getOwnerDocument()); - if (mq != null) { - ed = mq.getCMElementDeclaration(element); - } - return ed; - } - - /** - * Returns the attribute node within node at offset - * - * @param node - * @param offset - * @return Attr - */ - private Attr getCurrentAttrNode(Node node, int offset) { - if ((node instanceof IndexedRegion) && ((IndexedRegion) node).contains(offset) && (node.hasAttributes())) { - NamedNodeMap attrs = node.getAttributes(); - // go through each attribute in node and if attribute contains - // offset, return that attribute - for (int i = 0; i < attrs.getLength(); ++i) { - // assumption that if parent node is of type IndexedRegion, - // then its attributes will also be of type IndexedRegion - IndexedRegion attRegion = (IndexedRegion) attrs.item(i); - if (attRegion.contains(offset)) { - return (Attr) attrs.item(i); - } - } - } - return null; - } - - /** - * Returns the node the cursor is currently on in the document. null if no - * node is selected - * - * @param offset - * @return Node either element, doctype, text, or null - */ - private Node getCurrentNode(IDocument document, int offset) { - // get the current node at the offset (returns either: element, - // doctype, text) - IndexedRegion inode = null; - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document); - inode = sModel.getIndexedRegion(offset); - if (inode == null) - inode = sModel.getIndexedRegion(offset - 1); - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - - if (inode instanceof Node) { - return (Node) inode; - } - return null; - } - - /** - * Get the base location from the current model (local file system) - */ - private String getBaseLocation(IDocument document) { - String baseLoc = null; - - // get the base location from the current model - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(document); - if (sModel != null) { - IPath location = new Path(sModel.getBaseLocation()); - if (location.toFile().exists()) { - baseLoc = location.toString(); - } - else { - baseLoc = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(sModel.getBaseLocation()).toString(); - } - } - } - finally { - if (sModel != null) { - sModel.releaseFromRead(); - } - } - return baseLoc; - } - - /** - * Checks whether the given uriString is really pointing to a file - * - * @param uriString - * @return boolean - */ - private boolean isValidURI(String uriString) { - // try to create a uri - if (uriString != null) { - URI uri = null; - try { - uri = new URI(uriString); - } - catch (URISyntaxException e) { - // it is okay that this is not a uri - } - - File file = null; - // create a file from uri if it's not an absolute uri (ex: - // http://myfile) - if (uri != null && !uri.isAbsolute()) - file = new File(uri); - else - // create a file from uriString which is an absolute path (ex: - // d:/myfile) - file = new File(uriString); - // check if the newly created file exists - return file.exists(); - } - return false; - } - - /** - * Resolves the given URI information - * - * @param baseLocation - * @param publicId - * @param systemId - * @return String resolved uri. - */ - private String resolveURI(String baseLocation, String publicId, String systemId) { - // dont resolve if there's nothing to resolve - if ((baseLocation == null) && (publicId == null) && (systemId == null)) - return null; - return URIResolverPlugin.createResolver().resolve(baseLocation, publicId, systemId); - } - - /** - * Find the location hint for the given namespaceURI if it exists - * - * @param elementNode - - * cannot be null - * @param namespaceURI - - * cannot be null - * @return location hint (systemId) if it was found, null otherwise - */ - private String getLocationHint(Element elementNode, String namespaceURI) { - Attr schemaLocNode = elementNode.getAttributeNodeNS(XSI_NAMESPACE_URI, SCHEMA_LOCATION); - if (schemaLocNode != null) { - StringTokenizer st = new StringTokenizer(schemaLocNode.getValue()); - while (st.hasMoreTokens()) { - String publicId = st.hasMoreTokens() ? st.nextToken() : null; - String systemId = st.hasMoreTokens() ? st.nextToken() : null; - // found location hint - if (namespaceURI.equalsIgnoreCase(publicId)) - return systemId; - } - } - return null; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/BasicRefactorSearchRequestor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/BasicRefactorSearchRequestor.java deleted file mode 100644 index 4544376d40..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/BasicRefactorSearchRequestor.java +++ /dev/null @@ -1,360 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.lang.reflect.InvocationTargetException; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.search.SearchDocument; -import org.eclipse.jdt.core.search.SearchMatch; -import org.eclipse.jdt.core.search.SearchRequestor; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport; -import org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.text.edits.MalformedTreeException; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.text.edits.TextEdit; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IEditorReference; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.WorkspaceModifyOperation; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.common.encoding.CodedStreamCreator; -import org.eclipse.wst.sse.core.document.DocumentReader; -import org.eclipse.wst.sse.ui.StructuredTextEditor; - -/** - * Creates document change(s) for an IJavaElement rename. - * Changes are created for every type "match" in the workspace - * @author pavery - */ -public class BasicRefactorSearchRequestor extends SearchRequestor { - - /** - * Workspace operation to perform save on model for updated documents. - * Should only be done on models not open in an editor. - */ - private class SaveJspFileOp extends WorkspaceModifyOperation { - - private IDocument fJSPDoc = null; - private IFile fJSPFile = null; - - public SaveJspFileOp(IFile jspFile, IDocument jspDoc) { - this.fJSPDoc = jspDoc; - this.fJSPFile = jspFile; - } - - protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { - - // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=3765 - // save file w/ no intermediate model creation - - CodedStreamCreator codedStreamCreator = new CodedStreamCreator(); - Reader reader = new DocumentReader(this.fJSPDoc); - codedStreamCreator.set(this.fJSPFile, reader); - - ByteArrayOutputStream codedByteStream = null; - InputStream codedStream = null; - try { - codedByteStream = codedStreamCreator.getCodedByteArrayOutputStream(); - codedStream = new ByteArrayInputStream(codedByteStream.toByteArray()); - if (this.fJSPFile.exists()) - this.fJSPFile.setContents(codedStream, true, true, null); - else - this.fJSPFile.create(codedStream, false, null); - - } catch (CoreException e) { - Logger.logException(e); - } catch (IOException e) { - Logger.logException(e); - } - finally { - try { - if(codedByteStream != null) - codedByteStream.close(); - if(codedStream != null) - codedStream.close(); - } - catch (IOException e){ - // unlikely - } - } - } - } - // end inner class SaveJspFileOp - - /** - * Change class that wraps a text edit on the jsp document - */ - private class RenameChange extends Change { - - private TextEdit fEdit = null; - private IFile fJSPFile = null; - private IDocument fJSPDoc = null; - private String fDescription = JSPUIPlugin.getResourceString("%BasicRefactorSearchRequestor.0"); //$NON-NLS-1$ - - public RenameChange(IFile jspFile, IDocument jspDoc, TextEdit edit, String description) { - this.fEdit = edit; - this.fJSPFile = jspFile; - this.fJSPDoc = jspDoc; - this.fDescription = description; - } - - public RefactoringStatus isValid(IProgressMonitor pm)throws CoreException { - return new RefactoringStatus(); - } - - public Change perform(IProgressMonitor pm) throws CoreException { - RenameChange undoChange = null; - try { - - if(!isOpenInEditor(this.fJSPDoc)) { - // apply edit to JSP doc AND save model - undoChange = new RenameChange(this.fJSPFile, this.fJSPDoc, this.fEdit.apply(fJSPDoc), this.fDescription); - saveFile(this.fJSPFile, this.fJSPDoc); - } - else { - // just apply edit to JSP document - undoChange = new RenameChange(this.fJSPFile, this.fJSPDoc, this.fEdit.apply(fJSPDoc), this.fDescription); - } - - } catch (MalformedTreeException e) { - Logger.logException(e); - } catch (BadLocationException e) { - Logger.logException(e); - } - return undoChange; - } - - /** - * Performed in an operation since it modifies resources in the workspace - * @param jspDoc - * @throws CoreException - */ - private void saveFile(IFile jspFile, IDocument jspDoc) { - - SaveJspFileOp op = new SaveJspFileOp(jspFile, jspDoc); - - try { - op.run(JSPSearchSupport.getInstance().getProgressMonitor()); - } catch (InvocationTargetException e) { - Logger.logException(e); - } catch (InterruptedException e) { - Logger.logException(e); - } - } - - /** - * Checks if a document is open in an editor - * @param jspDoc - * @return - */ - private boolean isOpenInEditor(IDocument jspDoc) { - - IWorkbenchWindow[] windows = PlatformUI.getWorkbench().getWorkbenchWindows(); - IWorkbenchWindow w = null; - for (int i = 0; i < windows.length; i++) { - - w = windows[i]; - IWorkbenchPage page = w.getActivePage(); - if(page != null) { - - IEditorReference[] references = page.getEditorReferences(); - IEditorPart editor = null; - Object o = null; - IDocument doc = null; - for (int j = 0; j < references.length; j++) { - - editor = references[j].getEditor(true); - // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=3764 - // use adapter to get ITextEditor (for things like page designer) - o = editor.getAdapter(ITextEditor.class); - if(o != null && o instanceof StructuredTextEditor) { - - doc = ((StructuredTextEditor)o).getDocument(); - if(doc != null && doc.equals(jspDoc)) { - return true; - } - } - } - } - } - return false; - } - - public void initializeValidationData(IProgressMonitor pm) { - // TODO Auto-generated method stub - } - - public String getName() { - return this.fDescription; - } - - public Object getModifiedElement() { - return getElement(); - } - } - // end inner class RenameChange - - - /** The type being renamed (the old type)*/ - IJavaElement fElement = null; - /** The new name of the type being renamed*/ - private String fNewName = ""; //$NON-NLS-1$ - /** maps a JSPSearchDocument path -> MultiTextEdit for the java file*/ - private HashMap fSearchDocPath2JavaEditMap = null; - - public BasicRefactorSearchRequestor(IJavaElement element, String newName) { - this.fNewName = newName; - this.fElement = element; - this.fSearchDocPath2JavaEditMap = new HashMap(); - } - - public IJavaElement getElement() { - return this.fElement; - } - - /** - * @return the new name for the Type - */ - public String getNewName() { - return this.fNewName; - } - - /** - * @see org.eclipse.jdt.core.search.SearchRequestor#acceptSearchMatch(org.eclipse.jdt.core.search.SearchMatch) - */ - public void acceptSearchMatch(SearchMatch javaMatch) throws CoreException { - - String matchDocumentPath = javaMatch.getResource().getFullPath().toString(); - SearchDocument searchDoc = JSPSearchSupport.getInstance().getSearchDocument(matchDocumentPath); - - if (searchDoc != null && searchDoc instanceof JavaSearchDocumentDelegate) { - - String renameText = getRenameText((JavaSearchDocumentDelegate)searchDoc, javaMatch); - - // add it for the correct document - addJavaEdit(searchDoc.getPath(), new ReplaceEdit(javaMatch.getOffset(), javaMatch.getLength(), renameText)); - } - } - - /** - * @param searchDoc - * @return - */ - protected String getRenameText(JavaSearchDocumentDelegate searchDoc, SearchMatch javaMatch) { - return getNewName(); - } - - /** - * Adds to the multi edit for a give java document. - * @param javaDocument - * @param javaEdit - */ - private void addJavaEdit(String searchDocPath, ReplaceEdit javaEdit) { - - Object o = this.fSearchDocPath2JavaEditMap.get(searchDocPath); - if(o != null) { - - MultiTextEdit multi = (MultiTextEdit)o; - multi.addChild(javaEdit); - } - else { - // use a multi edit so doc position offsets get updated automatically - // when adding multiple child edits - MultiTextEdit multi = new MultiTextEdit(); - multi.addChild(javaEdit); - this.fSearchDocPath2JavaEditMap.put(searchDocPath, multi); - } - } - - /** - * - * @return all JSP changes for the search matches for the given Type - */ - public Change[] getChanges() { - - JSPSearchSupport support = JSPSearchSupport.getInstance(); - List changes = new ArrayList(); - Iterator keys = fSearchDocPath2JavaEditMap.keySet().iterator(); - String searchDocPath = null; - SearchDocument delegate = null; - - while(keys.hasNext()) { - // create on the fly - searchDocPath = (String)keys.next(); - MultiTextEdit javaEdit = (MultiTextEdit)fSearchDocPath2JavaEditMap.get(searchDocPath); - delegate = support.getSearchDocument(searchDocPath); - - if(delegate != null && delegate instanceof JavaSearchDocumentDelegate) { - JavaSearchDocumentDelegate javaDelegate = (JavaSearchDocumentDelegate)delegate; - changes.add(createChange(javaDelegate, javaDelegate.getJspTranslation().getJspEdit(javaEdit))); - } - } - return (Change[])changes.toArray(new Change[changes.size()]); - } - - private Change createChange(JavaSearchDocumentDelegate searchDoc, TextEdit edit) { - - IDocument doc = searchDoc.getJspTranslation().getJspDocument(); - String file = searchDoc.getFile().getName(); - String description = getDescription(); - try { - // document lines are 0 based - String lineNumber = Integer.toString(doc.getLineOfOffset(edit.getOffset()) + 1); - description += " " + MessageFormat.format(JSPUIPlugin.getResourceString("%BasicRefactorSearchRequestor.1"), new String[]{file, lineNumber}); //$NON-NLS-1$ - } - catch (BadLocationException e) { - Logger.logException(e); - } - return new RenameChange(searchDoc.getFile(), doc, edit, description); - } - - // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=3205 - // only relevant for IType refactorings - protected boolean isFullyQualified(String matchText) { - if(getElement() instanceof IType) { - String pkg = ((IType)getElement()).getPackageFragment().getElementName(); - return matchText.startsWith(pkg); - } - return false; - } - - /** - * Subclasses should override to better describe the change. - * @return - */ - protected String getDescription() { - return ""; //$NON-NLS-1$ - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPJavaSelectionProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPJavaSelectionProvider.java deleted file mode 100644 index 9b32c3542a..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPJavaSelectionProvider.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; - -class JSPJavaSelectionProvider { - static IJavaElement[] getSelection(ITextEditor textEditor) { - IJavaElement[] elements = null; - - IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); - ISelection selection = textEditor.getSelectionProvider().getSelection(); - if (selection instanceof ITextSelection) { - ITextSelection textSelection = (ITextSelection) selection; - // get the JSP translation object for this editor's document - XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(document); - try { - if (xmlModel != null) { - XMLDocument xmlDoc = xmlModel.getDocument(); - - JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (adapter != null) { - JSPTranslation translation = adapter.getJSPTranslation(); - elements = translation.getElementsFromJspRange(textSelection.getOffset(), textSelection.getOffset() + textSelection.getLength()); - } - } - } - finally { - if (xmlModel != null) - xmlModel.releaseFromRead(); - } - } - if (elements == null) { - elements = new IJavaElement[0]; - } - return elements; - } - -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMethodRenameChange.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMethodRenameChange.java deleted file mode 100644 index ac0d947224..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMethodRenameChange.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchScope; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; - -/** - * @author pavery - */ -public class JSPMethodRenameChange extends Change { - - public static Change[] createChangesFor(IMethod method, String newName) { - JSPSearchSupport support = JSPSearchSupport.getInstance(); - - // should be handled by JSPIndexManager - // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=3036 - // support.indexWorkspaceAndWait(); - - BasicRefactorSearchRequestor requestor = new JSPMethodRenameRequestor(method, newName); - support.searchRunnable(method, new JSPSearchScope(), requestor); - - return requestor.getChanges(); - } - - public String getName() { - return JSPUIPlugin.getResourceString("%JSP_changes"); //$NON-NLS-1$ - } - - public void initializeValidationData(IProgressMonitor pm) { - // pa_TODO implement - // must be implemented to decide correct value of isValid - } - - public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { - // pa_TODO implement - // This method must ensure that the change object is still valid. - // This is in particular interesting when performing an undo change - // since the workspace could have changed since the undo change has - // been created. - return new RefactoringStatus(); - } - - public Change perform(IProgressMonitor pm) throws CoreException { - // pa_TODO return the "undo" change here - return null; - } - - public Object getModifiedElement() { - // pa_TODO Auto-generated method stub - return null; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMethodRenameParticipant.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMethodRenameParticipant.java deleted file mode 100644 index 600a74a032..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMethodRenameParticipant.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -/* - * Created on May 6, 2004 - * - * TODO To change the template for this generated file go to - * Window - Preferences - Java - Code Style - Code Templates - */ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; - -/** - * @author pavery - */ -public class JSPMethodRenameParticipant extends RenameParticipant { - - private IMethod fMethod = null; - - /** - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object) - */ - protected boolean initialize(Object element) { - if(element instanceof IMethod) { - this.fMethod = (IMethod) element; - return true; - } - return false; - } - - /** - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName() - */ - public String getName() { - String name = ""; //$NON-NLS-1$ - if(this.fMethod != null) { - try { - name = this.fMethod.getSource(); - } catch (JavaModelException e) { - Logger.logException(e); - } - } - return name; - } - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) - */ - public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor) - */ - public Change createChange(IProgressMonitor pm) throws CoreException { - Change[] changes = JSPMethodRenameChange.createChangesFor(this.fMethod, getArguments().getNewName()); - CompositeChange multiChange = null; - if(changes.length > 0) - multiChange = new CompositeChange(JSPUIPlugin.getResourceString("%JSP_changes"), changes); //$NON-NLS-1$ - return multiChange; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMethodRenameRequestor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMethodRenameRequestor.java deleted file mode 100644 index c417700765..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMethodRenameRequestor.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import java.text.MessageFormat; - -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.search.SearchMatch; -import org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; - -/** - * @author pavery - */ -public class JSPMethodRenameRequestor extends BasicRefactorSearchRequestor { - - public JSPMethodRenameRequestor(IJavaElement element, String newName) { - super(element, newName); - } - - protected String getRenameText(JavaSearchDocumentDelegate searchDoc, SearchMatch javaMatch) { - - String javaText = searchDoc.getJspTranslation().getJavaText(); - String methodText = javaText.substring(javaMatch.getOffset(), javaMatch.getOffset() + javaMatch.getLength()); - String methodSuffix = methodText.substring(methodText.indexOf("(")); //$NON-NLS-1$ - return getNewName() + methodSuffix; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsp.ui.internal.java.refactoring.BasicRefactorSearchRequestor#getDescription() - */ - protected String getDescription() { - - String methodName = getElement().getElementName(); - String newName = getNewName(); - String description = MessageFormat.format(JSPUIPlugin.getResourceString("%BasicRefactorSearchRequestor.3"), new String[]{methodName, newName}); //$NON-NLS-1$ - return description; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMoveElementAction.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMoveElementAction.java deleted file mode 100644 index ce2c101b65..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPMoveElementAction.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import java.util.ResourceBundle; -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IResource; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.internal.corext.codemanipulation.CodeGenerationSettings; -import org.eclipse.jdt.internal.corext.refactoring.reorg.JavaMoveProcessor; -import org.eclipse.jdt.internal.corext.util.CodeFormatterUtil; -import org.eclipse.jdt.internal.ui.refactoring.RefactoringMessages; -import org.eclipse.jdt.internal.ui.refactoring.actions.RefactoringStarter; -import org.eclipse.jdt.internal.ui.refactoring.reorg.CreateTargetQueries; -import org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgMoveWizard; -import org.eclipse.jdt.internal.ui.refactoring.reorg.ReorgQueries; -import org.eclipse.jdt.ui.PreferenceConstants; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.ltk.core.refactoring.participants.MoveRefactoring; -import org.eclipse.ltk.ui.refactoring.RefactoringWizard; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.TextEditorAction; -import org.eclipse.wst.sse.ui.util.PlatformStatusLineUtil; - -/** - * A TextEditorAction that launches JDT move element wizard - * - * Still relies heavily on internal API - * will change post 3.0 with public move support - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61817 - * @author pavery - */ -public class JSPMoveElementAction extends TextEditorAction { - - public JSPMoveElementAction(ResourceBundle bundle, String prefix, ITextEditor editor) { - - super(bundle, prefix, editor); - } - - public boolean isEnabled() { - // always enabled, just print appropriate status to window - // if for some reason the action can't run (like multiple java elements selected) - - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.texteditor.TextEditorAction#update() - */ - public void update() { - super.update(); - PlatformStatusLineUtil.clearStatusLine(); - } - - private IJavaElement[] getSelectedElements() { - - IJavaElement[] elements = new IJavaElement[0]; - if (getTextEditor() != null) - elements = JSPJavaSelectionProvider.getSelection(getTextEditor()); - return elements; - } - - private IResource[] getResources(IJavaElement[] elements) { - - IResource[] resources = new IResource[elements.length]; - for (int i = 0; i < elements.length; i++) { - try { - resources[i] = elements[i].getPrimaryElement().getCorrespondingResource();//elements[i].getResource(); - } catch (JavaModelException e) { - Logger.logException(e); - } - } - return resources; - } - - /** - * will change post 3.0 with public move support - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61817 - */ - public void run() { - IJavaElement[] elements = getSelectedElements(); - if(elements.length > 0) { - - // need to check if it's movable - try { - JavaMoveProcessor processor= JavaMoveProcessor.create(getResources(elements), elements/*, getCodeGenerationSettings()*/); - Shell parent = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(); - - MoveRefactoring refactoring= new MoveRefactoring(processor); - - RefactoringWizard wizard= createWizard(refactoring); - - - /* - * We want to get the shell from the refactoring dialog but it's not - * known at this point, so we pass the wizard and then, once the dialog - * is open, we will have access to its shell. - */ - - processor.setCreateTargetQueries(new CreateTargetQueries(wizard)); - processor.setReorgQueries(new ReorgQueries(wizard)); - - new RefactoringStarter().activate(refactoring, wizard, parent, - RefactoringMessages.getString("OpenRefactoringWizardAction.refactoring"), //$NON-NLS-1$ - true); - - PlatformStatusLineUtil.clearStatusLine(); - - } catch (JavaModelException e) { - Logger.logException(e); - } - } - else { - PlatformStatusLineUtil.displayErrorMessage(JSPUIPlugin.getResourceString("%JSPMoveElementAction.0")); //$NON-NLS-1$ - } - } - - // these methods are copied from internal JDT class org.eclipse.jdt.internal.ui.preferences.JavaPreferencesSettings - /** - * will change post 3.0 with public move support - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61817 - */ - public static CodeGenerationSettings getCodeGenerationSettings() { - - IPreferenceStore store= PreferenceConstants.getPreferenceStore(); - - CodeGenerationSettings res= new CodeGenerationSettings(); - res.createComments= store.getBoolean(PreferenceConstants.CODEGEN_ADD_COMMENTS); - res.useKeywordThis= store.getBoolean(PreferenceConstants.CODEGEN_KEYWORD_THIS); - res.importOrder= getImportOrderPreference(store); - res.importThreshold= getImportNumberThreshold(store); - res.tabWidth= CodeFormatterUtil.getTabWidth(); - return res; - } - - /** - * will change post 3.0 with public move support - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61817 - */ - public static int getImportNumberThreshold(IPreferenceStore prefs) { - int threshold= prefs.getInt(PreferenceConstants.ORGIMPORTS_ONDEMANDTHRESHOLD); - if (threshold < 0) { - threshold= Integer.MAX_VALUE; - } - return threshold; - } - - /** - * will change post 3.0 with public move support - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61817 - */ - public static String[] getImportOrderPreference(IPreferenceStore prefs) { - String str= prefs.getString(PreferenceConstants.ORGIMPORTS_IMPORTORDER); - if (str != null) { - return unpackList(str, ";"); //$NON-NLS-1$ - } - return new String[0]; - } - - /** - * will change post 3.0 with public move support - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61817 - */ - private static String[] unpackList(String str, String separator) { - StringTokenizer tok= new StringTokenizer(str, separator); //$NON-NLS-1$ - int nTokens= tok.countTokens(); - String[] res= new String[nTokens]; - for (int i= 0; i < nTokens; i++) { - res[i]= tok.nextToken().trim(); - } - return res; - } - - /** - * will change post 3.0 with public move support - * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61817 - */ - private RefactoringWizard createWizard(MoveRefactoring refactoring) { - return new ReorgMoveWizard(refactoring); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPPackageRenameChange.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPPackageRenameChange.java deleted file mode 100644 index cc81a7b629..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPPackageRenameChange.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchScope; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; - -/** - * @author pavery - */ -public class JSPPackageRenameChange extends Change { - - public static Change[] createChangesFor(IPackageFragment pkg, String newName) { - JSPSearchSupport support = JSPSearchSupport.getInstance(); - - // should be handled by JSPIndexManager - // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=3036 - //support.indexWorkspaceAndWait(); - - BasicRefactorSearchRequestor requestor = new JSPPackageRenameRequestor(pkg, newName); - support.searchRunnable(pkg, new JSPSearchScope(), requestor); - - return requestor.getChanges(); - } - - public String getName() { - return JSPUIPlugin.getResourceString("%JSP_changes"); //$NON-NLS-1$ - } - - public void initializeValidationData(IProgressMonitor pm) { - // pa_TODO implement - // must be implemented to decide correct value of isValid - } - - public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { - // pa_TODO implement - // This method must ensure that the change object is still valid. - // This is in particular interesting when performing an undo change - // since the workspace could have changed since the undo change has - // been created. - return new RefactoringStatus(); - } - - public Change perform(IProgressMonitor pm) throws CoreException { - // TODO return the "undo" change here - return null; - } - - public Object getModifiedElement() { - - //return this.pkg; - return null; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPPackageRenameParticipant.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPPackageRenameParticipant.java deleted file mode 100644 index 719c3d78ca..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPPackageRenameParticipant.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; - -/** - * Remember to change the plugin.xml file if the name of this class changes. - * - * @author pavery - */ -public class JSPPackageRenameParticipant extends RenameParticipant { - - private IPackageFragment fPkg = null; - - /** - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object) - */ - protected boolean initialize(Object element) { - if(element instanceof IPackageFragment) { - this.fPkg = (IPackageFragment) element; - return true; - } - return false; - } - - /** - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName() - */ - public String getName() { - String name = ""; //$NON-NLS-1$ - if(this.fPkg != null) { - name = this.fPkg.getElementName(); - } - return name; - } - - /** - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) - */ - public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) { - // TODO Auto-generated method stub - return null; - } - - /** - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor) - */ - public Change createChange(IProgressMonitor pm) throws CoreException { - Change[] changes = JSPPackageRenameChange.createChangesFor(this.fPkg, getArguments().getNewName()); - CompositeChange multiChange = null; - if(changes.length > 0) - multiChange = new CompositeChange(JSPUIPlugin.getResourceString("%JSP_changes"), changes); //$NON-NLS-1$ - return multiChange; - } - - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPPackageRenameRequestor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPPackageRenameRequestor.java deleted file mode 100644 index 3e79baa69e..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPPackageRenameRequestor.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; - -/** - * Overrides get description - * @author pavery - */ -public class JSPPackageRenameRequestor extends BasicRefactorSearchRequestor { - - /** - * Element is the old package. newName is the new package name. - * @param element - * @param newName - */ - public JSPPackageRenameRequestor(IJavaElement element, String newName) { - super(element, newName); - } - - /* - * @see org.eclipse.jst.jsp.ui.internal.java.refactoring.BasicRefactorSearchRequestor#getDescription() - */ - protected String getDescription() { - String packageName = getElement().getElementName(); - String newName = getNewName(); - String description = JSPUIPlugin.getResourceString("%BasicRefactorSearchRequestor.5", new String[]{packageName, newName}); //$NON-NLS-1$ - return description; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPRenameElementAction.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPRenameElementAction.java deleted file mode 100644 index e4c772dff9..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPRenameElementAction.java +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import java.util.ResourceBundle; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IMethod; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.ui.refactoring.RenameSupport; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.texteditor.TextEditorAction; -import org.eclipse.wst.sse.ui.util.PlatformStatusLineUtil; - -/** - * A TextEditorAction that launches JDT rename element wizard - * - * @author pavery - */ -public class JSPRenameElementAction extends TextEditorAction { - - public JSPRenameElementAction(ResourceBundle bundle, String prefix, ITextEditor editor) { - - super(bundle, prefix, editor); - } - - public boolean isEnabled() { - // always enabled, just print appropriate status to window - // if for some reason the action can't run (like multiple java elements selected) - return true; - } - - /** - * @see org.eclipse.ui.texteditor.TextEditorAction#update() - */ - public void update() { - super.update(); - PlatformStatusLineUtil.clearStatusLine(); - } - - private IJavaElement getSelectedElement() { - IJavaElement element = null; - if (getTextEditor() != null) { - IJavaElement[] elements = JSPJavaSelectionProvider.getSelection(getTextEditor()); - if (elements.length == 1) - element = elements[0]; - } - return element; - } - - public void run() { - IJavaElement element = getSelectedElement(); - if(element != null) { - RenameSupport renameSupport = null; - try { - switch(element.getElementType()) { - case IJavaElement.TYPE: - renameSupport= RenameSupport.create((IType)element, element.getElementName(), RenameSupport.UPDATE_REFERENCES); - break; - case IJavaElement.METHOD: - renameSupport= RenameSupport.create((IMethod)element, element.getElementName(), RenameSupport.UPDATE_REFERENCES); - break; - case IJavaElement.PACKAGE_FRAGMENT: - renameSupport= RenameSupport.create((IPackageFragment)element, element.getElementName(), RenameSupport.UPDATE_REFERENCES); - break; - } - if(renameSupport != null) { - renameSupport.openDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); - PlatformStatusLineUtil.clearStatusLine(); - } - } - catch (CoreException e) { - Logger.logException(e); - } - } - else { - PlatformStatusLineUtil.displayErrorMessage(JSPUIPlugin.getResourceString("%JSPRenameElementAction.0")); //$NON-NLS-1$ - PlatformStatusLineUtil.addOneTimeClearListener(); - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeMoveChange.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeMoveChange.java deleted file mode 100644 index dba800962d..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeMoveChange.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.core.IType; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchScope; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; - -/** - * @author pavery - */ -public class JSPTypeMoveChange extends Change { - - public static Change[] createChangesFor(IType type, String newName) { - - JSPSearchSupport support = JSPSearchSupport.getInstance(); - // should be handled by JSPIndexManager - // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=3036 - // support.indexWorkspaceAndWait(); - - JSPTypeMoveRequestor requestor = new JSPTypeMoveRequestor(type, newName); - support.searchRunnable(type, new JSPSearchScope(), requestor); - - return requestor.getChanges(); - } - - public String getName() { - return JSPUIPlugin.getResourceString("%JSP_changes"); //$NON-NLS-1$ - } - - public void initializeValidationData(IProgressMonitor pm) { - // pa_TODO implement - // must be implemented to decide correct value of isValid - } - - public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { - // pa_TODO implement - // This method must ensure that the change object is still valid. - // This is in particular interesting when performing an undo change - // since the workspace could have changed since the undo change has - // been created. - return new RefactoringStatus(); - } - - public Change perform(IProgressMonitor pm) throws CoreException { - // TODO return the "undo" change here - return null; - } - - public Object getModifiedElement() { - return null; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeMoveParticipant.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeMoveParticipant.java deleted file mode 100644 index a3322c201d..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeMoveParticipant.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.core.IPackageFragment; -import org.eclipse.jdt.core.IType; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.MoveParticipant; - -/** - * @author pavery - */ -public class JSPTypeMoveParticipant extends MoveParticipant { - - IType fType = null; - - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object) - */ - protected boolean initialize(Object element) { - - if(element instanceof IType) { - this.fType = (IType)element; - return true; - } - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName() - */ - public String getName() { - - String name = ""; //$NON-NLS-1$ - if(this.fType != null) - name = this.fType.getElementName(); - return name; - } - - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) - */ - public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor) - */ - public Change createChange(IProgressMonitor pm) throws CoreException { - - if(pm != null && pm.isCanceled()) - return null; - - CompositeChange multiChange = null; - Object dest = getArguments().getDestination(); - Change[] changes = JSPTypeMoveChange.createChangesFor(fType, ((IPackageFragment)dest).getElementName()); - - if(dest instanceof IPackageFragment && changes.length > 0) - multiChange = new CompositeChange(JSPUIPlugin.getResourceString("%JSP_changes"), changes); //$NON-NLS-1$ - - return multiChange; - } - - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeMoveRequestor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeMoveRequestor.java deleted file mode 100644 index 01aaa315c6..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeMoveRequestor.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import java.text.MessageFormat; - -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.search.SearchMatch; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; - -/** - * @author pavery - */ -public class JSPTypeMoveRequestor extends BasicRefactorSearchRequestor { - - /** - * @param element - * @param newName - */ - public JSPTypeMoveRequestor(IJavaElement element, String newPackage) { - super(element, newPackage); - } - - protected String getRenameText(JavaSearchDocumentDelegate searchDoc, SearchMatch javaMatch) { - - String renameText = getElement().getElementName(); - - JSPTranslation trans = searchDoc.getJspTranslation(); - String matchText = trans.getJavaText().substring(javaMatch.getOffset(), javaMatch.getOffset() + javaMatch.getLength()); - - // if it's an import or jsp:useBean, we need to add the package name as well - if(trans.isImport(javaMatch.getOffset()) || trans.isUseBean(javaMatch.getOffset()) || isFullyQualified(matchText)) { - if(!getNewName().equals("")) //$NON-NLS-1$ - // getNewName() is the pkg name - renameText = getNewName() + "." + renameText; //$NON-NLS-1$ - } - return renameText; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsp.ui.internal.java.refactoring.BasicRefactorSearchRequestor#getDescription() - */ - protected String getDescription() { - - String typeName = getElement().getElementName(); - String newName = getNewName(); - String description = MessageFormat.format(JSPUIPlugin.getResourceString("%BasicRefactorSearchRequestor.2"), new String[]{typeName, newName}); //$NON-NLS-1$ - return description; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeRenameChange.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeRenameChange.java deleted file mode 100644 index 802acbf6c1..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeRenameChange.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.core.IType; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchScope; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; - - -/** - * @author pavery - */ -public class JSPTypeRenameChange extends Change { - - public static Change[] createChangesFor(IType type, String newName) { - JSPSearchSupport support = JSPSearchSupport.getInstance(); - - // should be handled by JSPIndexManager - // https://w3.opensource.ibm.com/bugzilla/show_bug.cgi?id=3036 - // support.indexWorkspaceAndWait(); - - - JSPTypeRenameRequestor requestor = new JSPTypeRenameRequestor(type, newName); - support.searchRunnable(type, new JSPSearchScope(), requestor); - - return requestor.getChanges(); - } - - public String getName() { - return JSPUIPlugin.getResourceString("%JSP_changes"); //$NON-NLS-1$ - } - - public void initializeValidationData(IProgressMonitor pm) { - // pa_TODO implement - // must be implemented to decide correct value of isValid - } - - public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException { - // pa_TODO implement - // This method must ensure that the change object is still valid. - // This is in particular interesting when performing an undo change - // since the workspace could have changed since the undo change has - // been created. - return new RefactoringStatus(); - } - - public Change perform(IProgressMonitor pm) throws CoreException { - // TODO return the "undo" change here - return null; - } - - public Object getModifiedElement() { - // TODO Auto-generated method stub - return null; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeRenameParticipant.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeRenameParticipant.java deleted file mode 100644 index 409dd804a0..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeRenameParticipant.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.ltk.core.refactoring.Change; -import org.eclipse.ltk.core.refactoring.CompositeChange; -import org.eclipse.ltk.core.refactoring.RefactoringStatus; -import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext; -import org.eclipse.ltk.core.refactoring.participants.RenameParticipant; - -/** - * Remember to change the plugin.xml file if the name of this class changes. - * - * @author pavery - */ -public class JSPTypeRenameParticipant extends RenameParticipant { - - private IType fType = null; - - /** - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object) - */ - protected boolean initialize(Object element) { - if(element instanceof IType) { - this.fType = (IType) element; - return true; - } - return false; - } - - /** - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName() - */ - public String getName() { - String name = ""; //$NON-NLS-1$ - if(this.fType != null) { - try { - name = this.fType.getSource(); - } catch (JavaModelException e) { - Logger.logException(e); - } - } - return name; - } - - /** - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext) - */ - public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) { - // TODO Auto-generated method stub - return null; - } - - /** - * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor) - */ - public Change createChange(IProgressMonitor pm) throws CoreException { - Change[] changes = JSPTypeRenameChange.createChangesFor(fType, getArguments().getNewName()); - CompositeChange multiChange = null; - if(changes.length > 0) - multiChange = new CompositeChange(JSPUIPlugin.getResourceString("%JSP_changes"), changes); //$NON-NLS-1$ - return multiChange; - } - - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeRenameRequestor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeRenameRequestor.java deleted file mode 100644 index 5566e72022..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/refactoring/JSPTypeRenameRequestor.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.refactoring; - -import java.text.MessageFormat; - -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.search.SearchMatch; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; - -/** - * Creates document change(s) for a type rename. - * Changes are created for every type "match" in the workspace - * @author pavery - */ -public class JSPTypeRenameRequestor extends BasicRefactorSearchRequestor { - - public JSPTypeRenameRequestor(IType type, String newName) { - super(type, newName); - } - - private IType getType() { - return (IType)getElement(); - } - - protected String getRenameText(JavaSearchDocumentDelegate searchDoc, SearchMatch javaMatch) { - - String renameText = getNewName(); - - String pkg = getType().getPackageFragment().getElementName(); - JSPTranslation trans = searchDoc.getJspTranslation(); - String matchText = trans.getJavaText().substring(javaMatch.getOffset(), javaMatch.getOffset() + javaMatch.getLength()); - - // if it's an import or jsp:useBean or fully qualified type, we need to add the package name as well - if(trans.isImport(javaMatch.getOffset()) || trans.isUseBean(javaMatch.getOffset()) || isFullyQualified(matchText)) { - if(!pkg.equals("")) //$NON-NLS-1$ - renameText = pkg + "." + renameText; //$NON-NLS-1$ - } - return renameText; - } - - - /* (non-Javadoc) - * @see org.eclipse.jst.jsp.ui.internal.java.refactoring.BasicRefactorSearchRequestor#getDescription() - */ - protected String getDescription() { - - String typeName = getElement().getElementName(); - String newName = getNewName(); - String description = MessageFormat.format(JSPUIPlugin.getResourceString("%BasicRefactorSearchRequestor.4"), new String[]{typeName, newName}); //$NON-NLS-1$ - return description; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/BasicJSPSearchRequestor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/BasicJSPSearchRequestor.java deleted file mode 100644 index 4744294892..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/BasicJSPSearchRequestor.java +++ /dev/null @@ -1,141 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.search; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jdt.core.search.SearchDocument; -import org.eclipse.jdt.core.search.SearchMatch; -import org.eclipse.jdt.core.search.SearchParticipant; -import org.eclipse.jdt.core.search.SearchRequestor; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport; -import org.eclipse.jst.jsp.core.internal.java.search.JavaSearchDocumentDelegate; - -/** - * Accepts matches from JSPSearchSupport.search(...) request. - * Adapts the results from java to JSP and displays in the SearchResultView. - * - * @author pavery - */ -public class BasicJSPSearchRequestor extends SearchRequestor { - - // for debugging - private static final boolean DEBUG; - static { - String value= Platform.getDebugOption("com.ibm.sse.model.jsp/debug/jspsearch"); //$NON-NLS-1$ - DEBUG= value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - - /** - * Maps java search coordinates to corresponding JSP coordinates. - * Adds the matches to the Search Results view. - * @see org.eclipse.jdt.core.search.SearchRequestor#acceptSearchMatch(org.eclipse.jdt.core.search.SearchMatch) - */ - public void acceptSearchMatch(SearchMatch match) throws CoreException { - - if(JSPSearchSupport.getInstance().isCanceled()) - return; - - String matchDocumentPath = match.getResource().getFullPath().toString(); - SearchDocument searchDoc = JSPSearchSupport.getInstance().getSearchDocument(matchDocumentPath); - - if (searchDoc != null && searchDoc instanceof JavaSearchDocumentDelegate) { - JavaSearchDocumentDelegate javaSearchDoc = (JavaSearchDocumentDelegate)searchDoc; - int jspStart = javaSearchDoc.getJspOffset(match.getOffset()); - int jspEnd = javaSearchDoc.getJspOffset(match.getOffset() + match.getLength()); - - JSPTranslation trans = javaSearchDoc.getJspTranslation(); - String jspText = trans.getJspText(); - String javaText = javaSearchDoc.getJavaText(); - - if (DEBUG) - displayDebugInfo(match, jspStart, jspEnd, jspText, javaText); - - if (jspStart > -1 && jspEnd > -1) - addSearchMatch(new Document(trans.getJspText()), javaSearchDoc.getFile(), jspStart, jspEnd, jspText); - } - } - - /** - * @param searchDoc - * @param jspStart - * @param jspEnd - * @param jspTranslation - * @param jspText - * @throws CoreException - */ - protected void addSearchMatch(IDocument jspDocument, IFile jspFile, int jspStart, int jspEnd, String jspText) { - // implement in subclass - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jdt.core.search.SearchRequestor#beginReporting() - */ - public void beginReporting() { - - if (DEBUG) - System.out.println("JSP Search requestor: beginReporting()"); //$NON-NLS-1$ - } - - /** - * @see org.eclipse.jdt.core.search.SearchRequestor#endReporting() - */ - public void endReporting() { - - if (DEBUG) - System.out.println("JSP Search requestor: endReporting()"); //$NON-NLS-1$ - } - - /** - * @see org.eclipse.jdt.core.search.SearchRequestor#enterParticipant(org.eclipse.jdt.core.search.SearchParticipant) - */ - public void enterParticipant(SearchParticipant participant) { - - if (DEBUG) - System.out.println("JSP Search requestor: enterParticipant()"); //$NON-NLS-1$ - } - - /** - * @see org.eclipse.jdt.core.search.SearchRequestor#exitParticipant(org.eclipse.jdt.core.search.SearchParticipant) - */ - public void exitParticipant(SearchParticipant participant) { - - if (DEBUG) - System.out.println("JSP Search requestor: exitParticipant()"); //$NON-NLS-1$ - } - - /** - * For debug. - * @param origMatch - * @param jspStart - * @param jspEnd - * @param jspText - * @param javaText - */ - private void displayDebugInfo(SearchMatch origMatch, int jspStart, int jspEnd, String jspText, String javaText) { - - if (origMatch == null || jspStart == -1 || jspEnd == -1 || jspEnd < jspStart || jspText == null || javaText == null) - return; - - System.out.println("+-----------------------------------------+"); //$NON-NLS-1$ - System.out.println("accept possible match [jspDoc: " + origMatch.getResource().getFullPath().toOSString() + " " + origMatch.getOffset() + ":" + origMatch.getOffset() + origMatch.getLength() + "]?"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - System.out.println("match info:"); //$NON-NLS-1$ - System.out.println("the java text is:" + javaText.substring(origMatch.getOffset(), origMatch.getOffset() + origMatch.getLength())); //$NON-NLS-1$ - System.out.println("java search match translates to jsp coords [start: " + jspStart + " end:" + jspEnd + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - System.out.println(" the jsp text is:" + jspText.substring(jspStart, jspEnd)); //$NON-NLS-1$ - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPFindOccurrencesAction.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPFindOccurrencesAction.java deleted file mode 100644 index c24bc2d48b..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPFindOccurrencesAction.java +++ /dev/null @@ -1,119 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.search; - -import java.util.ResourceBundle; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.search.IJavaSearchConstants; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.jst.jsp.core.internal.text.rules.StructuredTextPartitionerForJSP; -import org.eclipse.search.ui.ISearchQuery; -import org.eclipse.swt.graphics.Point; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.ui.StructuredTextEditor; -import org.eclipse.wst.sse.ui.internal.search.BasicFindOccurrencesAction; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; - -/** - * <p> - * Finds occurrences of Java elements in a JSP file using JSPSearchSupport. - * </p> - * - * @author pavery - */ -public class JSPFindOccurrencesAction extends BasicFindOccurrencesAction implements IJavaSearchConstants { - - private IFile fJSPFile = null; - - public JSPFindOccurrencesAction(ResourceBundle bundle, String prefix, ITextEditor editor) { - - super(bundle, prefix, editor); - } - - /** - * @see com.ibm.sse.editor.internal.search.BasicFindOccurrencesAction#getSearchQuery() - */ - public ISearchQuery getSearchQuery() { - return new JSPSearchQuery(getJspFile(), getJavaElement()); - } - - /** - * @see com.ibm.sse.editor.internal.search.BasicFindOccurrencesAction#update() - */ - public void update() { - - super.update(); - - if (isEnabled()) { - // do java element check here... - // should already be in a jsp/java partition - IJavaElement[] elements = getJavaElementsForCurrentSelection(); - // we can only find occurrences of one element - setEnabled(elements.length == 1); - } - } - - /** - * uses JSPTranslation to get currently selected Java elements. - * - * @return currently selected IJavaElements - */ - public IJavaElement[] getJavaElementsForCurrentSelection() { - - IJavaElement[] elements = new IJavaElement[0]; - StructuredTextEditor editor = (StructuredTextEditor) getTextEditor(); - // get JSP translation object for this viewer's document - IStructuredModel model = editor.getModel(); - if (model != null && model instanceof XMLModel) { - XMLDocument xmlDoc = ((XMLModel) model).getDocument(); - JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (adapter != null) { - JSPTranslation translation = adapter.getJSPTranslation(); - Point selected = editor.getSelectionRange(); - elements = translation.getElementsFromJspRange(selected.x, selected.x + selected.y); - } - } - return elements; - } - - /** - * @see com.ibm.sse.editor.internal.search.BasicFindOccurrencesAction#getPartitionTypes() - */ - public String[] getPartitionTypes() { - return new String[]{StructuredTextPartitionerForJSP.ST_DEFAULT_JSP, StructuredTextPartitionerForJSP.ST_JSP_CONTENT_JAVA}; - } - - /** - * @see com.ibm.sse.editor.internal.search.BasicFindOccurrencesAction#getRegionTypes() - */ - public String[] getRegionTypes() { - return new String[]{XMLRegionContext.BLOCK_TEXT, XMLJSPRegionContexts.JSP_CONTENT}; - } - - private IFile getJspFile() { - if (this.fJSPFile == null) - this.fJSPFile = ((StructuredTextEditor) getTextEditor()).getFileInEditor(); - return this.fJSPFile; - } - - private IJavaElement getJavaElement() { - IJavaElement[] elements = getJavaElementsForCurrentSelection(); - return elements.length > 0 ? elements[0] : null; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPOccurrencesSearchResult.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPOccurrencesSearchResult.java deleted file mode 100644 index f1d4f8e4db..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPOccurrencesSearchResult.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.search; - -import org.eclipse.search.ui.ISearchQuery; -import org.eclipse.search.ui.text.Match; -import org.eclipse.wst.sse.ui.internal.search.OccurrencesSearchResult; - -/** - * @author pavery - */ -public class JSPOccurrencesSearchResult extends OccurrencesSearchResult { - - public JSPOccurrencesSearchResult(ISearchQuery query) { - super(query); - } - - public Match[] getMatches() { - return ((JSPSearchQuery)getQuery()).getMatches(); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPSearchQuery.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPSearchQuery.java deleted file mode 100644 index 55f0dce370..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPSearchQuery.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.search; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IWorkspaceRunnable; -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.core.search.SearchDocument; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchScope; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport; -import org.eclipse.search.ui.ISearchResult; -import org.eclipse.wst.sse.ui.internal.SSEUIPlugin; -import org.eclipse.wst.sse.ui.internal.search.BasicSearchQuery; - -/** - * Implementation of <code>ISearchQuery</code> for <code>IJavaElement</code>s in JSP files. - * - * @author pavery - */ -public class JSPSearchQuery extends BasicSearchQuery { - - private class SingleFileSearch implements IWorkspaceRunnable { - - public void run(IProgressMonitor monitor) throws CoreException { - - if (getFile() != null && getJavaElement() != null) { - - JSPSearchSupport support = JSPSearchSupport.getInstance(); - // index the file - SearchDocument delegate = support.addJspFile(getFile()); - String scopePath = delegate.getPath(); - JSPSearchScope singleFileScope = new JSPSearchScope(new String[]{getFile().getFullPath().toString(), scopePath}); - - // perform a search - // by passing in this jsp search query, requstor can add matches - support.searchRunnable(getJavaElement(), singleFileScope, new JSPSingleFileSearchRequestor(getInstance())); - } - } - } - - /** the IJavaElement we are searching for in the file **/ - private IJavaElement fElement = null; - - public JSPSearchQuery(IFile file, IJavaElement element) { - super(file); - this.fElement = element; - } - - public IJavaElement getJavaElement() { - return this.fElement; - } - - // for access by inner class - public JSPSearchQuery getInstance() { - return this; - } - - /** - * @see com.ibm.sse.editor.internal.search.BasicSearchQuery#getRunnable() - */ - protected IWorkspaceRunnable getRunnable() { - return new SingleFileSearch(); - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.internal.search.BasicSearchQuery#doQuery() - */ - protected IStatus doQuery() { - - clearMatches(); - - IStatus status = Status.OK_STATUS; - try { - JSPSearchSupport support = JSPSearchSupport.getInstance(); - // index the file - SearchDocument delegate = support.addJspFile(getFile()); - String scopePath = delegate.getPath(); - JSPSearchScope singleFileScope = new JSPSearchScope(new String[]{getFile().getFullPath().toString(), scopePath}); - - // perform a searchs - // by passing in this jsp search query, requstor can add matches - support.searchRunnable(getJavaElement(), singleFileScope, new JSPSingleFileSearchRequestor(getInstance())); - } - catch (Exception e){ - status = new Status(IStatus.ERROR, "org.eclipse.wst.sse.ui", IStatus.OK, "", null); //$NON-NLS-1$ //$NON-NLS-2$ - } - return status; - } - - /** - * @see org.eclipse.search.ui.ISearchQuery#getLabel() - */ - public String getLabel() { - String[] args = {getSearchText(), getOccurrencesCountText(), getFilename()}; - return SSEUIPlugin.getResourceString("%OccurrencesSearchQuery.0", args); - } - - private String getFilename() { - String filename = SSEUIPlugin.getResourceString("%OccurrencesSearchQuery.2"); //$NON-NLS-1$ - if(getFile() != null) - filename = getFile().getName(); - return filename; - } - - private String getOccurrencesCountText() { - String count = ""; //$NON-NLS-1$ - // pa_TODO make dynamic - return count; - } - - /** - * @see com.ibm.sse.editor.internal.search.BasicSearchQuery#getSearchText() - */ - protected String getSearchText() { - return this.fElement.getElementName(); - } - - /** - * @see org.eclipse.search.ui.ISearchQuery#canRerun() - */ - public boolean canRerun() { - - return false; - } - - /** - * @see org.eclipse.search.ui.ISearchQuery#canRunInBackground() - */ - public boolean canRunInBackground() { - return true; - } - - /** - * @see org.eclipse.search.ui.ISearchQuery#getSearchResult() - */ - public ISearchResult getSearchResult() { - - return new JSPOccurrencesSearchResult(this); - } - -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPSearchRequestor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPSearchRequestor.java deleted file mode 100644 index ddd296aa57..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPSearchRequestor.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.search; - -import java.util.HashMap; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.ui.search.ISearchRequestor; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.search.ui.NewSearchUI; -import org.eclipse.search.ui.text.Match; - - -/** - * @author pavery - */ -public class JSPSearchRequestor extends BasicJSPSearchRequestor { - - private ISearchRequestor fJavaRequestor = null; - - public JSPSearchRequestor() { - super(); - } - - public JSPSearchRequestor(ISearchRequestor javaRequestor) { - // need to report matches to javaRequestor - this.fJavaRequestor = javaRequestor; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.jsp.ui.internal.java.search.BasicJSPSearchRequestor#addSearchMatch(com.ibm.sse.model.text.IStructuredDocument, org.eclipse.core.resources.IFile, int, int, java.lang.String) - */ - protected void addSearchMatch(IDocument jspDocument, IFile jspFile, int jspStart, int jspEnd, String jspText) { - - if(!jspFile.exists()) - return; - - int lineNumber = -1; - try { - lineNumber = jspDocument.getLineOfOffset(jspStart); - } catch (BadLocationException e) { - Logger.logException(e); - } - createSearchMarker(jspFile, jspStart, jspEnd, lineNumber); - - if(this.fJavaRequestor != null) { - Match match = new Match(jspFile, jspStart, jspEnd - jspStart); - this.fJavaRequestor.reportMatch(match); - } - } - - /** - * @param jspFile - * @param jspStart - * @param jspEnd - */ - private void createSearchMarker(IFile jspFile, int jspStart, int jspEnd, int lineNumber) { - - try { - IMarker marker = jspFile.createMarker(NewSearchUI.SEARCH_MARKER); - HashMap attributes = new HashMap(4); - attributes.put(IMarker.CHAR_START, new Integer(jspStart)); - attributes.put(IMarker.CHAR_END, new Integer(jspEnd)); - attributes.put(IMarker.LINE_NUMBER, new Integer(lineNumber)); - marker.setAttributes(attributes); - - } catch (CoreException e) { - Logger.logException(e); - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPSingleFileSearchRequestor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPSingleFileSearchRequestor.java deleted file mode 100644 index c058550111..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/JSPSingleFileSearchRequestor.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.search; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jface.text.IDocument; - - -/** - * <p> - * Special requestor that adds search results for single file search - * (Used for JSPFindOccurrences action). - * It groups each match as it's own result. - * </p> - * - * @author pavery - */ -public class JSPSingleFileSearchRequestor extends BasicJSPSearchRequestor { - - private JSPSearchQuery fQuery = null; - - public JSPSingleFileSearchRequestor(JSPSearchQuery query) { - this.fQuery = query; - } - - /** - * @see org.eclipse.jst.jsp.ui.internal.java.search.BasicJSPSearchRequestor#addSearchMatch(com.ibm.sse.model.text.IStructuredDocument, org.eclipse.core.resources.IFile, int, int, java.lang.String) - */ - protected void addSearchMatch(IDocument jspDocument, IFile jspFile, int jspStart, int jspEnd, String jspText) { - // add match to JSP query... - this.fQuery.addMatch(jspDocument, jspStart, jspEnd); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/ui/JSPMatchPresentation.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/ui/JSPMatchPresentation.java deleted file mode 100644 index 74b1a26c91..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/ui/JSPMatchPresentation.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.search.ui; - -import org.eclipse.jdt.ui.search.IMatchPresentation; -import org.eclipse.jface.viewers.ILabelProvider; -import org.eclipse.search.ui.text.Match; -import org.eclipse.ui.PartInitException; -import org.eclipse.wst.sse.ui.internal.search.BasicSearchLabelProvider; - -/** - * @author pavery - */ -public class JSPMatchPresentation implements IMatchPresentation { - - /** - * @see org.eclipse.jdt.ui.search.IMatchPresentation#createLabelProvider() - */ - public ILabelProvider createLabelProvider() { - return new BasicSearchLabelProvider(); - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.ui.search.IMatchPresentation#showMatch(org.eclipse.search.ui.text.Match, int, int, boolean) - */ - public void showMatch(Match match, int currentOffset, int currentLength, boolean activate) throws PartInitException { - // pa_TODO implement -// Object obj = match.getElement(); - // show match in JSP editor - if(activate) { - // use show in target? - } - else { - // just select - } - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/ui/JSPQueryParticipant.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/ui/JSPQueryParticipant.java deleted file mode 100644 index 853eae1d17..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/java/search/ui/JSPQueryParticipant.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.java.search.ui; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Platform; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.search.SearchPattern; -import org.eclipse.jdt.core.search.SearchRequestor; -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.PatternQuerySpecification; -import org.eclipse.jdt.ui.search.QuerySpecification; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchScope; -import org.eclipse.jst.jsp.core.internal.java.search.JSPSearchSupport; -import org.eclipse.jst.jsp.ui.internal.java.search.JSPSearchRequestor; - -/** - * @author pavery - */ -public class JSPQueryParticipant implements IQueryParticipant { - - // for debugging - private static final boolean DEBUG; - static { - String value= Platform.getDebugOption("com.ibm.sse.model.jsp/debug/jspsearch"); //$NON-NLS-1$ - DEBUG= value != null && value.equalsIgnoreCase("true"); //$NON-NLS-1$ - } - /** - * @see org.eclipse.jdt.ui.search.IQueryParticipant#search(org.eclipse.jdt.ui.search.ISearchRequestor, org.eclipse.jdt.ui.search.QuerySpecification, org.eclipse.core.runtime.IProgressMonitor) - */ - public void search(ISearchRequestor requestor, QuerySpecification querySpecification, IProgressMonitor monitor) throws CoreException { - - //indexIfNeeded(); - - // do search based on the particular Java query - if(querySpecification instanceof ElementQuerySpecification) { - // element search (eg. from global find references in Java file) - ElementQuerySpecification elementQuery = (ElementQuerySpecification)querySpecification; - IJavaElement element = elementQuery.getElement(); - - if(DEBUG) - System.out.println("JSP Query Participant searching on ELEMENT: " + element); //$NON-NLS-1$ - - SearchRequestor jspRequestor = new JSPSearchRequestor(requestor); - - // pa_TODO need to adapt JavaSearchScope to a JSPSearchScope - JSPSearchSupport.getInstance().search(element, new JSPSearchScope(), jspRequestor); - - } - else if(querySpecification instanceof PatternQuerySpecification) { - - // pattern search (eg. from Java search page) - PatternQuerySpecification patternQuery = (PatternQuerySpecification)querySpecification; - String pattern = patternQuery.getPattern(); - - if(DEBUG) - System.out.println("JSP Query Participant searching on PATTERN: " + pattern); //$NON-NLS-1$ - - SearchRequestor jspRequestor = new JSPSearchRequestor(requestor); - - JSPSearchSupport.getInstance().search(pattern, - new JSPSearchScope(), - patternQuery.getSearchFor(), - patternQuery.getLimitTo(), - SearchPattern.R_PATTERN_MATCH, - false, - jspRequestor); - } - } - - /** - * @see org.eclipse.jdt.ui.search.IQueryParticipant#estimateTicks(org.eclipse.jdt.ui.search.QuerySpecification) - */ - public int estimateTicks(QuerySpecification data) { - // pa_TODO use project file counter from JSPSearchSupport... - return 0; - } - - /** - * @see org.eclipse.jdt.ui.search.IQueryParticipant#getUIParticipant() - */ - public IMatchPresentation getUIParticipant() { - return new JSPMatchPresentation(); - } - -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/preferences/JSPUIPreferenceInitializer.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/preferences/JSPUIPreferenceInitializer.java deleted file mode 100644 index c623f27e68..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/preferences/JSPUIPreferenceInitializer.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.preferences; - -import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.wst.html.ui.style.IStyleConstantsHTML; -import org.eclipse.wst.sse.ui.preferences.CommonEditorPreferenceNames; -import org.eclipse.wst.sse.ui.preferences.ui.ColorHelper; -import org.eclipse.wst.xml.ui.style.IStyleConstantsXML; - -/** - * Sets default values for JSP UI preferences - */ -public class JSPUIPreferenceInitializer extends AbstractPreferenceInitializer { - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences() - */ - public void initializeDefaultPreferences() { - IPreferenceStore store = JSPUIPlugin.getDefault().getPreferenceStore(); - - // setting the same as HTML - store.setDefault(CommonEditorPreferenceNames.CONTENT_ASSIST_SUPPORTED, true); - store.setDefault(CommonEditorPreferenceNames.AUTO_PROPOSE, true); - store.setDefault(CommonEditorPreferenceNames.AUTO_PROPOSE_CODE, CommonEditorPreferenceNames.LT); - - store.setDefault(CommonEditorPreferenceNames.EDITOR_USE_INFERRED_GRAMMAR, true); - - // JSP Style Preferences - String NOBACKGROUNDBOLD = " | null | false"; //$NON-NLS-1$ - String styleValue = ColorHelper.getColorString(127, 0, 127) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_NAME, styleValue); - - styleValue = ColorHelper.getColorString(42, 0, 255) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE, styleValue); - - styleValue = "null" + NOBACKGROUNDBOLD; //$NON-NLS-1$ - store.setDefault(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS, styleValue); // specified value is black; leaving as widget default - - styleValue = ColorHelper.getColorString(63, 95, 191) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.COMMENT_BORDER, styleValue); - store.setDefault(IStyleConstantsXML.COMMENT_TEXT, styleValue); - - styleValue = ColorHelper.getColorString(0, 128, 128) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.TAG_BORDER, styleValue); - - styleValue = ColorHelper.getColorString(63, 127, 127) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsXML.TAG_NAME, styleValue); - - styleValue = ColorHelper.getColorString(191, 95, 63) + NOBACKGROUNDBOLD; - store.setDefault(IStyleConstantsHTML.SCRIPT_AREA_BORDER, styleValue); - } - -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryHTML.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryHTML.java deleted file mode 100644 index 4efab4eb27..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryHTML.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.projection; - -import org.eclipse.jface.text.source.projection.ProjectionViewer; -import org.eclipse.wst.html.core.HTML40Namespace; -import org.eclipse.wst.sse.core.AbstractAdapterFactory; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.w3c.dom.Node; - -public class ProjectionModelNodeAdapterFactoryHTML extends AbstractAdapterFactory { - // copies of this class located in: - // org.eclipse.wst.html.ui.internal.projection - // org.eclipse.jst.jsp.ui.internal.projection - - private ProjectionViewer fProjectionViewer; - - public ProjectionModelNodeAdapterFactoryHTML() { - adapterKey = ProjectionModelNodeAdapterHTML.class; - } - - /** - * Actually creates an adapter for the parent of target if target is the - * "adapt-able" node - */ - protected INodeAdapter createAdapter(INodeNotifier target) { - if ((fProjectionViewer != null) && (target instanceof Node) && ((Node) target).getNodeType() == Node.ELEMENT_NODE) { - Node node = (Node) target; - if (isNodeProjectable(node)) { - - // actually work with the parent node to listen for add, - // delete events - Node parent = node.getParentNode(); - if (parent instanceof INodeNotifier) { - INodeNotifier parentNotifier = (INodeNotifier) parent; - ProjectionModelNodeAdapterHTML parentAdapter = (ProjectionModelNodeAdapterHTML) parentNotifier.getExistingAdapter(ProjectionModelNodeAdapterHTML.class); - if (parentAdapter == null) { - // create a new adapter for parent - parentAdapter = new ProjectionModelNodeAdapterHTML(this); - parentNotifier.addAdapter(parentAdapter); - } - // call update on parent because a new node has just been - // added - parentAdapter.updateAdapter(parent); - } - } - } - - return null; - } - - ProjectionViewer getProjectionViewer() { - return fProjectionViewer; - } - - /** - * Returns true if node is a node type able to fold - * - * @param node - * @return boolean true if node is projectable, false otherwise - */ - boolean isNodeProjectable(Node node) { - if (node.getNodeType() == Node.ELEMENT_NODE) { - String tagName = node.getNodeName(); - // node is only projectable if it is head, body, script, style, - // table tags - if (HTML40Namespace.ElementName.HEAD.equalsIgnoreCase(tagName) || HTML40Namespace.ElementName.BODY.equalsIgnoreCase(tagName) || HTML40Namespace.ElementName.SCRIPT.equalsIgnoreCase(tagName) || HTML40Namespace.ElementName.STYLE.equalsIgnoreCase(tagName) || HTML40Namespace.ElementName.TABLE.equalsIgnoreCase((tagName))) - return true; - } - return false; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.sse.core.AbstractAdapterFactory#release() - */ - public void release() { - fProjectionViewer = null; - - super.release(); - } - - void setProjectionViewer(ProjectionViewer viewer) { - fProjectionViewer = viewer; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryJSP.java deleted file mode 100644 index bcaa7c0a13..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterFactoryJSP.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.projection; - -import org.eclipse.jst.jsp.core.JSP11Namespace; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.w3c.dom.Node; - -public class ProjectionModelNodeAdapterFactoryJSP extends ProjectionModelNodeAdapterFactoryHTML { - public ProjectionModelNodeAdapterFactoryJSP() { - adapterKey = ProjectionModelNodeAdapterJSP.class; - } - - /** - * Actually creates an adapter for the parent of target if target is the - * "adapt-able" node - */ - protected INodeAdapter createAdapter(INodeNotifier target) { - if ((getProjectionViewer() != null) && (target instanceof Node) && ((Node) target).getNodeType() == Node.ELEMENT_NODE) { - Node node = (Node) target; - if (isNodeProjectable(node)) { - - // actually work with the parent node to listen for add, - // delete events - Node parent = node.getParentNode(); - if (parent instanceof INodeNotifier) { - INodeNotifier parentNotifier = (INodeNotifier) parent; - ProjectionModelNodeAdapterJSP parentAdapter = (ProjectionModelNodeAdapterJSP) parentNotifier.getExistingAdapter(ProjectionModelNodeAdapterJSP.class); - if (parentAdapter == null) { - // create a new adapter for parent - parentAdapter = new ProjectionModelNodeAdapterJSP(this); - parentNotifier.addAdapter(parentAdapter); - } - // call update on parent because a new node has just been - // added - parentAdapter.updateAdapter(parent); - } - } - } - - return null; - } - - /** - * Returns true if node is a node type able to fold - * - * @param node - * @return boolean true if node is projectable, false otherwise - */ - boolean isNodeProjectable(Node node) { - if (node.getNodeType() == Node.ELEMENT_NODE) { - String tagName = node.getNodeName(); - // node is only projectable if it is jsp scriptlet tag - if (JSP11Namespace.ElementName.SCRIPTLET.equalsIgnoreCase(tagName)) - return true; - } - return false; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterHTML.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterHTML.java deleted file mode 100644 index 7f139c10ec..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterHTML.java +++ /dev/null @@ -1,240 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.projection; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.source.projection.ProjectionAnnotation; -import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel; -import org.eclipse.jface.text.source.projection.ProjectionViewer; -import org.eclipse.wst.sse.core.INodeAdapter; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.html.ui.internal.Logger; -import org.w3c.dom.Node; - -/** - * Updates projection annotation model with projection annotations for this - * adapter node's children - */ -public class ProjectionModelNodeAdapterHTML implements INodeAdapter { - - private class TagProjectionAnnotation extends ProjectionAnnotation { - private Node fNode; - - public TagProjectionAnnotation(Node node, boolean isCollapsed) { - super(isCollapsed); - fNode = node; - } - - public Node getNode() { - return fNode; - } - - public void setNode(Node node) { - fNode = node; - } - } - - // copies of this class located in: - // org.eclipse.wst.html.ui.internal.projection - // org.eclipse.jst.jsp.ui.internal.projection - private final static boolean debugProjectionPerf = "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.wst.html.ui/projectionperf")); //$NON-NLS-1$ //$NON-NLS-2$ - - private ProjectionModelNodeAdapterFactoryHTML fAdapterFactory; - private Map fTagAnnotations = new HashMap(); - - public ProjectionModelNodeAdapterHTML(ProjectionModelNodeAdapterFactoryHTML factory) { - fAdapterFactory = factory; - } - - /** - * Create a projection position from the given node. Able to get - * projection position if node isNodeProjectable. - * - * @param node - * @return null if no projection position possible, a Position otherwise - */ - private Position createProjectionPosition(Node node) { - Position pos = null; - if (fAdapterFactory.isNodeProjectable(node) && node instanceof IndexedRegion) { - IDocument document = fAdapterFactory.getProjectionViewer().getDocument(); - if (document != null) { - IndexedRegion inode = (IndexedRegion) node; - int start = inode.getStartOffset(); - int end = inode.getEndOffset(); - if (start >= 0 && start < end) { - try { - int startLine = document.getLineOfOffset(start); - int endLine = document.getLineOfOffset(end); - if (endLine + 1 < document.getNumberOfLines()) { - // projection_TODO allow only multi-line - // projection - // // check if projection start/end region is on - // the same line - // if (startLine < endLine) { - int offset = document.getLineOffset(startLine); - int endOffset = document.getLineOffset(endLine + 1); - pos = new Position(offset, endOffset - offset); - // } - } - } // } - catch (BadLocationException x) { - Logger.log(Logger.WARNING_DEBUG, null, x); - } - } - } - } - return pos; - } - - /** - * Find TagProjectionAnnotation for node in the current list of projection - * annotations for this adapter - * - * @param node - * @return TagProjectionAnnotation - */ - private TagProjectionAnnotation getExistingAnnotation(Node node) { - TagProjectionAnnotation anno = null; - - if ((node != null) && (!fTagAnnotations.isEmpty())) { - Iterator it = fTagAnnotations.keySet().iterator(); - while (it.hasNext() && anno == null) { - TagProjectionAnnotation a = (TagProjectionAnnotation) it.next(); - Node n = a.getNode(); - if (node.equals(n)) { - anno = a; - } - } - } - return anno; - } - - public boolean isAdapterForType(Object type) { - return type == ProjectionModelNodeAdapterHTML.class; - } - - public void notifyChanged(INodeNotifier notifier, int eventType, Object changedFeature, Object oldValue, Object newValue, int pos) { - // check if folding is even enabled, if not, just ignore notifyChanged - // events - if (fAdapterFactory.getProjectionViewer() == null) { - return; - } - - if ((eventType == INodeNotifier.STRUCTURE_CHANGED) && (notifier instanceof Node)) { - updateAdapter((Node) notifier); - } - - // projection_TODO allow only multi-line projection - // if ((eventType == INodeNotifier.CONTENT_CHANGED) && (changedFeature - // instanceof Node)) { - // Node node = (Node) changedFeature; - // if (node.getNodeType() == Node.TEXT_NODE) - // node = node.getParentNode(); - // if (node != null) - // updateOneNode(node); - // } - } - - /** - * Update the projection annotation of all the nodes that are children of - * node - * - * @param node - */ - void updateAdapter(Node node) { - long start = System.currentTimeMillis(); - - Map additions = new HashMap(); - Map projectionAnnotations = new HashMap(); - - // go through immediate child nodes and figure out projection - // model annotations - if (node != null) { - Node childNode = node.getFirstChild(); - while (childNode != null) { - Position newPos = createProjectionPosition(childNode); - if (newPos != null) { - TagProjectionAnnotation newAnnotation = new TagProjectionAnnotation(childNode, false); - TagProjectionAnnotation existing = getExistingAnnotation(childNode); - if (existing == null) { - // add to map containing all annotations for this - // adapter - projectionAnnotations.put(newAnnotation, newPos); - // add to map containing annotations to add - additions.put(newAnnotation, newPos); - } - else { - // add to map containing all annotations for this - // adapter - projectionAnnotations.put(existing, newPos); - // remove from map containing annotations to delete - fTagAnnotations.remove(existing); - } - } - childNode = childNode.getNextSibling(); - } - - // in the end, want to delete anything leftover in old list, add - // everything in additions, and update everything in - // projectionAnnotations - ProjectionAnnotation[] oldList = null; - if (!fTagAnnotations.isEmpty()) { - oldList = (ProjectionAnnotation[]) fTagAnnotations.keySet().toArray(new ProjectionAnnotation[0]); - } - ProjectionAnnotation[] modifyList = null; - if (!projectionAnnotations.isEmpty()) { - modifyList = (ProjectionAnnotation[]) projectionAnnotations.keySet().toArray(new ProjectionAnnotation[0]); - } - ProjectionViewer viewer = fAdapterFactory.getProjectionViewer(); - ProjectionAnnotationModel annotationModel = viewer.getProjectionAnnotationModel(); - annotationModel.modifyAnnotations(oldList, additions, modifyList); - } - - // save new list of annotations - fTagAnnotations = additions; - - long end = System.currentTimeMillis(); - if (debugProjectionPerf) { - String nodeName = node != null ? node.getNodeName() : "null"; - System.out.println("ProjectionModelNodeAdapterHTML.updateAdapter (" + nodeName + "):" + (end - start)); - } - } - - // projection_TODO allow only multi-line projection - // private void updateOneNode(Node node) { - // TagProjectionAnnotation existing = getExistingAnnotation(node); - // if (isNodeProjectable(node)) { - // Position pos = createProjectionPosition(node); - // // if node > 1 line and not existing, create and add - // if (pos != null && existing == null) { - // TagProjectionAnnotation newAnnotation = new - // TagProjectionAnnotation(node, false); - // fAdapterFactory.getProjectionViewer().getProjectionAnnotationModel().addAnnotation(newAnnotation, - // pos); - // fTagAnnotations.put(newAnnotation, pos); - // } - // // if node == 1 line and existing, remove - // if (pos == null && existing != null) { - // fAdapterFactory.getProjectionViewer().getProjectionAnnotationModel().removeAnnotation(existing); - // fTagAnnotations.remove(existing); - // } - // } - // } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterJSP.java deleted file mode 100644 index a195368688..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/ProjectionModelNodeAdapterJSP.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - * - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.projection; - -/** - * Updates projection annotation model with projection annotations for this - * adapter node's children - */ -public class ProjectionModelNodeAdapterJSP extends ProjectionModelNodeAdapterHTML { - public ProjectionModelNodeAdapterJSP(ProjectionModelNodeAdapterFactoryJSP factory) { - super(factory); - } - - public boolean isAdapterForType(Object type) { - return type == ProjectionModelNodeAdapterJSP.class; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/StructuredTextFoldingProviderJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/StructuredTextFoldingProviderJSP.java deleted file mode 100644 index 4e5c7bfdd3..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/projection/StructuredTextFoldingProviderJSP.java +++ /dev/null @@ -1,275 +0,0 @@ -package org.eclipse.jst.jsp.ui.internal.projection; - -import org.eclipse.core.runtime.Platform; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.source.projection.IProjectionListener; -import org.eclipse.jface.text.source.projection.ProjectionViewer; -import org.eclipse.wst.sse.core.IFactoryRegistry; -import org.eclipse.wst.sse.core.INodeNotifier; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.PropagatingAdapter; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.ui.internal.projection.IStructuredTextFoldingProvider; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -/** - * Updates the projection model of a structured model for JSP. - */ -public class StructuredTextFoldingProviderJSP implements IStructuredTextFoldingProvider, IProjectionListener { - private final static boolean debugProjectionPerf = "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.jst.jsp.ui/projectionperf")); //$NON-NLS-1$ //$NON-NLS-2$ - - private IDocument fDocument; - private ProjectionViewer fViewer; - - /** - * Adds an adapter to node and its children - * - * @param node - * @param level - */ - private void addAdapterToNodeAndChildren(Node node, int level) { - if (node instanceof INodeNotifier) { - INodeNotifier notifier = (INodeNotifier) node; - - // try and get the adapter for the current node and update the - // adapter with projection information - ProjectionModelNodeAdapterJSP adapter = (ProjectionModelNodeAdapterJSP) notifier.getExistingAdapter(ProjectionModelNodeAdapterJSP.class); - if (adapter != null) { - adapter.updateAdapter(node); - } - else { - // just call getadapter so the adapter is created and - // automatically initialized - notifier.getAdapterFor(ProjectionModelNodeAdapterJSP.class); - } - ProjectionModelNodeAdapterHTML adapter2 = (ProjectionModelNodeAdapterHTML) notifier.getExistingAdapter(ProjectionModelNodeAdapterHTML.class); - if (adapter2 != null) { - adapter2.updateAdapter(node); - } - else { - // just call getadapter so the adapter is created and - // automatically initialized - notifier.getAdapterFor(ProjectionModelNodeAdapterHTML.class); - } - - Node nextChild = node.getFirstChild(); - while (nextChild != null) { - Node childNode = nextChild; - nextChild = childNode.getNextSibling(); - - addAdapterToNodeAndChildren(childNode, level + 1); - } - } - } - - /** - * Goes through every node and adds an adapter onto each for tracking - * purposes - */ - private void addAllAdapters() { - long start = System.currentTimeMillis(); - - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); - if (sModel != null) { - int startOffset = 0; - IndexedRegion startNode = sModel.getIndexedRegion(startOffset); - if (startNode instanceof Node) { - int level = 0; - Node nextSibling = (Node) startNode; - while (nextSibling != null) { - Node currentNode = nextSibling; - nextSibling = currentNode.getNextSibling(); - - addAdapterToNodeAndChildren(currentNode, level); - } - } - } - } - finally { - if (sModel != null) { - sModel.releaseFromRead(); - } - } - long end = System.currentTimeMillis(); - if (debugProjectionPerf) - System.out.println("StructuredTextFoldingProviderJSP.addAllAdapters: " + (end - start)); - } - - /** - * Get the ProjectionModelNodeAdapterFactoryHTML to use with this - * provider. - * - * @return ProjectionModelNodeAdapterFactoryHTML - */ - private ProjectionModelNodeAdapterFactoryHTML getAdapterFactoryHTML(boolean createIfNeeded) { - long start = System.currentTimeMillis(); - - ProjectionModelNodeAdapterFactoryHTML factory = null; - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); - if (sModel != null) { - IFactoryRegistry factoryRegistry = sModel.getFactoryRegistry(); - - // getting the projectionmodelnodeadapter for the first time - // so do some initializing - if (!factoryRegistry.contains(ProjectionModelNodeAdapterHTML.class) && createIfNeeded) { - ProjectionModelNodeAdapterFactoryHTML newFactory = new ProjectionModelNodeAdapterFactoryHTML(); - - // add factory to factory registry - factoryRegistry.addFactory(newFactory); - - // add factory to propogating adapter - XMLModel domModel = (XMLModel) sModel; - Document document = domModel.getDocument(); - PropagatingAdapter propagatingAdapter = (PropagatingAdapter) ((INodeNotifier) document).getAdapterFor(PropagatingAdapter.class); - if (propagatingAdapter != null) { - propagatingAdapter.addAdaptOnCreateFactory(newFactory); - } - } - - // try and get the factory - factory = (ProjectionModelNodeAdapterFactoryHTML) factoryRegistry.getFactoryFor(ProjectionModelNodeAdapterHTML.class); - } - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - - long end = System.currentTimeMillis(); - if (debugProjectionPerf) - System.out.println("StructuredTextFoldingProviderJSP.getAdapterFactoryHTML: " + (end - start)); - return factory; - } - - /** - * Get the ProjectionModelNodeAdapterFactoryJSP to use with this provider. - * - * @return ProjectionModelNodeAdapterFactoryJSP - */ - private ProjectionModelNodeAdapterFactoryJSP getAdapterFactoryJSP(boolean createIfNeeded) { - long start = System.currentTimeMillis(); - - ProjectionModelNodeAdapterFactoryJSP factory = null; - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(fDocument); - if (sModel != null) { - IFactoryRegistry factoryRegistry = sModel.getFactoryRegistry(); - - // getting the projectionmodelnodeadapter for the first time - // so do some initializing - if (!factoryRegistry.contains(ProjectionModelNodeAdapterJSP.class) && createIfNeeded) { - ProjectionModelNodeAdapterFactoryJSP newFactory = new ProjectionModelNodeAdapterFactoryJSP(); - - // add factory to factory registry - factoryRegistry.addFactory(newFactory); - - // add factory to propogating adapter - XMLModel domModel = (XMLModel) sModel; - Document document = domModel.getDocument(); - PropagatingAdapter propagatingAdapter = (PropagatingAdapter) ((INodeNotifier) document).getAdapterFor(PropagatingAdapter.class); - if (propagatingAdapter != null) { - propagatingAdapter.addAdaptOnCreateFactory(newFactory); - } - } - - // try and get the factory - factory = (ProjectionModelNodeAdapterFactoryJSP) factoryRegistry.getFactoryFor(ProjectionModelNodeAdapterJSP.class); - } - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - - long end = System.currentTimeMillis(); - if (debugProjectionPerf) - System.out.println("StructuredTextFoldingProviderJSP.getAdapterFactoryJSP: " + (end - start)); - return factory; - } - - /** - * Initialize this provider with the correct document. Assumes projection - * is enabled. (otherwise, only install would have been called) - */ - public void initialize() { - if (!isInstalled()) - return; - - // set projection viewer to null on old document's adapter factory - projectionDisabled(); - - // clear out all annotations - if (fViewer.getProjectionAnnotationModel() != null) - fViewer.getProjectionAnnotationModel().removeAllAnnotations(); - fDocument = fViewer.getDocument(); - - if (fDocument != null) { - // set projection viewer on new document's adapter factory - ProjectionModelNodeAdapterFactoryJSP factory = getAdapterFactoryJSP(true); - if (factory != null) { - factory.setProjectionViewer(fViewer); - } - ProjectionModelNodeAdapterFactoryHTML factory2 = getAdapterFactoryHTML(true); - if (factory2 != null) { - factory2.setProjectionViewer(fViewer); - } - - addAllAdapters(); - } - } - - /** - * Associate a ProjectionViewer with this IStructuredTextFoldingProvider - * - * @param viewer - */ - public void install(ProjectionViewer viewer) { - // uninstall before trying to install new viewer - if (isInstalled()) { - uninstall(); - } - fViewer = viewer; - fViewer.addProjectionListener(this); - } - - private boolean isInstalled() { - return fViewer != null; - } - - public void projectionDisabled() { - ProjectionModelNodeAdapterFactoryJSP factory = getAdapterFactoryJSP(false); - if (factory != null) { - factory.setProjectionViewer(null); - } - ProjectionModelNodeAdapterFactoryHTML factory2 = getAdapterFactoryHTML(false); - if (factory2 != null) { - factory2.setProjectionViewer(null); - } - - fDocument = null; - } - - public void projectionEnabled() { - initialize(); - } - - /** - * Disconnect this IStructuredTextFoldingProvider from projection viewer - */ - public void uninstall() { - if (isInstalled()) { - projectionDisabled(); - - fViewer.removeProjectionListener(this); - fViewer = null; - } - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/JSPTranslationWrapper.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/JSPTranslationWrapper.java deleted file mode 100644 index a119c2b02f..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/JSPTranslationWrapper.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.reconcile; - -import org.eclipse.jface.text.reconciler.IReconcilableModel; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension; - -/** - * Wrapper class to make a JSPTranslation into an IReconcilableModel. - * Translation must be accessed via getTranslation() - * - * @pavery - */ -public class JSPTranslationWrapper implements IReconcilableModel { - private JSPTranslationExtension fTranslation = null; - - public JSPTranslationWrapper(JSPTranslationExtension trans) { - fTranslation = trans; - } - - public JSPTranslationExtension getTranslation() { - return fTranslation; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/ReconcileStepForJava.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/ReconcileStepForJava.java deleted file mode 100644 index fe0966de77..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/ReconcileStepForJava.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.reconcile; - -import java.util.List; - -import org.eclipse.core.resources.IFile; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.compiler.IProblem; -import org.eclipse.jface.text.Assert; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcilableModel; -import org.eclipse.jface.text.reconciler.IReconcileResult; -import org.eclipse.jface.text.reconciler.IReconcileStep; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension; -import org.eclipse.jst.jsp.core.internal.text.rules.StructuredTextPartitionerForJSP; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.sse.ui.internal.reconcile.ReconcileAnnotationKey; -import org.eclipse.wst.sse.ui.internal.reconcile.StructuredReconcileStep; -import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation; - -/** - * This reconcile step has a Java source document as input model and maintains - * a Java working copy as its model. - * - * @since 3.0 - */ -public class ReconcileStepForJava extends StructuredReconcileStep { - - /** - * Adapts an <code>ICompilationUnit</code> to the - * <code>ITextModel</code> interface. - */ - private class CompilationUnitAdapter implements IReconcilableModel { - - private ICompilationUnit fCompilationUnit; - - CompilationUnitAdapter(ICompilationUnit cu) { - fCompilationUnit = cu; - } - - private ICompilationUnit getCompilationUnit() { - return fCompilationUnit; - } - } - - private JSPTranslation fJspTranslation; - private CompilationUnitAdapter fModel; - private IStructuredDocument fStructuredDocument = null; - - /** - * Creates the last reconcile step of the pipe. - */ - public ReconcileStepForJava(IFile jspFile) { - // should handle more gracefully - Assert.isNotNull(jspFile); - initStructuredDocument(jspFile); - } - - /** - * Creates an intermediate reconcile step which adds the given step to the - * pipe. - */ - public ReconcileStepForJava(IReconcileStep step, IFile jspFile) { - super(step); - Assert.isNotNull(jspFile); - initStructuredDocument(jspFile); - } - - /** - * Structured Document used to create annotation removal keys - * - * @param jspFile - */ - private void initStructuredDocument(IFile jspFile) { - IStructuredModel sModel = null; - try { - sModel = StructuredModelManager.getModelManager().getExistingModelForRead(jspFile); - if (sModel != null) - fStructuredDocument = sModel.getStructuredDocument(); - } - finally { - if (sModel != null) - sModel.releaseFromRead(); - } - } - - /* - * @see AbstractReconcileStep#reconcileModel(DirtyRegion, IRegion) - */ - protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, IRegion subRegion) { - Assert.isTrue(getInputModel() instanceof JSPTranslationWrapper, "wrong model"); //$NON-NLS-1$ - fJspTranslation = ((JSPTranslationWrapper) getInputModel()).getTranslation(); - - if(DEBUG) - System.out.println("[trace reconciler] > reconciling model in JAVA step w/ dirty region: " + dirtyRegion.getText()); //$NON-NLS-1$ - - try { - fJspTranslation.setProblemCollectingActive(true); - fJspTranslation.reconcileCompilationUnit(); - } - finally { - if (fJspTranslation != null) - fJspTranslation.setProblemCollectingActive(false); - } - - List problems = null; - // I was frequently seeing null here, especially as editors closed, - // so just gaurding against that. (Not sure why it was null). - if (fJspTranslation != null) { - problems = fJspTranslation.getProblems(); - } - IReconcileResult[] results = adaptProblemsToAnnotations(problems); - return results; - } - - /** - * @return - */ - private IReconcileResult[] adaptProblemsToAnnotations(List problems) { - if (problems == null) - return new IReconcileResult[0]; - - TemporaryAnnotation[] annotations = new TemporaryAnnotation[problems.size()]; - IProblem p = null; - for (int i = 0; i < problems.size(); i++) { - p = (IProblem) problems.get(i); - annotations[i] = createTemporaryAnnotationFromProblem(p); - } - return annotations; - } - - /** - * Converts an IProblem to a TemporaryAnnotation. - * - * @param problem - * @return - */ - private TemporaryAnnotation createTemporaryAnnotationFromProblem(IProblem problem) { - String type = TemporaryAnnotation.ANNOT_ERROR; - if (problem.isWarning()) - type = TemporaryAnnotation.ANNOT_WARNING; - Position pos = new Position(problem.getSourceStart(), problem.getSourceEnd() - problem.getSourceStart() + 1); - JSPTranslationExtension translation = ((JSPTranslationWrapper) getInputModel()).getTranslation(); - int jspOffset = translation.getJspOffset(pos.offset); - - ReconcileAnnotationKey key = null; - if (jspOffset != -1 && fStructuredDocument != null) { - key = createKey(fStructuredDocument.getRegionAtCharacterOffset(jspOffset), ReconcileAnnotationKey.TOTAL); - } - else { - key = createKey(StructuredTextPartitionerForJSP.ST_DEFAULT_JSP, ReconcileAnnotationKey.TOTAL); - } - TemporaryAnnotation annotation = new TemporaryAnnotation(pos, type, problem.getMessage(), key, problem.getID()); - annotation.setAdditionalFixInfo(problem); - - return annotation; - } - - /* - * @see AbstractReconcileStep#getModel() - */ - public IReconcilableModel getModel() { - if (fModel == null) { - fModel = new CompilationUnitAdapter(fJspTranslation.getCompilationUnit()); - } - return fModel; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.reconciler.IReconcileStep#setInputModel(org.eclipse.jface.text.reconciler.IReconcilableModel) - */ - public void setInputModel(IReconcilableModel inputModel) { - super.setInputModel(inputModel); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/ReconcileStepForJspTranslation.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/ReconcileStepForJspTranslation.java deleted file mode 100644 index 00c0cb015e..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/ReconcileStepForJspTranslation.java +++ /dev/null @@ -1,332 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.reconcile; - -import java.util.HashMap; -import java.util.Iterator; - -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Position; -import org.eclipse.jface.text.reconciler.DirtyRegion; -import org.eclipse.jface.text.reconciler.IReconcilableModel; -import org.eclipse.jface.text.reconciler.IReconcileResult; -import org.eclipse.jface.text.reconciler.IReconcileStep; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationExtension; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.core.text.IStructuredDocument; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.core.text.ITextRegionList; -import org.eclipse.wst.sse.core.util.StringUtils; -import org.eclipse.wst.sse.ui.internal.reconcile.DocumentAdapter; -import org.eclipse.wst.sse.ui.internal.reconcile.StructuredReconcileStep; -import org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; - -/** - * Creates a JSPTranslation for use w/ the JavaReconcileStep. Adapts Java - * error positions to the JSP positions. - * - * @author pavery - */ -public class ReconcileStepForJspTranslation extends StructuredReconcileStep { - - /** - * This contains is the translated java document. We create this here, - * then set it as the model on the next step, ReconcileStepForJava - */ - private JSPTranslationWrapper fModel = null; - private IReconcileResult[] EMPTY_RECONCILE_RESULT_SET = new IReconcileResult[0]; - private JSPTranslationAdapter fTranslationAdapter = null; - private JSPTranslationExtension fJSPTranslation = null; - private static final boolean DEBUG = false; - - public ReconcileStepForJspTranslation(IReconcileStep step) { - super(step); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.reconciler.AbstractReconcileStep#reconcileModel(org.eclipse.jface.text.reconciler.DirtyRegion, - * org.eclipse.jface.text.IRegion) - */ - protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, IRegion subRegion) { - - if(DEBUG) - System.out.println("[trace reconciler] > translating JSP in JSP TRANSLATE step"); //$NON-NLS-1$ - - if (isCanceled() || dirtyRegion == null) - return EMPTY_RECONCILE_RESULT_SET; - - // create java model for java reconcile - JSPTranslationAdapter adapter = getJSPTranslationAdapter(); - fJSPTranslation = adapter.getJSPTranslation(); - fModel = new JSPTranslationWrapper(fJSPTranslation); - - if(DEBUG) - System.out.println("[trace reconciler] > JSP TRANSLATE step done"); //$NON-NLS-1$ - - // this step doesn't actually produce results, only creates the java - // model - return EMPTY_RECONCILE_RESULT_SET; - } - - /** - * @return - */ - private JSPTranslationAdapter getJSPTranslationAdapter() { - if (fTranslationAdapter == null) { - IReconcilableModel reconcilableModel = getInputModel(); - IDocument doc = null; - - if (reconcilableModel instanceof DocumentAdapter) - doc = ((DocumentAdapter) reconcilableModel).getDocument(); - - if (doc != null) { - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(doc); - if (model != null) { - XMLDocument xmlDoc = ((XMLModel) model).getDocument(); - fTranslationAdapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - } - } - finally { - if (model != null) - model.releaseFromRead(); - } - } - } - return fTranslationAdapter; - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.internal.ui.text.AbstractStructuredReconcileStep#getModel() - */ - public IReconcilableModel getModel() { - return fModel; - } - - /* - * @see org.eclipse.text.reconcilerpipe.AbstractReconcilePipeParticipant#convertToInputModel(org.eclipse.text.reconcilerpipe.IReconcileResult[]) - */ - protected IReconcileResult[] convertToInputModel(IReconcileResult[] inputResults) { - - if (inputResults == null) - return null; - - HashMap java2jspRanges = fJSPTranslation.getJava2JspMap(); - for (int i = 0; i < inputResults.length; i++) { - if (isCanceled()) - return EMPTY_RECONCILE_RESULT_SET; - if (!(inputResults[i] instanceof TemporaryAnnotation)) - continue; - TemporaryAnnotation result = (TemporaryAnnotation) inputResults[i]; - adaptJava2JspPosition(result, java2jspRanges); - } - - return inputResults; - } - - /** - * @param pos - * @param java2jspRanges - */ - private void adaptJava2JspPosition(TemporaryAnnotation annotation, HashMap java2jspRanges) { - Position pos = annotation.getPosition(); - int javaOffset = pos.offset; - int offsetInRange = 0; - Position jspPos, javaPos = null; - boolean found = false; - - // iterate all mapped java ranges - Iterator it = java2jspRanges.keySet().iterator(); - while (it.hasNext()) { - javaPos = (Position) it.next(); - if (!javaPos.includes(javaOffset)) - continue; - - offsetInRange = javaOffset - javaPos.offset; - jspPos = (Position) java2jspRanges.get(javaPos); - if (jspPos != null) { - pos.offset = jspPos.offset + offsetInRange; - found = true; - additionalPositionAdjustment(annotation, jspPos); - } - break; - } - // hide unmapped errors - if (!found) { - pos.offset = -1; - pos.length = 0; - } - } - - /** - * Adjusts java position to JSP position for ranges that don't map - * "exactly". eg. <%@include file=""%>, <jsp:useBean/>, <%@import - * src=""%>... - * - * @param pos - * @param jspPos - */ - private void additionalPositionAdjustment(TemporaryAnnotation annotation, Position jspPos) { - Position pos = annotation.getPosition(); - IStructuredDocument sDoc = null; - IStructuredDocumentRegion sdRegion = null; - // analyze the sdRegion to see if it's import, expression, include - ITextRegionList regions = null; - ITextRegion r = null; - String tagName = ""; //$NON-NLS-1$ - - sDoc = (IStructuredDocument) ((DocumentAdapter) getInputModel()).getDocument(); - sdRegion = sDoc.getRegionAtCharacterOffset(jspPos.offset); - // analyze the sdRegion to see if it's import, expression, include, - // useBean... - regions = sdRegion.getRegions(); - for (int i = 0; i < regions.size(); i++) { - r = regions.get(i); - if (r.getType() == XMLJSPRegionContexts.JSP_DIRECTIVE_NAME || r.getType() == XMLRegionContext.XML_TAG_NAME) { - tagName = sdRegion.getText(r).trim(); - if (tagName.equals("include")) { //$NON-NLS-1$ - adjustForInclude(annotation, pos, sdRegion, regions, i); - } - else if (tagName.equals("page")) { //$NON-NLS-1$ - adjustForPage(annotation, pos, sdRegion, regions, i); - } - else if (tagName.equals("jsp:useBean")) { //$NON-NLS-1$ - //adjustForUseBean(pos, sdRegion, regions, i); - // do nothing for usebean for now... - break; - } - // this can actually cause the WRONG node to be underlined - // esp in the case of embedded attr regions -// else { -// // catch all for all other cases for now, at least we'll -// // get -// // the squiggle in the general area of the problem instead -// // of some random place -// pos.offset = sdRegion.getStartOffset(r); -// pos.length = 1; -// break; -// } - } - } - } - - private void adjustForInclude(TemporaryAnnotation annotation, Position pos, IStructuredDocumentRegion sdRegion, ITextRegionList regions, int startingRegionNumber) { - ITextRegion r; - String tagName; - String noQuotes; - for (int j = startingRegionNumber; j < regions.size(); j++) { - r = regions.get(j); - if (r.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME && !sdRegion.getText(r).trim().equals("file")) //$NON-NLS-1$ - // there's only one attribute allowed for <@include - break; - else if (r.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - tagName = sdRegion.getText(r).trim(); - noQuotes = StringUtils.strip(tagName); - pos.offset = sdRegion.getStartOffset(r) + ((tagName.length() - noQuotes.length()) == 2 ? 1 : 0); - pos.length = noQuotes.length(); - annotation.setText(annotation.getText() + " (in file: \"" + noQuotes + "\")"); //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - } - } - - private void adjustForPage(TemporaryAnnotation annotation, Position pos, IStructuredDocumentRegion sdRegion, ITextRegionList regions, int startingRegionNumber) { - ITextRegion r; - String value; - int size = regions.size(); - - for (int j = startingRegionNumber; j < size; j++) { - r = regions.get(j); - if (r.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME && sdRegion.getText(r).trim().equals("import")) { //$NON-NLS-1$ - if (size > j + 2) { - r = regions.get(j + 2); - if (r.getType() == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) { - value = sdRegion.getText(r); - pos.offset = sdRegion.getStartOffset(r); - pos.length = value.trim().length(); - annotation.setText(annotation.getText() + " (in file: \"" + StringUtils.stripQuotes(value) + "\")"); //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - } - } - } - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.xml.reconcile.StructuredReconcileStep#release() - */ - public void release() { - if (fTranslationAdapter != null) { - if(DEBUG) { - System.out.println("ReconcileStepForJSPTranslation ["+this+"] releasing JSPTranslationAdapter " + fTranslationAdapter); - } - fTranslationAdapter.release(); - } - super.release(); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.jface.text.reconciler.IReconcileStep#setInputModel(org.eclipse.jface.text.reconciler.IReconcilableModel) - */ - public void setInputModel(IReconcilableModel inputModel) { - // force to rebuild translation - fTranslationAdapter = null; - if (DEBUG) { - System.out.println("======================================"); //$NON-NLS-1$ - System.out.println("setting input model" + inputModel); //$NON-NLS-1$ - System.out.println("======================================"); //$NON-NLS-1$ - } - super.setInputModel(inputModel); - - reinitTranslationAdapter(inputModel); - } - - /** - * @param inputModel - */ - private void reinitTranslationAdapter(IReconcilableModel inputModel) { - - IDocument doc = null; - if (inputModel instanceof DocumentAdapter) - doc = ((DocumentAdapter) inputModel).getDocument(); - - if (doc != null) { - IStructuredModel model = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(doc); - if(getJSPTranslationAdapter() != null) - getJSPTranslationAdapter().setXMLModel((XMLModel) model); - } - finally { - if (model != null) - model.releaseFromRead(); - } - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/StructuredTextReconcilingStrategyForJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/StructuredTextReconcilingStrategyForJSP.java deleted file mode 100644 index 7c0d7e8312..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/reconcile/StructuredTextReconcilingStrategyForJSP.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.reconcile; - -import org.eclipse.jface.text.reconciler.IReconcileStep; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.ui.internal.reconcile.AbstractStructuredTextReconcilingStrategy; - -/** - * - * @author pavery - */ -public class StructuredTextReconcilingStrategyForJSP extends AbstractStructuredTextReconcilingStrategy { - - public StructuredTextReconcilingStrategyForJSP(ITextEditor editor) { - super(editor); - } - - public void createReconcileSteps() { - - // the order is: - // 1. translation step - // 2. java step - if (getFile() != null) { - IReconcileStep javaStep = new ReconcileStepForJava(getFile()); - fFirstStep = new ReconcileStepForJspTranslation(javaStep); - } - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/taginfo/HTMLPrinter.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/taginfo/HTMLPrinter.java deleted file mode 100644 index 0a5716a587..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/taginfo/HTMLPrinter.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.taginfo; - - -import java.io.IOException; -import java.io.Reader; -import java.net.URL; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.SWTError; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Display; - - -/** - * Provides a set of convenience methods for creating HTML pages. - * Copied from org.eclipse.jdt.internal.ui.text.HTMLPrinter - */ -public class HTMLPrinter { - - private static RGB BG_COLOR_RGB= null; - - static { - final Display display= Display.getDefault(); - if (display != null && !display.isDisposed()) { - try { - display.asyncExec(new Runnable() { - /* - * @see java.lang.Runnable#run() - */ - public void run() { - BG_COLOR_RGB= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB(); - } - }); - } catch (SWTError err) { - // see: https://bugs.eclipse.org/bugs/show_bug.cgi?id=45294 - if (err.code != SWT.ERROR_DEVICE_DISPOSED) - throw err; - } - } - } - - private HTMLPrinter() { - } - - private static String replace(String text, char c, String s) { - - int previous= 0; - int current= text.indexOf(c, previous); - - if (current == -1) - return text; - - StringBuffer buffer= new StringBuffer(); - while (current > -1) { - buffer.append(text.substring(previous, current)); - buffer.append(s); - previous= current + 1; - current= text.indexOf(c, previous); - } - buffer.append(text.substring(previous)); - - return buffer.toString(); - } - - public static String convertToHTMLContent(String content) { - content= replace(content, '<', "<"); //$NON-NLS-1$ - return replace(content, '>', ">"); //$NON-NLS-1$ - } - - public static String read(Reader rd) { - - StringBuffer buffer= new StringBuffer(); - char[] readBuffer= new char[2048]; - - try { - int n= rd.read(readBuffer); - while (n > 0) { - buffer.append(readBuffer, 0, n); - n= rd.read(readBuffer); - } - return buffer.toString(); - } catch (IOException x) { - } - - return null; - } - - public static void insertPageProlog(StringBuffer buffer, int position, RGB bgRGB, URL styleSheetURL) { - - if (bgRGB == null) - insertPageProlog(buffer, position, styleSheetURL); - else { - StringBuffer pageProlog= new StringBuffer(300); - - pageProlog.append("<html>"); //$NON-NLS-1$ - - appendStyleSheetLink(pageProlog, styleSheetURL); - - pageProlog.append("<body text=\"#000000\" bgcolor=\""); //$NON-NLS-1$ - appendColor(pageProlog, bgRGB); - pageProlog.append("\"><font size=-1>"); //$NON-NLS-1$ - - buffer.insert(position, pageProlog.toString()); - } - } - - public static void insertPageProlog(StringBuffer buffer, int position, RGB bgRGB) { - if (bgRGB == null) - insertPageProlog(buffer, position); - else { - StringBuffer pageProlog= new StringBuffer(60); - pageProlog.append("<html><body text=\"#000000\" bgcolor=\""); //$NON-NLS-1$ - appendColor(pageProlog, bgRGB); - pageProlog.append("\"><font size=-1>"); //$NON-NLS-1$ - buffer.insert(position, pageProlog.toString()); - } - } - - private static void appendStyleSheetLink(StringBuffer buffer, URL styleSheetURL) { - if (styleSheetURL == null) - return; - - buffer.append("<head>"); //$NON-NLS-1$ - - buffer.append("<LINK REL=\"stylesheet\" HREF= \""); //$NON-NLS-1$ - buffer.append(styleSheetURL); - buffer.append("\" CHARSET=\"ISO-8859-1\" TYPE=\"text/css\">"); //$NON-NLS-1$ - - buffer.append("</head>"); //$NON-NLS-1$ - } - - private static void appendColor(StringBuffer buffer, RGB rgb) { - buffer.append('#'); - buffer.append(Integer.toHexString(rgb.red)); - buffer.append(Integer.toHexString(rgb.green)); - buffer.append(Integer.toHexString(rgb.blue)); - } - - public static void insertPageProlog(StringBuffer buffer, int position) { - insertPageProlog(buffer, position, getBgColor()); //$NON-NLS-1$ - } - - public static void insertPageProlog(StringBuffer buffer, int position, URL styleSheetURL) { - insertPageProlog(buffer, position, getBgColor(), styleSheetURL); //$NON-NLS-1$ - } - - private static RGB getBgColor() { - if (BG_COLOR_RGB != null) - return BG_COLOR_RGB; - else - return new RGB(255,255, 225); // RGB value of info bg color on WindowsXP - - } - - public static void addPageProlog(StringBuffer buffer) { - insertPageProlog(buffer, buffer.length()); - } - - public static void addPageEpilog(StringBuffer buffer) { - buffer.append("</font></body></html>"); //$NON-NLS-1$ - } - - public static void startBulletList(StringBuffer buffer) { - buffer.append("<ul>"); //$NON-NLS-1$ - } - - public static void endBulletList(StringBuffer buffer) { - buffer.append("</ul>"); //$NON-NLS-1$ - } - - public static void addBullet(StringBuffer buffer, String bullet) { - if (bullet != null) { - buffer.append("<li>"); //$NON-NLS-1$ - buffer.append(bullet); - buffer.append("</li>"); //$NON-NLS-1$ - } - } - - public static void addSmallHeader(StringBuffer buffer, String header) { - if (header != null) { - buffer.append("<h5>"); //$NON-NLS-1$ - buffer.append(header); - buffer.append("</h5>"); //$NON-NLS-1$ - } - } - - public static void addParagraph(StringBuffer buffer, String paragraph) { - if (paragraph != null) { - buffer.append("<p>"); //$NON-NLS-1$ - buffer.append(paragraph); - } - } - - public static void addParagraph(StringBuffer buffer, Reader paragraphReader) { - if (paragraphReader != null) - addParagraph(buffer, read(paragraphReader)); - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/taginfo/JSPJavaJavadocHoverProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/taginfo/JSPJavaJavadocHoverProcessor.java deleted file mode 100644 index 3528afa141..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/taginfo/JSPJavaJavadocHoverProcessor.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.taginfo; - -import java.io.Reader; - -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IMember; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.ui.JavaElementLabels; -import org.eclipse.jdt.ui.JavadocContentAccess; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextHover; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; - -/** - * Provides javadoc hover help documentation for java code inside JSPs - */ -public class JSPJavaJavadocHoverProcessor implements ITextHover { - private final long LABEL_FLAGS= JavaElementLabels.ALL_FULLY_QUALIFIED - | JavaElementLabels.M_PRE_RETURNTYPE | JavaElementLabels.M_PARAMETER_TYPES | JavaElementLabels.M_PARAMETER_NAMES | JavaElementLabels.M_EXCEPTIONS - | JavaElementLabels.F_PRE_TYPE_SIGNATURE; - - private String getInfoText(IJavaElement member) { - String label= JavaElementLabels.getElementLabel(member, LABEL_FLAGS); - StringBuffer buf= new StringBuffer(); - for (int i= 0; i < label.length(); i++) { - char ch= label.charAt(i); - if (ch == '<') { - buf.append("<"); //$NON-NLS-1$ - } else if (ch == '>') { - buf.append(">"); //$NON-NLS-1$ - } else { - buf.append(ch); - } - } - return buf.toString(); - } - - private String getHoverInfo(IJavaElement[] result) { - StringBuffer buffer= new StringBuffer(); - int nResults= result.length; - if (nResults == 0) - return null; - - if (nResults > 1) { - - for (int i= 0; i < result.length; i++) { - HTMLPrinter.startBulletList(buffer); - IJavaElement curr= result[i]; - if (curr instanceof IMember || curr.getElementType() == IJavaElement.LOCAL_VARIABLE) - HTMLPrinter.addBullet(buffer, getInfoText(curr)); - HTMLPrinter.endBulletList(buffer); - } - - } else { - - IJavaElement curr= result[0]; - if (curr instanceof IMember) { - IMember member= (IMember) curr; - HTMLPrinter.addSmallHeader(buffer, getInfoText(member)); - Reader reader; - try { - reader= JavadocContentAccess.getHTMLContentReader(member, true); - } catch (JavaModelException ex) { - return null; - } - if (reader != null) { - HTMLPrinter.addParagraph(buffer, reader); - } - } else if (curr.getElementType() == IJavaElement.LOCAL_VARIABLE) - HTMLPrinter.addSmallHeader(buffer, getInfoText(curr)); - } - - if (buffer.length() > 0) { - HTMLPrinter.insertPageProlog(buffer, 0); - HTMLPrinter.addPageEpilog(buffer); - return buffer.toString(); - } - - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) - */ - public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { - // get JSP translation object for this viewer's document - XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(textViewer.getDocument()); - try { - if(xmlModel != null) { - XMLDocument xmlDoc = xmlModel.getDocument(); - JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (adapter != null) { - JSPTranslation translation = adapter.getJSPTranslation(); - IJavaElement[] result = translation.getElementsFromJspRange(hoverRegion.getOffset(), hoverRegion.getOffset() + hoverRegion.getLength()); - return getHoverInfo(result); - } - } - } - finally { - if(xmlModel != null) - xmlModel.releaseFromRead(); - } - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.jface.text.ITextHover#getHoverRegion(org.eclipse.jface.text.ITextViewer, int) - */ - public IRegion getHoverRegion(ITextViewer textViewer, int offset) { - return JavaWordFinder.findWord(textViewer.getDocument(), offset); - } - -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/taginfo/JavaWordFinder.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/taginfo/JavaWordFinder.java deleted file mode 100644 index 7542ea18cd..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/internal/taginfo/JavaWordFinder.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.internal.taginfo; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Region; - -/** - * Copied from org.eclipse.jdt.internal.ui.text.JavaWordFinder - */ -public class JavaWordFinder { - - public static IRegion findWord(IDocument document, int offset) { - - int start= -1; - int end= -1; - - - try { - - int pos= offset; - char c; - - while (pos >= 0) { - c= document.getChar(pos); - if (!Character.isJavaIdentifierPart(c)) - break; - --pos; - } - - start= pos; - - pos= offset; - int length= document.getLength(); - - while (pos < length) { - c= document.getChar(pos); - if (!Character.isJavaIdentifierPart(c)) - break; - ++pos; - } - - end= pos; - - } catch (BadLocationException x) { - } - - if (start > -1 && end > -1) { - if (start == offset && end == offset) - return new Region(offset, 0); - else if (start == offset) - return new Region(start, end - start); - else - return new Region(start + 1, end - start - 1); - } - - return null; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPDirectiveOpenOnJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPDirectiveOpenOnJSP.java deleted file mode 100644 index 2fcb220508..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPDirectiveOpenOnJSP.java +++ /dev/null @@ -1,310 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.openon; - -import java.io.File; -import java.io.InputStream; -import java.net.URL; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; - -import org.eclipse.core.resources.IStorage; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jst.jsp.core.JSP11Namespace; -import org.eclipse.jst.jsp.core.internal.contentmodel.ITaglibRecord; -import org.eclipse.jst.jsp.core.internal.contentmodel.JarRecord; -import org.eclipse.jst.jsp.core.internal.contentmodel.TLDRecord; -import org.eclipse.jst.jsp.core.internal.contentmodel.TaglibIndex; -import org.eclipse.jst.jsp.core.internal.contentmodel.URLRecord; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ui.IEditorDescriptor; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IPersistableElement; -import org.eclipse.ui.IStorageEditorInput; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.ide.IDE; -import org.eclipse.wst.html.ui.openon.DefaultOpenOnHTML; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.w3c.dom.Attr; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; - -/** - * This action opens classes referenced in JSP directive tags of a JSP page. - * - * @deprecated Use base support for hyperlink navigation - */ -public class JSPDirectiveOpenOnJSP extends DefaultOpenOnHTML { - JSPJavaOpenOnJSP jspJavaOpenOn; - - static class StorageEditorInput implements IStorageEditorInput { - IStorage fStorage = null; - - StorageEditorInput(IStorage storage) { - fStorage = storage; - } - - public IStorage getStorage() throws CoreException { - return fStorage; - } - - public boolean exists() { - return fStorage != null; - } - - public ImageDescriptor getImageDescriptor() { - return null; - } - - public String getName() { - return fStorage.getName(); - } - - public IPersistableElement getPersistable() { - return null; - } - - public String getToolTipText() { - return fStorage.getFullPath().toString(); - } - - public Object getAdapter(Class adapter) { - return null; - } - } - - static class ZipStorage implements IStorage { - File fFile = null; - String fEntryName = null; - String fTitle = null; - - ZipStorage(File file, String entryName, String title) { - fFile = file; - fEntryName = entryName; - fTitle = title; - } - - public InputStream getContents() throws CoreException { - InputStream stream = null; - try { - ZipFile file = new ZipFile(fFile); - ZipEntry entry = file.getEntry(fEntryName); - stream = file.getInputStream(entry); - } - catch (Exception e) { - throw new CoreException(new Status(IStatus.ERROR, JSPUIPlugin.getDefault().getBundle().getSymbolicName(), IStatus.ERROR, fTitle, e)); - } - return stream; - } - - public IPath getFullPath() { - return new Path(fFile.getAbsolutePath() + IPath.SEPARATOR + fEntryName); - } - - public String getName() { - return fEntryName; - } - - public boolean isReadOnly() { - return true; - } - - public Object getAdapter(Class adapter) { - return null; - } - } - - static class URLStorage implements IStorage { - URL fURL = null; - - URLStorage(URL url) { - fURL = url; - } - - public InputStream getContents() throws CoreException { - InputStream stream = null; - try { - stream = fURL.openStream(); - } - catch (Exception e) { - throw new CoreException(new Status(IStatus.ERROR, JSPUIPlugin.getDefault().getBundle().getSymbolicName(), IStatus.ERROR, fURL.toString(), e)); - } - return stream; - } - - public IPath getFullPath() { - return new Path(fURL.toString()); - } - - public String getName() { - return new Path(fURL.getFile()).lastSegment(); - } - - public boolean isReadOnly() { - return true; - } - - public Object getAdapter(Class adapter) { - return null; - } - - } - - private JSPJavaOpenOnJSP getJSPJavaOpenOn() { - if (jspJavaOpenOn == null) { - jspJavaOpenOn = new JSPJavaOpenOnJSP(); - // set the document to current document - jspJavaOpenOn.setDocument(getDocument()); - } - return jspJavaOpenOn; - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.openon.AbstractOpenOn#setDocument(org.eclipse.jface.text.IDocument) - */ - public void setDocument(IDocument doc) { - super.setDocument(doc); - - // also set the document for jspJavaOpenOn - if (jspJavaOpenOn != null) { - jspJavaOpenOn.setDocument(doc); - } - } - - /** - * Get JSP translation object - * - * @return JSPTranslation if one exists, null otherwise - */ - private JSPTranslation getJSPTranslation() { - // get JSP translation object for this action's editor's document - XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - if (xmlModel != null) { - XMLDocument xmlDoc = xmlModel.getDocument(); - xmlModel.releaseFromRead(); - JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (adapter != null) { - return adapter.getJSPTranslation(); - } - } - return null; - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.AbstractOpenOn#doOpenOn(org.eclipse.jface.text.IRegion) - */ - protected void doOpenOn(IRegion region) { - boolean opened = false; - IRegion newRegion = doGetOpenOnRegion(region.getOffset()); - // if there is a corresponding Java source offset, then use - // JSPJavaOpenOnJSP - JSPTranslation jspTranslation = getJSPTranslation(); - if ((jspTranslation != null) && (newRegion != null) && (jspTranslation.getJavaOffset(newRegion.getOffset()) > -1)) { - getJSPJavaOpenOn().doOpenOn(newRegion); - opened = true; - } - - // check servlet and taglib mappings - if (!opened) { - Node current = getCurrentNode(newRegion.getOffset()); - if (current.getNodeType() == Node.ELEMENT_NODE) { - Attr attr = getLinkableAttr((Element) current); - if (attr != null) { - ITaglibRecord reference = TaglibIndex.resolve(getBaseLocation(), attr.getValue(), false); - if (reference != null) { - try { - switch (reference.getRecordType()) { - case (ITaglibRecord.TLD) : { - TLDRecord record = (TLDRecord) reference; - openFileInEditor(record.getLocation().toString()); - opened = true; - } - break; - case (ITaglibRecord.JAR) : { - JarRecord record = (JarRecord) reference; - IEditorInput input = new StorageEditorInput(new ZipStorage(record.getLocation().toFile(), "META-INF/taglib.tld", record.getLocation().toString())); - IEditorDescriptor editor = IDE.getEditorDescriptor(input.getName()); - if (editor != null) { - IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), input, editor.getId(), true); - opened = true; - } - } - break; - case (ITaglibRecord.URL) : { - URLRecord record = (URLRecord) reference; - IEditorInput input = new StorageEditorInput(new URLStorage(record.getURL())); - IEditorDescriptor editor = IDE.getEditorDescriptor(input.getName()); - if (editor != null) { - IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(), input, editor.getId(), true); - opened = true; - } - } - } - } - catch (Exception e) { - openFileFailed(); - } - } - } - } - } - - if (!opened) - super.doOpenOn(newRegion); - } - - /** - * Return an attr of element that is of type URI if one exists. or if - * element is jsp:usebean return the type or class attribute. null - * otherwise. - * - * @param element - - * cannot be null - * @return Attr - */ - protected Attr getLinkableAttr(Element element) { - String tagName = element.getTagName(); - - // usebean - if (JSP11Namespace.ElementName.USEBEAN.equalsIgnoreCase(tagName)) { - // get the list of attributes for this node - NamedNodeMap attrs = element.getAttributes(); - for (int i = 0; i < attrs.getLength(); ++i) { - Attr att = (Attr) attrs.item(i); - String attName = att.getName(); - // look for the type or class attribute - if ((JSP11Namespace.ATTR_NAME_TYPE.equalsIgnoreCase(attName)) || (JSP11Namespace.ATTR_NAME_CLASS.equalsIgnoreCase(attName))) { - return att; - } - } - } - - // otherwise, just look for attribute value of type URI - return super.getLinkableAttr(element); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPJavaOpenOnJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPJavaOpenOnJSP.java deleted file mode 100644 index 54dd288184..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/openon/JSPJavaOpenOnJSP.java +++ /dev/null @@ -1,290 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.openon; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.ILocalVariable; -import org.eclipse.jdt.core.ISourceRange; -import org.eclipse.jdt.core.ISourceReference; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.ui.JavaElementLabelProvider; -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.Region; -import org.eclipse.jface.window.Window; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.Logger; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.dialogs.ElementListSelectionDialog; -import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.ui.openon.AbstractOpenOn; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; - -/** - * This action opens classes referenced in JSP Java content of a JSP page. - * - * @deprecated Use base support for hyperlink navigation - */ -public class JSPJavaOpenOnJSP extends AbstractOpenOn { - - //private final String SSE_MODEL_ID = IModelManagerPlugin.ID; //$NON-NLS-1$ - private final String SELECT_JAVA_TITLE = JSPUIPlugin.getResourceString("%JSPJavaOpenOnJSP.0"); //$NON-NLS-1$ - private final String SELECT_JAVA_MESSAGE = JSPUIPlugin.getResourceString("%JSPJavaOpenOnJSP.1"); //$NON-NLS-1$ - - /** - * Get JSP translation object - * - * @return JSPTranslation if one exists, null otherwise - */ - private JSPTranslation getJSPTranslation() { - // get JSP translation object for this action's editor's document - XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - if (xmlModel != null) { - XMLDocument xmlDoc = xmlModel.getDocument(); - xmlModel.releaseFromRead(); - JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (adapter != null) { - return adapter.getJSPTranslation(); - } - } - return null; - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.AbstractOpenOn#doOpenOn(org.eclipse.jface.text.IRegion) - */ - protected void doOpenOn(IRegion region) { - JSPTranslation jspTranslation = getJSPTranslation(); - if (jspTranslation != null) { - IJavaElement element = getJavaElement(region, jspTranslation); - - // open local variable in the JSP file... - if (element instanceof ILocalVariable) { - // source reference has java text range info - if (element instanceof ISourceReference) { - try { - // get Java range, translate coordinate to JSP - ISourceRange range = ((ISourceReference) element).getSourceRange(); - int jspStart = jspTranslation.getJspOffset(range.getOffset()); - - // open the JSP editor - IEditorPart jspEditor = openDocumentEditor(); - // set the cursor to the declaration of the variable - if (jspEditor instanceof ITextEditor) { - ((ITextEditor) jspEditor).setHighlightRange(jspStart, 0, true); - } - } - catch (JavaModelException jme) { - Logger.logException("error getting source range from java element (local variable)", jme); //$NON-NLS-1$ - } - } - } - else { - try { - IEditorPart part = JavaUI.openInEditor(element); - if (part != null) { - if (element != null) - JavaUI.revealInEditor(part, element); - } - else { - // could not open editor - openFileFailed(); - } - } - catch (Exception e) { - Logger.log(Logger.WARNING_DEBUG, e.getMessage(), e); - } - } - } - } - - private IFile[] getFiles(IStructuredModel model) { - String location = model.getBaseLocation(); - IPath path = new Path(location); - if (!path.toFile().exists() && path.segmentCount() > 1) { - return new IFile[]{ResourcesPlugin.getWorkspace().getRoot().getFile(path)}; - } - return ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(path); - } - - /** - * Determine the one Java element to open file on - * - * @param region - * IRegion - * @param translation - * jsp java translation - * @return the one Java element to open file on - */ - private IJavaElement getJavaElement(IRegion region, JSPTranslation translation) { - if (region == null) { - return null; - } - - IJavaElement[] elements = translation.getElementsFromJspRange(region.getOffset(), region.getOffset() + region.getLength()); - if (elements == null || elements.length == 0) - return null; - IJavaElement candidate = elements[0]; - // more than one Java element was selected so ask user which element - // should open file open - if (elements.length > 1) { - candidate = selectJavaElement(elements); - } - return candidate; - } - - /** - * Shows a dialog for resolving an ambigous java element. This method was - * copied from org.eclipse.jdt.internal.ui.actions.OpenActionUtil except I - * set the shell, title, message in this method instead of passing it and - * this method is private - */ - private IJavaElement selectJavaElement(IJavaElement[] elements) { - - int nResults = elements.length; - if (nResults == 0) - return null; - if (nResults == 1) - return elements[0]; - int flags = JavaElementLabelProvider.SHOW_DEFAULT | JavaElementLabelProvider.SHOW_QUALIFIED | JavaElementLabelProvider.SHOW_ROOT; - ElementListSelectionDialog dialog = new ElementListSelectionDialog(null, new JavaElementLabelProvider(flags)); - dialog.setTitle(SELECT_JAVA_TITLE); - dialog.setMessage(SELECT_JAVA_MESSAGE); - dialog.setElements(elements); - if (dialog.open() == Window.OK) { - Object[] selection = dialog.getResult(); - if (selection != null && selection.length > 0) { - nResults = selection.length; - for (int i = 0; i < nResults; i++) { - Object current = selection[i]; - if (current instanceof IJavaElement) - return (IJavaElement) current; - } - } - } - return null; - } - - /* - * (non-Javadoc) - * - * @see com.ibm.sse.editor.AbstractOpenOn#doGetOpenOnRegion(int) - */ - protected IRegion doGetOpenOnRegion(int offset) { - IRegion region; - - // check and make sure this is a valid Java type - JSPTranslation jspTranslation = getJSPTranslation(); - IJavaElement[] elements = jspTranslation.getElementsFromJspRange(offset, offset); - // if no Java element found, this is not a valid openable region - if (elements == null || elements.length == 0) - region = null; - else { - // return the type region - region = selectWord(getDocument(), offset); - } - return region; - } - - /** - * Java always selects word when defining region - * - * @param document - * @param anchor - * @return IRegion - */ - private IRegion selectWord(IDocument document, int anchor) { - - try { - int offset = anchor; - char c; - - while (offset >= 0) { - c = document.getChar(offset); - if (!Character.isJavaIdentifierPart(c)) - break; - --offset; - } - - int start = offset; - - offset = anchor; - int length = document.getLength(); - - while (offset < length) { - c = document.getChar(offset); - if (!Character.isJavaIdentifierPart(c)) - break; - ++offset; - } - - int end = offset; - - if (start == end) - return new Region(start, 0); - else - return new Region(start + 1, end - start - 1); - - } - catch (BadLocationException x) { - return null; - } - } - - /** - * Open the editor associated with the current document - * - * @return the editor opened or null if an external editor was opened or - * no editor was opened - */ - private IEditorPart openDocumentEditor() { - IEditorPart theEditor = null; - - IStructuredModel model = null; - IFile file = null; - try { - model = StructuredModelManager.getModelManager().getExistingModelForRead(getDocument()); - IFile[] files = getFiles(model); - int i = 0; - while (i < files.length && file == null) { - if (files[i].exists()) { - file = files[i]; - } - else { - ++i; - } - } - } - finally { - if (model != null) { - model.releaseFromRead(); - } - } - if (file != null) { - theEditor = openFileInEditor(file); - } - return theEditor; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/preferences/ui/JSPColorPage.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/preferences/ui/JSPColorPage.java deleted file mode 100644 index b7a90eec23..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/preferences/ui/JSPColorPage.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.preferences.ui; - -import java.util.ArrayList; -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.Iterator; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jst.jsp.core.contenttype.ContentTypeIdForJSP; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.editor.IHelpContextIds; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.wst.html.ui.style.IStyleConstantsHTML; -import org.eclipse.wst.sse.core.IModelManager; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore; -import org.eclipse.wst.sse.ui.internal.preferences.OverlayPreferenceStore.OverlayKey; -import org.eclipse.wst.sse.ui.preferences.ui.StyledTextColorPicker; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.ui.preferences.XMLColorPage; -import org.eclipse.wst.xml.ui.style.IStyleConstantsXML; - -public class JSPColorPage extends XMLColorPage { - - /** - * Set up all the style preference keys in the overlay store - */ - protected OverlayKey[] createOverlayStoreKeys() { - ArrayList overlayKeys = new ArrayList(); - - ArrayList styleList = new ArrayList(); - initStyleList(styleList); - Iterator i = styleList.iterator(); - while (i.hasNext()) { - overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, (String)i.next())); - } - - OverlayPreferenceStore.OverlayKey[] keys = new OverlayPreferenceStore.OverlayKey[overlayKeys.size()]; - overlayKeys.toArray(keys); - return keys; - } - - public String getSampleText() { - return JSPUIPlugin.getResourceString("%Sample_JSP_doc"); //$NON-NLS-1$ = "<%@ page \n\tlanguage=\"java\" \n\tcontentType=\"text/html; charset=ISO-8859-1\"\n%>\n<jsp:include flush=\"true\" page=\"titleBar.jsp\"/>\n\n<%-- Use below tags ONLY for JSP 1.1 --%>\n<%\n\tSystem.out.println(\"Welcome!\");\n%>\n<%-- Use below tags ONLY for JSP 1.2 --%>\n<jsp:scriptlet>\n\tSystem.out.println(\"Welcome!\");\n</jsp:scriptlet>" - } - - protected void initContextStyleMap(Dictionary contextStyleMap) { - - initCommonContextStyleMap(contextStyleMap); - contextStyleMap.remove(XMLRegionContext.XML_CONTENT); // leave content between tags alone - contextStyleMap.remove(XMLRegionContext.XML_DECLARATION_OPEN); // xml/html specific - contextStyleMap.remove(XMLRegionContext.XML_DECLARATION_CLOSE); // xml/html specific - contextStyleMap.remove(XMLRegionContext.XML_ELEMENT_DECLARATION); // xml/html specific - contextStyleMap.remove(XMLRegionContext.XML_ELEMENT_DECL_CLOSE); // xml/html specific - - // contextStyleMap.put(XMLJSPRegionContexts.JSP_CONTENT, HTMLColorManager.SCRIPT_AREA); - // contextStyleMap.put(XMLJSPRegionContexts.BLOCK_TEXT, HTMLColorManager.SCRIPT_AREA); - contextStyleMap.put(XMLJSPRegionContexts.JSP_DECLARATION_OPEN, IStyleConstantsHTML.SCRIPT_AREA_BORDER); - contextStyleMap.put(XMLJSPRegionContexts.JSP_SCRIPTLET_OPEN, IStyleConstantsHTML.SCRIPT_AREA_BORDER); - contextStyleMap.put(XMLJSPRegionContexts.JSP_EXPRESSION_OPEN, IStyleConstantsHTML.SCRIPT_AREA_BORDER); - contextStyleMap.put(XMLJSPRegionContexts.JSP_DIRECTIVE_OPEN, IStyleConstantsHTML.SCRIPT_AREA_BORDER); - contextStyleMap.put(XMLJSPRegionContexts.JSP_DIRECTIVE_CLOSE, IStyleConstantsHTML.SCRIPT_AREA_BORDER); - contextStyleMap.put(XMLJSPRegionContexts.JSP_CLOSE, IStyleConstantsHTML.SCRIPT_AREA_BORDER); - contextStyleMap.put(XMLJSPRegionContexts.JSP_DIRECTIVE_NAME, IStyleConstantsXML.TAG_NAME); - contextStyleMap.put(XMLJSPRegionContexts.JSP_ROOT_TAG_NAME, IStyleConstantsXML.TAG_NAME); - contextStyleMap.put(XMLJSPRegionContexts.JSP_COMMENT_OPEN, IStyleConstantsXML.COMMENT_BORDER); - contextStyleMap.put(XMLJSPRegionContexts.JSP_COMMENT_TEXT, IStyleConstantsXML.COMMENT_TEXT); - contextStyleMap.put(XMLJSPRegionContexts.JSP_COMMENT_CLOSE, IStyleConstantsXML.COMMENT_BORDER); - - contextStyleMap.put(XMLJSPRegionContexts.XML_TAG_ATTRIBUTE_VALUE_DQUOTE, IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - contextStyleMap.put(XMLJSPRegionContexts.XML_TAG_ATTRIBUTE_VALUE_SQUOTE, IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - } - - protected void initDescriptions(Dictionary descriptions) { - initCommonDescriptions(descriptions); - descriptions.remove(IStyleConstantsXML.XML_CONTENT); // leave content between tags alone - descriptions.remove(IStyleConstantsXML.DECL_BORDER); // xml/html specific - descriptions.put(IStyleConstantsHTML.SCRIPT_AREA_BORDER, JSPUIPlugin.getResourceString("%JSP_Delimiters_UI_")); //$NON-NLS-1$ = "JSP Delimiters" - } - - protected void initStyleList(ArrayList list) { - initCommonStyleList(list); - list.remove(IStyleConstantsXML.XML_CONTENT); // leave content between tags alone - list.remove(IStyleConstantsXML.DECL_BORDER); // xml/html specific - list.add(IStyleConstantsHTML.SCRIPT_AREA_BORDER); - } - - protected void setupPicker(StyledTextColorPicker picker) { - IModelManager mmanager = StructuredModelManager.getModelManager(); - picker.setParser(mmanager.createStructuredDocumentFor(ContentTypeIdForJSP.ContentTypeID_JSP).getParser()); - - // create descriptions for hilighting types - Dictionary descriptions = new Hashtable(); - initDescriptions(descriptions); - - // map region types to hilighting types - Dictionary contextStyleMap = new Hashtable(); - initContextStyleMap(contextStyleMap); - - ArrayList styleList = new ArrayList(); - initStyleList(styleList); - - picker.setContextStyleMap(contextStyleMap); - picker.setDescriptions(descriptions); - picker.setStyleList(styleList); - - // updatePickerFont(picker); - } - /* (non-Javadoc) - * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) - */ - protected Control createContents(Composite parent) { - Control c = super.createContents(parent); - WorkbenchHelp.setHelp(c, IHelpContextIds.JSP_PREFWEBX_STYLES_HELPID); - return c; - } - /* (non-Javadoc) - * @see org.eclipse.jface.preference.PreferencePage#doGetPreferenceStore() - */ - protected IPreferenceStore doGetPreferenceStore() { - return JSPUIPlugin.getDefault().getPreferenceStore(); - } - /* (non-Javadoc) - * @see org.eclipse.wst.sse.ui.preferences.ui.AbstractColorPage#savePreferences() - */ - protected void savePreferences() { - JSPUIPlugin.getDefault().savePluginPreferences(); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/preferences/ui/JSPFilesPreferencePage.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/preferences/ui/JSPFilesPreferencePage.java deleted file mode 100644 index bd082eaf5e..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/preferences/ui/JSPFilesPreferencePage.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.preferences.ui; - -import org.eclipse.core.runtime.Preferences; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jst.jsp.core.internal.JSPCorePlugin; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.editor.IHelpContextIds; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.wst.html.ui.preferences.ui.HTMLFilesPreferencePage; - -public class JSPFilesPreferencePage extends HTMLFilesPreferencePage { - - /* (non-Javadoc) - * @see com.ibm.sse.editor.preferences.ui.AbstractPreferencePage#getModelPreferences() - */ - protected Preferences getModelPreferences() { - return JSPCorePlugin.getDefault().getPluginPreferences(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.PreferencePage#doGetPreferenceStore() - */ - protected IPreferenceStore doGetPreferenceStore() { - return JSPUIPlugin.getDefault().getPreferenceStore(); - } - - /* (non-Javadoc) - * @see com.ibm.sse.editor.xml.preferences.ui.XMLFilesPreferencePage#doSavePreferenceStore() - */ - protected void doSavePreferenceStore() { - JSPCorePlugin.getDefault().savePluginPreferences(); // model - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) - */ - protected Control createContents(Composite parent) { - Control c = super.createContents(parent); - WorkbenchHelp.setHelp(c, IHelpContextIds.JSP_PREFWEBX_FILES_HELPID); - return c; - } - /* (non-Javadoc) - * @see org.eclipse.wst.html.ui.preferences.ui.HTMLFilesPreferencePage#createContentsForLoadingGroup(org.eclipse.swt.widgets.Composite) - */ - protected void createContentsForLoadingGroup(Composite parent) { - // no loading preferences - } - /* (non-Javadoc) - * @see org.eclipse.wst.html.ui.preferences.ui.HTMLFilesPreferencePage#initializeValuesForLoadingGroup() - */ - protected void initializeValuesForLoadingGroup() { - // no loading preferences - } - /* (non-Javadoc) - * @see org.eclipse.wst.html.ui.preferences.ui.HTMLFilesPreferencePage#performDefaultsForLoadingGroup() - */ - protected void performDefaultsForLoadingGroup() { - // no loading preferences - } - /* (non-Javadoc) - * @see org.eclipse.wst.html.ui.preferences.ui.HTMLFilesPreferencePage#storeValuesForLoadingGroup() - */ - protected void storeValuesForLoadingGroup() { - // no loading preferences - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/preferences/ui/JSPTemplatePreferencePage.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/preferences/ui/JSPTemplatePreferencePage.java deleted file mode 100644 index 1a1462bbcc..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/preferences/ui/JSPTemplatePreferencePage.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.preferences.ui; - -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.jst.jsp.ui.internal.editor.IHelpContextIds; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.ui.texteditor.templates.TemplatePreferencePage; - - -/** - * Preference page for JSP templates - */ -public class JSPTemplatePreferencePage extends TemplatePreferencePage { - - public JSPTemplatePreferencePage() { - JSPUIPlugin jspEditorPlugin = JSPUIPlugin.getDefault(); - - setPreferenceStore(jspEditorPlugin.getPreferenceStore()); - setTemplateStore(jspEditorPlugin.getTemplateStore()); - setContextTypeRegistry(jspEditorPlugin.getTemplateContextRegistry()); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.preference.IPreferencePage#performOk() - */ - public boolean performOk() { - boolean ok = super.performOk(); - JSPUIPlugin.getDefault().savePluginPreferences(); - return ok; - } - - /* (non-Javadoc) - * @see org.eclipse.ui.texteditor.templates.TemplatePreferencePage#isShowFormatterSetting() - */ - protected boolean isShowFormatterSetting() { - // template formatting has not been implemented - return false; - } - /* (non-Javadoc) - * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite) - */ - protected Control createContents(Composite ancestor) { - Control c = super.createContents(ancestor); - WorkbenchHelp.setHelp(c, IHelpContextIds.JSP_PREFWEBX_TEMPLATES_HELPID); - return c; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/registry/AdapterFactoryProviderForJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/registry/AdapterFactoryProviderForJSP.java deleted file mode 100644 index 79398b815c..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/registry/AdapterFactoryProviderForJSP.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.registry; - -import java.util.Iterator; - -import org.eclipse.jst.jsp.core.PageDirectiveAdapter; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapterFactory; -import org.eclipse.jst.jsp.core.modelhandler.ModelHandlerForJSP; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.ui.views.properties.IPropertySource; -import org.eclipse.wst.html.ui.views.contentoutline.JFaceNodeAdapterFactoryForHTML; -import org.eclipse.wst.sse.core.AdapterFactory; -import org.eclipse.wst.sse.core.IFactoryRegistry; -import org.eclipse.wst.sse.core.IStructuredModel; -import org.eclipse.wst.sse.core.PropagatingAdapter; -import org.eclipse.wst.sse.core.modelhandler.IDocumentTypeHandler; -import org.eclipse.wst.sse.ui.registry.AdapterFactoryProvider; -import org.eclipse.wst.sse.ui.registry.AdapterFactoryRegistry; -import org.eclipse.wst.sse.ui.registry.embedded.EmbeddedAdapterFactoryProvider; -import org.eclipse.wst.sse.ui.util.Assert; -import org.eclipse.wst.sse.ui.views.contentoutline.IJFaceNodeAdapter; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; -import org.eclipse.wst.xml.ui.views.properties.XMLPropertySourceAdapterFactory; - -/** - * @author pavery - */ -public class AdapterFactoryProviderForJSP implements AdapterFactoryProvider { - - /* - * @see AdapterFactoryProvider#addAdapterFactories(IStructuredModel) - */ - public void addAdapterFactories(IStructuredModel structuredModel) { - // these are the main factories, on model's factory registry - addContentBasedFactories(structuredModel); - // ------- - // Must update/add to propagating adapters here too - addPropagatingAdapters(structuredModel); - // ------- - // Must update/add to "editor side" embedded adapters here too - addEmbeddedContentFactories(structuredModel); - - } - - protected void addContentBasedFactories(IStructuredModel structuredModel) { - IFactoryRegistry factoryRegistry = structuredModel.getFactoryRegistry(); - Assert.isNotNull(factoryRegistry, "Program Error: client caller must ensure model has factory registry"); //$NON-NLS-1$ - AdapterFactory factory = null; - // == this list came from the previous "HTML only" list - // factory = factoryRegistry.getFactoryFor(ContentAssistAdapter.class); - // if (factory == null) { - // factory = new HTMLContentAssistAdapterFactory(ContentAssistAdapter.class, false); - // factoryRegistry.addFactory(factory); - // } - // factory = factoryRegistry.getFactoryFor(ContentAssistAdapter.class); - // if (factory == null) { - // factory = new JSPContentAssistAdapterFactory(); - // factoryRegistry.addFactory(factory); - // } - // factory = factoryRegistry.getFactoryFor(DoubleClickAdapter.class); - // if (factory == null) { - // factory = new DoubleClickAdapterFactory(DoubleClickAdapter.class, true); - // factoryRegistry.addFactory(factory); - // } - // // == New adapter factories for tagInfo - // factory = factoryRegistry.getFactoryFor(HoverHelpAdapter.class); - // if (factory == null) { - // factory = new JSPHoverHelpAdapterFactory(HoverHelpAdapter.class, true); - // factoryRegistry.addFactory(factory); - // } - // factory = factoryRegistry.getFactoryFor(TagInfoProviderAdapter.class); - // if (factory == null) { - // factory = new JSTagInfoProviderAdapterFactory(TagInfoProviderAdapter.class, true); - // factoryRegistry.addFactory(factory); - // } - // == - // == this list came from the previous 'for both XML and HTML' list - factory = factoryRegistry.getFactoryFor(IPropertySource.class); - if (factory == null) { - factory = new XMLPropertySourceAdapterFactory(); - factoryRegistry.addFactory(factory); - } - factory = factoryRegistry.getFactoryFor(IJFaceNodeAdapter.class); - if (factory == null) { - factory = new JFaceNodeAdapterFactoryForHTML(IJFaceNodeAdapter.class, true); - factoryRegistry.addFactory(factory); - } - - factory = factoryRegistry.getFactoryFor(IJSPTranslation.class); - if (factory == null) { - factory = new JSPTranslationAdapterFactory(); - factoryRegistry.addFactory(factory); - } - } - - protected void addEmbeddedContentFactories(IStructuredModel structuredModel) { - - if (structuredModel instanceof XMLModel) { - XMLModel xmlModel = (XMLModel) structuredModel; - XMLDocument document = xmlModel.getDocument(); - PageDirectiveAdapter pageDirectiveAdapter = (PageDirectiveAdapter) document.getAdapterFor(PageDirectiveAdapter.class); - if (pageDirectiveAdapter != null) { - // made into registry mechanism - AdapterFactoryRegistry adapterRegistry = JSPUIPlugin.getDefault().getEmbeddedAdapterFactoryRegistry(); - Iterator adapterList = adapterRegistry.getAdapterFactories(); - // And all those appropriate for this particular type of content - while (adapterList.hasNext()) { - EmbeddedAdapterFactoryProvider provider = (EmbeddedAdapterFactoryProvider) adapterList.next(); - if (provider.isFor(pageDirectiveAdapter.getEmbeddedType())) { - provider.addAdapterFactories(structuredModel); - } - } - } - } - - } - - protected void addPropagatingAdapters(IStructuredModel structuredModel) { - // if (structuredModel instanceof XMLModel) { - // AdapterFactory factory = null; - // XMLModel xmlModel = (XMLModel) structuredModel; - // XMLDocument document = xmlModel.getDocument(); - // PropagatingAdapter propagatingAdapter = (PropagatingAdapter) document.getAdapterFor(PropagatingAdapter.class); - // if (propagatingAdapter != null) { - // DMW: 8/16/2002 removed since this one was no longer needed for page directive - // lanague. It might still be needed for script and meta languages? - // but even they were "commented out" in the JSPPageDirectiveLineStyleUpdaterFactory - // so not sure what the plan it there. - // factory = new JSPPageDirectiveLineStyleUpdaterFactory(); - // propagatingAdapter.addAdaptOnCreateFactory(factory); - // propagatingAdapter.initializeForFactory(factory, document); - // } - // } - - if (structuredModel instanceof XMLModel) { -// AdapterFactory factory = null; - XMLModel xmlModel = (XMLModel) structuredModel; - XMLDocument document = xmlModel.getDocument(); - PropagatingAdapter propagatingAdapter = (PropagatingAdapter) document.getAdapterFor(PropagatingAdapter.class); - if (propagatingAdapter != null) { - // checking if we should bother adding this factory - // if the preference says not to check validity, we don't bother creating this factory - // to improve performance... - //if(structuredModel.getStructuredPreferenceStore().getPreferenceString(CommonPreferenceNames.EDITOR_VALIDATION_METHOD).equals(CommonPreferenceNames.EDITOR_VALIDATION_CONTENT_MODEL)) { - //factory = new ReconcilerAdapterFactoryForXML(); - //propagatingAdapter.addAdaptOnCreateFactory(factory); - // (pa) perf: - //propagatingAdapter.initializeForFactory(factory, xmlModel.getDocument()); - //} - } - } - } - - /* - * @see AdapterFactoryProvider#isFor(ContentTypeDescription) - */ - public boolean isFor(IDocumentTypeHandler contentTypeDescription) { - return (contentTypeDescription instanceof ModelHandlerForJSP); - } - - public void reinitializeFactories(IStructuredModel structuredModel) { - // assuming the original ones have been removed already - // from the page directives registry. The original ones - // are removed when the embeddedContentType is set. - addEmbeddedContentFactories(structuredModel); - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/LineStyleProviderForJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/LineStyleProviderForJSP.java deleted file mode 100644 index 51016182cb..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/LineStyleProviderForJSP.java +++ /dev/null @@ -1,231 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.style; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.wst.html.ui.style.IStyleConstantsHTML; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.sse.ui.style.AbstractLineStyleProvider; -import org.eclipse.wst.sse.ui.style.LineStyleProvider; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; -import org.eclipse.wst.xml.ui.style.IStyleConstantsXML; - -public class LineStyleProviderForJSP extends AbstractLineStyleProvider implements LineStyleProvider{ - - private String language = null; - - // private static final String JAVA = "java"; //$NON-NLS-1$ - // private static final String[] JAVASCRIPT_LANGUAGE_KEYS = new String[] { - // "javascript", "javascript1.0", "javascript1.1_3", "javascript1.2", - // "javascript1.3", "javascript1.4", "javascript1.5", "javascript1.6", - // "jscript", "sashscript" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - // //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ - // //$NON-NLS-9$ //$NON-NLS-10$ - - public LineStyleProviderForJSP() { - super(); - loadColorsForJSPTags(); - } - - protected void clearColors() { - getTextAttributes().clear(); - } - - protected TextAttribute getAttributeFor(ITextRegion region) { - /** - * a method to centralize all the "sytle rules" for regions - */ - TextAttribute result = null; - // not sure why this is coming through null, but just to catch it - if (region == null) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_TEXT); - } - else { - - if (result == null) { - String type = region.getType(); - if ((type == XMLJSPRegionContexts.JSP_SCRIPTLET_OPEN) || (type == XMLJSPRegionContexts.JSP_DECLARATION_OPEN) || (type == XMLJSPRegionContexts.JSP_EXPRESSION_OPEN) || (type == XMLJSPRegionContexts.JSP_DIRECTIVE_OPEN) || (type == XMLJSPRegionContexts.JSP_DIRECTIVE_CLOSE) || (type == XMLJSPRegionContexts.JSP_CLOSE)) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsHTML.SCRIPT_AREA_BORDER); - } - else if (type == XMLJSPRegionContexts.JSP_DIRECTIVE_NAME || type == XMLJSPRegionContexts.JSP_ROOT_TAG_NAME) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_NAME); - } - else if ((type == XMLJSPRegionContexts.JSP_COMMENT_OPEN) || (type == XMLJSPRegionContexts.JSP_COMMENT_CLOSE)) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.COMMENT_BORDER); - } - else if (type == XMLJSPRegionContexts.JSP_COMMENT_TEXT) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.COMMENT_TEXT); - } - // ============ These are in common with XML --- (for XML form - // of tags) - // Note: this assume's this provider is only called for - // true JSP Nodes. If its called for others, then this will - // cause their tag names to be highlighted too! - // Further checks could be done to prevent that, but doesn't - // seem worth it, since if adpaters factories are working - // right, - // then wouldn't be needed. - else if (type == XMLRegionContext.XML_TAG_NAME) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_NAME); - } - else if ((type == XMLRegionContext.XML_TAG_OPEN) || (type == XMLRegionContext.XML_END_TAG_OPEN) || (type == XMLRegionContext.XML_TAG_CLOSE) || (type == XMLRegionContext.XML_EMPTY_TAG_CLOSE)) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_BORDER); - } - else if (type == XMLRegionContext.XML_TAG_ATTRIBUTE_NAME) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - } - else if ((type == XMLRegionContext.XML_TAG_ATTRIBUTE_VALUE) || (type == XMLJSPRegionContexts.XML_TAG_ATTRIBUTE_VALUE_DQUOTE) || (type == XMLJSPRegionContexts.XML_TAG_ATTRIBUTE_VALUE_SQUOTE)) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - } - else if (type == XMLRegionContext.XML_TAG_ATTRIBUTE_EQUALS) { - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS); - } - - // DMW: added 9/1/2002 Undefined color may need addjustment :) - else if (type == XMLRegionContext.UNDEFINED) - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.XML_CONTENT); - - else if (type == XMLRegionContext.WHITE_SPACE) - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.XML_CONTENT); - // DMW added 8/30/2002 -- should provide JSP specific - // preference for "custom tag content" (both tag dependent, - // BLOCKED_TEXT, and not, XML CONTENT) - else if (type == XMLRegionContext.XML_CONTENT) - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.XML_CONTENT); - else if (type == XMLRegionContext.BLOCK_TEXT) - result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_TEXT); - } - } - // default, return null to signal "not handled" - // in which case, other factories should be tried - return result; - } - - - protected IPreferenceStore getColorPreferences() { - return JSPUIPlugin.getDefault().getPreferenceStore(); - } - - protected void loadColorsForJSPTags() { - clearColors(); - - addTextAttribute(IStyleConstantsXML.TAG_NAME); - addTextAttribute(IStyleConstantsXML.TAG_BORDER); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS); - addTextAttribute(IStyleConstantsXML.COMMENT_BORDER); - addTextAttribute(IStyleConstantsXML.COMMENT_TEXT); - addTextAttribute(IStyleConstantsXML.CDATA_BORDER); - addTextAttribute(IStyleConstantsXML.CDATA_TEXT); - addTextAttribute(IStyleConstantsXML.DECL_BORDER); - addTextAttribute(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID); - addTextAttribute(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF); - addTextAttribute(IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF); - addTextAttribute(IStyleConstantsXML.DOCTYPE_NAME); - addTextAttribute(IStyleConstantsXML.PI_CONTENT); - addTextAttribute(IStyleConstantsXML.PI_BORDER); - addTextAttribute(IStyleConstantsXML.XML_CONTENT); - addTextAttribute(IStyleConstantsHTML.SCRIPT_AREA_BORDER); - } - - protected void handlePropertyChange(PropertyChangeEvent event) { - String styleKey = null; - - if (event != null) { - String prefKey = event.getProperty(); - // check if preference changed is a style preference - if (IStyleConstantsXML.TAG_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_NAME; - } - else if (IStyleConstantsXML.TAG_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_BORDER; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_NAME; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_VALUE.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_VALUE; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_EQUALS; - } - else if (IStyleConstantsXML.COMMENT_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.COMMENT_BORDER; - } - else if (IStyleConstantsXML.COMMENT_TEXT.equals(prefKey)) { - styleKey = IStyleConstantsXML.COMMENT_TEXT; - } - else if (IStyleConstantsXML.CDATA_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.CDATA_BORDER; - } - else if (IStyleConstantsXML.CDATA_TEXT.equals(prefKey)) { - styleKey = IStyleConstantsXML.CDATA_TEXT; - } - else if (IStyleConstantsXML.DECL_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.DECL_BORDER; - } - else if (IStyleConstantsXML.DOCTYPE_EXTERNAL_ID.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID; - } - else if (IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_PUBREF; - } - else if (IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_EXTERNAL_ID_SYSREF; - } - else if (IStyleConstantsXML.DOCTYPE_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.DOCTYPE_NAME; - } - else if (IStyleConstantsXML.PI_CONTENT.equals(prefKey)) { - styleKey = IStyleConstantsXML.PI_CONTENT; - } - else if (IStyleConstantsXML.PI_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsXML.PI_BORDER; - } - else if (IStyleConstantsXML.XML_CONTENT.equals(prefKey)) { - styleKey = IStyleConstantsXML.XML_CONTENT; - } - else if (IStyleConstantsHTML.SCRIPT_AREA_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsHTML.SCRIPT_AREA_BORDER; - } - } - - if (styleKey != null) { - // overwrite style preference with new value - addTextAttribute(styleKey); - super.handlePropertyChange(event); - } - } - - /** - * Returns the language. - * - * @return String - */ - public String getLanguage() { - return language; - } - - /** - * Sets the language. - * - * @param language - * The language to set - */ - public void setLanguage(String language) { - this.language = language; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaCodeScanner.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaCodeScanner.java deleted file mode 100644 index 7936a83f6f..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaCodeScanner.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.style.java; - - - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.rules.EndOfLineRule; -import org.eclipse.jface.text.rules.IRule; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.MultiLineRule; -import org.eclipse.jface.text.rules.SingleLineRule; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.text.rules.WhitespaceRule; -import org.eclipse.jface.text.rules.WordRule; -import org.eclipse.swt.graphics.Color; -import org.eclipse.wst.sse.ui.util.EditorUtility; - -/** - * A Java code scanner. - */ -public class JavaCodeScanner extends org.eclipse.jface.text.rules.RuleBasedScanner { - - private static String[] fgKeywords = {"abstract", //$NON-NLS-1$ - "break", //$NON-NLS-1$ - "case", "catch", "class", "continue", //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "default", "do", //$NON-NLS-2$//$NON-NLS-1$ - "else", "extends", //$NON-NLS-2$//$NON-NLS-1$ - "final", "finally", "for", //$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "if", "implements", "import", "instanceof", "interface", //$NON-NLS-5$//$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "native", "new", //$NON-NLS-2$//$NON-NLS-1$ - "package", "private", "protected", "public", //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "return", //$NON-NLS-1$ - "static", "super", "switch", "synchronized", //$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "this", "throw", "throws", "transient", "try", //$NON-NLS-5$//$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - "volatile", //$NON-NLS-1$ - "while", //$NON-NLS-1$ - "strictfp",//$NON-NLS-1$ - }; - private static String[] fgTypes = {"void", "boolean", "char", "byte", "short", "int", "long", "float", "double"};//$NON-NLS-9$//$NON-NLS-8$//$NON-NLS-7$//$NON-NLS-6$//$NON-NLS-5$//$NON-NLS-4$//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - private static String[] fgConstants = {"false", "null", "true"};//$NON-NLS-3$//$NON-NLS-2$//$NON-NLS-1$ - - /** - * Creates a Java code scanner - */ - public JavaCodeScanner() { - // if we use null here, system default will be used - Color background = null; //provider.getColor(JavaColorProvider.EDITOR_BACKGROUND); - - JavaColorProvider.getInstance().loadJavaColors(); - IToken keyword = new Token(new TextAttribute(EditorUtility.getColor(JavaColorProvider.KEYWORD), background, JavaColorProvider.KEYWORD_BOLD)); - IToken type = new Token(new TextAttribute(EditorUtility.getColor(JavaColorProvider.TYPE), background, JavaColorProvider.TYPE_BOLD)); - IToken string = new Token(new TextAttribute(EditorUtility.getColor(JavaColorProvider.STRING), background, JavaColorProvider.STRING_BOLD)); - IToken comment = new Token(new TextAttribute(EditorUtility.getColor(JavaColorProvider.SINGLE_LINE_COMMENT), background, JavaColorProvider.SINGLE_LINE_COMMENT_BOLD)); - IToken other = new Token(new TextAttribute(EditorUtility.getColor(JavaColorProvider.DEFAULT), background, JavaColorProvider.DEFAULT_BOLD)); - - - List rules = new ArrayList(); - - // Add rule for multiple line comments. - rules.add(new MultiLineRule("/*", "*/", comment));//$NON-NLS-1$ //$NON-NLS-2$ - - // Add rule for single line comments. - rules.add(new EndOfLineRule("//", comment));//$NON-NLS-1$ - - // Add rule for strings and character constants. - rules.add(new SingleLineRule("\"", "\"", string, '\\'));//$NON-NLS-2$//$NON-NLS-1$ - rules.add(new SingleLineRule("'", "'", string, '\\'));//$NON-NLS-2$//$NON-NLS-1$ - - // Add generic whitespace rule. - rules.add(new WhitespaceRule(new JavaWhitespaceDetector())); - - // Add word rule for keywords, types, and constants. - WordRule wordRule = new WordRule(new JavaWordDetector(), other); - for (int i = 0; i < fgKeywords.length; i++) - wordRule.addWord(fgKeywords[i], keyword); - for (int i = 0; i < fgTypes.length; i++) - wordRule.addWord(fgTypes[i], type); - for (int i = 0; i < fgConstants.length; i++) - wordRule.addWord(fgConstants[i], type); - rules.add(wordRule); - - - IRule[] result = new IRule[rules.size()]; - rules.toArray(result); - setRules(result); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaColorProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaColorProvider.java deleted file mode 100644 index 74cccc4907..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaColorProvider.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.style.java; - -import org.eclipse.jdt.ui.PreferenceConstants; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.preference.PreferenceConverter; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.RGB; - -/** - * Colors used in the Java editor - */ -public class JavaColorProvider { - - // people should not be setting these, even though they are currently not final - public static RGB MULTI_LINE_COMMENT = new RGB(128, 0, 0); - public static RGB SINGLE_LINE_COMMENT = new RGB(128, 128, 0); - public static RGB KEYWORD = new RGB(0, 0, 128); - public static RGB TYPE = new RGB(0, 0, 128); - public static RGB STRING = new RGB(0, 128, 0); - public static RGB DEFAULT = new RGB(0, 0, 0); - public static RGB JAVADOC_KEYWORD = new RGB(0, 128, 0); - public static RGB JAVADOC_TAG = new RGB(128, 128, 128); - public static RGB JAVADOC_LINK = new RGB(128, 128, 128); - public static RGB JAVADOC_DEFAULT = new RGB(0, 128, 128); - - public static int MULTI_LINE_COMMENT_BOLD = SWT.NORMAL; - public static int SINGLE_LINE_COMMENT_BOLD = SWT.NORMAL; - public static int KEYWORD_BOLD = SWT.BOLD; - public static int TYPE_BOLD = SWT.BOLD; - public static int STRING_BOLD = SWT.NORMAL; - public static int DEFAULT_BOLD = SWT.NORMAL; - public static int JAVADOC_KEYWORD_BOLD = SWT.BOLD; - public static int JAVADOC_TAG_BOLD = SWT.NORMAL; - public static int JAVADOC_LINK_BOLD = SWT.NORMAL; - public static int JAVADOC_DEFAULT_BOLD = SWT.NORMAL; - - /** - * @deprecated all editors use same - */ - public static RGB EDITOR_BACKGROUND = new RGB(255, 255, 255); - /** - * @deprecated all editors use same - */ - public static boolean EDITOR_CURRENT_LINE = true; - /** - * @deprecated all editors use same - */ - public static RGB EDITOR_CURRENT_LINE_COLOR = new RGB(128, 128, 128); - - private static JavaColorProvider fInstance = null; - - public static JavaColorProvider getInstance() { - if (fInstance == null) { - fInstance = new JavaColorProvider(); - } - return fInstance; - } - - /** - * Use colors from JDT plugin - */ - public void loadJavaColors() { - - IPreferenceStore jdtStore = PreferenceConstants.getPreferenceStore(); - MULTI_LINE_COMMENT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_COLOR); - SINGLE_LINE_COMMENT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_COLOR); - KEYWORD = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR); - TYPE = KEYWORD; - STRING = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_STRING_COLOR); - DEFAULT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVA_DEFAULT_COLOR); - JAVADOC_KEYWORD = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_KEYWORD_COLOR); - JAVADOC_TAG = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_TAG_COLOR); - JAVADOC_LINK = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_LINKS_COLOR); - JAVADOC_DEFAULT = PreferenceConverter.getColor(jdtStore, PreferenceConstants.EDITOR_JAVADOC_DEFAULT_COLOR); - - MULTI_LINE_COMMENT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_MULTI_LINE_COMMENT_BOLD) ? SWT.BOLD : SWT.NORMAL; - SINGLE_LINE_COMMENT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_SINGLE_LINE_COMMENT_BOLD) ? SWT.BOLD : SWT.NORMAL; - KEYWORD_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD) ? SWT.BOLD : SWT.NORMAL; - TYPE_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD) ? SWT.BOLD : SWT.NORMAL; - STRING_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_STRING_BOLD) ? SWT.BOLD : SWT.NORMAL; - DEFAULT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVA_DEFAULT_BOLD) ? SWT.BOLD : SWT.NORMAL; - JAVADOC_TAG_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVADOC_TAG_BOLD) ? SWT.BOLD : SWT.NORMAL; - JAVADOC_LINK_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVADOC_LINKS_BOLD) ? SWT.BOLD : SWT.NORMAL; - JAVADOC_DEFAULT_BOLD = jdtStore.getBoolean(PreferenceConstants.EDITOR_JAVADOC_DEFAULT_BOLD) ? SWT.BOLD : SWT.NORMAL; - -// EDITOR_BACKGROUND = new RGB(255, 255, 255); - -// IPreferenceStore sseStore = SSEUIPlugin.getDefault().getPreferenceStore(); -// EDITOR_CURRENT_LINE = sseStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE); -// EDITOR_CURRENT_LINE_COLOR = PreferenceConverter.getColor(sseStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_CURRENT_LINE_COLOR); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaWhitespaceDetector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaWhitespaceDetector.java deleted file mode 100644 index 3d28deda7e..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaWhitespaceDetector.java +++ /dev/null @@ -1,26 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.style.java; - - - -/** - * A java aware white space detector. - */ -public class JavaWhitespaceDetector implements org.eclipse.jface.text.rules.IWhitespaceDetector { - - /** - * @see org.eclipse.jface.text.rules.IWhitespaceDetector#isWhitespace - */ - public boolean isWhitespace(char c) { - return Character.isWhitespace(c); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaWordDetector.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaWordDetector.java deleted file mode 100644 index 08cd1a157f..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/JavaWordDetector.java +++ /dev/null @@ -1,32 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.style.java; - - -/** - * A Java aware word detector. - */ -public class JavaWordDetector implements org.eclipse.jface.text.rules.IWordDetector { - - /** - * @see org.eclipse.jface.text.rules.IWordDetector#isWordIdentifierPart - */ - public boolean isWordPart(char c) { - return Character.isJavaIdentifierPart(c); - } - - /** - * @see org.eclipse.jface.text.rules.IWordDetector#isWordIdentifierStart - */ - public boolean isWordStart(char c) { - return Character.isJavaIdentifierStart(c); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/LineStyleProviderForJava.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/LineStyleProviderForJava.java deleted file mode 100644 index fdbccce417..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/style/java/LineStyleProviderForJava.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.style.java; - -import java.util.Collection; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITypedRegion; -import org.eclipse.jface.text.TextAttribute; -import org.eclipse.jface.text.rules.IToken; -import org.eclipse.jface.text.rules.RuleBasedScanner; -import org.eclipse.jface.text.rules.Token; -import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.swt.custom.StyleRange; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Point; -import org.eclipse.wst.html.ui.style.IStyleConstantsHTML; -import org.eclipse.wst.sse.ui.style.AbstractLineStyleProvider; -import org.eclipse.wst.sse.ui.style.LineStyleProvider; -import org.eclipse.wst.sse.ui.util.EditorUtility; -import org.eclipse.wst.xml.ui.style.IStyleConstantsXML; -import org.w3c.dom.Node; - -// Note: many of the methods in this class were based on (or copied from) those -// found in the example Java Editor -public class LineStyleProviderForJava extends AbstractLineStyleProvider implements LineStyleProvider{ - - private IDocument fDocument; - /** The scanner it uses */ - protected RuleBasedScanner fScanner; - /** The default text attribute if non is returned as data by the current token */ - protected TextAttribute fDefaultTextAttribute; - protected Node targetNode; - - public LineStyleProviderForJava() { - super(); - loadColors(); - fScanner = new JavaCodeScanner(); - fDefaultTextAttribute = new TextAttribute(EditorUtility.getColor(JavaColorProvider.DEFAULT)); - - } - - /** - * Adds style information to the given text presentation. - * - * @param presentation the text presentation to be extended - * @param offset the offset of the range to be styled - * @param length the length of the range to be styled - * @param attr the attribute describing the style of the range to be styled - */ - protected void addRange(Collection presentation, int offset, int length, TextAttribute attr) { - - Point range = getHighlighter().getTextViewer().getSelectedRange(); - int caret = range.x; - int selection = range.y; - IDocument doc = getDocument(); - Color bg = attr.getBackground(); - // all editors use same background color -// // if current line highlight on, use line highlight color for background -// if(JavaColorProvider.EDITOR_CURRENT_LINE && selection == 1) { -// try { -// IRegion lineRegion = doc.getLineInformation(doc.getLineOfOffset(caret)); -// if(lineRegion.getOffset()<=offset && offset<=lineRegion.getOffset()+lineRegion.getLength()) -// bg = EditorUtility.getColor(JavaColorProvider.EDITOR_CURRENT_LINE_COLOR); -// -// } catch (BadLocationException e) { -// Logger.logException(e); -// } -// } - - presentation.add(new StyleRange(offset, length, attr.getForeground(), bg, attr.getStyle())); - } - - protected void clearColors() { - getTextAttributes().clear(); - } - - /** - * Returns a text attribute encoded in the given token. If the token's - * data is not <code>null</code> and a text attribute it is assumed that - * it is the encoded text attribute. It returns the default text attribute - * if there is no encoded text attribute found. - * - * @param token the token whose text attribute is to be determined - * @return the token's text attribute - */ - protected TextAttribute getTokenTextAttribute(IToken token) { - Object data = token.getData(); - if (data instanceof TextAttribute) - return (TextAttribute) data; - return fDefaultTextAttribute; - } - - protected void loadColors() { - clearColors(); - - addTextAttribute(IStyleConstantsHTML.SCRIPT_AREA_BORDER); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_NAME); - addTextAttribute(IStyleConstantsXML.TAG_ATTRIBUTE_VALUE); - } - - protected void handlePropertyChange(PropertyChangeEvent event) { - String styleKey = null; - - if (event != null) { - String prefKey = event.getProperty(); - // check if preference changed is a style preference - if (IStyleConstantsHTML.SCRIPT_AREA_BORDER.equals(prefKey)) { - styleKey = IStyleConstantsHTML.SCRIPT_AREA_BORDER; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_NAME.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_NAME; - } - else if (IStyleConstantsXML.TAG_ATTRIBUTE_VALUE.equals(prefKey)) { - styleKey = IStyleConstantsXML.TAG_ATTRIBUTE_VALUE; - } - } - - if (styleKey != null) { - // overwrite style preference with new value - addTextAttribute(styleKey); - super.handlePropertyChange(event); - } - } - - public boolean prepareRegions(ITypedRegion typedRegion, int ssssrequestedStart, int ssssrequestedLength, Collection holdResults) { - boolean result = true; - try { - // ideally, eventually, we'll have a "virtualDocument" we can - // refer to, but for now ... we'll simple rescan the one region. - // use simple adjustment (since "sub-content" starts at 0 - int offsetAdjustment = typedRegion.getOffset(); - String content = super.getDocument().get(typedRegion.getOffset(), typedRegion.getLength()); - IDocument document = new Document(content); - this.setDocument(document); - - int lastStart = 0; - int length = 0; - IToken lastToken = Token.UNDEFINED; - - int remainingLength = typedRegion.getLength(); - fScanner.setRange(fDocument, lastStart, remainingLength); - - while (true) { - - IToken token = fScanner.nextToken(); - - if (token.isEOF()) { - if (!lastToken.isUndefined() && length != 0) - addRange(holdResults, lastStart + offsetAdjustment, length, getTokenTextAttribute(lastToken)); - break; - } - - if (token.isWhitespace()) { - length += fScanner.getTokenLength(); - continue; - } - - if (lastToken.isUndefined()) { - lastToken = token; - length += fScanner.getTokenLength(); - continue; - } - - if (token != lastToken) { - addRange(holdResults, lastStart + offsetAdjustment, length, getTokenTextAttribute(lastToken)); - lastToken = token; - lastStart = fScanner.getTokenOffset(); - length = fScanner.getTokenLength(); - continue; - } - - length += fScanner.getTokenLength(); - } - } - catch (BadLocationException e) { - // shouldn't happen, but we don't want it to stop other highlighting, if it does. - result = false; - } - return result; - } - - protected IPreferenceStore getColorPreferences() { - return JSPUIPlugin.getDefault().getPreferenceStore(); - } - - protected void setDocument(IDocument document) { - fDocument = document; - } - - public void setTargetNode(org.w3c.dom.Node newTargetNode) { - targetNode = newTargetNode; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPBestMatchHoverProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPBestMatchHoverProcessor.java deleted file mode 100644 index 7b95115864..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPBestMatchHoverProcessor.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.taginfo; - -import org.eclipse.jface.text.ITextHover; -import org.eclipse.wst.sse.ui.taginfo.AbstractBestMatchHoverProcessor; - -/** - * Provides the best jsp hover help documentation (by using other hover help processors) - * Priority of hover help processors is: - * AnnotationHoverProcessor, JSPTagInfoHoverProcessor - */ -public class JSPBestMatchHoverProcessor extends AbstractBestMatchHoverProcessor { - JSPTagInfoHoverProcessor fTagInfoHover; - - /* (non-Javadoc) - * @see com.ibm.sse.editor.structured.taginfo.AbstractBestMatchHoverProcessor#getTagInfoHover() - */ - protected ITextHover getTagInfoHover() { - if (fTagInfoHover == null) { - fTagInfoHover = new JSPTagInfoHoverProcessor(); - } - return fTagInfoHover; - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPInformationProvider.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPInformationProvider.java deleted file mode 100644 index 4fbb9e0a5a..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPInformationProvider.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.taginfo; - - - -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jface.text.information.IInformationProvider; -import org.eclipse.jface.text.information.IInformationProviderExtension; - -/** - * Provides context information for JSP tags (Shows tooltip description) - * - * @author amywu - */ -public class JSPInformationProvider implements IInformationProvider, IInformationProviderExtension { - - private JSPBestMatchHoverProcessor fTextHover = null; - - public JSPInformationProvider() { - fTextHover = new JSPBestMatchHoverProcessor(); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.text.information.IInformationProvider#getSubject(org.eclipse.jface.text.ITextViewer, int) - */ - public IRegion getSubject(ITextViewer textViewer, int offset) { - return fTextHover.getHoverRegion(textViewer, offset); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.text.information.IInformationProvider#getInformation(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) - */ - public String getInformation(ITextViewer textViewer, IRegion subject) { - return (String)getInformation2(textViewer, subject); - } - - /* (non-Javadoc) - * @see org.eclipse.jface.text.information.IInformationProviderExtension#getInformation2(org.eclipse.jface.text.ITextViewer, org.eclipse.jface.text.IRegion) - */ - public Object getInformation2(ITextViewer textViewer, IRegion subject) { - return fTextHover.getHoverInfo(textViewer, subject); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPJavaBestMatchHoverProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPJavaBestMatchHoverProcessor.java deleted file mode 100644 index 54ac2f81ca..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPJavaBestMatchHoverProcessor.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.taginfo; - -import org.eclipse.jface.text.ITextHover; -import org.eclipse.jst.jsp.ui.internal.taginfo.JSPJavaJavadocHoverProcessor; -import org.eclipse.ui.IEditorPart; -import org.eclipse.wst.sse.ui.taginfo.AbstractBestMatchHoverProcessor; - -/** - * Provides the best jsp java hover help documentation (by using other hover help processors) - * Priority of hover help processors is: - * AnnotationHoverProcessor, JSPJavaJavadocHover - */ -public class JSPJavaBestMatchHoverProcessor extends AbstractBestMatchHoverProcessor { - private JSPJavaJavadocHoverProcessor fTagInfoHover; - - protected ITextHover getTagInfoHover() { - if (fTagInfoHover == null) { - fTagInfoHover = new JSPJavaJavadocHoverProcessor(); - } - return fTagInfoHover; - } - - /** - * @deprecated This method should no longer be needed since it was only added - * for the now deprecated JSPJavaJavadocHover - * @param editor - */ - public void setEditor(IEditorPart editor) { -// // jspjavajavadoc hover requires an editor to be set -// ((JSPJavaJavadocHover) getTagInfoHover()).setEditor(editor); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPJavaJavadocHover.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPJavaJavadocHover.java deleted file mode 100644 index 76fe88fb2f..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPJavaJavadocHover.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.taginfo; - -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.internal.ui.text.java.hover.JavadocHover; -import org.eclipse.jface.text.IRegion; -import org.eclipse.jface.text.ITextViewer; -import org.eclipse.jst.jsp.core.internal.java.IJSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslation; -import org.eclipse.jst.jsp.core.internal.java.JSPTranslationAdapter; -import org.eclipse.wst.sse.core.StructuredModelManager; -import org.eclipse.wst.xml.core.document.XMLDocument; -import org.eclipse.wst.xml.core.document.XMLModel; - -/** - * Provides javadoc hover help documentation for java code inside JSPs - * @deprecated use JSPJavaJavadocHoverProcessor instead - */ -public class JSPJavaJavadocHover extends JavadocHover { - - public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { - // get JSP translation object for this viewer's document - XMLModel xmlModel = (XMLModel) StructuredModelManager.getModelManager().getExistingModelForRead(textViewer.getDocument()); - try { - if(xmlModel != null) { - XMLDocument xmlDoc = xmlModel.getDocument(); - JSPTranslationAdapter adapter = (JSPTranslationAdapter) xmlDoc.getAdapterFor(IJSPTranslation.class); - if (adapter != null) { - JSPTranslation translation = adapter.getJSPTranslation(); - IJavaElement[] result = translation.getElementsFromJspRange(hoverRegion.getOffset(), hoverRegion.getOffset() + hoverRegion.getLength()); - return getHoverInfo(result); - } - } - } - finally { - if(xmlModel != null) - xmlModel.releaseFromRead(); - } - return null; - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPTagInfoHoverProcessor.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPTagInfoHoverProcessor.java deleted file mode 100644 index 40a96a5696..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/taginfo/JSPTagInfoHoverProcessor.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.taginfo; - - - -import org.eclipse.wst.html.ui.taginfo.HTMLTagInfoHoverProcessor; -import org.eclipse.wst.sse.core.IndexedRegion; -import org.eclipse.wst.sse.core.text.IStructuredDocumentRegion; -import org.eclipse.wst.sse.core.text.ITextRegion; -import org.eclipse.wst.xml.core.document.XMLNode; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; - -/** - * Provides hover help documentation for JSP tags - */ -public class JSPTagInfoHoverProcessor extends HTMLTagInfoHoverProcessor { - - /* (non-Javadoc) - * @see com.ibm.sed.structured.taginfo.AbstractTextHoverProcessor#computeRegionHelp(com.ibm.sed.model.IndexedRegion, com.ibm.sed.model.xml.XMLNode, com.ibm.sed.structured.text.IStructuredDocumentRegion, com.ibm.sed.structured.text.ITextRegion) - */ - protected String computeRegionHelp(IndexedRegion treeNode, XMLNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) { - String result = null; - - if (region == null) - return null; - - String regionType = region.getType(); - if (regionType == XMLJSPRegionContexts.JSP_DIRECTIVE_NAME) { - result = computeJSPDirHelp((XMLNode) treeNode, parentNode, flatNode, region); - } - else - result = super.computeRegionHelp(treeNode, parentNode, flatNode, region); - - return result; - } - - /** - * Computes the hover help for the jsp directive name - * for now, treat jsp directives like any other tag name - */ - protected String computeJSPDirHelp(XMLNode xmlnode, XMLNode parentNode, IStructuredDocumentRegion flatNode, ITextRegion region) { - return computeTagNameHelp(xmlnode, parentNode, flatNode, region); - } - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSP.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSP.java deleted file mode 100644 index 971def77fb..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSP.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.templates; - -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeIds; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeXML; - -/** - * Base class for JSP template context types. Templates of this context - * type apply to any place within JSP content type. - */ -public class TemplateContextTypeJSP extends TemplateContextTypeXML { - public static final String JSP_PREFIX = "jsp_"; //$NON-NLS-1$ - - public TemplateContextTypeJSP() { - this(generateContextTypeId(TemplateContextTypeIds.ALL), JSPUIPlugin.getResourceString("%TemplateContextTypeJSP.0")); //$NON-NLS-1$ - } - - /** - * @param id - * @param name - */ - public TemplateContextTypeJSP(String id, String name) { - super(id, name); - } - - /* - * (non-Javadoc) - * @see com.ibm.sse.editor.xml.templates.TemplateContextTypeXML#generateContextTypeId(java.lang.String) - */ - public static String generateContextTypeId(String base_contextTypeId) { - return JSP_PREFIX+base_contextTypeId; - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSPAttribute.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSPAttribute.java deleted file mode 100644 index 65d6b878a5..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSPAttribute.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.templates; - -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeIds; - -/** - * Templates of this context type apply to any attributes within JSP content type. - */ -public class TemplateContextTypeJSPAttribute extends TemplateContextTypeJSP { - - public TemplateContextTypeJSPAttribute() { - super(generateContextTypeId(TemplateContextTypeIds.ATTRIBUTE), JSPUIPlugin.getResourceString("%TemplateContextTypeJSPAttribute.0")); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSPAttributeValue.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSPAttributeValue.java deleted file mode 100644 index f408d315ed..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSPAttributeValue.java +++ /dev/null @@ -1,25 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.templates; - -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeIds; - -/** - * Templates of this context type apply to any attribute values - * within JSP content type. - */ -public class TemplateContextTypeJSPAttributeValue extends TemplateContextTypeJSP { - - public TemplateContextTypeJSPAttributeValue() { - super(generateContextTypeId(TemplateContextTypeIds.ATTRIBUTEVALUE), JSPUIPlugin.getResourceString("%TemplateContextTypeJSPAttributeValue.0")); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSPTag.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSPTag.java deleted file mode 100644 index 36ecea8b2f..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/templates/TemplateContextTypeJSPTag.java +++ /dev/null @@ -1,24 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.templates; - -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.wst.xml.ui.templates.TemplateContextTypeIds; - -/** - * Templates of this context type apply to any tags within JSP content type. - */ -public class TemplateContextTypeJSPTag extends TemplateContextTypeJSP { - - public TemplateContextTypeJSPTag() { - super(generateContextTypeId(TemplateContextTypeIds.TAG), JSPUIPlugin.getResourceString("%TemplateContextTypeJSPTag.0")); //$NON-NLS-1$ - } -} diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/text/JSPDocumentRegionEdgeMatcher.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/text/JSPDocumentRegionEdgeMatcher.java deleted file mode 100644 index 5d4d384181..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/text/JSPDocumentRegionEdgeMatcher.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.text; - -import org.eclipse.jdt.internal.ui.text.JavaPairMatcher; -import org.eclipse.wst.sse.ui.text.DocumentRegionEdgeMatcher; -import org.eclipse.wst.xml.core.jsp.model.parser.temp.XMLJSPRegionContexts; -import org.eclipse.wst.xml.core.parser.XMLRegionContext; - -public class JSPDocumentRegionEdgeMatcher extends DocumentRegionEdgeMatcher { - - protected final static char[] BRACKETS = {'{', '}', '(', ')', '[', ']'}; - - /** - * @param validContexts - * @param nextMatcher - */ - public JSPDocumentRegionEdgeMatcher() { - super(new String[]{XMLRegionContext.XML_TAG_NAME, XMLRegionContext.XML_COMMENT_TEXT, XMLJSPRegionContexts.JSP_COMMENT_TEXT, XMLJSPRegionContexts.JSP_DIRECTIVE_NAME, XMLJSPRegionContexts.JSP_ROOT_TAG_NAME, XMLRegionContext.XML_CDATA_TEXT, XMLRegionContext.XML_PI_OPEN, XMLRegionContext.XML_PI_CONTENT}, new JavaPairMatcher(BRACKETS)); - } -}
\ No newline at end of file diff --git a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/views/contentoutline/JSPContentOutlineConfiguration.java b/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/views/contentoutline/JSPContentOutlineConfiguration.java deleted file mode 100644 index b9e79d5466..0000000000 --- a/bundles/org.eclipse.jst.jsp.ui/src/org/eclipse/jst/jsp/ui/views/contentoutline/JSPContentOutlineConfiguration.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are 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: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.jsp.ui.views.contentoutline; - -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jst.jsp.ui.internal.JSPUIPlugin; -import org.eclipse.wst.html.ui.views.contentoutline.HTMLContentOutlineConfiguration; - -//public class JSPContentOutlineConfiguration extends StructuredContentOutlineConfiguration { -public class JSPContentOutlineConfiguration extends HTMLContentOutlineConfiguration { - - // private static final String ATT_CLASS = "class"; //$NON-NLS-1$ - - // TODO: Automate the loading of a real configuration based on the model type at - // creation time; clear on unConfigure so that a new embedded configuration can - // be used - //private StructuredContentOutlineConfiguration fEmbeddedConfiguration = null; - - /** - * @param editor - */ - public JSPContentOutlineConfiguration() { - super(); - } - /* (non-Javadoc) - * @see org.eclipse.wst.sse.ui.views.contentoutline.StructuredContentOutlineConfiguration#getPreferenceStore() - */ - protected IPreferenceStore getPreferenceStore() { - return JSPUIPlugin.getDefault().getPreferenceStore(); - } -}
\ No newline at end of file |