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

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

Introduction

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

Prototype

public static IStatus validateJavaTypeName(String name) 

Source Link

Document

Validate the given Java type name, either simple or qualified.

Usage

From source file:ar.com.tadp.xml.rinzo.jdt.actions.ClassNameSelectedAction.java

License:Open Source License

public boolean isEnabled() {
    IStatus status = JavaConventions.validateJavaTypeName(this.getSelection());
    if (status.getCode() == IStatus.OK || status.getSeverity() == IStatus.WARNING) {
        IType type = JDTUtils.findType(this.getSelection());
        return this.getEnableValue(type);
    }/*from  ww w.ja va 2s. c  o m*/
    return false;
}

From source file:ar.com.tadp.xml.rinzo.jdt.JDTUtils.java

License:Open Source License

/**
 * Opens the type corresponding to the class name using the associated editor.
 * //from ww  w.j av  a 2 s .  c  o m
 * @param selection the name of the class to be opened.
 * @return
 */
public static boolean openType(String selection) {
    if (selection.length() > 0 && JavaConventions.validateJavaTypeName(selection).isOK()) {
        try {
            IType type = JDTUtils.findType(selection);
            if (type != null) {
                JavaUI.openInEditor(type);
                return true;
            }
        } catch (Exception e) {
        }
    }
    return false;
}

From source file:ar.com.tadp.xml.rinzo.jdt.resources.validation.ClassNamesValidatorVisitor.java

License:Open Source License

private boolean isClassName(XMLAttribute attribute) {
    return JavaConventions.validateJavaTypeName(attribute.getValue()).isOK()
            && attribute.getValue().contains(".");
}

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

License:Mozilla Public License

protected IStatus nameChanged() {
    SpindleStatus status = new SpindleStatus();
    String appname = getTextValue();
    if ("".equals(appname)) {
        status.setError("");
        return status;
    }// www.  java 2s  .  c o m
    if (appname.indexOf('.') != -1) {
        status.setError(UIPlugin.getString(fName + ".error.QualifiedName"));
        return status;
    }

    IStatus val = JavaConventions.validateJavaTypeName(appname);
    if (!val.isOK()) {
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(UIPlugin.getString(fName + ".error.InvalidAppName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(UIPlugin.getString(fName + ".warning.AppNameDiscouraged", val.getMessage()));
            return status;
        }
    }
    if (fPackageField != null && fPackageField.getPackageFragment() != null) {
        try {
            IContainer folder = (IContainer) fPackageField.getPackageFragment().getUnderlyingResource();
            IFile file = folder.getFile(new Path(appname + ".application"));
            if (file.exists()) {
                status.setError(UIPlugin.getString(fName + ".error.AppAlreadyExists", appname));
            }
        } catch (JavaModelException e) {
            // do nothing
        }
    }
    char first = appname.charAt(0);
    if (Character.isLowerCase(first)) {
        status.setWarning(
                UIPlugin.getString(fName + ".warning.AppNameDiscouraged", "first character is lowercase"));
    }

    return status;

}

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

License:Mozilla Public License

protected IStatus nameChanged() {
    SpindleStatus status = new SpindleStatus();
    String name = getTextValue();
    if ("".equals(name)) {
        status.setError("");
        return status;
    }//from  w  ww  . ja  va 2 s .  c  om
    if (name.indexOf('.') != -1) {
        status.setError(UIPlugin.getString(fName + ".error.QualifiedName"));
        return status;
    }

    IStatus val = JavaConventions.validateJavaTypeName(name);
    if (!val.isOK()) {
        if (val.getSeverity() == IStatus.ERROR) {
            String message = val.getMessage();
            message = StringUtils.replace(message, "type", "");
            status.setError(UIPlugin.getString(fName + ".error.InvalidComponentName", message));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            String message = val.getMessage();
            message = StringUtils.replace(message, "Java", "Tapestry");
            message = StringUtils.replace(message, "type", "component/page");
            status.setWarning(UIPlugin.getString(fName + ".warning.ComponentNameDiscouraged", name, message));
            return status;
        }
    }
    char first = name.charAt(0);
    if (Character.isLowerCase(first)) {
        status.setWarning(UIPlugin.getString(fName + ".warning.ComponentNameDiscouraged",
                "first character is lowercase"));
    }

    return status;
}

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

License:Mozilla Public License

protected IStatus nameChanged() {
    SpindleStatus status = new SpindleStatus();
    String appname = getTextValue();
    if ("".equals(appname)) {
        status.setError("");
        return status;
    }// w  w w.  j a v a2s. c o  m
    if (appname.indexOf('.') != -1) {
        status.setError(UIPlugin.getString(fName + ".error.QualifiedName"));
        return status;
    }

    IStatus val = JavaConventions.validateJavaTypeName(appname);
    if (!val.isOK()) {
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(UIPlugin.getString(fName + ".error.InvalidClassName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(UIPlugin.getString(fName + ".warning.ClassNameDiscouraged", val.getMessage()));
            return status;
        }
    }
    if (fPackageField != null && fPackageField.getPackageFragment() != null) {
        try {
            IContainer folder = (IContainer) fPackageField.getPackageFragment().getUnderlyingResource();
            IFile file = folder.getFile(new Path(appname + ".java"));
            if (file.exists()) {
                status.setError(UIPlugin.getString(fName + ".error.ClassAlreadyExists", appname));
                return status;
            }
        } catch (JavaModelException e) {
            // do nothing
        }
    }
    char first = appname.charAt(0);
    if (Character.isLowerCase(first)) {
        status.setWarning(
                UIPlugin.getString(fName + ".warning.ClassNameDiscouraged", "first character is lowercase"));
    }

    return status;

}

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

License:Mozilla Public License

protected IStatus nameChanged() {
    SpindleStatus status = new SpindleStatus();
    String appname = getTextValue();
    if ("".equals(appname)) {
        status.setError("");
        return status;
    }//from   www .  j  a v  a 2s  . c o m
    if (appname.indexOf('.') != -1) {
        status.setError(UIPlugin.getString(fName + ".error.QualifiedName"));
        return status;
    }

    IStatus val = JavaConventions.validateJavaTypeName(appname);
    if (!val.isOK()) {
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(UIPlugin.getString(fName + ".error.InvalidName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(UIPlugin.getString(fName + ".warning.NameDiscouraged", val.getMessage()));
            return status;
        }
    }
    if (fPackageField != null && fPackageField.getPackageFragment() != null) {
        try {
            IContainer folder = (IContainer) fPackageField.getPackageFragment().getUnderlyingResource();
            IFile file = folder.getFile(new Path(appname + ".library"));
            if (file.exists()) {
                status.setError(UIPlugin.getString(fName + ".error.AlreadyExists", appname));
            }
        } catch (JavaModelException e) {
            // do nothing
        }
    }
    char first = appname.charAt(0);
    if (Character.isLowerCase(first)) {
        status.setWarning(
                UIPlugin.getString(fName + ".warning.NameDiscouraged", "first character is lowercase"));
    }

    return status;

}

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

License:Mozilla Public License

protected IStatus typeChanged() {
    //IPackageFragmentRoot root =
    // packageChooser.getContainer().getPackageFragmentRoot();
    chosenType = null;/*from www  . ja  v a2s .  c  o m*/
    SpindleStatus status = new SpindleStatus();
    String typeName = getTextValue();
    if ("".equals(typeName)) {
        status.setError(UIPlugin.getString(name + ".error.EnterTypeName"));
        return status;
    }
    IStatus val = JavaConventions.validateJavaTypeName(typeName);
    if (!val.isOK()) {
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(UIPlugin.getString(name + ".error.InvalidTypeName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(UIPlugin.getString(name + ".warning.TypeNameDiscouraged", val.getMessage()));
        }
    }
    try {
        chosenType = resolveTypeName(typeName);
        if (chosenType == null) {
            status.setError(UIPlugin.getString(name + ".error.TypeNameNotExist", typeName));
            return status;
        }
        if (requiredType != null) {
            if (requiredType.isInterface()) {
                if (!implementsInterface(chosenType, hierarchyRoot)) {
                    status.setError(UIPlugin.getString(name + ".error.MustImplementInterface", hierarchyRoot));
                } else if (!extendsType(chosenType, requiredType)) {
                    status.setError(UIPlugin.getString(name + ".error.MustExtendClass", hierarchyRoot));
                }
            }

        }
    } catch (JavaModelException e) {
        UIPlugin.log(e);
    }

    return status;
}

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

License:Mozilla Public License

protected IStatus typeChanged() {
    //IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();
    fChosenType = null;/*from   w w  w  .ja  va2  s. c  o  m*/
    SpindleStatus status = new SpindleStatus();
    String typeName = getTextValue();
    if ("".equals(typeName)) {
        status.setError(UIPlugin.getString(fName + ".error.EnterTypeName"));
        return status;
    }
    IStatus val = JavaConventions.validateJavaTypeName(typeName);
    if (!val.isOK()) {
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(UIPlugin.getString(fName + ".error.InvalidTypeName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(UIPlugin.getString(fName + ".warning.TypeNameDiscouraged", val.getMessage()));
        }
    }
    try {
        fChosenType = resolveTypeName(typeName);
        if (fChosenType == null) {
            status.setError(UIPlugin.getString(fName + ".error.TypeNameNotExist"));
            return status;
        }
        if (fRequiredType != null) {
            if (fRequiredType.isInterface()) {
                if (!CoreUtils.implementsInterface(fChosenType, fHierarchyRoot)) {
                    status.setError(
                            UIPlugin.getString(fName + ".error.MustImplementInterface", fHierarchyRoot));
                } else if (!extendsType(fChosenType, fRequiredType)) {
                    status.setError(UIPlugin.getString(fName + ".error.MustExtendClass", fHierarchyRoot));
                }
            }

        }
    } catch (JavaModelException e) {
        UIPlugin.log(e);
    }

    return status;
}

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

License:Mozilla Public License

/**
 * @see AbstractNameField#nameChanged()//from  w w w  .  j a va  2s  . c o m
 */
protected IStatus nameChanged() {
    SpindleStatus status = new SpindleStatus();
    String current = getTextValue();
    if (current == null || "".equals(current)) {
        status.setError("");
        return status;
    }
    if (current.indexOf('.') != -1) {
        status.setError(UIPlugin.getString(fName + ".error.QualifiedName"));
        return status;
    }
    IStatus val = JavaConventions.validateJavaTypeName(current);
    if (!val.isOK()) {
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(UIPlugin.getString(fName + ".error.InvalidServletName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(UIPlugin.getString(fName + ".warning.ServletNameDiscouraged", val.getMessage()));
            return status;
        }
    }
    if (fPackageField != null && fPackageField.getPackageFragment() != null) {
        try {
            IContainer folder = (IContainer) fPackageField.getPackageFragment().getUnderlyingResource();
            IFile file = folder.getFile(new Path(current + ".java"));
            if (file.exists()) {
                status.setError(UIPlugin.getString(fName + ".error.AppAlreadyExists", current));
            }
        } catch (JavaModelException e) {
            // do nothing
        }
    }
    char first = current.charAt(0);
    if (Character.isLowerCase(first)) {
        status.setWarning(
                UIPlugin.getString(fName + ".warning.AppNameDiscouraged", "first character is lowercase"));
    }

    return status;
}