public boolean visit(IResource resource) throws CoreException { if (resource.isDerived()) { return false; } handler.handleResourceStart(resource); if (resource.getType() == IResource.FILE && ContentTypeUtils.isGroovyLikeFileName(resource.getName())) { if (Util.isExcluded(resource, includes, excludes)) { return false; } GroovyCompilationUnit unit = (GroovyCompilationUnit) JavaCore.create((IFile) resource); if (unit != null && unit.isOnBuildPath()) { if (monitor.isCanceled()) { throw new OperationCanceledException(); } monitor.subTask(resource.getName()); handler.setResource((IFile) resource); Map<Integer, String> commentsMap = findComments(unit); StaticTypeCheckerRequestor requestor = new StaticTypeCheckerRequestor(handler, commentsMap, onlyAssertions); TypeInferencingVisitorWithRequestor visitor = new TypeInferencingVisitorFactory().createVisitor(unit); try { unit.becomeWorkingCopy(monitor); visitor.visitCompilationUnit(requestor); } finally { unit.discardWorkingCopy(); } } } return true; }
@Override public Object getHoverInfo2(ITextViewer textViewer, IRegion hoverRegion) { IEditorPart editor = getEditor(); if (editor == null) { return null; } IFile file = (IFile) editor.getEditorInput().getAdapter(IFile.class); if (file == null) { return null; } if (!ContentTypeUtils.isGroovyLikeFileName(file.getName())) { return null; } // first check to see if there would be a debug hover // if so, don't do any more work if (!alwaysReturnInformation) { // Object o = new Object(); Object o = debugHover.getHoverInfo2(textViewer, hoverRegion); if (o != null) { // don't actually return anything since we // want the real debug hover to do the actual work return null; } } IJavaElement[] elements = getJavaElementsAt(textViewer, hoverRegion); if (shouldComputeHover(elements)) { // might be null and if so, punt to the JavadocHover return computeHover(hoverRegion, elements); } else { return null; } }
/* (non-Javadoc) * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object, java.lang.Class) */ public Object getAdapter(Object adaptableObject, Class adapterType) { Object returnValue = null; if (adaptableObject instanceof IFile) { IFile file = (IFile) adaptableObject; if (ContentTypeUtils.isGroovyLikeFileName(file.getName())) { if (ClassNode.class.equals(adapterType) || ClassNode[].class.equals(adapterType)) { try { // we know this will be a GCU because of the file extension GroovyCompilationUnit unit = (GroovyCompilationUnit) JavaCore.createCompilationUnitFrom(file); ModuleNode module = unit.getModuleNode(); if (module != null) { List<ClassNode> classNodeList = module.getClasses(); if (classNodeList != null && !classNodeList.isEmpty()) { if (ClassNode.class.equals(adapterType)) { returnValue = classNodeList.get(0); } else if (ClassNode[].class.equals(adapterType)) { returnValue = classNodeList.toArray(new ClassNode[0]); } } } } catch (Exception ex) { GroovyCore.logException("error adapting file to ClassNode", ex); } } } } return returnValue; }