List of usage examples for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE
int K_SOURCE
To view the source code for org.eclipse.jdt.core IPackageFragmentRoot K_SOURCE.
Click Source Link
From source file:com.siteview.mde.internal.core.builders.BundleErrorReporter.java
License:Open Source License
private void addProjectPackages(IProject proj) { try {//from ww w. j av a 2s. c o m if (proj.hasNature(JavaCore.NATURE_ID)) { IJavaProject jp = JavaCore.create(proj); IPackageFragmentRoot[] roots = jp.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE || (roots[i].getKind() == IPackageFragmentRoot.K_BINARY && !roots[i].isExternal())) { IJavaElement[] children = roots[i].getChildren(); for (int j = 0; j < children.length; j++) { IPackageFragment f = (IPackageFragment) children[j]; String name = f.getElementName(); if (name.equals("")) //$NON-NLS-1$ name = "."; //$NON-NLS-1$ if (f.hasChildren() || f.getNonJavaResources().length > 0) fProjectPackages.add(name); } } } } } catch (CoreException ce) { } }
From source file:com.siteview.mde.internal.core.util.ManifestUtils.java
License:Open Source License
public static boolean isImmediateRoot(IPackageFragmentRoot root) throws JavaModelException { int kind = root.getKind(); return kind == IPackageFragmentRoot.K_SOURCE || (kind == IPackageFragmentRoot.K_BINARY && !root.isExternal()); }
From source file:com.siteview.mde.internal.core.util.PDEJavaHelper.java
License:Open Source License
private static IPackageFragmentRoot[] getRoots(IJavaProject jProject) { ArrayList result = new ArrayList(); try {/*from w w w . jav a 2s. c o m*/ IPackageFragmentRoot[] roots = jProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE || jProject.getProject().equals(roots[i].getCorrespondingResource()) || (roots[i].isArchive() && !roots[i].isExternal())) { result.add(roots[i]); } } } catch (JavaModelException e) { } return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]); }
From source file:com.siteview.mde.internal.launching.launcher.LaunchArgumentsHelper.java
License:Open Source License
private static String getStartupJarPath() throws CoreException { IMonitorModelBase model = MonitorRegistry.findModel("org.eclipse.platform"); //$NON-NLS-1$ if (model != null && model.getUnderlyingResource() != null) { IProject project = model.getUnderlyingResource().getProject(); if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject jProject = JavaCore.create(project); IPackageFragmentRoot[] roots = jProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE && roots[i].getPackageFragment("org.eclipse.core.launcher").exists()) { //$NON-NLS-1$ IPath path = jProject.getOutputLocation().removeFirstSegments(1); return project.getLocation().append(path).toOSString(); }/*from w w w . j ava 2 s .c o m*/ } } if (project.getFile("startup.jar").exists()) //$NON-NLS-1$ return project.getFile("startup.jar").getLocation().toOSString(); //$NON-NLS-1$ } File startupJar = new Path(TargetPlatform.getLocation()).append("startup.jar").toFile(); //$NON-NLS-1$ // if something goes wrong with the preferences, fall back on the startup.jar // in the running eclipse. if (!startupJar.exists()) startupJar = new Path(TargetPlatform.getDefaultLocation()).append("startup.jar").toFile(); //$NON-NLS-1$ return startupJar.exists() ? startupJar.getAbsolutePath() : null; }
From source file:com.siteview.mde.internal.ui.editor.build.RuntimeInfoSection.java
License:Open Source License
private IPackageFragmentRoot[] computeSourceFolders() { ArrayList folders = new ArrayList(); IBuildModel buildModel = getBuildModel(); IProject project = buildModel.getUnderlyingResource().getProject(); try {//from w w w . jav a 2 s . c o m if (project.hasNature(JavaCore.NATURE_ID)) { IJavaProject jProject = JavaCore.create(project); IPackageFragmentRoot[] roots = jProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) folders.add(roots[i]); } } catch (JavaModelException e) { MDEPlugin.logException(e); } catch (CoreException e) { MDEPlugin.logException(e); } return (IPackageFragmentRoot[]) folders.toArray(new IPackageFragmentRoot[folders.size()]); }
From source file:com.siteview.mde.internal.ui.editor.contentassist.TypePackageCompletionProcessor.java
License:Open Source License
private ICompilationUnit getWorkingCopy(IProject project) throws JavaModelException { IPackageFragmentRoot[] roots = JavaCore.create(project).getPackageFragmentRoots(); if (roots.length > 0) { IPackageFragment frag = null;// w w w. j a va 2 s. c o m for (int i = 0; i < roots.length; i++) if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE || project.equals(roots[i].getCorrespondingResource()) || (roots[i].isArchive() && !roots[i].isExternal())) { IJavaElement[] elems = roots[i].getChildren(); if ((elems.length > 0) && (i < elems.length) && (elems[i] instanceof IPackageFragment)) { frag = (IPackageFragment) elems[i]; break; } } if (frag != null) return frag.getCompilationUnit("Dummy2.java").getWorkingCopy(new NullProgressMonitor()); //$NON-NLS-1$ } return null; }
From source file:com.siteview.mde.internal.ui.editor.monitor.ImportPackageSection.java
License:Open Source License
private void setElements(ConditionalListSelectionDialog dialog) { Set forbidden = getForbiddenIds(); boolean allowJava = "true".equals(getBundle().getHeader(ICoreConstants.ECLIPSE_JREBUNDLE)); //$NON-NLS-1$ ArrayList elements = new ArrayList(); ArrayList conditional = new ArrayList(); IMonitorModelBase[] models = MonitorRegistry.getActiveModels(); Set nameVersions = new HashSet(); // Set of NameVersionDescriptors, used to remove duplicate entries for (int i = 0; i < models.length; i++) { BundleDescription desc = models[i].getBundleDescription(); // If the current model is a fragment, it can export packages only if its parent has hasExtensibleAPI set if (isFragmentThatCannotExportPackages(models[i])) continue; String id = desc == null ? null : desc.getSymbolicName(); if (id == null || forbidden.contains(id)) continue; ExportPackageDescription[] exported = desc.getExportPackages(); for (int j = 0; j < exported.length; j++) { String name = exported[j].getName(); NameVersionDescriptor nameVersion = new NameVersionDescriptor(exported[j].getName(), exported[j].getVersion().toString(), NameVersionDescriptor.TYPE_PACKAGE); if (("java".equals(name) || name.startsWith("java.")) && !allowJava) //$NON-NLS-1$ //$NON-NLS-2$ continue; if (nameVersions.add(nameVersion) && (fHeader == null || !fHeader.hasPackage(name))) elements.add(new ImportItemWrapper(exported[j])); }/* ww w .ja va 2 s. com*/ IMonitorModelBase model = (IMonitorModelBase) getPage().getMDEEditor().getAggregateModel(); if (model instanceof IBundlePluginModelBase) { IBundleModel bmodel = ((IBundlePluginModelBase) model).getBundleModel(); if (bmodel != null) { ExportPackageHeader header = (ExportPackageHeader) bmodel.getBundle() .getManifestHeader(Constants.EXPORT_PACKAGE); if (header != null) { ExportPackageObject[] pkgs = header.getPackages(); for (int j = 0; j < pkgs.length; j++) { String name = pkgs[j].getName(); String version = pkgs[j].getVersion(); NameVersionDescriptor nameVersion = new NameVersionDescriptor(name, version, NameVersionDescriptor.TYPE_PACKAGE); if (nameVersions.add(nameVersion) && (fHeader == null || !fHeader.hasPackage(name))) elements.add(new ImportItemWrapper(pkgs[j])); } } } } } for (int i = 0; i < models.length; i++) { try { // add un-exported packages in workspace non-binary plug-ins IResource resource = models[i].getUnderlyingResource(); IProject project = resource != null ? resource.getProject() : null; if (project == null || !project.hasNature(JavaCore.NATURE_ID) || WorkspaceModelManager.isBinaryProject(project) || !PDEProject.getManifest(project).exists()) continue; // If the current model is a fragment, it can export packages only if its parent has hasExtensibleAPI set if (isFragmentThatCannotExportPackages(models[i])) continue; IJavaProject jp = JavaCore.create(project); IPackageFragmentRoot[] roots = jp.getPackageFragmentRoots(); for (int j = 0; j < roots.length; j++) { if (roots[j].getKind() == IPackageFragmentRoot.K_SOURCE || (roots[j].getKind() == IPackageFragmentRoot.K_BINARY && !roots[j].isExternal())) { IJavaElement[] children = roots[j].getChildren(); for (int k = 0; k < children.length; k++) { IPackageFragment f = (IPackageFragment) children[k]; String name = f.getElementName(); NameVersionDescriptor nameVersion = new NameVersionDescriptor(name, null, NameVersionDescriptor.TYPE_PACKAGE); if (name.equals("")) //$NON-NLS-1$ name = "."; //$NON-NLS-1$ if (nameVersions.add(nameVersion) && (f.hasChildren() || f.getNonJavaResources().length > 0)) conditional.add(new ImportItemWrapper(f)); } } } } catch (CoreException e) { } } dialog.setElements(elements.toArray()); dialog.setConditionalElements(conditional.toArray()); }
From source file:com.siteview.mde.internal.ui.editor.monitor.ImportPackageSection.java
License:Open Source License
private IPackageFragmentRoot[] getSourceRoots() throws JavaModelException { ArrayList result = new ArrayList(); IProject project = getPage().getMDEEditor().getCommonProject(); // would normally return array of size 0, but by returning null can optimize the search to run faster. if (project == null) { return null; }// ww w. j av a 2 s . com IPackageFragmentRoot[] roots = JavaCore.create(project).getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE || (roots[i].isArchive() && !roots[i].isExternal())) result.add(roots[i]); } return (IPackageFragmentRoot[]) result.toArray(new IPackageFragmentRoot[result.size()]); }
From source file:com.siteview.mde.internal.ui.editor.monitor.JavaAttributeWizardPage.java
License:Open Source License
private void initializeExpectedValues() { // source folder name, package name, class name int loc = className.indexOf(":"); //$NON-NLS-1$ if (loc != -1) { if (loc < className.length()) { initialValues.classArgs = className.substring(loc + 1, className.length()); className = className.substring(0, loc); }/*from w w w . ja va 2 s. c o m*/ if (loc > 0) initialValues.className = className.substring(0, loc); else if (loc == 0) initialValues.className = ""; //$NON-NLS-1$ } loc = className.lastIndexOf('.'); if (loc != -1) { initialValues.packageName = className.substring(0, loc); initialValues.className = className.substring(loc + 1); } if (javaProject == null) return; try { if (initialValues.packageFragmentRoot == null) { IPackageFragmentRoot srcEntryDft = null; IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { srcEntryDft = roots[i]; break; } } if (srcEntryDft != null) initialValues.packageFragmentRoot = srcEntryDft; else { initialValues.packageFragmentRoot = javaProject .getPackageFragmentRoot(javaProject.getResource()); } if (initialValues.packageFragment == null && initialValues.packageFragmentRoot != null && initialValues.packageName != null && initialValues.packageName.length() > 0) { IFolder packageFolder = project.getFolder(initialValues.packageName); initialValues.packageFragment = initialValues.packageFragmentRoot .getPackageFragment(packageFolder.getProjectRelativePath().toOSString()); } } // superclass and interface if (attInfo == null) { initialValues.interfaceName = "org.osgi.framework.BundleActivator"; //$NON-NLS-1$ initialValues.interfaceType = findTypeForName(initialValues.interfaceName); IEclipsePreferences prefs = new ProjectScope(project).getNode(MDECore.PLUGIN_ID); if (prefs != null && !prefs.getBoolean(ICoreConstants.EXTENSIONS_PROPERTY, true)) { return; } if (model != null) { IMonitorImport[] imports = model.getMonitorBase().getImports(); for (int i = 0; i < imports.length; i++) { if (imports[i].getId().equals("org.eclipse.ui")) { //$NON-NLS-1$ initialValues.superClassName = "org.eclipse.ui.plugin.AbstractUIPlugin"; //$NON-NLS-1$ initialValues.interfaceName = null; initialValues.interfaceType = null; break; } } } initialValues.superClassType = findTypeForName(initialValues.superClassName); return; } String schemaBasedOn = attInfo.getBasedOn(); if (schemaBasedOn == null || schemaBasedOn.length() == 0) { initialValues.superClassName = "java.lang.Object"; //$NON-NLS-1$ initialValues.superClassType = findTypeForName(initialValues.superClassName); return; } int del = schemaBasedOn.indexOf(':'); if (del != -1) { if (del == 0) { initialValues.superClassName = "java.lang.Object"; //$NON-NLS-1$ } else { initialValues.superClassName = schemaBasedOn.substring(0, del); } initialValues.superClassType = findTypeForName(initialValues.superClassName); if (del < schemaBasedOn.length() - 1) { initialValues.interfaceName = schemaBasedOn.substring(del + 1); initialValues.interfaceType = findTypeForName(initialValues.interfaceName); } } else { int schemaLoc = schemaBasedOn.lastIndexOf("."); //$NON-NLS-1$ if (schemaLoc != -1 && schemaLoc < schemaBasedOn.length()) { IType type = findTypeForName(schemaBasedOn); if (type != null && type.isInterface()) { initialValues.interfaceName = schemaBasedOn; initialValues.interfaceType = type; } else if (type != null && type.isClass()) { initialValues.superClassName = schemaBasedOn; initialValues.superClassType = type; } } } } catch (JavaModelException e) { MDEPlugin.logException(e); } }
From source file:com.siteview.mde.internal.ui.editor.schema.NewClassCreationWizard.java
License:Open Source License
private void initializeValues(IProject project, String value) throws JavaModelException { value = TextUtil.trimNonAlphaChars(value); IJavaProject javaProject = JavaCore.create(project); IPackageFragmentRoot srcEntryDft = null; IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots(); for (int i = 0; i < roots.length; i++) { if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE) { srcEntryDft = roots[i];//from w w w. j a v a 2s .com break; } } if (srcEntryDft != null) packageRoot = srcEntryDft; else packageRoot = javaProject.getPackageFragmentRoot(javaProject.getResource()); String packageNameString = null; int index = value.lastIndexOf("."); //$NON-NLS-1$ if (index == -1) { className = value; } else { className = value.substring(index + 1); packageNameString = value.substring(0, index); } if (packageNameString != null && packageRoot != null) { IFolder packageFolder = project.getFolder(packageNameString); packageName = packageRoot.getPackageFragment(packageFolder.getProjectRelativePath().toOSString()); } }