@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; } } public String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException {
@Override public String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException { JavadocContents javadocContents = getJavadocContents(monitor); if (javadocContents == null) return null; return javadocContents.getModuleDoc(); } public JavadocContents getJavadocContents(IProgressMonitor monitor) throws JavaModelException {
@Override public String getKey(boolean forceOpen) throws JavaModelException { return getKey(this, forceOpen); } @Override
public JavadocContents getJavadocContents(IProgressMonitor monitor) throws JavaModelException { PerProjectInfo projectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(getJavaProject().getProject()); JavadocContents cachedJavadoc = null; synchronized (projectInfo.javadocCache) { cachedJavadoc = (JavadocContents) projectInfo.javadocCache.get(this); } if (cachedJavadoc != null && cachedJavadoc != BinaryType.EMPTY_JAVADOC) { return cachedJavadoc; } URL baseLocation= getJavadocBaseLocation(); if (baseLocation == null) { return null; } StringBuffer pathBuffer = new StringBuffer(baseLocation.toExternalForm()); if (!(pathBuffer.charAt(pathBuffer.length() - 1) == '/')) { pathBuffer.append('/'); } pathBuffer.append(getElementName()).append(JavadocConstants.MODULE_FILE_SUFFIX); if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException(); String contents = getURLContents(baseLocation, String.valueOf(pathBuffer)); JavadocContents javadocContents = new JavadocContents(contents); synchronized (projectInfo.javadocCache) { projectInfo.javadocCache.put(this, javadocContents); } return javadocContents; } @Override
protected BinaryModule readBinaryModule(AbstractClassFile classFile, HashMap newElements, IBinaryModule modDecl) { this.binaryChildren = JavaElement.NO_ELEMENTS; this.typeParameters = TypeParameter.NO_TYPE_PARAMETERS; if (modDecl != null) {//may not be a valid class file // TODO: The following needs fix once we can get ModuleDeclaration from IndexBinaryType char[] modName = modDecl.name(); BinaryModule handle = new BinaryModule(classFile, new String(modName)); ModuleDescriptionInfo moduleInfo = ModuleDescriptionInfo.createModule(modDecl); setModule(handle); newElements.put(handle, moduleInfo); this.binaryChildren = new JavaElement[] { handle }; return handle; } return null; } /**
public String toString(String lineDelimiter) { StringBuffer buffer = new StringBuffer(); try { toStringContent(buffer, lineDelimiter); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return buffer.toString(); } }
public JavadocContents getJavadocContents(IProgressMonitor monitor) throws JavaModelException { PerProjectInfo projectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(getJavaProject().getProject()); JavadocContents cachedJavadoc = null; synchronized (projectInfo.javadocCache) { cachedJavadoc = (JavadocContents) projectInfo.javadocCache.get(this); } if (cachedJavadoc != null && cachedJavadoc != BinaryType.EMPTY_JAVADOC) { return cachedJavadoc; } URL baseLocation= getJavadocBaseLocation(); if (baseLocation == null) { return null; } StringBuffer pathBuffer = new StringBuffer(baseLocation.toExternalForm()); if (!(pathBuffer.charAt(pathBuffer.length() - 1) == '/')) { pathBuffer.append('/'); } pathBuffer.append(getElementName()).append(JavadocConstants.MODULE_FILE_SUFFIX); if (monitor != null && monitor.isCanceled()) throw new OperationCanceledException(); String contents = getURLContents(baseLocation, String.valueOf(pathBuffer)); JavadocContents javadocContents = new JavadocContents(contents); synchronized (projectInfo.javadocCache) { projectInfo.javadocCache.put(this, javadocContents); } return javadocContents; } public String toString(String lineDelimiter) {
@Override public IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) { switch (token.charAt(0)) { case JEM_MODULE: if (!memento.hasMoreTokens()) return this; String modName = memento.nextToken(); JavaElement mod = new BinaryModule(this, modName); return mod.getHandleFromMemento(memento, owner); } return null; } /**
@Override public String toString(String lineDelimiter) { StringBuffer buffer = new StringBuffer(); try { toStringContent(buffer, lineDelimiter); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return buffer.toString(); } }
@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 IJavaElement getHandleFromMemento(String token, MementoTokenizer memento, WorkingCopyOwner owner) { switch (token.charAt(0)) { case JEM_MODULE: if (!memento.hasMoreTokens()) return this; String modName = memento.nextToken(); JavaElement mod = new BinaryModule(this, modName); return mod.getHandleFromMemento(memento, owner); } return null; } /**
public String getKey(boolean forceOpen) throws JavaModelException { return getKey(this, forceOpen); } @Override
public String getAttachedJavadoc(IProgressMonitor monitor) throws JavaModelException { JavadocContents javadocContents = getJavadocContents(monitor); if (javadocContents == null) return null; return javadocContents.getModuleDoc(); } public JavadocContents getJavadocContents(IProgressMonitor monitor) throws JavaModelException {
/** * 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; }
static class IntArrayList { public int[] list = new int[5]; public int length = 0; public void add(int i) { if (this.list.length == this.length) { System.arraycopy(this.list, 0, this.list = new int[this.length*2], 0, this.length); } this.list[this.length++] = i; } }
static class IntArrayList { public int[] list = new int[5]; public int length = 0; public void add(int i) { if (this.list.length == this.length) { System.arraycopy(this.list, 0, this.list = new int[this.length*2], 0, this.length); } this.list[this.length++] = i; } }