-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for issue #544: add breakpoint with double-click in class file ruler
- Loading branch information
1 parent
ac1d902
commit 090c6b7
Showing
6 changed files
with
181 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...vy.eclipse.ui/src/org/codehaus/groovy/eclipse/adapters/ClassFileEditorAdapterFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Copyright 2009-2018 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.adapters; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.codehaus.groovy.ast.ClassNode; | ||
import org.codehaus.groovy.ast.ModuleNode; | ||
import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration; | ||
import org.eclipse.core.runtime.IAdapterFactory; | ||
import org.eclipse.jdt.core.ITypeRoot; | ||
import org.eclipse.jdt.core.dom.CompilationUnit; | ||
import org.eclipse.jdt.groovy.core.util.ReflectionUtils; | ||
import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; | ||
import org.eclipse.jdt.internal.ui.javaeditor.ClassFileEditor; | ||
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility; | ||
import org.eclipse.jdt.ui.SharedASTProvider; | ||
|
||
public class ClassFileEditorAdapterFactory implements IAdapterFactory { | ||
|
||
@Override | ||
public Class<?>[] getAdapterList() { | ||
return new Class[] {ClassNode.class, ClassNode[].class, ModuleNode.class}; | ||
} | ||
|
||
@Override @SuppressWarnings("unchecked") | ||
public <T> T getAdapter(Object adaptable, Class<T> adapterType) { | ||
T result = null; | ||
if (adaptable instanceof ClassFileEditor && Arrays.asList(getAdapterList()).contains(adapterType)) { | ||
ClassFileEditor editor = (ClassFileEditor) adaptable; | ||
// trigger discriminator in MultiplexingCommentRecorderParser | ||
ITypeRoot root = EditorUtility.getEditorInputJavaElement(editor, false); | ||
CompilationUnit unit = SharedASTProvider.getAST(root, SharedASTProvider.WAIT_YES, null); | ||
if (unit.getClass().getName().equals("org.codehaus.jdt.groovy.core.dom.GroovyCompilationUnit")) { | ||
// TODO: Is there a better way to get from GroovyCompilationUnit to GroovyCompilationUnitDeclaration? | ||
Object resolver = ReflectionUtils.executeNoArgPrivateMethod(org.eclipse.jdt.core.dom.AST.class, "getBindingResolver", unit.getAST()); | ||
CompilationUnitScope scope = (CompilationUnitScope) ReflectionUtils.executeNoArgPrivateMethod(resolver.getClass(), "scope", resolver); | ||
|
||
ModuleNode moduleNode = ((GroovyCompilationUnitDeclaration) scope.referenceContext).getModuleNode(); | ||
if (adapterType.equals(ModuleNode.class)) { | ||
result = (T) moduleNode; | ||
} else if (moduleNode != null) { | ||
List<ClassNode> classNodes = moduleNode.getClasses(); | ||
if (classNodes != null && !classNodes.isEmpty()) { | ||
if (adapterType.equals(ClassNode.class)) { | ||
result = (T) classNodes.get(0); | ||
} else if (adapterType.equals(ClassNode[].class)) { | ||
result = (T) classNodes.toArray(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 58 additions & 43 deletions
101
...ipse.ui/src/org/codehaus/groovy/eclipse/debug/ui/GroovyBreakpointRulerActionDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,89 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2000-2012 IBM Corporation, SpringSource 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 | ||
/* | ||
* Copyright 2009-2018 the original author or authors. | ||
* | ||
* Contributors: IBM Corporation - initial version | ||
* Andrew Eisenberg - convert for use with Groovy | ||
******************************************************************************/ | ||
* 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.debug.ui; | ||
|
||
import org.codehaus.jdt.groovy.model.GroovyNature; | ||
import org.eclipse.core.resources.IResource; | ||
import static org.codehaus.jdt.groovy.model.GroovyNature.hasGroovyNature; | ||
|
||
import org.codehaus.groovy.ast.ModuleNode; | ||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.runtime.Adapters; | ||
import org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate; | ||
import org.eclipse.jdt.core.IClassFile; | ||
import org.eclipse.jdt.groovy.core.util.ReflectionUtils; | ||
import org.eclipse.jface.action.IAction; | ||
import org.eclipse.jface.text.source.IVerticalRulerInfo; | ||
import org.eclipse.swt.widgets.Event; | ||
import org.eclipse.ui.IEditorInput; | ||
import org.eclipse.ui.IEditorPart; | ||
import org.eclipse.ui.IFileEditorInput; | ||
import org.eclipse.ui.texteditor.ITextEditor; | ||
|
||
public class GroovyBreakpointRulerActionDelegate extends RulerToggleBreakpointActionDelegate { | ||
|
||
private IEditorPart fEditorPart; | ||
private GroovyBreakpointRulerAction groovyDelegate; | ||
/** | ||
* @see IEditorActionDelegate#setActiveEditor(bIAction, IEditorPart) | ||
*/ | ||
@Override | ||
public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) { | ||
fEditorPart = targetEditor; | ||
super.setActiveEditor(callerAction, targetEditor); | ||
} | ||
private GroovyBreakpointRulerAction delegate; | ||
|
||
|
||
/** | ||
* @see AbstractRulerActionDelegate#createAction() | ||
*/ | ||
@Override | ||
protected IAction createAction(ITextEditor editor, | ||
IVerticalRulerInfo rulerInfo) { | ||
IResource resource; | ||
IEditorInput editorInput = editor.getEditorInput(); | ||
if (editorInput instanceof IFileEditorInput) { | ||
resource = ((IFileEditorInput) editorInput).getFile(); | ||
if (GroovyNature.hasGroovyNature(resource.getProject())) { | ||
groovyDelegate = new GroovyBreakpointRulerAction(rulerInfo, editor, | ||
fEditorPart); | ||
return groovyDelegate; | ||
} | ||
protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) { | ||
IProject project = getProject(editor.getEditorInput()); | ||
if (project != null && hasGroovyNature(project) && hasGroovySource(editor)) { | ||
delegate = new GroovyBreakpointRulerAction(rulerInfo, editor, getEditorPart()); | ||
return delegate; | ||
} | ||
// else: use jdt's action | ||
return super.createAction(editor, rulerInfo); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event) | ||
*/ | ||
@Override | ||
public void runWithEvent(IAction action, Event event) { | ||
if(groovyDelegate != null) { | ||
groovyDelegate.runWithEvent(event); | ||
if (delegate != null) { | ||
delegate.runWithEvent(event); | ||
} else { | ||
super.runWithEvent(action, event); | ||
} | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
groovyDelegate = null; | ||
if (delegate != null) { | ||
delegate.dispose(); | ||
delegate = null; | ||
} | ||
super.dispose(); | ||
} | ||
|
||
//-------------------------------------------------------------------------- | ||
|
||
protected IEditorPart getEditorPart() { | ||
return (IEditorPart) ReflectionUtils.getPrivateField(RulerToggleBreakpointActionDelegate.class, "fEditor", this); | ||
} | ||
|
||
protected IProject getProject(IEditorInput editorInput) { | ||
IFile file = Adapters.adapt(editorInput, IFile.class); | ||
if (file != null) { | ||
return file.getProject(); | ||
} | ||
|
||
IClassFile classFile = Adapters.adapt(editorInput, IClassFile.class); | ||
if (classFile != null) { | ||
return classFile.getJavaProject().getProject(); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected boolean hasGroovySource(ITextEditor editor) { | ||
return (Adapters.adapt(editor, ModuleNode.class) != null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters