Index: META-INF/MANIFEST.MF =================================================================== --- META-INF/MANIFEST.MF (revision 21993) +++ META-INF/MANIFEST.MF (working copy) @@ -18,6 +18,7 @@ org.codehaus.groovy.eclipse.editor, org.codehaus.groovy.eclipse.editor.actions, org.codehaus.groovy.eclipse.editor.highlighting, + org.codehaus.groovy.eclipse.editor.outline, org.codehaus.groovy.eclipse.launchers, org.codehaus.groovy.eclipse.preferences, org.codehaus.groovy.eclipse.refactoring.actions, Index: plugin.xml =================================================================== --- plugin.xml (revision 21993) +++ plugin.xml (working copy) @@ -17,6 +17,7 @@ + Index: schema/outlineExtension.exsd =================================================================== --- schema/outlineExtension.exsd (revision 0) +++ schema/outlineExtension.exsd (revision 21993) @@ -0,0 +1,101 @@ + + + + + + + + + Replace the Outline page in the Groovy editor with new one. Useful for plugging in your own DSL. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Associate a project nature with a specific Outline page for a Groovy editor. + + + + + + + The project nature that this extension applies to. + + + + + + + + + + Extender class. Must implement <tt>org.codehaus.groovy.eclipse.editor.outline.IOutlineExtender</tt> + + + + + + + + + + + + + + + 2.1.2 + + + + + + + + + Copyright (c) 2011 Codehaus.org, SpringSource, and others. +<br/> +Contributors:<br/> +Maxime Hamm - Initial API and implementation + + + + Index: src/org/codehaus/groovy/eclipse/editor/GroovyEditor.java =================================================================== --- src/org/codehaus/groovy/eclipse/editor/GroovyEditor.java (revision 21993) +++ src/org/codehaus/groovy/eclipse/editor/GroovyEditor.java (working copy) @@ -31,6 +31,8 @@ import org.codehaus.groovy.eclipse.editor.actions.GroovyTabAction; import org.codehaus.groovy.eclipse.editor.actions.IGroovyEditorActionDefinitionIds; import org.codehaus.groovy.eclipse.editor.highlighting.GroovySemanticReconciler; +import org.codehaus.groovy.eclipse.editor.outline.GroovyOutlinePage; +import org.codehaus.groovy.eclipse.editor.outline.OutlineExtenderRegistry; import org.codehaus.groovy.eclipse.refactoring.actions.FormatAllGroovyAction; import org.codehaus.groovy.eclipse.refactoring.actions.FormatGroovyAction; import org.codehaus.groovy.eclipse.refactoring.actions.FormatKind; @@ -64,6 +66,7 @@ import org.eclipse.jdt.internal.ui.actions.CleanUpAction; import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor; import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor; +import org.eclipse.jdt.internal.ui.javaeditor.JavaOutlinePage; import org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer; import org.eclipse.jdt.internal.ui.javaeditor.selectionactions.SelectionHistory; import org.eclipse.jdt.internal.ui.javaeditor.selectionactions.StructureSelectionAction; @@ -840,14 +843,6 @@ ReflectionUtils.setPrivateField(RefactorActionGroup.class, actionFieldName, group, newAction); } - /* - * Make accessible to source viewer - */ - @Override - protected ITypeRoot getInputJavaElement() { - return super.getInputJavaElement(); - } - private IFile getFile() { IEditorInput input = getEditorInput(); if (input instanceof FileEditorInput) { @@ -862,7 +857,7 @@ * or returns null if the input is not a {@link GroovyCompilationUnit}. */ public GroovyCompilationUnit getGroovyCompilationUnit() { - ITypeRoot root = getInputJavaElement(); + ITypeRoot root = super.getInputJavaElement(); if (root instanceof GroovyCompilationUnit) { return (GroovyCompilationUnit) root; } else { @@ -886,7 +881,7 @@ return this.getFile(); } if (GroovyCompilationUnit.class == required || ICompilationUnit.class == required || CompilationUnit.class == required) { - return this.getInputJavaElement(); + return super.getInputJavaElement(); } if (ModuleNode.class == required) { @@ -1288,4 +1283,43 @@ public VerifyKeyListener getGroovyBracketInserter() { return groovyBracketInserter; } + + /** + * outline management + */ + private GroovyOutlinePage page; + + @Override + protected ITypeRoot getInputJavaElement() { + return page != null ? page.getOutlineCompilationUnit() : super.getInputJavaElement(); + } + + @Override + protected void synchronizeOutlinePage(ISourceReference element, boolean checkIfOutlinePageActive) { + if (page != null) { + page.refresh(); + } + super.synchronizeOutlinePage(element, checkIfOutlinePageActive); + } + + @Override + protected ISourceReference computeHighlightRangeSourceReference() { + return page != null ? page.getChildrenAt(getCaretOffset()) : super.computeHighlightRangeSourceReference(); + } + + @Override + protected JavaOutlinePage createOutlinePage() { + OutlineExtenderRegistry outlineExtenderRegistry = GroovyPlugin.getDefault().getOutlineTools().getOutlineExtenderRegistry(); + + page = outlineExtenderRegistry.getGroovyOutlinePageForEditor(getGroovyCompilationUnit().getJavaProject().getProject(), + fOutlinerContextMenuId, this); + if (page != null) { + setOutlinePageInput(page, getEditorInput()); + return page; + } else { + return super.createOutlinePage(); + } + + } + } \ No newline at end of file Index: src/org/codehaus/groovy/eclipse/editor/GroovyOutlineTools.java =================================================================== --- src/org/codehaus/groovy/eclipse/editor/GroovyOutlineTools.java (revision 0) +++ src/org/codehaus/groovy/eclipse/editor/GroovyOutlineTools.java (revision 21993) @@ -0,0 +1,40 @@ + /* + * Copyright 2003-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.groovy.eclipse.editor; + +import org.codehaus.groovy.eclipse.editor.outline.OutlineExtenderRegistry; + +/** + * @author Maxime Hamm + * @created april 8, 2011 + * Tools to manager outline content + */ +public class GroovyOutlineTools { + + private OutlineExtenderRegistry outlineExtenderRegistry; + + public void dispose() { + outlineExtenderRegistry = null; + } + + public OutlineExtenderRegistry getOutlineExtenderRegistry() { + if (outlineExtenderRegistry == null) { + outlineExtenderRegistry = new OutlineExtenderRegistry(); + outlineExtenderRegistry.initialize(); + } + return outlineExtenderRegistry; + } +} Index: src/org/codehaus/groovy/eclipse/editor/outline/GroovyOutlinePage.java =================================================================== --- src/org/codehaus/groovy/eclipse/editor/outline/GroovyOutlinePage.java (revision 0) +++ src/org/codehaus/groovy/eclipse/editor/outline/GroovyOutlinePage.java (revision 0) @@ -0,0 +1,125 @@ +/* + * Copyright 2003-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.groovy.eclipse.editor.outline; + +import org.codehaus.groovy.eclipse.editor.GroovyEditor; +import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; +import org.eclipse.jdt.internal.ui.JavaPlugin; +import org.eclipse.jdt.internal.ui.JavaPluginImages; +import org.eclipse.jdt.internal.ui.javaeditor.JavaOutlinePage; +import org.eclipse.jdt.internal.ui.viewsupport.SourcePositionComparator; +import org.eclipse.jdt.ui.JavaElementComparator; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.PlatformUI; + +/** + * @author Maxime Hamm + * @created 7 avr. 2011 + */ +public class GroovyOutlinePage extends JavaOutlinePage { + + private OCompilationUnit outlineUnit = null; + + public GroovyOutlinePage(String contextMenuID, GroovyEditor editor, OCompilationUnit unit) { + super(contextMenuID, editor); + outlineUnit = unit; + } + + public void refresh() { + initializeViewer(); + + outlineUnit.refreshChildren(); + getOutlineViewer().refresh(); + } + + public OCompilationUnit getOutlineCompilationUnit() { + return outlineUnit; + } + + @Override + protected void contextMenuAboutToShow(IMenuManager menu) { + // none + } + + private boolean isInitialized = false; + private void initializeViewer() { + if (isInitialized) { + return; + } + // remove actions + IActionBars actionBars = getSite().getActionBars(); + IToolBarManager toolBarManager = actionBars.getToolBarManager(); + toolBarManager.removeAll(); + toolBarManager.add(new GroovyLexicalSortingAction()); + toolBarManager.update(true); + isInitialized = true; + } + + /** + * @param caretOffset + * @return + */ + public IOJavaElement getChildrenAt(int caretOffset) { + return getOutlineCompilationUnit().getChildrenAt(caretOffset); + } + + /**************************************************************** + * @author Maxime HAMM + * @created 7 avr. 2011 + */ + public class GroovyLexicalSortingAction extends Action { + + private JavaElementComparator fComparator = new JavaElementComparator(); + + private SourcePositionComparator fSourcePositonComparator = new SourcePositionComparator(); + + public GroovyLexicalSortingAction() { + super(); + PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJavaHelpContextIds.LEXICAL_SORTING_OUTLINE_ACTION); + setText("Link with Editor"); + JavaPluginImages.setLocalImageDescriptors(this, "alphab_sort_co.gif"); //$NON-NLS-1$ + + boolean checked = JavaPlugin.getDefault().getPreferenceStore().getBoolean("LexicalSortingAction.isChecked"); //$NON-NLS-1$ + valueChanged(checked, false); + } + + @Override + public void run() { + valueChanged(isChecked(), true); + } + + private void valueChanged(final boolean on, boolean store) { + setChecked(on); + BusyIndicator.showWhile(getOutlineViewer().getControl().getDisplay(), new Runnable() { + public void run() { + if (on) { + getOutlineViewer().setComparator(fComparator); + } else { + getOutlineViewer().setComparator(fSourcePositonComparator); + } + } + }); + + if (store) + JavaPlugin.getDefault().getPreferenceStore().setValue("LexicalSortingAction.isChecked", on); //$NON-NLS-1$ + } + } + +} Index: src/org/codehaus/groovy/eclipse/editor/outline/IOJavaElement.java =================================================================== --- src/org/codehaus/groovy/eclipse/editor/outline/IOJavaElement.java (revision 0) +++ src/org/codehaus/groovy/eclipse/editor/outline/IOJavaElement.java (revision 0) @@ -0,0 +1,37 @@ +/* + * Copyright 2003-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.groovy.eclipse.editor.outline; + +import org.codehaus.groovy.ast.ASTNode; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.ISourceReference; + +/** + * @author Maxime HAMM + * @created 7 avr. 2011 + */ +public interface IOJavaElement extends IJavaElement, ISourceReference { + + /** + * get groovy node + * + * @return + */ + public ASTNode getNode(); + + + +} Index: src/org/codehaus/groovy/eclipse/editor/outline/IOutlineExtender.java =================================================================== --- src/org/codehaus/groovy/eclipse/editor/outline/IOutlineExtender.java (revision 0) +++ src/org/codehaus/groovy/eclipse/editor/outline/IOutlineExtender.java (revision 0) @@ -0,0 +1,46 @@ + /* + * Copyright 2003-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.groovy.eclipse.editor.outline; + +import org.codehaus.groovy.eclipse.editor.GroovyEditor; +import org.codehaus.jdt.groovy.model.GroovyCompilationUnit; + +/** + * Extends the Groovy Editor to allow update the outline content. + * See the extension point + * org.codehaus.groovy.eclipse.ui.outlineExtension + * + * @author Maxime Hamm + * @created April 4, 2011 + */ +public interface IOutlineExtender { + + /** + * Return the outline page to use for the editor's unit + * + * @param contextMenuID + * @param editor + * @return the outline page + */ + GroovyOutlinePage getGroovyOutlinePageForEditor(String contextMenuID, GroovyEditor editor); + + /** + * @return true if this extender want's to setup the outline view + * for the unit file + */ + boolean appliesTo(GroovyCompilationUnit unit); + +} Index: src/org/codehaus/groovy/eclipse/editor/outline/OCompilationUnit.java =================================================================== --- src/org/codehaus/groovy/eclipse/editor/outline/OCompilationUnit.java (revision 0) +++ src/org/codehaus/groovy/eclipse/editor/outline/OCompilationUnit.java (revision 0) @@ -0,0 +1,103 @@ +/* + * Copyright 2003-2010 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.groovy.eclipse.editor.outline; + +import java.util.Map; + +import org.codehaus.groovy.ast.ASTNode; +import org.codehaus.jdt.groovy.model.GroovyCompilationUnit; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.internal.core.OpenableElementInfo; +import org.eclipse.jdt.internal.core.PackageFragment; + +/** + * + * @author maxime + * @created 1 avr. 2011 + */ +public abstract class OCompilationUnit extends GroovyCompilationUnit implements IOJavaElement { + + private GroovyCompilationUnit unit; + + private IOJavaElement[] children = null; + + public OCompilationUnit(GroovyCompilationUnit unit) { + super((PackageFragment) unit.getParent(), unit.getElementName(), unit.getOwner()); + this.unit = unit; + this.owner = unit.owner; + refresh(); + } + + /** + * refresh children list + * + * @return + */ + public abstract IOJavaElement[] refreshChildren(); + + /** + * get the mock method link to active carret offset + * + * @param caretOffset + * @return + */ + public abstract IOJavaElement getChildrenAt(int caretOffset); + + /** + * get groovy node linked to this elemen + */ + public ASTNode getNode() { + return unit.getModuleNode(); + } + + /** + * refresh children + */ + protected void refresh() { + this.children = refreshChildren(); + } + + /** + * get children + */ + @Override + public IJavaElement[] getChildren() { + return children; + } + + /** + * get groovy compilation unit + * + * @return + */ + public GroovyCompilationUnit getUnit() { + return unit; + } + + /** + * This method will probably never get called, but if it ever is by + * accident, it could cause some big problems with the mode. + */ + @SuppressWarnings("rawtypes") + @Override + protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) + throws JavaModelException { + return true; + } +} Index: src/org/codehaus/groovy/eclipse/editor/outline/OField.java =================================================================== --- src/org/codehaus/groovy/eclipse/editor/outline/OField.java (revision 0) +++ src/org/codehaus/groovy/eclipse/editor/outline/OField.java (revision 0) @@ -0,0 +1,101 @@ +/* + * Copyright 2003-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.groovy.eclipse.editor.outline; + +import org.codehaus.groovy.ast.ASTNode; +import org.codehaus.jdt.groovy.model.GroovyCompilationUnit; +import org.eclipse.jdt.internal.core.SourceField; +import org.eclipse.jdt.internal.core.SourceFieldElementInfo; + +/** + * @author maxime hamm + * @created 11 avr. 2011 + */ +public abstract class OField extends SourceField implements IOJavaElement { + + protected ASTNode node; + + public OField(OType parent, ASTNode node, String name) { + super(parent, name); + this.node = node; + } + + public ASTNode getNode() { + return node; + } + + /** + * The element name node. + * i.e the node that will be highlighted int the editor when you will select + * the field in the outline view + * + * @return + */ + public abstract ASTNode getElementNameNode(); + + /** + * @return The field type to display. + */ + @Override + public abstract String getTypeSignature(); + + + @Override + protected Object createElementInfo() { + return new OFieldInfo(); + } + + public GroovyCompilationUnit getUnit() { + if (getParent() instanceof OType) { + return ((OType) getParent()).getUnit(); + } else { + return (GroovyCompilationUnit) getParent(); + } + } + + /**************************************************************************** + * @author maxime hamm + * @created 11 avr. 2011 + */ + public class OFieldInfo extends SourceFieldElementInfo { + + @Override + public int getNameSourceStart() { + return getElementNameNode().getStart(); + } + + @Override + public int getNameSourceEnd() { + return getNameSourceStart() + getElementNameNode().getLength(); + } + + @Override + public int getDeclarationSourceStart() { + return node.getStart(); + } + + @Override + public int getDeclarationSourceEnd() { + return node.getEnd(); + } + + @Override + public String getTypeSignature() { + return OField.this.getTypeSignature(); + } + } + +} Index: src/org/codehaus/groovy/eclipse/editor/outline/OMethod.java =================================================================== --- src/org/codehaus/groovy/eclipse/editor/outline/OMethod.java (revision 0) +++ src/org/codehaus/groovy/eclipse/editor/outline/OMethod.java (revision 0) @@ -0,0 +1,106 @@ +/* + * Copyright 2003-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.groovy.eclipse.editor.outline; + +import org.codehaus.groovy.ast.ASTNode; +import org.codehaus.jdt.groovy.model.GroovyCompilationUnit; +import org.eclipse.jdt.internal.core.SourceMethod; +import org.eclipse.jdt.internal.core.SourceMethodInfo; + +/** + * @author maxime hamm + * @created 1 avr. 2011 + */ +public abstract class OMethod extends SourceMethod implements IOJavaElement { + + protected ASTNode node; + + /** + * @param parent the parent type + * @param node the node that matches the whole method source source (not + * only the method name or method signature but also the method + * body) + * @param name the method name + */ + public OMethod(OType parent, ASTNode node, String name) { + super(parent, name, null); + this.node = node; + } + + public ASTNode getNode() { + return node; + } + + /** + * The element name node. + * i.e the node that will be highlighted int the editor when you will select + * the method in the outline view + * + * @return + */ + public abstract ASTNode getElementNameNode(); + + /** + * @return The return type to display. + */ + public abstract String getReturnTypeName(); + + @Override + protected Object createElementInfo() { + return new OMethodInfo(); + } + + public GroovyCompilationUnit getUnit() { + if (getParent() instanceof OType) { + return ((OType) getParent()).getUnit(); + } else { + return (GroovyCompilationUnit) getParent(); + } + } + + /**************************************************************************** + * @author maxime hamm + * @created 3 avr. 2011 + */ + public class OMethodInfo extends SourceMethodInfo { + + @Override + public int getNameSourceStart() { + return getElementNameNode().getStart(); + } + + @Override + public int getNameSourceEnd() { + return getNameSourceStart() + getElementNameNode().getLength(); + } + + @Override + public int getDeclarationSourceStart() { + return node.getStart(); + } + + @Override + public int getDeclarationSourceEnd() { + return node.getEnd(); + } + + @Override + public char[] getReturnTypeName() { + return OMethod.this.getReturnTypeName().toCharArray(); + } + } + +} Index: src/org/codehaus/groovy/eclipse/editor/outline/OType.java =================================================================== --- src/org/codehaus/groovy/eclipse/editor/outline/OType.java (revision 0) +++ src/org/codehaus/groovy/eclipse/editor/outline/OType.java (revision 0) @@ -0,0 +1,143 @@ +/* + * Copyright 2003-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.groovy.eclipse.editor.outline; + +import java.util.LinkedList; + +import org.codehaus.groovy.ast.ASTNode; +import org.codehaus.groovy.eclipse.core.GroovyCore; +import org.codehaus.jdt.groovy.model.GroovyCompilationUnit; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.internal.core.JavaElement; +import org.eclipse.jdt.internal.core.SourceType; +import org.eclipse.jdt.internal.core.SourceTypeElementInfo; + +/** + * @author maxime + * @created 1 avr. 2011 + */ +public abstract class OType extends SourceType implements IOJavaElement { + + protected ASTNode node; + + private LinkedList children = new LinkedList(); + + /** + * @param parent the parent type + * @param node the node that matches the whole type source source (not + * only the type name but also the type body) + * @param name the type name + */ + public OType(IOJavaElement parent, ASTNode node, String name) { + super((JavaElement) parent, name); + this.node = node; + } + + /** + * The element name node + * i.e the node that will be highlighted int the editor when you will select + * the type in the outline view + */ + public abstract ASTNode getElementNameNode(); + + + @Override + protected Object createElementInfo() { + return new OTypeInfo(); + } + + public GroovyCompilationUnit getUnit() { + if (getParent() instanceof OType) { + return ((OType) getParent()).getUnit(); + } else { + return (GroovyCompilationUnit) getParent(); + } + } + + public ASTNode getNode() { + return node; + } + + @Override + public IJavaElement[] getChildren() throws JavaModelException { + return this.children.toArray(new IJavaElement[] {}); + } + public LinkedList getChildrenList() { + return children; + } + public void addChild(IOJavaElement child) { + children.addLast(child); + } + + /** + * get the mock method link to active carret offset + * + * @param caretOffset + * @return + */ + public IOJavaElement getChildrenAt(int caretOffset) { + try { + if (!hasChildren()) { + return this; + } + for (IJavaElement je : getChildren()) { + IOJavaElement m = (IOJavaElement) je; + ASTNode n = m.getNode(); + if (n.getStart() <= caretOffset && n.getEnd() >= caretOffset) { + if (m instanceof OType) { + return ((OType) je).getChildrenAt(caretOffset); + } else { + return m; + } + } + } + } catch (JavaModelException e) { + GroovyCore.logException(e.getMessage(), e); + } + return this; + } + + /**************************************************************************** + * @author maxime + * @created 3 avr. 2011 + */ + public class OTypeInfo extends SourceTypeElementInfo { + + @Override + public int getNameSourceStart() { + return getElementNameNode().getStart(); + } + + @Override + public int getNameSourceEnd() { + return getElementNameNode().getEnd(); + } + + @Override + public int getDeclarationSourceStart() { + return node.getStart(); + } + + @Override + public int getDeclarationSourceEnd() { + return node.getEnd(); + } + + } + + +} Index: src/org/codehaus/groovy/eclipse/editor/outline/OutlineExtenderRegistry.groovy =================================================================== --- src/org/codehaus/groovy/eclipse/editor/outline/OutlineExtenderRegistry.groovy (revision 0) +++ src/org/codehaus/groovy/eclipse/editor/outline/OutlineExtenderRegistry.groovy (revision 0) @@ -0,0 +1,75 @@ +/* + * Copyright 2003-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.codehaus.groovy.eclipse.editor.outline; + +import org.codehaus.groovy.eclipse.editor.GroovyEditor +import org.eclipse.core.resources.IProject +import org.eclipse.core.runtime.IExtensionPoint +import org.eclipse.core.runtime.IExtensionRegistry +import org.eclipse.core.runtime.Platform +import org.eclipse.ui.internal.WorkbenchPlugin + +/** + * Manages the OutlineExtenderRegistry + * This class is a singleton and is managed by {@link GroovyTextTools} + * @author Maxime Hamm + * @created April 4, 2011 + */ +public class OutlineExtenderRegistry { + + public static final String EXTENSION_POINT = 'org.codehaus.groovy.eclipse.ui.outlineExtension' + public static final String NATURE_ID = 'natureID' + public static final String EXTENDER = 'extender' + + def natureToExtenderMap + + def initialize() { + natureToExtenderMap = [:] + IExtensionRegistry registry = Platform.getExtensionRegistry() + IExtensionPoint extensionPoint = registry.getExtensionPoint(EXTENSION_POINT) + extensionPoint.extensions.each { + it.configurationElements.each { + def natureid = it.getAttribute(NATURE_ID) + Object object = WorkbenchPlugin.createExtension(it, EXTENDER) + if (object instanceof IOutlineExtender) { + natureToExtenderMap.put(natureid, object); + } + } + } + } + + IOutlineExtender getExtender(String natureID) { + natureToExtenderMap."${natureID}" + } + + GroovyOutlinePage getGroovyOutlinePageForEditor(IProject project, String contextMenuID, GroovyEditor editor) { + if (!project) { + return + } + def groovyOutlinePage + project.description.natureIds.each { + def extender = getExtender(it) + if (extender && extender.appliesTo(editor.getGroovyCompilationUnit())) { + def page = extender.getGroovyOutlinePageForEditor(contextMenuID, editor) + if (page != null) { + groovyOutlinePage = page + return + } + } + } + groovyOutlinePage + } +} Index: src/org/codehaus/groovy/eclipse/GroovyPlugin.java =================================================================== --- src/org/codehaus/groovy/eclipse/GroovyPlugin.java (revision 21993) +++ src/org/codehaus/groovy/eclipse/GroovyPlugin.java (working copy) @@ -19,6 +19,7 @@ import org.codehaus.groovy.eclipse.debug.ui.EnsureJUnitFont; import org.codehaus.groovy.eclipse.debug.ui.GroovyDebugOptionsEnforcer; import org.codehaus.groovy.eclipse.debug.ui.GroovyJavaDebugElementAdapterFactory; +import org.codehaus.groovy.eclipse.editor.GroovyOutlineTools; import org.codehaus.groovy.eclipse.editor.GroovyTextTools; import org.codehaus.groovy.eclipse.preferences.AskToConvertLegacyProjects; import org.codehaus.groovy.eclipse.refactoring.actions.DelegatingCleanUpPostSaveListener; @@ -77,6 +78,8 @@ private GroovyTextTools textTools; + private GroovyOutlineTools outlineTools; + public static final String PLUGIN_ID = "org.codehaus.groovy.eclipse.ui"; public static final String GROOVY_TEMPLATE_CTX = "org.codehaus.groovy.eclipse.templates"; @@ -180,6 +183,7 @@ public void start(BundleContext context) throws Exception { super.start(context); textTools = new GroovyTextTools(); + outlineTools = new GroovyOutlineTools(); addMonospaceFontListener(); DelegatingCleanUpPostSaveListener.installCleanUp(); @@ -241,6 +245,8 @@ super.stop(context); textTools.dispose(); textTools = null; + outlineTools.dispose(); + outlineTools = null; DelegatingCleanUpPostSaveListener.uninstallCleanUp(); removeMonospaceFontListener(); @@ -254,4 +260,8 @@ public GroovyTextTools getTextTools() { return textTools; } + + public GroovyOutlineTools getOutlineTools() { + return outlineTools; + } } \ No newline at end of file