Search in sources :

Example 1 with JavaPackageName

use of org.eclipse.sapphire.java.JavaPackageName in project liferay-ide by liferay.

the class NewLiferayComponentValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    NewLiferayComponentOp op = _op();
    String className = op.getComponentClassName().content(true);
    if (!CoreUtil.isNullOrEmpty(className)) {
        IStatus status = JavaConventions.validateJavaTypeName(className, CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7);
        int classNameStatus = status.getSeverity();
        if (className.indexOf('.') != -1) {
            classNameStatus = IStatus.ERROR;
        }
        if (classNameStatus == IStatus.ERROR) {
            retval = Status.createErrorStatus("Invalid class name");
        }
    }
    String projectName = op.getProjectName().content(true);
    if (projectName != null) {
        IProject project = CoreUtil.getProject(projectName);
        if (project != null) {
            try {
                JavaPackageName pack = op.getPackageName().content(true);
                if (pack != null) {
                    String packageName = pack.toString();
                    IJavaProject javaProject = JavaCore.create(project);
                    IType type = javaProject.findType(packageName + "." + className);
                    if (type != null) {
                        retval = Status.createErrorStatus(packageName + "." + className + " already exists.");
                    }
                }
            } catch (Exception e) {
                ProjectCore.logError("Checking component class name failed.", e);
            }
        }
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) JavaPackageName(org.eclipse.sapphire.java.JavaPackageName) IStatus(org.eclipse.core.runtime.IStatus) IJavaProject(org.eclipse.jdt.core.IJavaProject) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType)

Example 2 with JavaPackageName

use of org.eclipse.sapphire.java.JavaPackageName in project liferay-ide by liferay.

the class JavaPackageNameValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    NewLiferayComponentOp op = _op();
    String projectName = op.getProjectName().text(false);
    if (projectName != null) {
        IJavaProject javaproject = JavaCore.create(CoreUtil.getProject(op.getProjectName().text(false)));
        if (CoreUtil.getSourceFolders(javaproject).size() == 0) {
            retval = Status.createErrorStatus("Unable to find any source folders.");
            return retval;
        }
    }
    JavaPackageName packageName = op.getPackageName().content(true);
    if (packageName != null) {
        IStatus status = JavaConventions.validatePackageName(packageName.toString(), CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7);
        int packageNameStatus = status.getSeverity();
        if (packageNameStatus == IStatus.ERROR) {
            retval = Status.createErrorStatus("Invalid package name");
        }
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) JavaPackageName(org.eclipse.sapphire.java.JavaPackageName) IStatus(org.eclipse.core.runtime.IStatus) IJavaProject(org.eclipse.jdt.core.IJavaProject)

Aggregations

IStatus (org.eclipse.core.runtime.IStatus)2 IJavaProject (org.eclipse.jdt.core.IJavaProject)2 JavaPackageName (org.eclipse.sapphire.java.JavaPackageName)2 Status (org.eclipse.sapphire.modeling.Status)2 IProject (org.eclipse.core.resources.IProject)1 IType (org.eclipse.jdt.core.IType)1