Example usage for org.eclipse.jdt.core JavaConventions validatePackageName

List of usage examples for org.eclipse.jdt.core JavaConventions validatePackageName

Introduction

In this page you can find the example usage for org.eclipse.jdt.core JavaConventions validatePackageName.

Prototype

public static IStatus validatePackageName(String name) 

Source Link

Document

Validate the given package name.

Usage

From source file:com.buglabs.dragonfly.ui.wizards.bugProject.NewProjectMainPage.java

License:Open Source License

public boolean isPageComplete() {

    setErrorMessage(null);/*from   www  .j ava2  s  . c  om*/

    String projName = pinfo.getProjectName();

    char[] cs = projName.toCharArray();
    if (cs.length != 0) {
        if (cs.length > projectNameSize) {
            setErrorMessage("Project name limit reached!");
            return false;
        }
        for (int i = 0; i < cs.length; i++) {
            if (cs[i] == ' ' || cs[i] == '_') {
                continue;
            }
            if (!Character.isLetterOrDigit(cs[i]) && cs[i] != '.') {
                setErrorMessage("Invalid project name.");
                return false;
            }
        }

        if (ResourcesPlugin.getWorkspace().validateName(projName, IFile.PROJECT).getSeverity() != IStatus.OK
                || !JavaConventions.validatePackageName(ProjectUtils.formatNameToPackage(projName)).isOK()) {
            setErrorMessage("Invalid project name.");
            return false;
        }

        IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(pinfo.getProjectName());
        if (proj.exists()) {
            setErrorMessage("Project with name " + pinfo.getProjectName() + " already exists.");
            return false;
        }
        return true;
    }
    return false;
}

From source file:com.iw.plugins.spindle.ui.wizards.fields.PackageDialogField.java

License:Mozilla Public License

public IStatus packageChanged() {
    SpindleStatus status = new SpindleStatus();
    checkButtonEnabled();/*  www. j a  va  2 s.c  om*/
    String packName = getTextValue();
    if (!"".equals(packName)) {
        IStatus val = JavaConventions.validatePackageName(packName);
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(UIPlugin.getString(name + ".error.InvalidPackageName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(UIPlugin.getString(name + ".warning.DiscouragedPackageName", val.getMessage()));
            // continue
        }
    } else {

        status.setError(UIPlugin.getString(name + ".error.defaultPackage"));
        return status;
    }

    IPackageFragmentRoot root;
    if (container == null) {
        root = null;
    } else {
        root = container.getPackageFragmentRoot();
    }
    if (root != null) {
        IPackageFragment pack = root.getPackageFragment(packName);
        try {
            if (fSourcePackagesOnly && root.getKind() == IPackageFragmentRoot.K_BINARY) {
                status.setError(UIPlugin.getString(name + ".error.PackageMustBeSource"));
                return status;
            }

            IPath rootPath = root.getPath();
            IPath outputPath = root.getJavaProject().getOutputLocation();
            if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                // if the bin folder is inside of our root, dont allow to name a
                // package
                // like the bin folder
                IPath packagePath = pack.getUnderlyingResource().getFullPath();
                if (outputPath.isPrefixOf(packagePath)) {
                    status.setError(UIPlugin.getString(name + ".error.ClashOutputLocation"));
                    return status;
                }
            }
        } catch (JavaModelException e) {
            UIPlugin.log(e);
            // let pass
        }

        currentPackage = pack;
        if (currentPackage != null && nameField != null) {
            try {
                IContainer folder = (IContainer) getPackageFragment().getUnderlyingResource();

                boolean isComponent = nameField.getKind() == AbstractNameField.COMPONENT_NAME;
                IFile file = folder
                        .getFile(new Path(nameField.getTextValue() + (isComponent ? ".jwc" : ".page")));
                if (file.exists()) {

                    status.setError(UIPlugin.getString(name + ".error.ComponentAlreadyExists",
                            file.getFullPath().toString()));
                    return status;
                }
            } catch (JavaModelException e) {
                UIPlugin.log(e);
            }
        }
    } else {
        status.setError("");
    }
    return status;
}

From source file:com.iw.plugins.spindle.wizards.fields.PackageDialogField.java

License:Mozilla Public License

public IStatus packageChanged() {
    SpindleStatus status = new SpindleStatus();
    checkButtonEnabled();//from   w w w.  j a  v  a 2 s . com
    String packName = getTextValue();
    if (!"".equals(packName)) {
        IStatus val = JavaConventions.validatePackageName(packName);
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(
                    MessageUtil.getFormattedString(name + ".error.InvalidPackageName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(
                    MessageUtil.getFormattedString(name + ".warning.DiscouragedPackageName", val.getMessage()));
            // continue
        }
    } else {

        status.setError("Using the default package is not allowed. Choose (or enter) a package");
        return status;
    }

    IPackageFragmentRoot root;
    if (container == null) {
        root = null;
    } else {
        root = container.getPackageFragmentRoot();
    }
    if (root != null) {
        IPackageFragment pack = root.getPackageFragment(packName);
        try {
            IPath rootPath = root.getPath();
            IPath outputPath = root.getJavaProject().getOutputLocation();
            if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                // if the bin folder is inside of our root, dont allow to name a package
                // like the bin folder
                IPath packagePath = pack.getUnderlyingResource().getFullPath();
                if (outputPath.isPrefixOf(packagePath)) {
                    status.setError(MessageUtil.getString(name + ".error.ClashOutputLocation"));
                    return status;
                }
            }
        } catch (JavaModelException e) {
            TapestryPlugin.getDefault().logException(e);
            // let pass         
        }

        currentPackage = pack;
    } else {
        status.setError("");
    }
    return status;
}

From source file:com.iw.plugins.spindle.wizards.project.PackageDialogField.java

License:Mozilla Public License

public IStatus packageChanged() {
    SpindleStatus status = new SpindleStatus();

    String packName = getTextValue().trim();

    if ("".equals(packName)) {

        status.setError("");

    } else {/*  w w  w  . j a va  2s  .  c  o m*/
        IStatus val = JavaConventions.validatePackageName(packName);
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(
                    MessageUtil.getFormattedString(name + ".error.InvalidPackageName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(
                    MessageUtil.getFormattedString(name + ".warning.DiscouragedPackageName", val.getMessage()));
            // continue
        }
    }

    return status;
}

From source file:org.ebayopensource.vjet.eclipse.internal.ui.wizards.VjoNewPackageWizardPage.java

License:Open Source License

private void checkCorrectName(StatusInfo status, String packName) {
    IStatus val = JavaConventions.validatePackageName(packName);

    if (val.getSeverity() == IStatus.ERROR) {
        invalidPackageName(status, val, packName);
    } else if (val.getSeverity() == IStatus.WARNING) {
        discouragedPackageName(status, val);
    }/*from  w  w w  .  ja v  a  2 s  . co  m*/
}

From source file:org.eclipse.dltk.mod.internal.corext.refactoring.Checks.java

License:Open Source License

public static RefactoringStatus checkPackageName(String newName) {
    return checkName(newName, JavaConventions.validatePackageName(newName));

}

From source file:org.eclipse.jst.j2ee.internal.common.operations.NewJavaClassDataModelProvider.java

License:Open Source License

/**
 * This method will validate whether the specified package name is a valid java package name. It
 * will be called during the doValidateProperty(String). This method will accept null. It will
 * not return null.//  w  w w. j  av  a 2s . c  o  m
 * 
 * @see NewJavaClassDataModelProvider#validate(String)
 * 
 * @param packName --
 *            the package name
 * @return IStatus of if the package name is valid
 */
private IStatus validateJavaPackage(String packName) {
    if (packName != null && packName.trim().length() > 0) {
        // Use standard java conventions to validate the package name
        IStatus javaStatus = JavaConventions.validatePackageName(packName);
        if (javaStatus.getSeverity() == IStatus.ERROR) {
            String msg = J2EECommonMessages.ERR_JAVA_PACAKGE_NAME_INVALID + javaStatus.getMessage();
            return WTPCommonPlugin.createErrorStatus(msg);
        } else if (javaStatus.getSeverity() == IStatus.WARNING) {
            String msg = J2EECommonMessages.ERR_JAVA_PACKAGE_NAME_WARNING + javaStatus.getMessage();
            return WTPCommonPlugin.createWarningStatus(msg);
        }
    }
    // java package name is valid
    return WTPCommonPlugin.OK_STATUS;
}

From source file:org.ect.codegen.ea.ui.CaCodeGenerator.java

License:Open Source License

public IStatus validateGenModel(IGenModel genModel) {
    // Extract genModel properties.
    String basePackage = genModel.getProperty(PROPERTY_BASE_PACKAGE);
    String javaClass = genModel.getProperty(PROPERTY_CONNECTOR_CLASS);

    // Check whether the class file name is ok.
    IStatus status = JavaConventions.validateCompilationUnitName(javaClass + ".java");
    if (!status.isOK())
        return status;

    // Check whether the class name is not according to the conventions.
    // This includes a check for capital letter at the beginning.
    status = JavaConventions.validateJavaTypeName(javaClass);
    if (!status.isOK())
        return status;

    // Validate the package name.
    status = JavaConventions.validatePackageName(basePackage);
    if (!status.isOK())
        return status;

    return Status.OK_STATUS;
}

From source file:org.hibernate.eclipse.launch.CodeGenerationSettingsTab.java

License:Open Source License

private void dialogChanged() {
    boolean configSelected = getConfigurationName().length() == 0;
    outputdir.setEnabled(!configSelected);
    reverseengineer.setEnabled(!configSelected);
    useOwnTemplates.setEnabled(!configSelected);
    useExternalProcess.setEnabled(!configSelected);

    boolean useExternalProcessFlag = useExternalProcess.isSelected();
    preferRawCompositeIds/*from   w ww. ja v a2  s.c  o  m*/
            .setEnabled(reverseengineer.isSelected() && !configSelected && !useExternalProcessFlag);
    if (useExternalProcessFlag) {
        preferRawCompositeIds.setSelection(true);
    }

    if (configSelected) {
        updateStatus(HibernateConsoleMessages.CodeGenerationSettingsTab_console_cfg_must_be_specified);
        return;
    }

    String msg = PathHelper.checkDirectory(outputdir.getText(),
            HibernateConsoleMessages.CodeGenerationSettingsTab_output_directory, true);

    if (msg != null) {
        updateStatus(msg);
        return;
    }

    String warning = null;
    if (packageName.isEnabled() && getOutputPackage().length() > 0) {
        IStatus val = JavaConventions.validatePackageName(getOutputPackage());
        if (val.getSeverity() == IStatus.ERROR) {
            updateStatus(val.getMessage());
            return;
        } else if (val.getSeverity() == IStatus.WARNING) {
            warning = val.getMessage();
        }
    }

    if (reverseEngineeringSettings.isEnabled() && reverseEngineeringSettings.getText().trim().length() > 0) {
        msg = PathHelper.checkFile(reverseEngineeringSettings.getText(),
                HibernateConsoleMessages.CodeGenerationSettingsTab_reveng_xml_3, true);
        if (msg != null) {
            updateStatus(msg);
            return;
        }
    }

    if (reverseEngineeringStrategy.isEnabled() && reverseEngineeringStrategy.getText().trim().length() > 0) {
        IStatus val = JavaConventions.validateJavaTypeName(getReverseEngineeringStrategy(),
                JavaCore.VERSION_1_5, JavaCore.VERSION_1_5);
        if (val.getSeverity() == IStatus.ERROR) {
            updateStatus(val.getMessage());
            return;
        } else if (val.getSeverity() == IStatus.WARNING) {
            warning = val.getMessage();
        }
    }

    if (useOwnTemplates.isSelected()) {
        msg = PathHelper.checkDirectory(templatedir.getText(),
                HibernateConsoleMessages.CodeGenerationSettingsTab_template_dir, true);
        if (msg != null) {
            updateStatus(msg);
            return;
        } else {
            // imprecise and inefficient to check recursively all for .vm
            /*IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(getTemplateDirectory() );
            IResource[] files = new IFile[0];
            boolean found = false;
                    
            if(resource.getType() == IResource.FOLDER) {
            try {
                found = ( (IFolder)resource).accept(new IResourceProxyVisitor() {
                    
             public boolean visit(IResourceProxy proxy) throws CoreException {
                return false;
             }
                    
              });
            } catch (CoreException e) {
                // noop
            }
            }
                    
            if(!found) {
            setMessage("No templates (*.vm) found in template directory", IMessageProvider.WARNING);
            } else {
            setMessage(null);
            }*/
        }
    }

    if (warning != null) {
        setMessage(warning);
    } else {
        setMessage(null);
    }

    updateStatus(null);
}

From source file:org.jboss.ide.eclipse.as.ui.mbeans.wizards.pages.NewSessionBeanWizardPage.java

License:Open Source License

protected IPackageFragment getPackageFragment(String packageName) throws CoreException {
    // This was copied over from NewTypeWizardPage.packageChanged, and made more generic so we could use it for multiple package inputs
    StatusInfo status = new StatusInfo();

    if (packageName.length() > 0) {
        IStatus val = JavaConventions.validatePackageName(packageName);
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(NewWizardMessages.bind(NewWizardMessages.NewTypeWizardPage_error_InvalidPackageName,
                    val.getMessage()));
            throw new CoreException(status);
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(NewWizardMessages.bind(
                    NewWizardMessages.NewTypeWizardPage_warning_DiscouragedPackageName, val.getMessage()));
            // continue
        }/*from ww  w  . ja v  a2 s . c om*/
    } else {
        status.setWarning(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged);
    }

    IPackageFragmentRoot root = getPackageFragmentRoot();
    if (root != null) {
        if (root.getJavaProject().exists() && packageName.length() > 0) {
            try {
                IPath rootPath = root.getPath();
                IPath outputPath = root.getJavaProject().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(packageName.replace('.', '/'));
                    if (outputPath.isPrefixOf(packagePath)) {
                        status.setError(NewWizardMessages.NewTypeWizardPage_error_ClashOutputLocation);
                        throw new CoreException(status);
                    }
                }
            } catch (JavaModelException e) {
                JavaPlugin.log(e);
                // let pass         
            }
        }

        return root.getPackageFragment(packageName);
    } else {
        status.setError(""); //$NON-NLS-1$
    }

    throw new CoreException(status);
}