List of usage examples for org.eclipse.jdt.core IAccessRule K_NON_ACCESSIBLE
int K_NON_ACCESSIBLE
To view the source code for org.eclipse.jdt.core IAccessRule K_NON_ACCESSIBLE.
Click Source Link
From source file:at.bestsolution.javafx.ide.jdt.internal.JavaEditor.java
License:Open Source License
@Inject public JavaEditor(BorderPane pane, IEditorInput input) { editor = new SourceEditor(); pane.setCenter(editor);//w w w . ja v a2s .c om IResourceFileInput fsInput = (IResourceFileInput) input; try { unit = ((ICompilationUnit) JavaCore.create(fsInput.getFile())) .getWorkingCopy(new FXWorkingCopyOwner(new IProblemRequestor() { private List<ProblemMarker> l = new ArrayList<>(); @Override public boolean isActive() { // TODO Auto-generated method stub return true; } @Override public void endReporting() { setMarkers(l); } @Override public void beginReporting() { l.clear(); } @Override public void acceptProblem(IProblem problem) { int linenumber = problem.getSourceLineNumber(); int startCol = problem.getSourceStart(); int endCol = problem.getSourceEnd(); if (endCol == startCol) { endCol++; } String description = problem.getMessage(); ProblemMarker marker = new ProblemMarker( problem.isError() ? at.bestsolution.javafx.ide.editor.ProblemMarker.Type.ERROR : at.bestsolution.javafx.ide.editor.ProblemMarker.Type.WARNING, linenumber, startCol, endCol, description); l.add(marker); } }), new NullProgressMonitor()); } catch (JavaModelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } final Document doc = createDocument(unit); editor.setDocument(doc); editor.setContentProposalComputer(new ContentProposalComputer() { @Override public List<Proposal> computeProposals(String line, String prefix, int offset) { final List<Proposal> l = new ArrayList<ContentProposalComputer.Proposal>(); try { unit.codeComplete(offset, new CompletionRequestor() { @Override public void accept(CompletionProposal proposal) { String completion = new String(proposal.getCompletion()); if (!Flags.isPublic(proposal.getFlags())) { return; } if (proposal.getKind() == CompletionProposal.METHOD_REF) { String sig = Signature.toString(new String(proposal.getSignature()), new String(proposal.getName()), null, false, false); StyledString s = new StyledString(sig + " : " + Signature.getSimpleName(Signature .toString(Signature.getReturnType(new String(proposal.getSignature()))))); s.appendString( " - " + Signature.getSignatureSimpleName( new String(proposal.getDeclarationSignature())), Style.colored("#AAAAAA")); l.add(new Proposal(Type.METHOD, completion, s)); } else if (proposal.getKind() == CompletionProposal.FIELD_REF) { StyledString s = new StyledString( completion + " : " + (proposal.getSignature() != null ? Signature.getSignatureSimpleName( new String(proposal.getSignature())) : "<unknown>")); s.appendString( " - " + (proposal.getDeclarationSignature() != null ? Signature.getSignatureSimpleName( new String(proposal.getDeclarationSignature())) : "<unknown>"), Style.colored("#AAAAAA")); l.add(new Proposal(Type.FIELD, completion, s)); } else if (proposal.getKind() == CompletionProposal.TYPE_REF) { if (proposal.getAccessibility() == IAccessRule.K_NON_ACCESSIBLE) { return; } StyledString s = new StyledString( Signature.getSignatureSimpleName(new String(proposal.getSignature()))); s.appendString(" - " + new String(proposal.getDeclarationSignature()), Style.colored("#AAAAAA")); l.add(new Proposal(Type.TYPE, new String(proposal.getCompletion()), s)); } else { System.err.println(proposal); } } }); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return l; } }); editor.setSaveCallback(new Runnable() { @Override public void run() { try { unit.commitWorkingCopy(true, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); try { unit.reconcile(ICompilationUnit.NO_AST, true, null, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.android.ide.eclipse.adt.internal.project.AndroidClasspathContainerInitializer.java
License:Open Source License
/** * Generates an array of {@link IClasspathEntry} from a set of paths. * @see #getTargetPaths(IAndroidTarget)// w w w .j av a2s . c om */ private static IClasspathEntry[] createClasspathEntriesFromPaths(String[] paths, IAndroidTarget target) { ArrayList<IClasspathEntry> list = new ArrayList<IClasspathEntry>(); // First, we create the IClasspathEntry for the framework. // now add the android framework to the class path. // create the path object. IPath androidLib = new Path(paths[CACHE_INDEX_JAR]); IPath androidSrc = null; String androidSrcOsPath = null; IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); if (target != null) { androidSrcOsPath = ProjectHelper.loadStringProperty(root, getAndroidSourceProperty(target)); } if (androidSrcOsPath != null && androidSrcOsPath.trim().length() > 0) { androidSrc = new Path(androidSrcOsPath); } if (androidSrc == null) { androidSrc = new Path(paths[CACHE_INDEX_SRC]); File androidSrcFile = new File(paths[CACHE_INDEX_SRC]); if (!androidSrcFile.isDirectory()) { androidSrc = null; } } if (androidSrc == null && target != null) { Bundle bundle = getSourceBundle(); if (bundle != null) { AndroidVersion version = target.getVersion(); String apiString = version.getApiString(); String sourcePath = apiString + SOURCES_ZIP; URL sourceURL = bundle.getEntry(sourcePath); if (sourceURL != null) { URL url = null; try { url = FileLocator.resolve(sourceURL); } catch (IOException ignore) { } if (url != null) { androidSrcOsPath = url.getFile(); if (new File(androidSrcOsPath).isFile()) { androidSrc = new Path(androidSrcOsPath); } } } } } // create the java doc link. String androidApiURL = ProjectHelper.loadStringProperty(root, PROPERTY_ANDROID_API); String apiURL = null; if (androidApiURL != null && testURL(androidApiURL)) { apiURL = androidApiURL; } else { if (testURL(paths[CACHE_INDEX_DOCS_URI])) { apiURL = paths[CACHE_INDEX_DOCS_URI]; } else if (testURL(ANDROID_API_REFERENCE)) { apiURL = ANDROID_API_REFERENCE; } } IClasspathAttribute[] attributes = null; if (apiURL != null && !NULL_API_URL.equals(apiURL)) { IClasspathAttribute cpAttribute = JavaCore .newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, apiURL); attributes = new IClasspathAttribute[] { cpAttribute }; } // create the access rule to restrict access to classes in // com.android.internal IAccessRule accessRule = JavaCore.newAccessRule(new Path("com/android/internal/**"), //$NON-NLS-1$ IAccessRule.K_NON_ACCESSIBLE); IClasspathEntry frameworkClasspathEntry = JavaCore.newLibraryEntry(androidLib, androidSrc, // source attachment path null, // default source attachment root path. new IAccessRule[] { accessRule }, attributes, false // not exported. ); list.add(frameworkClasspathEntry); // now deal with optional libraries if (paths.length >= 5) { String docPath = paths[CACHE_INDEX_OPT_DOCS_URI]; int i = 4; while (i < paths.length) { Path jarPath = new Path(paths[i++]); attributes = null; if (docPath.length() > 0) { attributes = new IClasspathAttribute[] { JavaCore .newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, docPath) }; } IClasspathEntry entry = JavaCore.newLibraryEntry(jarPath, null, // source attachment path null, // default source attachment root path. null, attributes, false // not exported. ); list.add(entry); } } if (apiURL != null) { ProjectHelper.saveStringProperty(root, PROPERTY_ANDROID_API, apiURL); } if (androidSrc != null && target != null) { ProjectHelper.saveStringProperty(root, getAndroidSourceProperty(target), androidSrc.toOSString()); } return list.toArray(new IClasspathEntry[list.size()]); }
From source file:com.android.ide.eclipse.adt.project.internal.AndroidClasspathContainerInitializer.java
License:Open Source License
/** * Generates an array of {@link IClasspathEntry} from a set of paths. * @see #getTargetPaths(IAndroidTarget)/*from ww w . j av a 2s. c o m*/ */ private static IClasspathEntry[] createClasspathEntriesFromPaths(String[] paths) { ArrayList<IClasspathEntry> list = new ArrayList<IClasspathEntry>(); // First, we create the IClasspathEntry for the framework. // now add the android framework to the class path. // create the path object. IPath android_lib = new Path(paths[CACHE_INDEX_JAR]); IPath android_src = new Path(paths[CACHE_INDEX_SRC]); // create the java doc link. IClasspathAttribute cpAttribute = JavaCore.newClasspathAttribute( IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, paths[CACHE_INDEX_DOCS_URI]); // create the access rule to restrict access to classes in com.android.internal IAccessRule accessRule = JavaCore.newAccessRule(new Path("com/android/internal/**"), //$NON-NLS-1$ IAccessRule.K_NON_ACCESSIBLE); IClasspathEntry frameworkClasspathEntry = JavaCore.newLibraryEntry(android_lib, android_src, // source attachment path null, // default source attachment root path. new IAccessRule[] { accessRule }, new IClasspathAttribute[] { cpAttribute }, false // not exported. ); list.add(frameworkClasspathEntry); // now deal with optional libraries if (paths.length >= 5) { String docPath = paths[CACHE_INDEX_OPT_DOCS_URI]; int i = 4; while (i < paths.length) { Path jarPath = new Path(paths[i++]); IClasspathAttribute[] attributes = null; if (docPath.length() > 0) { attributes = new IClasspathAttribute[] { JavaCore .newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, docPath) }; } IClasspathEntry entry = JavaCore.newLibraryEntry(jarPath, null, // source attachment path null, // default source attachment root path. null, attributes, false // not exported. ); list.add(entry); } } return list.toArray(new IClasspathEntry[list.size()]); }
From source file:com.codenvy.ide.ext.java.server.core.launching.environments.DefaultAccessRuleParticipant.java
License:Open Source License
public IAccessRule[][] getAccessRules(IExecutionEnvironment environment, IVMInstallType vm, LibraryLocation[] libraries, IJavaProject project) { IAccessRule[][] allRules = null;//from w ww . j a va2 s . c om 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; }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
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//from w ww. java 2s . c o m 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; }
From source file:com.codenvy.ide.ext.java.server.internal.core.ClasspathEntry.java
License:Open Source License
public static IAccessRule[] getAccessRules(IPath[] accessibleFiles, IPath[] nonAccessibleFiles) { int accessibleFilesLength = accessibleFiles == null ? 0 : accessibleFiles.length; int nonAccessibleFilesLength = nonAccessibleFiles == null ? 0 : nonAccessibleFiles.length; int length = accessibleFilesLength + nonAccessibleFilesLength; if (length == 0) return null; IAccessRule[] accessRules = new IAccessRule[length]; for (int i = 0; i < accessibleFilesLength; i++) { accessRules[i] = JavaCore.newAccessRule(accessibleFiles[i], IAccessRule.K_ACCESSIBLE); }//from w w w . j ava 2 s.c om for (int i = 0; i < nonAccessibleFilesLength; i++) { accessRules[accessibleFilesLength + i] = JavaCore.newAccessRule(nonAccessibleFiles[i], IAccessRule.K_NON_ACCESSIBLE); } return accessRules; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.TypeNameMatchRequestorWrapper.java
License:Open Source License
public void acceptType(int modifiers, char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, String path, AccessRestriction access) { // Get type// ww w .j a v a 2 s . co m try { IType type = null; if (this.handleFactory != null) { //todo openable Openable openable = null;//this.handleFactory.createOpenable(path, this.scope); if (openable == null) return; switch (openable.getElementType()) { case IJavaElement.COMPILATION_UNIT: ICompilationUnit cu = (ICompilationUnit) openable; if (enclosingTypeNames != null && enclosingTypeNames.length > 0) { type = cu.getType(new String(enclosingTypeNames[0])); for (int j = 1, l = enclosingTypeNames.length; j < l; j++) { type = type.getType(new String(enclosingTypeNames[j])); } type = type.getType(new String(simpleTypeName)); } else { type = cu.getType(new String(simpleTypeName)); } break; case IJavaElement.CLASS_FILE: type = ((IClassFile) openable).getType(); break; } } else { int separatorIndex = path.indexOf(IJavaSearchScope.JAR_FILE_ENTRY_SEPARATOR); type = separatorIndex == -1 ? createTypeFromPath(path, new String(simpleTypeName), enclosingTypeNames) : createTypeFromJar(path, separatorIndex); } // Accept match if the type has been found if (type != null) { // hierarchy scopes require one more check: if (!(this.scope instanceof org.eclipse.jdt.internal.core.search.HierarchyScope) || ((HierarchyScope) this.scope).enclosesFineGrained(type)) { // Create the match final JavaSearchTypeNameMatch match = new JavaSearchTypeNameMatch(type, modifiers); // Update match accessibility if (access != null) { switch (access.getProblemId()) { case IProblem.ForbiddenReference: match.setAccessibility(IAccessRule.K_NON_ACCESSIBLE); break; case IProblem.DiscouragedReference: match.setAccessibility(IAccessRule.K_DISCOURAGED); break; } } // Accept match this.requestor.acceptTypeNameMatch(match); } } } catch (JavaModelException e) { // skip } }
From source file:com.google.cloud.tools.eclipse.appengine.libraries.persistence.LibraryClasspathContainerSerializerTest.java
License:Apache License
private IAccessRule getAccessRule(final String pattern, final boolean accessible) { return new IAccessRule() { @Override/*w w w . j a v a 2 s. com*/ 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; } } }; }
From source file:com.google.cloud.tools.eclipse.appengine.libraries.repository.LibraryClasspathContainerResolverService.java
License:Apache License
private static IAccessRule[] getAccessRules(List<Filter> filters) { IAccessRule[] accessRules = new IAccessRule[filters.size()]; int idx = 0;/* w ww . j a v a 2 s . c o m*/ 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; }
From source file:io.sarl.eclipse.util.JavaClasspathParser.java
License:Apache License
@SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:innerassignment" })
private static IAccessRule[] decodeAccessRules(NodeList list) {
if (list == null) {
return null;
}//w ww . ja v a 2s. c om
final int length = list.getLength();
if (length == 0) {
return null;
}
IAccessRule[] result = new IAccessRule[length];
int index = 0;
for (int i = 0; i < length; i++) {
final Node accessRule = list.item(i);
if (accessRule.getNodeType() == Node.ELEMENT_NODE) {
final Element elementAccessRule = (Element) accessRule;
final String pattern = elementAccessRule.getAttribute(ClasspathEntry.TAG_PATTERN);
if (pattern == null) {
continue;
}
final String tagKind = elementAccessRule.getAttribute(ClasspathEntry.TAG_KIND);
final int kind;
if (ClasspathEntry.TAG_ACCESSIBLE.equals(tagKind)) {
kind = IAccessRule.K_ACCESSIBLE;
} else if (ClasspathEntry.TAG_NON_ACCESSIBLE.equals(tagKind)) {
kind = IAccessRule.K_NON_ACCESSIBLE;
} else if (ClasspathEntry.TAG_DISCOURAGED.equals(tagKind)) {
kind = IAccessRule.K_DISCOURAGED;
} else {
continue;
}
final boolean ignoreIfBetter = "true" //$NON-NLS-1$
.equals(elementAccessRule.getAttribute(ClasspathEntry.TAG_IGNORE_IF_BETTER));
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;
}