Skip to content
This repository
Browse code

Code select support for binary groovy files.

no tests.
  • Loading branch information...
commit 1d101e7f36e88db56d8fab9169027d18636950b1 1 parent 04a49fd
Andrew Eisenberg authored April 05, 2013
13  .../org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/integration/internal/GroovyLanguageSupport.java
@@ -27,6 +27,7 @@
27 27
 import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyErrorCollectorForJDT;
28 28
 import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyTypeDeclaration;
29 29
 import org.codehaus.jdt.groovy.internal.compiler.ast.JDTResolver;
  30
+import org.codehaus.jdt.groovy.model.GroovyClassFileWorkingCopy;
30 31
 import org.codehaus.jdt.groovy.model.GroovyCompilationUnit;
31 32
 import org.codehaus.jdt.groovy.model.GroovyNature;
32 33
 import org.eclipse.core.resources.IProject;
@@ -51,6 +52,7 @@
51 52
 import org.eclipse.jdt.internal.compiler.SourceElementParser;
52 53
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
53 54
 import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
  55
+import org.eclipse.jdt.internal.compiler.env.IBinaryType;
54 56
 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
55 57
 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
56 58
 import org.eclipse.jdt.internal.compiler.parser.Parser;
@@ -256,4 +258,15 @@ public IJavaSearchScope expandSearchScope(IJavaSearchScope scope, SearchPattern
256 258
 		}
257 259
 		return scope;
258 260
 	}
  261
+
  262
+	public boolean isInterestingBinary(BinaryType type, IBinaryType typeInfo) {
  263
+		return isInterestingProject(type.getJavaProject().getProject())
  264
+				&& ContentTypeUtils.isGroovyLikeFileName(type.sourceFileName(typeInfo));
  265
+	}
  266
+
  267
+	public IJavaElement[] binaryCodeSelect(ClassFile classFile, int offset, int length, WorkingCopyOwner owner)
  268
+			throws JavaModelException {
  269
+		GroovyCompilationUnit binaryUnit = new GroovyClassFileWorkingCopy(classFile, owner);
  270
+		return binaryUnit.codeSelect(offset, length, owner);
  271
+	}
259 272
 }
40  base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/model/GroovyClassFile.java
... ...
@@ -1,40 +0,0 @@
1  
-/*******************************************************************************
2  
- * Copyright (c) 2010 Codehaus.org, SpringSource, and others.
3  
- * All rights reserved. This program and the accompanying materials
4  
- * are made available under the terms of the Eclipse Public License v1.0
5  
- * which accompanies this distribution, and is available at
6  
- * http://www.eclipse.org/legal/epl-v10.html
7  
- *
8  
- * Contributors:
9  
- *     Andrew Eisenberg - Additional work
10  
- *******************************************************************************/
11  
-package org.codehaus.jdt.groovy.model;
12  
-
13  
-import org.eclipse.jdt.core.IJavaElement;
14  
-import org.eclipse.jdt.core.JavaModelException;
15  
-import org.eclipse.jdt.core.WorkingCopyOwner;
16  
-import org.eclipse.jdt.internal.core.ClassFile;
17  
-import org.eclipse.jdt.internal.core.PackageFragment;
18  
-
19  
-/**
20  
- * Don't think I need thisce
21  
- * 
22  
- * @author Andrew Eisenberg
23  
- * @created Oct 22, 2010
24  
- */
25  
-public class GroovyClassFile extends ClassFile {
26  
-
27  
-	protected GroovyClassFile(PackageFragment parent, String nameWithoutExtension) {
28  
-		super(parent, nameWithoutExtension);
29  
-	}
30  
-
31  
-	@Override
32  
-	protected IJavaElement[] codeSelect(org.eclipse.jdt.internal.compiler.env.ICompilationUnit cu, int offset, int length,
33  
-			WorkingCopyOwner o) throws JavaModelException {
34  
-
35  
-		if (CodeSelectHelperFactory.selectHelper != null) {
36  
-			// return CodeSelectHelperFactory.selectHelper.select(this, offset, length);
37  
-		}
38  
-		return new IJavaElement[0];
39  
-	}
40  
-}
246  base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/model/GroovyClassFileWorkingCopy.java
... ...
@@ -0,0 +1,246 @@
  1
+/*******************************************************************************
  2
+ * Copyright (c) 2012 VMWare, Inc.
  3
+ * All rights reserved. This program and the accompanying materials
  4
+ * are made available under the terms of the Eclipse Public License v1.0
  5
+ * which accompanies this distribution, and is available at
  6
+ * http://www.eclipse.org/legal/epl-v10.html
  7
+ *
  8
+ * Contributors:
  9
+ *     VMWare, Inc. - initial API and implementation
  10
+ *******************************************************************************/
  11
+package org.codehaus.jdt.groovy.model;
  12
+
  13
+import org.codehaus.groovy.ast.ModuleNode;
  14
+import org.codehaus.jdt.groovy.internal.compiler.ast.GroovyCompilationUnitDeclaration;
  15
+import org.codehaus.jdt.groovy.internal.compiler.ast.JDTResolver;
  16
+import org.codehaus.jdt.groovy.model.GroovyCompilationUnit;
  17
+import org.codehaus.jdt.groovy.model.ModuleNodeMapper.ModuleNodeInfo;
  18
+import org.eclipse.core.resources.IResource;
  19
+import org.eclipse.core.runtime.IPath;
  20
+import org.eclipse.core.runtime.IProgressMonitor;
  21
+import org.eclipse.core.runtime.NullProgressMonitor;
  22
+import org.eclipse.jdt.core.IBuffer;
  23
+import org.eclipse.jdt.core.IJavaElement;
  24
+import org.eclipse.jdt.core.IJavaModelStatusConstants;
  25
+import org.eclipse.jdt.core.JavaModelException;
  26
+import org.eclipse.jdt.core.ToolFactory;
  27
+import org.eclipse.jdt.core.WorkingCopyOwner;
  28
+import org.eclipse.jdt.core.compiler.CharOperation;
  29
+import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
  30
+import org.eclipse.jdt.core.util.IClassFileReader;
  31
+import org.eclipse.jdt.groovy.core.Activator;
  32
+import org.eclipse.jdt.groovy.core.util.ReflectionUtils;
  33
+import org.eclipse.jdt.internal.core.BinaryType;
  34
+import org.eclipse.jdt.internal.core.BufferManager;
  35
+import org.eclipse.jdt.internal.core.ClassFile;
  36
+import org.eclipse.jdt.internal.core.ClassFileWorkingCopy;
  37
+import org.eclipse.jdt.internal.core.CompilationUnitElementInfo;
  38
+import org.eclipse.jdt.internal.core.DefaultWorkingCopyOwner;
  39
+import org.eclipse.jdt.internal.core.JavaModelManager.PerWorkingCopyInfo;
  40
+import org.eclipse.jdt.internal.core.JavaModelStatus;
  41
+import org.eclipse.jdt.internal.core.Openable;
  42
+import org.eclipse.jdt.internal.core.PackageFragment;
  43
+import org.eclipse.jdt.internal.core.PackageFragmentRoot;
  44
+import org.eclipse.jdt.internal.core.util.Disassembler;
  45
+import org.eclipse.jdt.internal.core.util.Util;
  46
+
  47
+/**
  48
+ * Working copy for groovy class files. Allows access to the ModuleNode for class files if the source is available. Copied from
  49
+ * {@link ClassFileWorkingCopy} Groovy changes marked
  50
+ * 
  51
+ * @author Andrew Eisenberg
  52
+ * @author Christian Dupuis
  53
+ * @created Dec 11, 2009
  54
+ */
  55
+public class GroovyClassFileWorkingCopy extends GroovyCompilationUnit {
  56
+
  57
+	public ClassFile classFile;
  58
+
  59
+	// GROOVY Change
  60
+	private final PerWorkingCopyInfo info;
  61
+	private CompilationUnitElementInfo elementInfo;
  62
+	private ModuleNode moduleNode;
  63
+	private ModuleNodeInfo moduleNodeInfo;
  64
+
  65
+	// GROOVY End
  66
+
  67
+	public GroovyClassFileWorkingCopy(ClassFile classFile, WorkingCopyOwner owner) {
  68
+		super((PackageFragment) classFile.getParent(), ((BinaryType) classFile.getType())
  69
+				.getSourceFileName(null/* no info available */), owner);
  70
+		this.classFile = classFile;
  71
+		// GROOVY Change
  72
+		info = new PerWorkingCopyInfo(this, null);
  73
+		// GROOVY End
  74
+	}
  75
+
  76
+	public void commitWorkingCopy(boolean force, IProgressMonitor monitor) throws JavaModelException {
  77
+		throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INVALID_ELEMENT_TYPES, this));
  78
+	}
  79
+
  80
+	public IBuffer getBuffer() throws JavaModelException {
  81
+		// GROOVY Always use the classFile's buffer
  82
+		// old
  83
+		// if (isWorkingCopy())
  84
+		// return super.getBuffer();
  85
+		// else
  86
+		// GROOVY end
  87
+		return this.classFile.getBuffer();
  88
+	}
  89
+
  90
+	public char[] getContents() {
  91
+		try {
  92
+			IBuffer buffer = getBuffer();
  93
+			if (buffer == null)
  94
+				return CharOperation.NO_CHAR;
  95
+			char[] characters = buffer.getCharacters();
  96
+			if (characters == null)
  97
+				return CharOperation.NO_CHAR;
  98
+			return characters;
  99
+		} catch (JavaModelException e) {
  100
+			return CharOperation.NO_CHAR;
  101
+		}
  102
+	}
  103
+
  104
+	public IPath getPath() {
  105
+		return this.classFile.getPath();
  106
+	}
  107
+
  108
+	public IJavaElement getPrimaryElement(boolean checkOwner) {
  109
+		if (checkOwner && isPrimary())
  110
+			return this;
  111
+		return new ClassFileWorkingCopy(this.classFile, DefaultWorkingCopyOwner.PRIMARY);
  112
+	}
  113
+
  114
+	public IResource resource(PackageFragmentRoot root) {
  115
+		if (root.isArchive())
  116
+			return root.resource(root);
  117
+		return this.classFile.resource(root);
  118
+	}
  119
+
  120
+	/**
  121
+	 * @see Openable#openBuffer(IProgressMonitor, Object)
  122
+	 */
  123
+	protected IBuffer openBuffer(IProgressMonitor pm, Object info) throws JavaModelException {
  124
+
  125
+		// create buffer
  126
+		IBuffer buffer = this.owner.createBuffer(this);
  127
+		if (buffer == null)
  128
+			return null;
  129
+
  130
+		// set the buffer source
  131
+		if (buffer.getCharacters() == null) {
  132
+			IBuffer classFileBuffer = this.classFile.getBuffer();
  133
+			if (classFileBuffer != null) {
  134
+				buffer.setContents(classFileBuffer.getCharacters());
  135
+			} else {
  136
+				// Disassemble
  137
+				IClassFileReader reader = ToolFactory.createDefaultClassFileReader(this.classFile, IClassFileReader.ALL);
  138
+				Disassembler disassembler = new Disassembler();
  139
+				String contents = disassembler.disassemble(reader,
  140
+						Util.getLineSeparator("", getJavaProject()), ClassFileBytesDisassembler.WORKING_COPY); //$NON-NLS-1$
  141
+				buffer.setContents(contents);
  142
+			}
  143
+		}
  144
+
  145
+		// add buffer to buffer cache
  146
+		BufferManager bufManager = getBufferManager();
  147
+
  148
+		// GROOVY Change access to private member
  149
+		// old
  150
+		// bufManager.addBuffer(buffer);
  151
+		// new
  152
+		if (buffer.getContents() != null) {
  153
+			ReflectionUtils.executePrivateMethod(BufferManager.class,
  154
+					"addBuffer", new Class<?>[] { IBuffer.class }, bufManager, new Object[] { buffer }); //$NON-NLS-1$
  155
+		}
  156
+		// GROOVY End
  157
+
  158
+		// listen to buffer changes
  159
+		buffer.addBufferChangedListener(this);
  160
+
  161
+		return buffer;
  162
+	}
  163
+
  164
+	protected void toStringName(StringBuffer buffer) {
  165
+		buffer.append(this.classFile.getElementName());
  166
+	}
  167
+
  168
+	// GROOVY Change
  169
+	// all be a working copy
  170
+	// build structure only needs to happen once.
  171
+	@Override
  172
+	public PerWorkingCopyInfo getPerWorkingCopyInfo() {
  173
+		if (elementInfo == null) {
  174
+			try {
  175
+				elementInfo = (CompilationUnitElementInfo) createElementInfo();
  176
+				// FIXADE in E4.2, this method takes 3 args
  177
+				// when no longer supporting E3.7, then remove this
  178
+				// and uncomment the line below
  179
+				openWhenClosed(elementInfo, new NullProgressMonitor());
  180
+				// openWhenClosed(elementInfo, true, new NullProgressMonitor());
  181
+			} catch (JavaModelException e) {
  182
+				elementInfo = null;
  183
+				Activator.getDefault().getLog().log(e.getJavaModelStatus());
  184
+			}
  185
+		}
  186
+		return info;
  187
+	}
  188
+
  189
+	/**
  190
+	 * Cache module node locally and not in the mapper
  191
+	 */
  192
+	@Override
  193
+	protected void maybeCacheModuleNode(PerWorkingCopyInfo perWorkingCopyInfo,
  194
+			GroovyCompilationUnitDeclaration compilationUnitDeclaration) {
  195
+		if (compilationUnitDeclaration != null) {
  196
+			moduleNode = compilationUnitDeclaration.getModuleNode();
  197
+			moduleNode.setDescription(this.name);
  198
+			JDTResolver resolver;
  199
+			if (ModuleNodeMapper.shouldStoreResovler()) {
  200
+				resolver = (JDTResolver) compilationUnitDeclaration.getCompilationUnit().getResolveVisitor();
  201
+			} else {
  202
+				resolver = null;
  203
+			}
  204
+
  205
+			moduleNodeInfo = new ModuleNodeInfo(moduleNode, resolver);
  206
+		}
  207
+	}
  208
+
  209
+	@Override
  210
+	public ModuleNodeInfo getModuleInfo(boolean force) {
  211
+		return moduleNodeInfo;
  212
+	}
  213
+
  214
+	@Override
  215
+	public ModuleNodeInfo getNewModuleInfo() {
  216
+		return moduleNodeInfo;
  217
+	}
  218
+
  219
+	/**
  220
+	 * ModuleNode is not cached in the Mapper, but rather cached locally
  221
+	 */
  222
+	@Override
  223
+	public ModuleNode getModuleNode() {
  224
+		// ensure moduleNode is initialized
  225
+		getPerWorkingCopyInfo();
  226
+		return moduleNode;
  227
+	}
  228
+
  229
+	@Override
  230
+	public IResource resource() {
  231
+		return getJavaProject().getResource();
  232
+	}
  233
+
  234
+	@Override
  235
+	public char[] getFileName() {
  236
+		return name.toCharArray(); 
  237
+	}
  238
+
  239
+	@Override
  240
+	public boolean isOnBuildPath() {
  241
+		// a call to super.isOnBuildPath() will always return false,
  242
+		// but it should be true
  243
+		return true;
  244
+	}
  245
+	// GROOVY End
  246
+}
4  base/org.eclipse.jdt.groovy.core/src/org/codehaus/jdt/groovy/model/ModuleNodeMapper.java
@@ -40,7 +40,7 @@
40 40
  */
41 41
 public class ModuleNodeMapper {
42 42
 
43  
-	public class ModuleNodeInfo {
  43
+	public static class ModuleNodeInfo {
44 44
 		public ModuleNodeInfo(ModuleNode module, JDTResolver resolver) {
45 45
 			this.module = module;
46 46
 			this.resolver = resolver;
@@ -81,7 +81,7 @@ void store(PerWorkingCopyInfo info, ModuleNode module, JDTResolver resolver) {
81 81
 		DSL_BUNDLE_INSTALLED = result;
82 82
 	}
83 83
 
84  
-	private boolean shouldStoreResovler() {
  84
+	public static boolean shouldStoreResovler() {
85 85
 		return DSL_BUNDLE_INSTALLED;
86 86
 	}
87 87
 
12  jdt-patch/e42/org.eclipse.jdt.core/groovy/org/codehaus/jdt/groovy/integration/DefaultLanguageSupport.java
@@ -12,6 +12,8 @@
12 12
 package org.codehaus.jdt.groovy.integration;
13 13
 
14 14
 import org.eclipse.core.resources.IProject;
  15
+import org.eclipse.jdt.core.IJavaElement;
  16
+import org.eclipse.jdt.core.JavaModelException;
15 17
 import org.eclipse.jdt.core.WorkingCopyOwner;
16 18
 import org.eclipse.jdt.core.search.IJavaSearchScope;
17 19
 import org.eclipse.jdt.core.search.SearchPattern;
@@ -21,11 +23,13 @@
21 23
 import org.eclipse.jdt.internal.compiler.ISourceElementRequestor;
22 24
 import org.eclipse.jdt.internal.compiler.SourceElementParser;
23 25
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
  26
+import org.eclipse.jdt.internal.compiler.env.IBinaryType;
24 27
 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
25 28
 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
26 29
 import org.eclipse.jdt.internal.compiler.parser.Parser;
27 30
 import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
28 31
 import org.eclipse.jdt.internal.core.BinaryType;
  32
+import org.eclipse.jdt.internal.core.ClassFile;
29 33
 import org.eclipse.jdt.internal.core.CompilationUnit;
30 34
 import org.eclipse.jdt.internal.core.JavaProject;
31 35
 import org.eclipse.jdt.internal.core.PackageFragment;
@@ -123,4 +127,12 @@ public IJavaSearchScope expandSearchScope(IJavaSearchScope scope, SearchPattern
123 127
 	    // never expand
124 128
 		return scope;
125 129
 	}
  130
+
  131
+	public boolean isInterestingBinary(BinaryType type, IBinaryType typeInfo) {
  132
+		return false;
  133
+	}
  134
+
  135
+	public IJavaElement[] binaryCodeSelect(ClassFile classFile, int offset, int length, WorkingCopyOwner owner) throws JavaModelException {
  136
+		return new IJavaElement[0];
  137
+	}
126 138
 }
22  jdt-patch/e42/org.eclipse.jdt.core/groovy/org/codehaus/jdt/groovy/integration/LanguageSupport.java
@@ -12,6 +12,9 @@
12 12
 package org.codehaus.jdt.groovy.integration;
13 13
 
14 14
 import org.eclipse.core.resources.IProject;
  15
+import org.eclipse.jdt.core.IClassFile;
  16
+import org.eclipse.jdt.core.IJavaElement;
  17
+import org.eclipse.jdt.core.JavaModelException;
15 18
 import org.eclipse.jdt.core.WorkingCopyOwner;
16 19
 import org.eclipse.jdt.core.search.IJavaSearchScope;
17 20
 import org.eclipse.jdt.core.search.SearchPattern;
@@ -21,11 +24,13 @@
21 24
 import org.eclipse.jdt.internal.compiler.ISourceElementRequestor;
22 25
 import org.eclipse.jdt.internal.compiler.SourceElementParser;
23 26
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
  27
+import org.eclipse.jdt.internal.compiler.env.IBinaryType;
24 28
 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
25 29
 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
26 30
 import org.eclipse.jdt.internal.compiler.parser.Parser;
27 31
 import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
28 32
 import org.eclipse.jdt.internal.core.BinaryType;
  33
+import org.eclipse.jdt.internal.core.ClassFile;
29 34
 import org.eclipse.jdt.internal.core.CompilationUnit;
30 35
 import org.eclipse.jdt.internal.core.PackageFragment;
31 36
 import org.eclipse.jdt.internal.core.search.indexing.IndexingParser;
@@ -114,5 +119,22 @@ SourceElementParser getSourceElementParser(ISourceElementRequestor requestor, IP
114 119
 	 * @return an expanded scope if required, or the initial scope if there is no change
115 120
 	 */
116 121
 	IJavaSearchScope expandSearchScope(IJavaSearchScope scope, SearchPattern pattern, SearchRequestor requestor);
  122
+
  123
+	/**
  124
+	 * @param type a binary type that may or may not come from Groovy
  125
+	 * @param typeInfo type info for the given type
  126
+	 * @return true iff the binary type was compiled from groovy sources
  127
+	 */
  128
+	boolean isInterestingBinary(BinaryType type, IBinaryType typeInfo);
  129
+
  130
+	/**
  131
+	 * Performs code select on the given {@link IClassFile}
  132
+	 * @param classFile the class file to use, must be a classFile known to be of groovy origin
  133
+	 * @param offset the start of the selection
  134
+	 * @param length the length of the selection
  135
+	 * @param owner the {@link WorkingCopyOwner} for this operation
  136
+	 * @return {@link IJavaElement}s corresponding to the given selection.
  137
+	 */
  138
+	IJavaElement[] binaryCodeSelect(ClassFile classFile, int offset, int length, WorkingCopyOwner owner) throws JavaModelException;
117 139
 
118 140
 }
25  jdt-patch/e42/org.eclipse.jdt.core/groovy/org/codehaus/jdt/groovy/integration/LanguageSupportFactory.java
@@ -13,7 +13,9 @@
13 13
 
14 14
 import org.eclipse.core.resources.IProject;
15 15
 import org.eclipse.core.runtime.Platform;
  16
+import org.eclipse.jdt.core.IJavaElement;
16 17
 import org.eclipse.jdt.core.JavaCore;
  18
+import org.eclipse.jdt.core.JavaModelException;
17 19
 import org.eclipse.jdt.core.WorkingCopyOwner;
18 20
 import org.eclipse.jdt.core.search.IJavaSearchScope;
19 21
 import org.eclipse.jdt.core.search.SearchPattern;
@@ -23,11 +25,13 @@
23 25
 import org.eclipse.jdt.internal.compiler.ISourceElementRequestor;
24 26
 import org.eclipse.jdt.internal.compiler.SourceElementParser;
25 27
 import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
  28
+import org.eclipse.jdt.internal.compiler.env.IBinaryType;
26 29
 import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
27 30
 import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
28 31
 import org.eclipse.jdt.internal.compiler.parser.Parser;
29 32
 import org.eclipse.jdt.internal.compiler.problem.ProblemReporter;
30 33
 import org.eclipse.jdt.internal.core.BinaryType;
  34
+import org.eclipse.jdt.internal.core.ClassFile;
31 35
 import org.eclipse.jdt.internal.core.CompilationUnit;
32 36
 import org.eclipse.jdt.internal.core.PackageFragment;
33 37
 import org.eclipse.jdt.internal.core.search.indexing.IndexingParser;
@@ -174,4 +178,25 @@ public static IJavaSearchScope expandSearchScope(IJavaSearchScope scope, SearchP
174 178
 	public static boolean isGroovyLanguageSupportInstalled() {
175 179
 		return getLanguageSupport().getClass().getName().endsWith("GroovyLanguageSupport"); //$NON-NLS-1$
176 180
 	}
  181
+
  182
+	/**
  183
+	 * @param type a binary type that may or may not come from Groovy
  184
+	 * @return true iff the binary type was compiled from groovy sources
  185
+	 */
  186
+	public static boolean isInterestingBinary(BinaryType type, IBinaryType typeInfo) {
  187
+		return getLanguageSupport().isInterestingBinary(type, typeInfo);
  188
+	}
  189
+
  190
+	/**
  191
+	 * Performs code select on the given {@link ClassFile}
  192
+	 * @param classFile the class file to use, must be a classFile known to be of groovy origin
  193
+	 * @param offset the start of the selection
  194
+	 * @param length the length of the selection
  195
+	 * @param owner the {@link WorkingCopyOwner} for this operation
  196
+	 * @return {@link IJavaElement}s corresponding to the given selection.
  197
+	 * @throws JavaModelException 
  198
+	 */
  199
+	public static IJavaElement[] binaryCodeSelect(ClassFile classFile, int offset, int length, WorkingCopyOwner owner) throws JavaModelException {
  200
+		return getLanguageSupport().binaryCodeSelect(classFile, offset, length, owner);
  201
+	}
177 202
 }
14  jdt-patch/e42/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/ClassFile.java
@@ -16,6 +16,7 @@
16 16
 import java.util.zip.ZipEntry;
17 17
 import java.util.zip.ZipFile;
18 18
 
  19
+import org.codehaus.jdt.groovy.integration.LanguageSupportFactory;
19 20
 import org.eclipse.core.resources.IContainer;
20 21
 import org.eclipse.core.resources.IFile;
21 22
 import org.eclipse.core.resources.IFolder;
@@ -164,8 +165,19 @@ public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyO
164 165
 	IBuffer buffer = getBuffer();
165 166
 	char[] contents;
166 167
 	if (buffer != null && (contents = buffer.getCharacters()) != null) {
167  
-	    BinaryType type = (BinaryType) getType();
  168
+		BinaryType type = (BinaryType) getType();
  169
+		// GROOVY start
  170
+		/*old{
168 171
 		BasicCompilationUnit cu = new BasicCompilationUnit(contents, null, type.sourceFileName((IBinaryType) type.getElementInfo()));
  172
+		}new*/
  173
+		
  174
+		// handle code select for Groovy files differently
  175
+	    IBinaryType typeInfo = (IBinaryType) type.getElementInfo();
  176
+	    if (LanguageSupportFactory.isInterestingBinary(type, typeInfo)) {
  177
+	    	return LanguageSupportFactory.binaryCodeSelect(this, offset, length, owner);
  178
+	    }
  179
+		BasicCompilationUnit cu = new BasicCompilationUnit(contents, null, type.sourceFileName(typeInfo));
  180
+		// GROOVY end
169 181
 		return super.codeSelect(cu, offset, length, owner);
170 182
 	} else {
171 183
 		//has no associated souce

0 notes on commit 1d101e7

Please sign in to comment.
Something went wrong with that request. Please try again.