Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.IPackageFragmentRoot


        throws JavaModelException {
        boolean isRoot = false;
        if (project == null || pack == null || !(pack instanceof IContainer)) {
            return isRoot;
        }
        IPackageFragmentRoot root = project.getPackageFragmentRoot(pack);
        IClasspathEntry clPathEntry = null;
        if (root != null) {
            clPathEntry = root.getRawClasspathEntry();
        }
        isRoot = clPathEntry != null;
        return isRoot;
    }
View Full Code Here


     * <code>null</code> if it does not exist. The rootPath must be specified as a
     * project relative path. The empty path refers to the default package fragment.
     */
    protected IPackageFragment getPackageFragment(String rootPath,
        String packageName) throws JavaModelException {
        IPackageFragmentRoot root1 = getPackageFragmentRoot(rootPath);
        if (root1 == null) {
            return null;
        }
        return root1.getPackageFragment(packageName);
    }
View Full Code Here

        IPath path = new Path(rootPath);
        if (path.isAbsolute()) {
            IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace()
                .getRoot();
            IResource resource = workspaceRoot.findMember(path);
            IPackageFragmentRoot root1;
            if (resource == null) {
                // external jar
                root1 = project.getPackageFragmentRoot(rootPath);
            } else {
                // resource in the workspace
                root1 = project.getPackageFragmentRoot(resource);
            }
            return root1;
        }
        IPackageFragmentRoot[] roots = project.getPackageFragmentRoots();
        if (roots == null || roots.length == 0) {
            return null;
        }
        for (int i = 0; i < roots.length; i++) {
            IPackageFragmentRoot root1 = roots[i];
            if (!root1.isExternal()
                && root1.getUnderlyingResource().getProjectRelativePath()
                    .equals(path)) {
                return root1;
            }
        }
        return null;
View Full Code Here

    private void createRule(IJavaProject project)
            throws JavaModelException, IOException {
        String s = "org/drools/ide/resource/DroolsTest.java.template";
        IFolder folder = project.getProject().getFolder("src/java");
        IPackageFragmentRoot packageFragmentRoot = project
                .getPackageFragmentRoot(folder);
        IPackageFragment packageFragment = packageFragmentRoot
                .createPackageFragment("com.sample", true, null);
        InputStream inputstream = getClass().getClassLoader()
                .getResourceAsStream(s);
        packageFragment.createCompilationUnit("DroolsTest.java", new String(
                readStream(inputstream)), true, null);
View Full Code Here

  }
   
    private void addSourceFolder(IJavaProject project, List list, String s) throws CoreException {
        IFolder folder = project.getProject().getFolder(s);
        createFolder(folder);
        IPackageFragmentRoot ipackagefragmentroot = project.getPackageFragmentRoot(folder);
        list.add(JavaCore.newSourceEntry(ipackagefragmentroot.getPath()));
    }
View Full Code Here

     * @see org.eclipse.jdt.ui.wizards.NewContainerWizardPage#containerChanged()
     */
    @Override
    protected IStatus containerChanged() {
        IStatus status = super.containerChanged();
        IPackageFragmentRoot root = getPackageFragmentRoot();
        if ((fTypeKind == ANNOTATION_TYPE || fTypeKind == ENUM_TYPE) && !status.matches(IStatus.ERROR)) {
            if (root != null && !JavaModelUtil.is50OrHigher(root.getJavaProject())) {
                // error as createType will fail otherwise (bug 96928)
                return new StatusInfo(IStatus.ERROR, Messages.format(NewWizardMessages.NewTypeWizardPage_warning_NotJDKCompliant, BasicElementLabels.getJavaElementName(root.getJavaProject().getElementName())));
            }
            if (fTypeKind == ENUM_TYPE) {
                try {
                    // if findType(...) == null then Enum is unavailable
                    if (findType(root.getJavaProject(), "java.lang.Enum") == null) //$NON-NLS-1$
                        return new StatusInfo(IStatus.WARNING, NewWizardMessages.NewTypeWizardPage_warning_EnumClassNotFound);
                } catch (JavaModelException e) {
                    JavaPlugin.log(e);
                }
            }
        }

        fCurrPackageCompletionProcessor.setPackageFragmentRoot(root);
        if (root != null) {
            fEnclosingTypeCompletionProcessor.setPackageFragment(root.getPackageFragment("")); //$NON-NLS-1$
        }
        return status;
    }
View Full Code Here

     *
     * @return the status of the validation
     */
    protected IStatus packageChanged() {
        StatusInfo status = new StatusInfo();
        IPackageFragmentRoot root = getPackageFragmentRoot();
        fPackageDialogField.enableButton(root != null);

        IJavaProject project = root != null ? root.getJavaProject() : null;

        String packName = getPackageText();
        if (packName.length() > 0) {
            IStatus val = validatePackageName(packName, project);
            if (val.getSeverity() == IStatus.ERROR) {
                status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName, val.getMessage()));
                return status;
            } else if (val.getSeverity() == IStatus.WARNING) {
                status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage()));
                // continue
            }
        } else {
            status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged);
        }

        if (project != null) {
            if (project.exists() && packName.length() > 0) {
                try {
                    IPath rootPath = root.getPath();
                    IPath outputPath = project.getOutputLocation();
                    if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                        // if the bin folder is inside of our root, don't allow to name a package
                        // like the bin folder
                        IPath packagePath = rootPath.append(packName.replace('.', '/'));
                        if (outputPath.isPrefixOf(packagePath)) {
                            status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
                            return status;
                        }
                    }
                } catch (JavaModelException e) {
                    JavaPlugin.log(e);
                    // let pass
                }
            }

            fCurrPackage = root.getPackageFragment(packName);
            IResource resource = fCurrPackage.getResource();
            if (resource != null) {
                if (resource.isVirtual()) {
                    status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageIsVirtual);
                    return status;
View Full Code Here

     */
    protected IStatus enclosingTypeChanged() {
        StatusInfo status = new StatusInfo();
        fCurrEnclosingType = null;

        IPackageFragmentRoot root = getPackageFragmentRoot();

        fEnclosingTypeDialogField.enableButton(root != null);
        if (root == null) {
            status.setError(""); //$NON-NLS-1$
            return status;
        }

        String enclName = getEnclosingTypeText();
        if (enclName.length() == 0) {
            status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeEnterName);
            return status;
        }
        try {
            IType type = findType(root.getJavaProject(), enclName);
            if (type == null) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeNotExists);
                return status;
            }

            if (type.getCompilationUnit() == null) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotInCU);
                return status;
            }
            if (!JavaModelUtil.isEditable(type.getCompilationUnit())) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingNotEditable);
                return status;
            }

            fCurrEnclosingType = type;
            IPackageFragmentRoot enclosingRoot = JavaModelUtil.getPackageFragmentRoot(type);
            if (!enclosingRoot.equals(root)) {
                status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_EnclosingNotInSourceFolder);
            }
            return status;
        } catch (JavaModelException e) {
            status.setError(NewWizardMessages.NewTypeWizardPage_error_EnclosingTypeNotExists);
View Full Code Here

     *
     * @return the status of the validation
     */
    protected IStatus superClassChanged() {
        StatusInfo status = new StatusInfo();
        IPackageFragmentRoot root = getPackageFragmentRoot();
        fSuperClassDialogField.enableButton(root != null);

        fSuperClassStubTypeContext = null;

        String sclassName = getSuperClass();
        if (sclassName.length() == 0) {
            // accept the empty field (stands for java.lang.Object)
            return status;
        }

        if (root != null) {
            Type type = TypeContextChecker.parseSuperClass(sclassName);
            if (type == null) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperClassName);
                return status;
            }
            if (type instanceof ParameterizedType && !JavaModelUtil.is50OrHigher(root.getJavaProject())) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_SuperClassNotParameterized);
                return status;
            }
        } else {
            status.setError(""); //$NON-NLS-1$
View Full Code Here

     * @return the status of the validation
     */
    protected IStatus superInterfacesChanged() {
        StatusInfo status = new StatusInfo();

        IPackageFragmentRoot root = getPackageFragmentRoot();
        fSuperInterfacesDialogField.enableButton(0, root != null);

        if (root != null) {
            List<InterfaceWrapper> elements = fSuperInterfacesDialogField.getElements();
            int nElements = elements.size();
            for (int i = 0; i < nElements; i++) {
                String intfname = elements.get(i).interfaceName;
                Type type = TypeContextChecker.parseSuperInterface(intfname);
                if (type == null) {
                    status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidSuperInterfaceName, BasicElementLabels.getJavaElementName(intfname)));
                    return status;
                }
                if (type instanceof ParameterizedType && !JavaModelUtil.is50OrHigher(root.getJavaProject())) {
                    status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_SuperInterfaceNotParameterized, BasicElementLabels.getJavaElementName(intfname)));
                    return status;
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.IPackageFragmentRoot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.