private CPListElement createCPVariableElement(IPath path) { CPListElement elem= new CPListElement(fCurrJProject, IClasspathEntry.CPE_VARIABLE, path, null); IPath resolvedPath= JavaCore.getResolvedVariablePath(path); elem.setIsMissing((resolvedPath == null) || !resolvedPath.toFile().exists()); return elem; }
private static IClasspathEntry getUpdatedEntry(IClasspathEntry currEntry, IClasspathEntry updatedEntry, String[] updatedAttributes, IJavaProject jproject) { if (updatedAttributes == null) { return updatedEntry; // used updated entry 'as is' } CPListElement currElem= CPListElement.createFromExisting(currEntry, jproject); CPListElement newElem= CPListElement.createFromExisting(updatedEntry, jproject); for (int i= 0; i < updatedAttributes.length; i++) { String attrib= updatedAttributes[i]; currElem.setAttribute(attrib, newElem.getAttribute(attrib)); } return currElem.getClasspathEntry(); }
private static boolean isExternalArchiveOrLibrary(CPListElement entry) { if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY || entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { if (entry.getResource() instanceof IFolder) { return false; } return true; } return false; }
private void attributeUpdated(CPListElement selElement, String[] changedAttributes) { Object parentContainer= selElement.getParentContainer(); if (parentContainer instanceof CPListElement) { // inside a container: apply changes right away IClasspathEntry updatedEntry= selElement.getClasspathEntry(); updateContainerEntry(updatedEntry, changedAttributes, fCurrJProject, ((CPListElement) parentContainer).getPath()); } }
private void editElementEntry(CPListElement elem) { CPListElement[] res= null; switch (elem.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: res= openContainerSelectionDialog(elem); break; case IClasspathEntry.CPE_LIBRARY: IResource resource= elem.getResource(); if (resource == null) { res= openExtJarFileDialog(elem); } else if (resource.getType() == IResource.FILE) { res= openJarFileDialog(elem); } break; case IClasspathEntry.CPE_VARIABLE: res= openVariableSelectionDialog(elem); break; } if (res != null && res.length > 0) { CPListElement curr= res[0]; curr.setExported(elem.isExported()); fLibrariesList.replaceElement(elem, curr); } }
public IClasspathEntry getNewEntry() { CPListElement elem= CPListElement.createFromExisting(fEntry, fProject); IPath sourceAttachmentPath= getSourceAttachmentPath(); String encoding= getEncoding(); elem.setAttribute(CPListElement.SOURCEATTACHMENT, sourceAttachmentPath); elem.setAttribute(CPListElement.SOURCE_ATTACHMENT_ENCODING, encoding); return elem.getClasspathEntry(); }
private static boolean addToExclusions(IPath entryPath, CPListElement curr) { IPath[] exclusionFilters= (IPath[]) curr.getAttribute(CPListElement.EXCLUSION); if (!JavaModelUtil.isExcludedPath(entryPath, exclusionFilters)) { IPath pathToExclude= entryPath.removeFirstSegments(curr.getPath().segmentCount()).addTrailingSeparator(); IPath[] newExclusionFilters= new IPath[exclusionFilters.length + 1]; System.arraycopy(exclusionFilters, 0, newExclusionFilters, 0, exclusionFilters.length); newExclusionFilters[exclusionFilters.length]= pathToExclude; curr.setAttribute(CPListElement.EXCLUSION, newExclusionFilters); return true; } return false; }
private CPListElement[] doOpenInternalJarFileDialog(CPListElement existing, Object parent) { IPath path = existing.getPath(); IPath selectedPaths[] = BuildPathDialogAccess.chooseJAREntries(this.getShell(), path, new IPath[0]); if (selectedPaths != null) { List<CPListElement> elements = new ArrayList<>(); for (int i= 0; i < selectedPaths.length; i++) { CPListElement cpElement = new CPListElement(parent, fDummyProject, IClasspathEntry.CPE_LIBRARY, selectedPaths[i], null); cpElement.setAttribute(CPListElement.SOURCEATTACHMENT, BuildPathSupport.guessSourceAttachment(cpElement)); cpElement.setAttribute(CPListElement.JAVADOC, BuildPathSupport.guessJavadocLocation(cpElement)); elements.add(cpElement); } return elements.toArray(new CPListElement[0]); } return null; }
private void addExclusionPatterns(CPListElement newEntry, List<CPListElement> existing, Set<CPListElement> modifiedEntries) { IPath entryPath= newEntry.getPath(); for (int i= 0; i < existing.size(); i++) { CPListElement curr= existing.get(i); IPath currPath= curr.getPath(); if (curr != newEntry && curr.getEntryKind() == IClasspathEntry.CPE_SOURCE && currPath.isPrefixOf(entryPath)) { boolean added= curr.addToExclusions(entryPath); if (added) { modifiedEntries.add(curr); } } } }
@Override public boolean equals(Object other) { if (other != null && other.getClass().equals(getClass())) { CPListElement elem= (CPListElement) other; return getClasspathEntry().equals(elem.getClasspathEntry()); } return false; }
private CPListElement newCPLibraryElement(IResource res) { return new CPListElement(fCurrJProject, IClasspathEntry.CPE_LIBRARY, res.getFullPath(), res); }
private IClasspathEntry newClasspathEntry() { IClasspathAttribute[] extraAttributes= getClasspathAttributes(); switch (fEntryKind) { case IClasspathEntry.CPE_SOURCE: IPath[] inclusionPattern= (IPath[]) getAttribute(INCLUSION); IPath[] exclusionPattern= (IPath[]) getAttribute(EXCLUSION); IPath outputLocation= (IPath) getAttribute(OUTPUT); return JavaCore.newSourceEntry(fPath, inclusionPattern, exclusionPattern, outputLocation, extraAttributes); case IClasspathEntry.CPE_LIBRARY: { IPath attach= (IPath) getAttribute(SOURCEATTACHMENT); IAccessRule[] accesRules= (IAccessRule[]) getAttribute(ACCESSRULES); return JavaCore.newLibraryEntry(fPath, attach, null, accesRules, extraAttributes, isExported()); IAccessRule[] accesRules= (IAccessRule[]) getAttribute(ACCESSRULES); boolean combineAccessRules= ((Boolean) getAttribute(COMBINE_ACCESSRULES)).booleanValue(); return JavaCore.newProjectEntry(fPath, accesRules, combineAccessRules, extraAttributes, isExported()); IAccessRule[] accesRules= (IAccessRule[]) getAttribute(ACCESSRULES); return JavaCore.newContainerEntry(fPath, accesRules, extraAttributes, isExported()); IPath varAttach= (IPath) getAttribute(SOURCEATTACHMENT); IAccessRule[] accesRules= (IAccessRule[]) getAttribute(ACCESSRULES); return JavaCore.newVariableEntry(fPath, varAttach, null, accesRules, extraAttributes, isExported());
public Object[] getChildren(ListDialogField field, Object element) { if (element instanceof CPListElement) { return ((CPListElement) element).getChildren(false); } return EMPTY_ARR; }
protected void filterAndSetSelection(List<?> list) { ArrayList<Object> res= new ArrayList<>(list.size()); for (int i= list.size()-1; i >= 0; i--) { Object curr= list.get(i); if (curr instanceof CPListElement) { CPListElement elem= (CPListElement) curr; if (elem.getParentContainer() == null && isEntryKind(elem.getEntryKind())) { res.add(curr); } } } setSelection(res, false); }
private boolean canEdit(List selElements) { if (selElements.size() != 1) { return false; } Object elem= selElements.get(0); if (elem instanceof CPListElement) { CPListElement curr= (CPListElement) elem; return !(curr.getResource() instanceof IFolder) && curr.getParentContainer() == null; } if (elem instanceof CPListElementAttribute) { return true; } return false; }
private static CPListElement findElement(IJavaElement element, CPListElement[] elements) { IPath path= element.getPath(); for (int i= 0; i < elements.length; i++) { CPListElement cur= elements[i]; if (cur.getEntryKind() == IClasspathEntry.CPE_SOURCE && cur.getPath().equals(path)) { return cur; } } return null; }
/** * Reset the output folder for the given entry to the default output folder * * @param entry the <code>CPListElement</code> to be edited * @param project the Java project * @return an attribute representing the modified output folder * @throws JavaModelException */ public static CPListElementAttribute resetOutputFolder(CPListElement entry, IJavaProject project) throws JavaModelException { entry.setAttribute(CPListElement.OUTPUT, null); CPListElementAttribute outputFolder= new CPListElementAttribute(entry, CPListElement.OUTPUT, entry.getAttribute(CPListElement.OUTPUT), true); return outputFolder; }
private void editElementEntry(CPListElement elem) { CPListElement[] res= openProjectDialog(elem); if (res != null && res.length > 0) { CPListElement curr= res[0]; curr.setExported(elem.isExported()); fProjectsList.replaceElement(elem, curr); } }
private List getExistingContainers(CPListElement[] existingElements) { List res= new ArrayList(); for (int i= 0; i < existingElements.length; i++) { IResource resource= existingElements[i].getResource(); if (resource instanceof IContainer) { res.add(resource); } } Set keys= fNonExistingFolders.keySet(); for (Iterator iter= keys.iterator(); iter.hasNext();) { IFolder folder= (IFolder)iter.next(); res.add(folder); } return res; }
private static boolean containsSourceFolders(CPJavaProject cpProject) { List elements= cpProject.getCPListElements(); for (Iterator iterator= elements.iterator(); iterator.hasNext();) { CPListElement element= (CPListElement)iterator.next(); if (element.getEntryKind() == IClasspathEntry.CPE_SOURCE) return true; } return false; }