@Override public IModularClassFile getModularClassFile() { // don't hold on the .class file extension to save memory // also make sure to not use substring as the resulting String may hold on the underlying char[] which might be much bigger than necessary return new ModularClassFile(this); }
@Override public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException { String source = getSource(); if (source != null) { BasicCompilationUnit cu = new BasicCompilationUnit( getSource().toCharArray(), null, TypeConstants.MODULE_INFO_FILE_NAME_STRING, getJavaProject()); // use project to retrieve corresponding .java IFile codeComplete(cu, cu, offset, requestor, owner, null/*extended context isn't computed*/, monitor); } }
@Override public IModuleDescription getModule() throws JavaModelException { if (this.binaryModule == null) { openWhenClosed(createElementInfo(), false, null); if (this.binaryModule == null) throw newNotPresentException(); } return this.binaryModule; } }
/** * @see ITypeRoot */ public IJavaElement getElementAt(int position) throws JavaModelException { IJavaElement parentElement = getParent(); while (parentElement.getElementType() != IJavaElement.PACKAGE_FRAGMENT_ROOT) { parentElement = parentElement.getParent(); } PackageFragmentRoot root = (PackageFragmentRoot) parentElement; SourceMapper mapper = root.getSourceMapper(); if (mapper == null) { return null; } else { // ensure this class file's buffer is open so that source ranges are computed getBuffer(); IModuleDescription module = getModule(); return findElement(module, position, mapper); } } @Override
private IBinaryModule getJarBinaryModuleInfo() throws CoreException, IOException, ClassFormatException { BinaryModuleDescriptor descriptor = BinaryModuleFactory.createDescriptor(this); if (descriptor == null) { return null; } IBinaryModule result = null; IPackageFragmentRoot root = getPackageFragmentRoot(); if (getPackageFragmentRoot() instanceof JarPackageFragmentRoot) { if (root instanceof JrtPackageFragmentRoot || this.name.equals(IModule.MODULE_INFO)) { PackageFragment pkg = (PackageFragment) getParent(); JarPackageFragmentRoot jarRoot = (JarPackageFragmentRoot) getPackageFragmentRoot(); String entryName = jarRoot.getClassFilePath(Util.concatWith(pkg.names, getElementName(), '/')); byte[] contents = getClassFileContent(jarRoot, entryName); if (contents != null) { String fileName = root.getHandleIdentifier() + IDependent.JAR_FILE_ENTRY_SEPARATOR + entryName; ClassFileReader classFileReader = new ClassFileReader(contents, fileName.toCharArray(), false); return classFileReader.getModuleDeclaration(); } } else { result = BinaryModuleFactory.readModule(descriptor, null); } } else { result = BinaryModuleFactory.readModule(descriptor, null); } return result; }
public void locateMatches(MatchLocator locator, ModularClassFile mClassFile) throws CoreException { SearchPattern pattern = locator.pattern; this.modularClassFile = mClassFile; this.binaryModule = this.modularClassFile.getBinaryModuleInfo(); if (this.binaryModule == null) return; // cache all the details this.moduleDesc = mClassFile.getModule(); this.moduleName = this.binaryModule.name(); this.module = locator.lookupEnvironment.getModule(this.moduleName); matchModuleDeclaration(pattern, locator); matchModuleReferences(pattern, locator); matchPackageReferences(pattern, locator); matchTypeReferences(pattern, locator); } private void matchModuleDeclaration(SearchPattern pattern, MatchLocator locator) throws CoreException {
/** * Creates the single child element for this class file adding the resulting * new handle (of type {@link IBinaryModule}) and info object to the newElements table. * Returns true if successful, or false if an error is encountered parsing the class file. * * @see Openable * @see Signature */ @Override protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { IBinaryModule moduleInfo = getBinaryModuleInfo(); if (moduleInfo == null) { // The structure of a class file is unknown if a class file format errors occurred //during the creation of the diet class file representative of this ClassFile. info.setChildren(JavaElement.NO_ELEMENTS); return false; } // Read the module BinaryModule module = ((ClassFileInfo) info).readBinaryModule(this, (HashMap<?,?>) newElements, moduleInfo); if (module != null) { this.binaryModule = module; info.setChildren(new IJavaElement[] {module}); ((PackageFragmentRootInfo) getPackageFragmentRoot().getElementInfo()).setModule(module); } return true; }
/** Loads the buffer via SourceMapper, and maps it in SourceMapper */ private IBuffer mapSource(SourceMapper mapper) throws JavaModelException { char[] contents = mapper.findSource(getModule()); if (contents != null) { // create buffer IBuffer buffer = BufferManager.createBuffer(this); if (buffer == null) return null; BufferManager bufManager = getBufferManager(); bufManager.addBuffer(buffer); // set the buffer source if (buffer.getCharacters() == null){ buffer.setContents(contents); } // listen to buffer changes buffer.addBufferChangedListener(this); // do the source mapping mapper.mapSource((NamedMember) getModule(), contents, null); return buffer; } else { // create buffer IBuffer buffer = BufferManager.createNullBuffer(this); if (buffer == null) return null; BufferManager bufManager = getBufferManager(); bufManager.addBuffer(buffer); // listen to buffer changes buffer.addBufferChangedListener(this); return buffer; } }
IBinaryModule info = getJarBinaryModuleInfo(); if (info == null) { throw newNotPresentException();
@Override public ISourceRange getSourceRange() throws JavaModelException { SourceMapper mapper= getSourceMapper(); if (mapper != null) { // ensure the class file's buffer is open so that source ranges are computed ((ModularClassFile)getClassFile()).getBuffer(); return mapper.getSourceRange(this); } else { return SourceMapper.UNKNOWN_RANGE; } } @Override
@Override public IModule getModuleInfo() throws JavaModelException { if (this.info == null) { ModularClassFile classFile = (ModularClassFile) this.parent; this.info = classFile.getBinaryModuleInfo(); } return this.info; } @Override
/** * @see ITypeRoot */ @Override public IJavaElement getElementAt(int position) throws JavaModelException { IJavaElement parentElement = getParent(); while (parentElement.getElementType() != IJavaElement.PACKAGE_FRAGMENT_ROOT) { parentElement = parentElement.getParent(); } PackageFragmentRoot root = (PackageFragmentRoot) parentElement; SourceMapper mapper = root.getSourceMapper(); if (mapper == null) { return null; } else { // ensure this class file's buffer is open so that source ranges are computed getBuffer(); IModuleDescription module = getModule(); return findElement(module, position, mapper); } } @Override
IPackageFragmentRoot root = getPackageFragmentRoot(); if (getPackageFragmentRoot() instanceof JarPackageFragmentRoot) { if (root instanceof JrtPackageFragmentRoot || this.name.equals(IModule.MODULE_INFO)) { PackageFragment pkg = (PackageFragment) getParent(); JarPackageFragmentRoot jarRoot = (JarPackageFragmentRoot) getPackageFragmentRoot(); String entryName = jarRoot.getClassFilePath(Util.concatWith(pkg.names, getElementName(), '/')); byte[] contents = getClassFileContent(jarRoot, entryName); if (contents != null) { String fileName;
public void locateMatches(MatchLocator locator, ModularClassFile mClassFile) throws CoreException { SearchPattern pattern = locator.pattern; this.modularClassFile = mClassFile; this.binaryModule = this.modularClassFile.getBinaryModuleInfo(); if (this.binaryModule == null) return; // cache all the details this.moduleDesc = mClassFile.getModule(); this.moduleName = this.binaryModule.name(); this.module = locator.lookupEnvironment.getModule(this.moduleName); matchModuleDeclaration(pattern, locator); matchModuleReferences(pattern, locator); matchPackageReferences(pattern, locator); matchTypeReferences(pattern, locator); } private void matchModuleDeclaration(SearchPattern pattern, MatchLocator locator) throws CoreException {
/** * Creates the single child element for this class file adding the resulting * new handle (of type {@link IBinaryModule}) and info object to the newElements table. * Returns true if successful, or false if an error is encountered parsing the class file. * * @see Openable * @see Signature */ @Override protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws JavaModelException { IBinaryModule moduleInfo = getBinaryModuleInfo(); if (moduleInfo == null) { // The structure of a class file is unknown if a class file format errors occurred //during the creation of the diet class file representative of this ClassFile. info.setChildren(JavaElement.NO_ELEMENTS); return false; } // Create & link a handle: BinaryModule module = new BinaryModule(this, moduleInfo); newElements.put(module, moduleInfo); info.setChildren(new IJavaElement[] {module}); this.binaryModule = module; if (info instanceof ClassFileInfo) { ((ClassFileInfo) info).setModule(module); } ((PackageFragmentRootInfo) getPackageFragmentRoot().getElementInfo()).setModule(module); return true; }
/** Loads the buffer via SourceMapper, and maps it in SourceMapper */ private IBuffer mapSource(SourceMapper mapper) throws JavaModelException { char[] contents = mapper.findSource(getModule()); if (contents != null) { // create buffer IBuffer buffer = BufferManager.createBuffer(this); if (buffer == null) return null; BufferManager bufManager = getBufferManager(); bufManager.addBuffer(buffer); // set the buffer source if (buffer.getCharacters() == null){ buffer.setContents(contents); } // listen to buffer changes buffer.addBufferChangedListener(this); // do the source mapping mapper.mapSource((NamedMember) getModule(), contents, null); return buffer; } else { // create buffer IBuffer buffer = BufferManager.createNullBuffer(this); if (buffer == null) return null; BufferManager bufManager = getBufferManager(); bufManager.addBuffer(buffer); // listen to buffer changes buffer.addBufferChangedListener(this); return buffer; } }
IBinaryModule info = getJarBinaryModuleInfo(); if (info == null) { throw newNotPresentException();
@Override public IJavaElement[] codeSelect(int offset, int length, WorkingCopyOwner owner) throws JavaModelException { IBuffer buffer = getBuffer(); char[] contents; if (buffer != null && (contents = buffer.getCharacters()) != null) { BasicCompilationUnit cu = new BasicCompilationUnit(contents, null, TypeConstants.MODULE_INFO_FILE_NAME_STRING, this); return super.codeSelect(cu, offset, length, owner); } else { // has no associated source return new IJavaElement[] {}; } }
@Override public void codeComplete(int offset, CompletionRequestor requestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException { String source = getSource(); if (source != null) { BasicCompilationUnit cu = new BasicCompilationUnit( getSource().toCharArray(), null, TypeConstants.MODULE_INFO_FILE_NAME_STRING, getJavaProject()); // use project to retrieve corresponding .java IFile codeComplete(cu, cu, offset, requestor, owner, null/*extended context isn't computed*/, monitor); } }
@Override public IModuleDescription getModule() throws JavaModelException { if (this.binaryModule == null) { openWhenClosed(createElementInfo(), false, null); if (this.binaryModule == null) throw newNotPresentException(); } return this.binaryModule; } }