Search in sources :

Example 6 with StatusInfo

use of org.eclipse.jdt.internal.ui.dialogs.StatusInfo in project bndtools by bndtools.

the class NewTypeWizardPage method enclosingTypeChanged.

/**
     * Hook method that gets called when the enclosing type name has changed. The method validates the enclosing type
     * and returns the status of the validation. It also updates the enclosing type model.
     * <p>
     * Subclasses may extend this method to perform their own validation.
     * </p>
     *
     * @return the status of the validation
     */
protected IStatus enclosingTypeChanged() {
    StatusInfo status = new StatusInfo();
    fCurrEnclosingType = null;
    IPackageFragmentRoot root = getPackageFragmentRoot();
    fEnclosingTypeDialogField.enableButton(root != null);
    if (root == null) {
        //$NON-NLS-1$
        status.setError("");
        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);
        JavaPlugin.log(e);
        return status;
    }
}
Also used : JavaModelException(org.eclipse.jdt.core.JavaModelException) StatusInfo(org.eclipse.jdt.internal.ui.dialogs.StatusInfo) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IType(org.eclipse.jdt.core.IType)

Example 7 with StatusInfo

use of org.eclipse.jdt.internal.ui.dialogs.StatusInfo in project bndtools by bndtools.

the class SuperInterfaceSelectionDialog method addSelectedInterfaces.

/*
     * Adds selected interfaces to the list.
     */
private void addSelectedInterfaces() {
    StructuredSelection selection = getSelectedItems();
    if (selection == null)
        return;
    for (Iterator<?> iter = selection.iterator(); iter.hasNext(); ) {
        Object obj = iter.next();
        if (obj instanceof TypeNameMatch) {
            accessedHistoryItem(obj);
            TypeNameMatch type = (TypeNameMatch) obj;
            String qualifiedName = getNameWithTypeParameters(type.getType());
            String message;
            if (fTypeWizardPage.addSuperInterface(qualifiedName)) {
                message = Messages.format(NewWizardMessages.SuperInterfaceSelectionDialog_interfaceadded_info, BasicElementLabels.getJavaElementName(qualifiedName));
            } else {
                message = Messages.format(NewWizardMessages.SuperInterfaceSelectionDialog_interfacealreadyadded_info, BasicElementLabels.getJavaElementName(qualifiedName));
            }
            updateStatus(new StatusInfo(IStatus.INFO, message));
        }
    }
}
Also used : TypeNameMatch(org.eclipse.jdt.core.search.TypeNameMatch) StatusInfo(org.eclipse.jdt.internal.ui.dialogs.StatusInfo) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection)

Example 8 with StatusInfo

use of org.eclipse.jdt.internal.ui.dialogs.StatusInfo in project bndtools by bndtools.

the class NewTypeWizardPage method packageChanged.

/**
     * A hook method that gets called when the package field has changed. The method validates the package name and
     * returns the status of the validation. The validation also updates the package fragment model.
     * <p>
     * Subclasses may extend this method to perform their own validation.
     * </p>
     *
     * @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) {
        assert (root != 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;
            }
            if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_PackageNameFiltered);
                return status;
            }
        }
    } else {
        //$NON-NLS-1$
        status.setError("");
    }
    return status;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) JavaModelException(org.eclipse.jdt.core.JavaModelException) IJavaProject(org.eclipse.jdt.core.IJavaProject) IPath(org.eclipse.core.runtime.IPath) StatusInfo(org.eclipse.jdt.internal.ui.dialogs.StatusInfo) IResource(org.eclipse.core.resources.IResource) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot)

Example 9 with StatusInfo

use of org.eclipse.jdt.internal.ui.dialogs.StatusInfo in project bndtools by bndtools.

the class NewTypeWizardPage method typeNameChanged.

/**
     * Hook method that gets called when the type name has changed. The method validates the type name and returns the
     * status of the validation.
     * <p>
     * Subclasses may extend this method to perform their own validation.
     * </p>
     *
     * @return the status of the validation
     */
protected IStatus typeNameChanged() {
    StatusInfo status = new StatusInfo();
    fCurrType = null;
    String typeNameWithParameters = getTypeName();
    // must not be empty
    if (typeNameWithParameters.length() == 0) {
        status.setError(NewWizardMessages.NewTypeWizardPage_error_EnterTypeName);
        return status;
    }
    String typeName = getTypeNameWithoutParameters();
    if (typeName.indexOf('.') != -1) {
        status.setError(NewWizardMessages.NewTypeWizardPage_error_QualifiedName);
        return status;
    }
    IJavaProject project = getJavaProject();
    IStatus val = validateJavaTypeName(typeName, project);
    if (val.getSeverity() == IStatus.ERROR) {
        status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, val.getMessage()));
        return status;
    } else if (val.getSeverity() == IStatus.WARNING) {
        status.setWarning(Messages.format(NewWizardMessages.NewTypeWizardPage_warning_TypeNameDiscouraged, val.getMessage()));
    // continue checking
    }
    // must not exist
    if (!isEnclosingTypeSelected()) {
        IPackageFragment pack = getPackageFragment();
        if (pack != null) {
            ICompilationUnit cu = pack.getCompilationUnit(getCompilationUnitName(typeName));
            fCurrType = cu.getType(typeName);
            IResource resource = cu.getResource();
            if (resource.exists()) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
                return status;
            }
            if (!ResourcesPlugin.getWorkspace().validateFiltered(resource).isOK()) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameFiltered);
                return status;
            }
            URI location = resource.getLocationURI();
            if (location != null) {
                try {
                    IFileStore store = EFS.getStore(location);
                    if (store.fetchInfo().exists()) {
                        status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExistsDifferentCase);
                        return status;
                    }
                } catch (CoreException e) {
                    status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_uri_location_unkown, BasicElementLabels.getURLPart(Resources.getLocationString(resource))));
                }
            }
        }
    } else {
        IType type = getEnclosingType();
        if (type != null) {
            fCurrType = type.getType(typeName);
            if (fCurrType.exists()) {
                status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists);
                return status;
            }
        }
    }
    if (!typeNameWithParameters.equals(typeName) && project != null) {
        if (!JavaModelUtil.is50OrHigher(project)) {
            status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeParameters);
            return status;
        }
        //$NON-NLS-1$//$NON-NLS-2$
        String typeDeclaration = "class " + typeNameWithParameters + " {}";
        ASTParser parser = ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL);
        parser.setSource(typeDeclaration.toCharArray());
        parser.setProject(project);
        CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);
        IProblem[] problems = compilationUnit.getProblems();
        if (problems.length > 0) {
            status.setError(Messages.format(NewWizardMessages.NewTypeWizardPage_error_InvalidTypeName, problems[0].getMessage()));
            return status;
        }
    }
    return status;
}
Also used : CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IStatus(org.eclipse.core.runtime.IStatus) IPackageFragment(org.eclipse.jdt.core.IPackageFragment) URI(java.net.URI) IProblem(org.eclipse.jdt.core.compiler.IProblem) IType(org.eclipse.jdt.core.IType) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) StatusInfo(org.eclipse.jdt.internal.ui.dialogs.StatusInfo) IFileStore(org.eclipse.core.filesystem.IFileStore) ASTParser(org.eclipse.jdt.core.dom.ASTParser) IResource(org.eclipse.core.resources.IResource)

Aggregations

StatusInfo (org.eclipse.jdt.internal.ui.dialogs.StatusInfo)9 IPackageFragmentRoot (org.eclipse.jdt.core.IPackageFragmentRoot)5 IStatus (org.eclipse.core.runtime.IStatus)4 IType (org.eclipse.jdt.core.IType)4 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 JavaModelException (org.eclipse.jdt.core.JavaModelException)3 IResource (org.eclipse.core.resources.IResource)2 ParameterizedType (org.eclipse.jdt.core.dom.ParameterizedType)2 Type (org.eclipse.jdt.core.dom.Type)2 URI (java.net.URI)1 IFileStore (org.eclipse.core.filesystem.IFileStore)1 CoreException (org.eclipse.core.runtime.CoreException)1 IPath (org.eclipse.core.runtime.IPath)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IPackageFragment (org.eclipse.jdt.core.IPackageFragment)1 IProblem (org.eclipse.jdt.core.compiler.IProblem)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 ASTParser (org.eclipse.jdt.core.dom.ASTParser)1 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)1 Assignment (org.eclipse.jdt.core.dom.Assignment)1