private OpenDeclarationDescriptor classFileNavigation(IClassFile classFile, IJavaElement element) throws JavaModelException { OpenDeclarationDescriptor dto = DtoFactory.getInstance().createDto(OpenDeclarationDescriptor.class); dto.setPath(classFile.getType().getFullyQualifiedName()); dto.setLibId(classFile.getAncestor(IPackageFragmentRoot.PACKAGE_FRAGMENT_ROOT).hashCode()); dto.setBinary(true); if (classFile.getSourceRange() != null) { if (element instanceof ISourceReference) { ISourceRange nameRange = ((ISourceReference) element).getNameRange(); dto.setOffset(nameRange.getOffset()); dto.setLength(nameRange.getLength()); } } return dto; }
private IJavaProject createJavaProjectThroughActiveEditor() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); if(page.getActiveEditor().getEditorInput() instanceof IFileEditorInput) { IFileEditorInput input = (IFileEditorInput) page.getActiveEditor().getEditorInput(); IFile file = input.getFile(); IProject activeProject = file.getProject(); IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(activeProject.getName()); return JavaCore.create(project); } else if(page.getActiveEditor().getEditorInput() instanceof IClassFileEditorInput) { IClassFileEditorInput classFileEditorInput=(InternalClassFileEditorInput)page.getActiveEditor().getEditorInput() ; IClassFile classFile=classFileEditorInput.getClassFile(); return classFile.getJavaProject(); } return null; }
public void createClassRepo(String jarFileName, String Package) { ClassRepo.INSTANCE.flusRepo(); try { IPackageFragmentRoot iPackageFragmentRoot = getIPackageFragment(jarFileName); if (iPackageFragmentRoot != null) { IPackageFragment fragment = iPackageFragmentRoot.getPackageFragment(Package); if (fragment != null) { for (IClassFile element : fragment.getClassFiles()) { ClassRepo.INSTANCE.addClass(element,"","",false); } } else { new CustomMessageBox(SWT.ERROR, Package + " Package not found in jar " + iPackageFragmentRoot.getElementName(), "ERROR").open(); } } } catch (JavaModelException e) { LOGGER.error("Error occurred while loading class from jar {}", jarFileName, e); } loadClassesFromSettingsFolder(); }
public ClassDetails(IClassFile classFile, String jarFileName, String packageName, boolean isUserDefined) { LOGGER.debug("Extracting methods from "+classFile.getElementName()); try { this.javaDoc=getJavaDoc(classFile); intialize(classFile,jarFileName,packageName, isUserDefined); for (IJavaElement iJavaElement : classFile.getChildren()) { if (iJavaElement instanceof IType) { IType iType = (IType) iJavaElement; for (IMethod iMethod : iType.getMethods()) { addMethodsToClass(iMethod); } } } } catch (JavaModelException e) { LOGGER.error("Error occurred while fetching methods from class"+cName); } }
private void intialize(IClassFile classFile, String jarFileName, String packageName, boolean isUserDefined) { this.cName = StringUtils.removeEndIgnoreCase(classFile.getElementName(), Constants.CLASS_EXTENSION); displayName=cName; if(StringUtils.isNotBlank(jarFileName)){ jarName=jarFileName; } if(StringUtils.isNotBlank(packageName)){ this.packageName=packageName; } if(StringUtils.isBlank(javaDoc)){ javaDoc=Constants.EMPTY_STRING; } if(isUserDefined){ isUserDefined=true; displayName=cName+Constants.USER_DEFINED_SUFFIX; updateJavaDoc(jarFileName, packageName); } }
/** * Given a source name info, search the associated source file or class file from the source container list. * * @param sourcePath * the target source name (e.g. com\microsoft\java\debug\xxx.java). * @param containers * the source container list. * @return the associated source file or class file. */ public static Object findSourceElement(String sourcePath, ISourceContainer[] containers) { if (containers == null) { return null; } for (ISourceContainer container : containers) { try { Object[] objects = container.findSourceElements(sourcePath); if (objects.length > 0 && (objects[0] instanceof IResource || objects[0] instanceof IClassFile)) { return objects[0]; } } catch (CoreException e) { // do nothing. } } return null; }
/** * Given a stack frame, find the target project that the associated source file belongs to. * * @param stackFrame * the stack frame. * @param containers * the source container list. * @return the context project. */ public static IProject findProject(StackFrame stackFrame, ISourceContainer[] containers) { Location location = stackFrame.location(); try { Object sourceElement = findSourceElement(location.sourcePath(), containers); if (sourceElement instanceof IResource) { return ((IResource) sourceElement).getProject(); } else if (sourceElement instanceof IClassFile) { IJavaProject javaProject = ((IClassFile) sourceElement).getJavaProject(); if (javaProject != null) { return javaProject.getProject(); } } } catch (AbsentInformationException e) { // When the compiled .class file doesn't contain debug source information, return null. } return null; }
@Override public String getSourceFileURI(String fullyQualifiedName, String sourcePath) { if (sourcePath == null) { return null; } Object sourceElement = JdtUtils.findSourceElement(sourcePath, getSourceContainers()); if (sourceElement instanceof IResource) { return getFileURI((IResource) sourceElement); } else if (sourceElement instanceof IClassFile) { try { IClassFile file = (IClassFile) sourceElement; if (file.getBuffer() != null) { return getFileURI(file); } } catch (JavaModelException e) { // do nothing. } } return null; }
private String getContents(IClassFile cf) { String source = null; if (cf != null) { try { IBuffer buffer = cf.getBuffer(); if (buffer != null) { source = buffer.getContents(); } } catch (JavaModelException e) { logger.log(Level.SEVERE, String.format("Failed to parse the source contents of the class file: %s", e.toString()), e); } if (source == null) { source = ""; } } return source; }
private static IClassFile resolveClassFile(String uriString) { if (uriString == null || uriString.isEmpty()) { return null; } try { URI uri = new URI(uriString); if (uri != null && JDT_SCHEME.equals(uri.getScheme()) && "contents".equals(uri.getAuthority())) { String handleId = uri.getQuery(); IJavaElement element = JavaCore.create(handleId); IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); return cf; } } catch (URISyntaxException e) { // ignore } return null; }
@Test public void testTraverse1() throws Exception { final Set<String> expected = new HashSet<String>( Arrays.asList(EXPECTEDTYPES)); TypeTraverser t = new TypeTraverser(root); t.process(new ITypeVisitor() { public void visit(IType type, String vmname) { assertTrue("Unexpected type: " + vmname, expected.remove(vmname)); } public void visit(ICompilationUnit unit) throws JavaModelException { } public void visit(IClassFile classfile) throws JavaModelException { } }, MONITOR); assertTrue("Not all types processed: " + expected, expected.isEmpty()); }
/** * Creates a location for a given java element. * Element can be a {@link ICompilationUnit} or {@link IClassFile} * * @param element * @return location or null * @throws JavaModelException */ public static Location toLocation(IJavaElement element) throws JavaModelException{ ICompilationUnit unit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); if (unit == null && cf == null) { return null; } if (element instanceof ISourceReference) { ISourceRange nameRange = getNameRange(element); if (SourceRange.isAvailable(nameRange)) { if (cf == null) { return toLocation(unit, nameRange.getOffset(), nameRange.getLength()); } else { return toLocation(cf, nameRange.getOffset(), nameRange.getLength()); } } } return null; }
/** * Appends the label for a class file. Considers the CF_* flags. * * @param classFile the element to render * @param flags the rendering flags. Flags with names starting with 'CF_' are considered. */ public void appendClassFileLabel(IClassFile classFile, long flags) { if (getFlag(flags, JavaElementLabels.CF_QUALIFIED)) { IPackageFragment pack= (IPackageFragment) classFile.getParent(); if (!pack.isDefaultPackage()) { appendPackageFragmentLabel(pack, (flags & QUALIFIER_FLAGS)); fBuilder.append('.'); } } fBuilder.append(classFile.getElementName()); if (getFlag(flags, JavaElementLabels.CF_POST_QUALIFIED)) { fBuilder.append(JavaElementLabels.CONCAT_STRING); appendPackageFragmentLabel((IPackageFragment) classFile.getParent(), flags & QUALIFIER_FLAGS); } }
@Override public String getSource(IClassFile classFile, IProgressMonitor monitor) throws CoreException { String source = null; try { IBuffer buffer = classFile.getBuffer(); if (buffer != null) { if (monitor.isCanceled()) { return null; } source = buffer.getContents(); JavaLanguageServerPlugin.logInfo("ClassFile contents request completed"); } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Exception getting java element ", e); } return source; }
private Location computeDefinitionNavigation(ITypeRoot unit, int line, int column, IProgressMonitor monitor) { try { IJavaElement element = JDTUtils.findElementAtSelection(unit, line, column, this.preferenceManager, monitor); if (element == null) { return null; } ICompilationUnit compilationUnit = (ICompilationUnit) element.getAncestor(IJavaElement.COMPILATION_UNIT); IClassFile cf = (IClassFile) element.getAncestor(IJavaElement.CLASS_FILE); if (compilationUnit != null || (cf != null && cf.getSourceRange() != null) ) { return JDTUtils.toLocation(element); } if (element instanceof IMember && ((IMember) element).getClassFile() != null) { return JDTUtils.toLocation(((IMember) element).getClassFile()); } } catch (JavaModelException e) { JavaLanguageServerPlugin.logException("Problem computing definition for" + unit.getElementName(), e); } return null; }
@Test public void testHoverThrowable() throws Exception { String uriString = ClassFileUtil.getURI(project, "java.lang.Exception"); IClassFile classFile = JDTUtils.resolveClassFile(uriString); String contents = JavaLanguageServerPlugin.getContentProviderManager().getSource(classFile, monitor); IDocument document = new Document(contents); IRegion region = new FindReplaceDocumentAdapter(document).find(0, "Throwable", true, false, false, false); int offset = region.getOffset(); int line = document.getLineOfOffset(offset); int character = offset - document.getLineOffset(line); TextDocumentIdentifier textDocument = new TextDocumentIdentifier(uriString); Position position = new Position(line, character); TextDocumentPositionParams params = new TextDocumentPositionParams(textDocument, position); Hover hover = handler.hover(params, monitor); assertNotNull(hover); assertTrue("Unexpected hover ", !hover.getContents().isEmpty()); }
protected Object[] getPackageContent(IPackageFragment fragment) throws JavaModelException { // hierarchical package mode ArrayList<Object> result = new ArrayList<Object>(); getHierarchicalPackageChildren((IPackageFragmentRoot) fragment.getParent(), fragment, result); IClassFile[] classFiles = fragment.getClassFiles(); List<IClassFile> filtered = new ArrayList<>(); // filter inner classes for (IClassFile classFile : classFiles) { if (!classFile.getElementName().contains("$")) { filtered.add(classFile); } } Object[] nonPackages = concatenate(filtered.toArray(), fragment.getNonJavaResources()); if (result.isEmpty()) return nonPackages; Collections.addAll(result, nonPackages); return result.toArray(); }
public ClassContent getContent(IJavaProject project, String path) throws JavaModelException { // java class or file IType type = project.findType(path); if (type != null) { if (type.isBinary()) { IClassFile classFile = type.getClassFile(); if (classFile.getSourceRange() != null) { return createContent(classFile.getSource(), false); } else { return createContent(sourcesGenerator.generateSource(classFile.getType()), true); } } else { return createContent(type.getCompilationUnit().getSource(), false); } } throw new JavaModelException(new JavaModelStatus(0, "Can't find type: " + path)); }
public static ResourceMapping create(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.TYPE: return create((IType) element); case IJavaElement.COMPILATION_UNIT: return create((ICompilationUnit) element); case IJavaElement.CLASS_FILE: return create((IClassFile) element); case IJavaElement.PACKAGE_FRAGMENT: return create((IPackageFragment) element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return create((IPackageFragmentRoot) element); case IJavaElement.JAVA_PROJECT: return create((IJavaProject) element); case IJavaElement.JAVA_MODEL: return create((IJavaModel) element); default: return null; } }
protected IType transplantHandle(IJavaElement parent, IType element) { switch (parent.getElementType()) { case IJavaElement.COMPILATION_UNIT: return ((ICompilationUnit) parent).getType(element.getElementName()); case IJavaElement.CLASS_FILE: return ((IClassFile) parent).getType(); case IJavaElement.METHOD: return ((IMethod) parent).getType(element.getElementName(), element.getOccurrenceCount()); case IJavaElement.FIELD: return ((IField) parent).getType(element.getElementName(), element.getOccurrenceCount()); case IJavaElement.INITIALIZER: return ((IInitializer) parent) .getType(element.getElementName(), element.getOccurrenceCount()); case IJavaElement.TYPE: return ((IType) parent).getType(element.getElementName(), element.getOccurrenceCount()); default: throw new IllegalStateException(element.toString()); } }
/** * @param newCfSource the source * @param originalCf the class file to get the name and project from * @param resolveBindings whether bindings are to be resolved * @param recovery whether statements and binding recovery should be enabled * @param pm an {@link IProgressMonitor}, or <code>null</code> * @return the parsed CompilationUnit */ public CompilationUnit parse( String newCfSource, IClassFile originalCf, boolean resolveBindings, boolean recovery, IProgressMonitor pm) { fParser.setResolveBindings(resolveBindings); fParser.setStatementsRecovery(recovery); fParser.setBindingsRecovery(recovery); fParser.setSource(newCfSource.toCharArray()); String cfName = originalCf.getElementName(); fParser.setUnitName(cfName.substring(0, cfName.length() - 6) + JavaModelUtil.DEFAULT_CU_SUFFIX); fParser.setProject(originalCf.getJavaProject()); fParser.setCompilerOptions(getCompilerOptions(originalCf)); CompilationUnit newCUNode = (CompilationUnit) fParser.createAST(pm); return newCUNode; }
private static boolean isBinaryElement(Object element) throws JavaModelException { if (element instanceof IMember) { return ((IMember) element).isBinary(); } else if (element instanceof ICompilationUnit) { return true; } else if (element instanceof IClassFile) { return false; } else if (element instanceof IPackageFragment) { return isBinaryElement(((IPackageFragment) element).getParent()); } else if (element instanceof IPackageFragmentRoot) { return ((IPackageFragmentRoot) element).getKind() == IPackageFragmentRoot.K_BINARY; } return false; }
public IFile getFile(Object element) { if (element instanceof IJavaElement) { IJavaElement javaElement = (IJavaElement) element; ICompilationUnit cu = (ICompilationUnit) javaElement.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) { return (IFile) cu.getResource(); } else { IClassFile cf = (IClassFile) javaElement.getAncestor(IJavaElement.CLASS_FILE); if (cf != null) return (IFile) cf.getResource(); } return null; } if (element instanceof IFile) return (IFile) element; return null; }
/** * Appends the label for a class file. Considers the CF_* flags. * * @param classFile the element to render * @param flags the rendering flags. Flags with names starting with 'CF_' are considered. */ public void appendClassFileLabel(IClassFile classFile, long flags) { if (getFlag(flags, JavaElementLabels.CF_QUALIFIED)) { IPackageFragment pack = (IPackageFragment) classFile.getParent(); if (!pack.isDefaultPackage()) { appendPackageFragmentLabel(pack, (flags & QUALIFIER_FLAGS)); fBuffer.append('.'); } } fBuffer.append(classFile.getElementName()); if (getFlag(flags, JavaElementLabels.CF_POST_QUALIFIED)) { int offset = fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); appendPackageFragmentLabel((IPackageFragment) classFile.getParent(), flags & QUALIFIER_FLAGS); if (getFlag(flags, JavaElementLabels.COLORIZE)) { fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); } } }
/** * Creates and returns a class file element for the given <code>.class</code> file, its project * being the given project. Returns <code>null</code> if unable to recognize the class file. */ public static IClassFile createClassFileFrom(IFile file, IJavaProject project) { if (file == null) { return null; } if (project == null) { project = JavaCore.create(file.getProject()); } IPackageFragment pkg = (IPackageFragment) determineIfOnClasspath(file, (JavaProject) project); if (pkg == null) { // fix for 1FVS7WE // not on classpath - make the root its folder, and a default package PackageFragmentRoot root = (PackageFragmentRoot) project.getPackageFragmentRoot(file.getParent()); pkg = root.getPackageFragment(CharOperation.NO_STRINGS); } return pkg.getClassFile(file.getName()); }
private static boolean isAccessibleClass(IType type) throws JavaModelException { int flags = type.getFlags(); if (Flags.isInterface(flags)) { return false; } IJavaElement parent = type.getParent(); while (true) { if (parent instanceof ICompilationUnit || parent instanceof IClassFile) { return true; } if (!(parent instanceof IType) || !Flags.isStatic(flags) || !Flags.isPublic(flags)) { return false; } flags = ((IType) parent).getFlags(); parent = parent.getParent(); } }
protected static void cleanupBuffer(IClassFile file) { IBuffer buffer = BufferManager.getDefaultBufferManager().getBuffer(file); if (buffer != null) { try { // Remove the buffer Method method = BufferManager.class.getDeclaredMethod( "removeBuffer", new Class[] {IBuffer.class}); method.setAccessible(true); method.invoke( BufferManager.getDefaultBufferManager(), new Object[] {buffer}); } catch (Exception e) { JavaDecompilerPlugin.getDefault().getLog().log(new Status( Status.ERROR, JavaDecompilerPlugin.PLUGIN_ID, 0, e.getMessage(), e)); } } }
/** * Appends the label for a class file. Considers the CF_* flags. * * @param classFile the element to render * @param flags the rendering flags. Flags with names starting with 'CF_' are considered. */ public void appendClassFileLabel(IClassFile classFile, long flags) { if (getFlag(flags, CF_QUALIFIED)) { IPackageFragment pack= (IPackageFragment) classFile.getParent(); if (!pack.isDefaultPackage()) { appendPackageFragmentLabel(pack, (flags & QUALIFIER_FLAGS)); fBuffer.append('.'); } } fBuffer.append(classFile.getElementName()); if (getFlag(flags, CF_POST_QUALIFIED)) { int offset= fBuffer.length(); fBuffer.append(CONCAT_STRING); appendPackageFragmentLabel((IPackageFragment) classFile.getParent(), flags & QUALIFIER_FLAGS); } }
public IFile getFile(Object element) { if (element instanceof IJavaElement) { IJavaElement javaElement= (IJavaElement) element; ICompilationUnit cu= (ICompilationUnit) javaElement.getAncestor(IJavaElement.COMPILATION_UNIT); if (cu != null) { return (IFile) cu.getResource(); } else { IClassFile cf= (IClassFile) javaElement.getAncestor(IJavaElement.CLASS_FILE); if (cf != null) return (IFile) cf.getResource(); } return null; } if (element instanceof IFile) return (IFile) element; return null; }
/** * @see MarkerRulerAction#getResource() */ @Override protected IResource getResource() { IResource resource= null; IEditorInput input= getTextEditor().getEditorInput(); if (input instanceof IClassFileEditorInput) { IClassFile c= ((IClassFileEditorInput) input).getClassFile(); IResourceLocator locator= (IResourceLocator) c.getAdapter(IResourceLocator.class); if (locator != null) { try { resource= locator.getContainingResource(c); } catch (JavaModelException x) { // ignore but should inform } } } return resource; }
/** * Appends the label for a class file. Considers the CF_* flags. * * @param classFile the element to render * @param flags the rendering flags. Flags with names starting with 'CF_' are considered. */ public void appendClassFileLabel(IClassFile classFile, long flags) { if (getFlag(flags, JavaElementLabels.CF_QUALIFIED)) { IPackageFragment pack= (IPackageFragment) classFile.getParent(); if (!pack.isDefaultPackage()) { appendPackageFragmentLabel(pack, (flags & QUALIFIER_FLAGS)); fBuffer.append('.'); } } fBuffer.append(classFile.getElementName()); if (getFlag(flags, JavaElementLabels.CF_POST_QUALIFIED)) { int offset= fBuffer.length(); fBuffer.append(JavaElementLabels.CONCAT_STRING); appendPackageFragmentLabel((IPackageFragment) classFile.getParent(), flags & QUALIFIER_FLAGS); if (getFlag(flags, JavaElementLabels.COLORIZE)) { fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE); } } }
private static boolean isBinaryElement(Object element) throws JavaModelException { if (element instanceof IMember) { return ((IMember)element).isBinary(); } else if (element instanceof ICompilationUnit) { return true; } else if (element instanceof IClassFile) { return false; } else if (element instanceof IPackageFragment) { return isBinaryElement(((IPackageFragment) element).getParent()); } else if (element instanceof IPackageFragmentRoot) { return ((IPackageFragmentRoot) element).getKind() == IPackageFragmentRoot.K_BINARY; } return false; }
/** * @see AddMarkerAction#getResource() */ @Override protected IResource getResource() { IResource resource= null; IEditorInput input= getTextEditor().getEditorInput(); if (input instanceof IClassFileEditorInput) { IClassFile c= ((IClassFileEditorInput) input).getClassFile(); IResourceLocator locator= (IResourceLocator) c.getAdapter(IResourceLocator.class); if (locator != null) { try { resource= locator.getContainingResource(c); } catch (JavaModelException x) { // ignore but should inform } } } return resource; }
public static ResourceMapping create(IJavaElement element) { switch (element.getElementType()) { case IJavaElement.TYPE: return create((IType)element); case IJavaElement.COMPILATION_UNIT: return create((ICompilationUnit)element); case IJavaElement.CLASS_FILE: return create((IClassFile)element); case IJavaElement.PACKAGE_FRAGMENT: return create((IPackageFragment)element); case IJavaElement.PACKAGE_FRAGMENT_ROOT: return create((IPackageFragmentRoot)element); case IJavaElement.JAVA_PROJECT: return create((IJavaProject)element); case IJavaElement.JAVA_MODEL: return create((IJavaModel)element); default: return null; } }
static RefactoringStatusContext createRefactoringStatusContext(IJavaElement element) { if (element instanceof IMember) { return JavaStatusContext.create((IMember) element); } if (element instanceof ISourceReference) { IOpenable openable= element.getOpenable(); try { if (openable instanceof ICompilationUnit) { return JavaStatusContext.create((ICompilationUnit) openable, ((ISourceReference) element).getSourceRange()); } else if (openable instanceof IClassFile) { return JavaStatusContext.create((IClassFile) openable, ((ISourceReference) element).getSourceRange()); } } catch (JavaModelException e) { // ignore } } return null; }
private IMember getMember(IStructuredSelection selection) { if (selection.size() != 1) return null; Object o= selection.getFirstElement(); if (o instanceof IMember) { IMember member= (IMember)o; try { if (member.getNameRange() == null) return null; } catch (JavaModelException ex) { return null; } IClassFile file= member.getClassFile(); if (file != null) { try { if (file.getSourceRange() != null) return member; } catch (JavaModelException e) { return null; } } return member; } return null; }
/** * Returns the input for the given element. The Java breadcrumb does not show some elements of * the model: * <ul> * <li><code>ITypeRoots</li> * <li><code>IPackageDeclaration</li> * <li><code>IImportContainer</li> * <li><code>IImportDeclaration</li> * </ul> * * @param element the potential input element * @return the element to use as input */ private IJavaElement getInput(IJavaElement element) { try { if (element instanceof IImportDeclaration) element= element.getParent(); if (element instanceof IImportContainer) element= element.getParent(); if (element instanceof IPackageDeclaration) element= element.getParent(); if (element instanceof ICompilationUnit) { IType[] types= ((ICompilationUnit) element).getTypes(); if (types.length > 0) element= types[0]; } if (element instanceof IClassFile) element= ((IClassFile) element).getType(); return element; } catch (JavaModelException e) { return null; } }
private void exportExternalClassFolderElement(IJavaElement javaElement, IPath classFolderPath, IProgressMonitor progressMonitor) throws JavaModelException, InterruptedException { if (javaElement instanceof IClassFile) { IClassFile classFile= (IClassFile) javaElement; IPath path= classFile.getPath(); IPath destination= path.removeFirstSegments(classFolderPath.segmentCount()).setDevice(null); try { ((IJarBuilderExtension) fJarBuilder).writeFile(path.toFile(), destination); } catch (CoreException e) { handleCoreExceptionOnExport(e); } finally { progressMonitor.worked(1); ModalContext.checkCanceled(progressMonitor); } } else if (javaElement instanceof IPackageFragment) { IJavaElement[] children= ((IPackageFragment) javaElement).getChildren(); for (int i= 0; i < children.length; i++) { exportExternalClassFolderElement(children[i], classFolderPath, progressMonitor); } } }
private void addJavaElement(List<Object> selectedElements, IJavaElement je) { if (je.getElementType() == IJavaElement.COMPILATION_UNIT) selectedElements.add(je); else if (je.getElementType() == IJavaElement.CLASS_FILE) selectedElements.add(je); else if (je.getElementType() == IJavaElement.JAVA_PROJECT) selectedElements.add(je); else if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT) { if (!isInArchiveOrExternal(je)) selectedElements.add(je); } else if (je.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT) { if (!isInArchiveOrExternal(je)) selectedElements.add(je); } else { IOpenable openable= je.getOpenable(); if (openable instanceof ICompilationUnit) selectedElements.add(((ICompilationUnit) openable).getPrimary()); else if (openable instanceof IClassFile && !isInArchiveOrExternal(je)) selectedElements.add(openable); } }