* </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;
}
String typeDeclaration = "class " + typeNameWithParameters + " {}"; //$NON-NLS-1$//$NON-NLS-2$
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;
}