private void addDependenciesToClasspath(IProject project, IFolder folder, IProgressMonitor monitor) throws CoreException { List<IClasspathEntry> newEntries = new ArrayList<>(); IClasspathAttribute[] nonDependencyAttribute = new IClasspathAttribute[] {UpdateClasspathAttributeUtil.createNonDependencyAttribute()}; // Add all the jars under lib folder to the classpath File libFolder = folder.getLocation().toFile(); for (File file : libFolder.listFiles()) { IPath path = Path.fromOSString(file.toPath().toString()); newEntries.add(JavaCore.newLibraryEntry(path, null, null, new IAccessRule[0], nonDependencyAttribute, false /* isExported */)); } ClasspathUtil.addClasspathEntries(project, newEntries, monitor); }
private static IAccessRule newAccessRule(final String pattern, final boolean accessible) { return new IAccessRule() { @Override public boolean ignoreIfBetter() { return false; } @Override public IPath getPattern() { return new Path(pattern); } @Override public int getKind() { if (accessible) { return IAccessRule.K_ACCESSIBLE; } else { return IAccessRule.K_NON_ACCESSIBLE; } } }; }
public static boolean isFiltered(TypeNameMatch match) { boolean filteredByPattern = getDefault().filter(match.getFullyQualifiedName()); if (filteredByPattern) return true; int accessibility = match.getAccessibility(); switch (accessibility) { case IAccessRule.K_NON_ACCESSIBLE: return JavaCore.ENABLED.equals( JavaCore.getOption(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK)); case IAccessRule.K_DISCOURAGED: return JavaCore.ENABLED.equals( JavaCore.getOption(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK)); default: return false; } }
/** * Adds the access rules to each list in the given collection. If the last rule in a given * collection is the wild card pattern then no more rules are added to that collection. * * @param accessRules the list of {@link org.eclipse.jdt.core.IAccessRule}s * @param collect the array of lists to collect the {@link org.eclipse.jdt.core.IAccessRule}s in */ private void addRules(IAccessRule[][] accessRules, ArrayList<List<IAccessRule>> collect) { for (int i = 0; i < accessRules.length; i++) { IAccessRule[] libRules = accessRules[i]; List<IAccessRule> list = collect.get(i); // if the last rule is a **/* pattern, don't add any more rules, as they will have no effect if (!list.isEmpty()) { IAccessRule lastRule = list.get(list.size() - 1); if (lastRule.getPattern().equals(ALL_PATTERN)) { continue; } } for (int j = 0; j < libRules.length; j++) { list.add(libRules[j]); } } }
@Override public boolean equals(Object obj) { IAccessRule[][] rules = null; if (obj instanceof RuleEntry) { rules = ((RuleEntry) obj).fRules; } if (obj instanceof IAccessRule[][]) { rules = (IAccessRule[][]) obj; } if (fRules == rules) { return true; } if (rules != null) { if (fRules.length == rules.length) { for (int i = 0; i < fRules.length; i++) { if (!rulesEqual(fRules[i], rules[i])) { return false; } } return true; } } return false; }
private boolean canEdit(List<Object> list) { if (list.size() != 1) return false; Object firstElement= list.get(0); if (firstElement instanceof IAccessRule) return false; if (firstElement instanceof CPListElementAttribute) { CPListElementAttribute attrib= (CPListElementAttribute) firstElement; if (!attrib.isBuiltIn()) { ClasspathAttributeConfiguration config= fAttributeDescriptors.get(attrib.getKey()); return config != null && config.canEdit(attrib.getClasspathAttributeAccess()); } } return true; }
private void removeEntry() { List<Object> selElements= fProjectsList.getSelectedElements(); for (int i= selElements.size() - 1; i >= 0 ; i--) { Object elem= selElements.get(i); if (elem instanceof CPListElementAttribute) { CPListElementAttribute attrib= (CPListElementAttribute) elem; if (attrib.isBuiltIn()) { String key= attrib.getKey(); Object value= null; if (key.equals(CPListElement.ACCESSRULES)) { value= new IAccessRule[0]; } attrib.getParent().setAttribute(key, value); } else { removeCustomAttribute(attrib); } selElements.remove(i); } } if (selElements.isEmpty()) { fProjectsList.refresh(); fClassPathList.dialogFieldChanged(); // validate } else { fProjectsList.removeElements(selElements); } }
@Override public String getText(Object element) { if (element instanceof CPListElement) { return getCPListElementText((CPListElement) element); } else if (element instanceof CPListElementAttribute) { CPListElementAttribute attribute= (CPListElementAttribute) element; String text= getCPListElementAttributeText(attribute); if (attribute.isNonModifiable()) { return Messages.format(NewWizardMessages.CPListLabelProvider_non_modifiable_attribute, text); } return text; } else if (element instanceof CPUserLibraryElement) { return getCPUserLibraryText((CPUserLibraryElement) element); } else if (element instanceof IAccessRule) { IAccessRule rule= (IAccessRule) element; return Messages.format(NewWizardMessages.CPListLabelProvider_access_rules_label, new String[] { AccessRulesLabelProvider.getResolutionLabel(rule.getKind()), BasicElementLabels.getPathLabel(rule.getPattern(), false)}); } return super.getText(element); }
@Override public int category(Object obj) { if (obj instanceof CPListElement) { CPListElement element= (CPListElement) obj; if (element.getParentContainer() != null) { return CONTAINER_ENTRY; } switch (element.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: return LIBRARY; case IClasspathEntry.CPE_PROJECT: return PROJECT; case IClasspathEntry.CPE_SOURCE: return SOURCE; case IClasspathEntry.CPE_VARIABLE: return VARIABLE; case IClasspathEntry.CPE_CONTAINER: return CONTAINER; } } else if (obj instanceof CPListElementAttribute) { return ATTRIBUTE; } else if (obj instanceof IAccessRule) { return ATTRIBUTE; } return OTHER; }
public void acceptUnresolvedName(char[] name) { int relevance = computeBaseRelevance(); relevance += computeRelevanceForResolution(false); relevance += computeRelevanceForInterestingProposal(); relevance += computeRelevanceForCaseMatching(this.completionToken, name); relevance += computeRelevanceForQualification(false); relevance += computeRelevanceForRestrictions(IAccessRule.K_ACCESSIBLE); // no access restriction for local variable CompletionEngine.this.noProposal = false; if(!CompletionEngine.this.requestor.isIgnored(CompletionProposal.LOCAL_VARIABLE_REF)) { InternalCompletionProposal proposal = CompletionEngine.this.createProposal(CompletionProposal.LOCAL_VARIABLE_REF, CompletionEngine.this.actualCompletionPosition); proposal.setSignature(JAVA_LANG_OBJECT_SIGNATURE); proposal.setPackageName(JAVA_LANG_NAME); proposal.setTypeName(OBJECT); proposal.setName(name); proposal.setCompletion(name); proposal.setFlags(Flags.AccDefault); proposal.setReplaceRange(this.startPosition - this.offset, this.endPosition - this.offset); proposal.setTokenRange(this.tokenStart - this.offset, this.tokenEnd - this.offset); proposal.setRelevance(relevance); CompletionEngine.this.requestor.accept(proposal); if(DEBUG) { CompletionEngine.this.printDebug(proposal); } } }
private void writeAccessRules(IvyClasspathContainerImpl ivycp, Document document, Node cpEntryNode, IAccessRule[] accessRules) { if (accessRules == null) { return; } Node accessRulesNode = document.createElement(ACCESS_RULES); cpEntryNode.appendChild(accessRulesNode); for (IAccessRule accessRule : accessRules) { Node accessRuleNode = document.createElement(RULE); accessRulesNode.appendChild(accessRuleNode); NamedNodeMap attributes = accessRuleNode.getAttributes(); Attr attr = document.createAttribute(PATTERN); attr.setValue(accessRule.getPattern().toString()); attributes.setNamedItem(attr); attr = document.createAttribute(KIND); attr.setValue(Integer.toString(accessRule.getKind())); attributes.setNamedItem(attr); } }
private IClasspathEntry doBuildEntry(ArtifactDownloadReport artifact, IPath classpathArtifact, IAccessRule[] rules) { IPath sourcesArtifact = getArtifactPath(artifact, sourceArtifactMatcher, mapping.isMapIfOnlyOneSource(), ""); IPath javadocArtifact = getArtifactPath(artifact, javadocArtifactMatcher, mapping.isMapIfOnlyOneJavadoc(), ""); IPath sources = attachmentManager.getSourceAttachment(classpathArtifact, sourcesArtifact); IPath sourcesRoot = attachmentManager.getSourceAttachmentRoot(classpathArtifact, sourcesArtifact); IClasspathAttribute[] att = getExtraAttribute(classpathArtifact, javadocArtifact); if (sources != null) { IvyDEMessage.debug("Attaching sources " + sources + " to " + classpathArtifact); } if (javadocArtifact != null) { IvyDEMessage.debug("Attaching javadoc " + javadocArtifact + " to " + classpathArtifact); } if (rules != null) { IvyDEMessage.debug("Setting OSGi access rules on " + classpathArtifact); } return JavaCore.newLibraryEntry(classpathArtifact, sources, sourcesRoot, rules, att, false); }
private static void addJunit4ToClasspath(IProject newProject, IProgressMonitor monitor) throws CoreException { IClasspathAttribute nonDependencyAttribute = UpdateClasspathAttributeUtil.createNonDependencyAttribute(); IClasspathEntry junit4Container = JavaCore.newContainerEntry( JUnitCore.JUNIT4_CONTAINER_PATH, new IAccessRule[0], new IClasspathAttribute[] {nonDependencyAttribute}, false); ClasspathUtil.addClasspathEntry(newProject, junit4Container, monitor); }
@Before public void setUp() throws IOException, CoreException { serializedContainer = loadFile("testdata/serializedContainer.json"); List<IClasspathEntry> classpathEntries = Arrays.asList( newClasspathEntry(IClasspathEntry.CPE_LIBRARY, "/test/path/to/jar", "/test/path/to/src", new IClasspathAttribute[] {newAttribute("attrName", "attrValue")}, new IAccessRule[] {newAccessRule("/com/example/accessible", true /* accessible */), newAccessRule("/com/example/nonaccessible", false /* accessible */)}, true)); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { IJavaProject project = invocation.getArgumentAt(0, IJavaProject.class); String fileId = invocation.getArgumentAt(1, String.class); IPath path = stateLocationProvider.getContainerStateFile(project, fileId, false); if (path != null && path.toFile() != null) { path.toFile().delete(); } return null; } }).when(stateLocationProvider).removeContainerStateFile(any(IJavaProject.class), anyString()); when(binaryBaseLocationProvider.getBaseLocation()).thenReturn(new Path("/test")); when(sourceBaseLocationProvider.getBaseLocation()).thenReturn(new Path("/test")); MavenCoordinates coordinates = new MavenCoordinates.Builder() .setGroupId("com.google").setArtifactId("jarartifact").build(); LibraryFile libraryFile = new LibraryFile(coordinates); List<LibraryFile> libraryFiles = new ArrayList<>(); libraryFiles.add(libraryFile); container = new LibraryClasspathContainer(new Path(CONTAINER_PATH), CONTAINER_DESCRIPTION, classpathEntries, libraryFiles); }
private static void compare(LibraryClasspathContainer expected, LibraryClasspathContainer actual) { assertEquals(expected.getPath(), actual.getPath()); assertEquals(expected.getKind(), actual.getKind()); assertEquals(expected.getDescription(), actual.getDescription()); for (int i = 0; i < expected.getClasspathEntries().length; i++) { IClasspathEntry classpathEntry = expected.getClasspathEntries()[i]; IClasspathEntry otherClasspathEntry = actual.getClasspathEntries()[i]; assertEquals(classpathEntry.getPath(), otherClasspathEntry.getPath()); assertEquals(classpathEntry.getEntryKind(), otherClasspathEntry.getEntryKind()); assertEquals(classpathEntry.getSourceAttachmentPath(), otherClasspathEntry.getSourceAttachmentPath()); assertEquals(classpathEntry.isExported(), otherClasspathEntry.isExported()); for (int j = 0; j < classpathEntry.getAccessRules().length; j++) { IAccessRule accessRule = classpathEntry.getAccessRules()[j]; IAccessRule otherAccessRule = otherClasspathEntry.getAccessRules()[j]; assertEquals(accessRule.getKind(), otherAccessRule.getKind()); assertEquals(accessRule.getPattern(), otherAccessRule.getPattern()); } for (int k = 0; k < classpathEntry.getExtraAttributes().length; k++) { IClasspathAttribute classpathAttribute = classpathEntry.getExtraAttributes()[k]; IClasspathAttribute otherClasspathAttribute = otherClasspathEntry.getExtraAttributes()[k]; assertEquals(classpathAttribute.getName(), otherClasspathAttribute.getName()); assertEquals(classpathAttribute.getValue(), otherClasspathAttribute.getValue()); } } List<LibraryFile> libraryFiles = actual.getLibraryFiles(); if (libraryFiles.size() != 0) { for (int i = 0; i < libraryFiles.size(); i++) { assertEquals(libraryFiles.get(i), actual.getLibraryFiles().get(i)); } } }
private static IClasspathEntry makeClasspathEntry(Library library) throws CoreException { IClasspathAttribute[] classpathAttributes = new IClasspathAttribute[1]; if (library.isExport()) { boolean isWebApp = true; classpathAttributes[0] = UpdateClasspathAttributeUtil.createDependencyAttribute(isWebApp); } else { classpathAttributes[0] = UpdateClasspathAttributeUtil.createNonDependencyAttribute(); } // in practice, this method will only be called for the master library IPath containerPath = new Path(LibraryClasspathContainer.CONTAINER_PATH_PREFIX) .append(library.getId()); return JavaCore.newContainerEntry(containerPath, new IAccessRule[0], classpathAttributes, false); }
private void setAccessRules(IAccessRule[] accessRules) { this.accessRules = new SerializableAccessRules[accessRules.length]; for (int i = 0; i < accessRules.length; i++) { IAccessRule rule = accessRules[i]; this.accessRules[i] = new SerializableAccessRules(rule); } }
private IAccessRule[] getAccessRules() { IAccessRule[] rules = new IAccessRule[accessRules.length]; for (int i = 0; i < accessRules.length; i++) { rules[i] = accessRules[i].toAccessRule(); } return rules; }
static AccessRuleKind forInt(int kind) { switch (kind) { case IAccessRule.K_ACCESSIBLE: return ACCESSIBLE; case IAccessRule.K_DISCOURAGED: return DISCOURAGED; case IAccessRule.K_NON_ACCESSIBLE: return FORBIDDEN; default: throw new IllegalArgumentException("Invalid access rule kind value: " + kind); } }
private static IAccessRule[] getAccessRules(List<Filter> filters) { IAccessRule[] accessRules = new IAccessRule[filters.size()]; int idx = 0; for (Filter filter : filters) { int accessRuleKind = filter.isExclude() ? IAccessRule.K_NON_ACCESSIBLE : IAccessRule.K_ACCESSIBLE; accessRules[idx++] = JavaCore.newAccessRule(new Path(filter.getPattern()), accessRuleKind); } return accessRules; }
public ClasspathEntry( int contentKind, int entryKind, IPath path, IPath[] inclusionPatterns, IPath[] exclusionPatterns, IPath sourceAttachmentPath, IPath sourceAttachmentRootPath, IPath specificOutputLocation, boolean isExported, IAccessRule[] accessRules, boolean combineAccessRules, IClasspathAttribute[] extraAttributes) { this( contentKind, entryKind, path, inclusionPatterns, exclusionPatterns, sourceAttachmentPath, sourceAttachmentRootPath, specificOutputLocation, null, isExported, accessRules, combineAccessRules, extraAttributes); }
static IAccessRule[] decodeAccessRules(NodeList list) { if (list == null) return null; int length = list.getLength(); if (length == 0) return null; IAccessRule[] result = new IAccessRule[length]; int index = 0; for (int i = 0; i < length; i++) { Node accessRule = list.item(i); if (accessRule.getNodeType() == Node.ELEMENT_NODE) { Element elementAccessRule = (Element) accessRule; String pattern = elementAccessRule.getAttribute(TAG_PATTERN); if (pattern == null) continue; String tagKind = elementAccessRule.getAttribute(TAG_KIND); int kind; if (TAG_ACCESSIBLE.equals(tagKind)) kind = IAccessRule.K_ACCESSIBLE; else if (TAG_NON_ACCESSIBLE.equals(tagKind)) kind = IAccessRule.K_NON_ACCESSIBLE; else if (TAG_DISCOURAGED.equals(tagKind)) kind = IAccessRule.K_DISCOURAGED; else continue; boolean ignoreIfBetter = "true".equals(elementAccessRule.getAttribute(TAG_IGNORE_IF_BETTER)); // $NON-NLS-1$ result[index++] = new ClasspathAccessRule( new Path(pattern), ignoreIfBetter ? kind | IAccessRule.IGNORE_IF_BETTER : kind); } } if (index != length) System.arraycopy(result, 0, result = new IAccessRule[index], 0, index); return result; }
/** @see org.eclipse.jdt.core.IClasspathEntry#getAccessRules() */ public IAccessRule[] getAccessRules() { if (this.accessRuleSet == null) return NO_ACCESS_RULES; AccessRule[] rules = this.accessRuleSet.getAccessRules(); int length = rules.length; if (length == 0) return NO_ACCESS_RULES; IAccessRule[] result = new IAccessRule[length]; System.arraycopy(rules, 0, result, 0, length); return result; }
public IAccessRule[][] getAccessRules( IExecutionEnvironment environment, IVMInstallType vm, LibraryLocation[] libraries, IJavaProject project) { IAccessRule[][] allRules = null; allRules = fgRules.get(environment.getId()); if (allRules == null || allRules.length != libraries.length) { // if a different number of libraries, create a new set of rules String[] packages = retrieveSystemPackages(environment); IAccessRule[] packageRules = null; if (packages.length > 0) { packageRules = new IAccessRule[packages.length + 1]; for (int i = 0; i < packages.length; i++) { packageRules[i] = JavaCore.newAccessRule( new Path(packages[i].replace('.', IPath.SEPARATOR)), IAccessRule.K_ACCESSIBLE); } // add IGNORE_IF_BETTER flag in case another explicit entry allows access (see bug 228488) packageRules[packages.length] = JavaCore.newAccessRule( new Path("**/*"), IAccessRule.K_NON_ACCESSIBLE | IAccessRule.IGNORE_IF_BETTER); // $NON-NLS-1$ } else { packageRules = new IAccessRule[0]; } allRules = new IAccessRule[libraries.length][]; for (int i = 0; i < allRules.length; i++) { allRules[i] = packageRules; } fgRules.put(environment.getId(), allRules); } return allRules; }
public IAccessRule[][] getAccessRules( IVMInstallType vm, LibraryLocation[] libraries, IJavaProject project) { IAccessRuleParticipant[] participants = getParticipants(); Map<IAccessRuleParticipant, IAccessRule[][]> rulesByParticipant = collectRulesByParticipant(participants, vm, libraries, project); synchronized (this) { Map<IAccessRuleParticipant, IAccessRule[][]> cachedRules = fParticipantMap.get(vm); if (cachedRules == null || !cachedRules.equals(rulesByParticipant)) { ArrayList<List<IAccessRule>> libLists = new ArrayList<List<IAccessRule>>(); // array of lists of access rules for (int i = 0; i < libraries.length; i++) { libLists.add(new ArrayList<IAccessRule>()); } for (int i = 0; i < participants.length; i++) { IAccessRuleParticipant participant = participants[i]; addRules(rulesByParticipant.get(participant), libLists); } IAccessRule[][] allRules = new IAccessRule[libraries.length][]; for (int i = 0; i < libLists.size(); i++) { List<IAccessRule> l = libLists.get(i); allRules[i] = l.toArray(new IAccessRule[l.size()]); } fParticipantMap.put(vm, rulesByParticipant); fRuleCache.put(vm, allRules); return allRules; } return fRuleCache.get(vm); } }
/** * Returns a map of participant to the access rules for that participant for the given VM, * libraries, and project. * * @param participants access rule participants * @param vm the VM * @param libraries the {@link LibraryLocation}s * @param project the {@link org.eclipse.jdt.core.IJavaProject} context * @return the mapping of {@link IAccessRuleParticipant} to {@link * org.eclipse.jdt.core.IAccessRule}s */ private Map<IAccessRuleParticipant, IAccessRule[][]> collectRulesByParticipant( IAccessRuleParticipant[] participants, IVMInstallType vm, LibraryLocation[] libraries, IJavaProject project) { Map<IAccessRuleParticipant, IAccessRule[][]> map = new HashMap<IAccessRuleParticipant, IAccessRule[][]>(); for (int i = 0; i < participants.length; i++) { // TODO: use safe runnable map.put(participants[i], participants[i].getAccessRules(this, vm, libraries, project)); } return map; }
/** * Checks if the two arrays of rules are equal (same rules in each position in the array) * * @param a First list of rules to compare, must not be <code>null</code> * @param b Second list of rules to compare, must not be <code>null</code> * @return <code>true</code> if the arrays are equal, <code>false</code> otherwise */ private static boolean rulesEqual(IAccessRule[] a, IAccessRule[] b) { if (a == b) { return true; } if (a.length != b.length) { return false; } for (int j = 0; j < a.length; j++) { if (!a[j].equals(b[j])) { return false; } } return true; }
private void setClasspathEntry(IClasspathEntry entry) { this.kind = entry.getEntryKind(); this.path = entry.getPath(); this.exported = entry.isExported(); this.outputLocation = entry.getOutputLocation(); this.accessRules = new ArrayList<>(); for (IAccessRule rule : entry.getAccessRules()) { this.accessRules.add(rule); } this.attributes = new HashMap<>(); for (IClasspathAttribute attribute : entry.getExtraAttributes()) { attributes.put(attribute.getName(), attribute.getValue()); } this.sourcePath = entry.getSourceAttachmentPath(); this.sourceRootPath = entry.getSourceAttachmentRootPath(); setInclusionPatterns(entry.getInclusionPatterns()); setExclusionPatterns(entry.getExclusionPatterns()); this.combineAccessRules = entry.combineAccessRules(); String groupId = attributes.get(ClasspathManager.GROUP_ID_ATTRIBUTE); String artifactId = attributes.get(ClasspathManager.ARTIFACT_ID_ATTRIBUTE); String version = attributes.get(ClasspathManager.VERSION_ATTRIBUTE); String packaging = attributes.get(ClasspathManager.PACKAGING_ATTRIBUTE); String classifier = attributes.get(ClasspathManager.CLASSIFIER_ATTRIBUTE); if (groupId != null && artifactId != null && version != null) { this.artifactKey = new MavenArtifactKey(groupId, artifactId, version, packaging, classifier); } }
@Override public IClasspathEntry[] getClasspathEntries() { // Note that the GWT SDK puts the javadoc in "doc/javadoc" IPath gwtJavadocLocation = getInstallationPath().append(new Path("doc/javadoc")); IClasspathAttribute[] extraAttributes = new IClasspathAttribute[0]; if (gwtJavadocLocation.toFile().exists()) { extraAttributes = new IClasspathAttribute[] {JavaCore.newClasspathAttribute( IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, gwtJavadocLocation.toFile() .toURI().toString())}; } List<IClasspathEntry> buildClasspathEntries = new ArrayList<IClasspathEntry>(); if (validate().isOK()) { List<IPath> buildClasspaths = getBuildClasspaths(); for (IPath buildClasspath : buildClasspaths) { if (buildClasspath.lastSegment().startsWith("gwt-")) { buildClasspathEntries.add(JavaCore.newLibraryEntry(buildClasspath, null, null, new IAccessRule[0], extraAttributes, false)); } else { buildClasspathEntries.add(JavaCore.newLibraryEntry(buildClasspath, Util.findSourcesJarForClassesJar(buildClasspath), null, new IAccessRule[0], new IClasspathAttribute[0], false)); } } } return buildClasspathEntries.toArray(NO_ICLASSPATH_ENTRIES); }
private void addEntry(final List<IClasspathEntry> cpEntries, final String bundleId) { Bundle bundle = Platform.getBundle(bundleId); if (bundle != null) { cpEntries.add(JavaCore.newLibraryEntry(bundlePath(bundle), sourcePath(bundle), null, new IAccessRule[] {}, null, false)); } }
public static boolean isFiltered(TypeNameMatch match) { boolean filteredByPattern= getDefault().filter(match.getFullyQualifiedName()); if (filteredByPattern) return true; int accessibility= match.getAccessibility(); switch (accessibility) { case IAccessRule.K_NON_ACCESSIBLE: return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_FORBIDDEN_REFERENCE_CHECK)); case IAccessRule.K_DISCOURAGED: return JavaCore.ENABLED.equals(JavaCore.getOption(JavaCore.CODEASSIST_DISCOURAGED_REFERENCE_CHECK)); default: return false; } }
private boolean canRemove(List<Object> list) { if (list.size() == 0) { return false; } for (int i= 0; i < list.size(); i++) { Object elem= list.get(i); if (elem instanceof CPListElementAttribute) { CPListElementAttribute attrib= (CPListElementAttribute) elem; if (attrib.isNonModifiable()) { return false; } if (attrib.isBuiltIn()) { if (attrib.getKey().equals(CPListElement.ACCESSRULES)) { return ((IAccessRule[]) attrib.getValue()).length > 0; } if (attrib.getValue() == null) { return false; } } else { ClasspathAttributeConfiguration config= fAttributeDescriptors.get(attrib.getKey()); if (config == null || !config.canRemove(attrib.getClasspathAttributeAccess()) ) { return false; } } } else if (elem instanceof CPListElement) { // ok to remove } else if (elem instanceof CPUserLibraryElement) { // ok to remove } else { // unknown element return false; } } return true; }
public Object[] getChildren(TreeListDialogField<CPUserLibraryElement> field, Object element) { if (element instanceof CPUserLibraryElement) { CPUserLibraryElement elem= (CPUserLibraryElement) element; return elem.getChildren(); } else if (element instanceof CPListElement) { return ((CPListElement)element).getChildren(false); } else if (element instanceof CPListElementAttribute) { CPListElementAttribute attribute= (CPListElementAttribute) element; if (CPListElement.ACCESSRULES.equals(attribute.getKey())) { return (IAccessRule[]) attribute.getValue(); } } return EMPTY; }
public Object[] getChildren(TreeListDialogField<CPListElement> field, Object element) { if (element instanceof CPListElement) { return ((CPListElement) element).getChildren(false); } else if (element instanceof CPListElementAttribute) { CPListElementAttribute attribute= (CPListElementAttribute) element; if (CPListElement.ACCESSRULES.equals(attribute.getKey())) { return (IAccessRule[]) attribute.getValue(); } } return EMPTY_ARR; }
private boolean canRemove(List<?> selElements) { if (selElements.size() == 0) { return false; } for (int i= 0; i < selElements.size(); i++) { Object elem= selElements.get(i); if (elem instanceof CPListElementAttribute) { CPListElementAttribute attrib= (CPListElementAttribute) elem; if (attrib.isNonModifiable()) { return false; } if (attrib.isBuiltIn()) { if (attrib.getParent().isInContainer(JavaRuntime.JRE_CONTAINER) && CPListElement.ACCESSRULES.equals(attrib.getKey())) { return false; // workaround for 166519 until we have full story } if (attrib.getKey().equals(CPListElement.ACCESSRULES)) { return ((IAccessRule[]) attrib.getValue()).length > 0; } if (attrib.getValue() == null) { return false; } } else { if (!canRemoveCustomAttribute(attrib)) { return false; } } } else if (elem instanceof CPListElement) { CPListElement curr= (CPListElement) elem; if (curr.getParentContainer() != null) { return false; } } else { // unknown element return false; } } return true; }
private ListDialogField<IAccessRule> createListContents(CPListElement entryToEdit) { String label= NewWizardMessages.AccessRulesDialog_rules_label; String[] buttonLabels= new String[] { NewWizardMessages.AccessRulesDialog_rules_add, NewWizardMessages.AccessRulesDialog_rules_edit, null, NewWizardMessages.AccessRulesDialog_rules_up, NewWizardMessages.AccessRulesDialog_rules_down, null, NewWizardMessages.AccessRulesDialog_rules_remove }; TypeRestrictionAdapter adapter= new TypeRestrictionAdapter(); AccessRulesLabelProvider labelProvider= new AccessRulesLabelProvider(); ListDialogField<IAccessRule> patternList= new ListDialogField<IAccessRule>(adapter, buttonLabels, labelProvider); patternList.setDialogFieldListener(adapter); patternList.setLabelText(label); patternList.setRemoveButtonIndex(IDX_REMOVE); patternList.setUpButtonIndex(IDX_UP); patternList.setDownButtonIndex(IDX_DOWN); patternList.enableButton(IDX_EDIT, false); IAccessRule[] rules= (IAccessRule[]) entryToEdit.getAttribute(CPListElement.ACCESSRULES); ArrayList<IAccessRule> elements= new ArrayList<IAccessRule>(rules.length); for (int i= 0; i < rules.length; i++) { elements.add(rules[i]); } patternList.setElements(elements); patternList.selectFirstElement(); return patternList; }