List of usage examples for org.eclipse.jdt.core JavaConventions validateTypeVariableName
public static IStatus validateTypeVariableName(String name, String sourceLevel, String complianceLevel)
From source file:com.android.ide.eclipse.adt.internal.wizards.newproject.ApplicationInfoPage.java
License:Open Source License
/** * Validates the given activity name// ww w . j a v a 2 s . co m * * @param activityFieldContents the activity name to validate * @return a status for whether the activity name is valid */ public static IStatus validateActivity(String activityFieldContents) { // Validate activity field if (activityFieldContents == null || activityFieldContents.length() == 0) { return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, "Activity name must be specified."); } else if (ACTIVITY_NAME_SUFFIX.equals(activityFieldContents)) { return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, "Enter a valid activity name"); } else if (activityFieldContents.contains("..")) { //$NON-NLS-1$ return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, "Package segments in activity name cannot be empty (..)"); } // The activity field can actually contain part of a sub-package name // or it can start with a dot "." to indicates it comes from the parent package // name. String packageName = ""; //$NON-NLS-1$ int pos = activityFieldContents.lastIndexOf('.'); if (pos >= 0) { packageName = activityFieldContents.substring(0, pos); if (packageName.startsWith(".")) { //$NON-NLS-1$ packageName = packageName.substring(1); } activityFieldContents = activityFieldContents.substring(pos + 1); } // the activity field can contain a simple java identifier, or a // package name or one that starts with a dot. So if it starts with a dot, // ignore this dot -- the rest must look like a package name. if (activityFieldContents.length() > 0 && activityFieldContents.charAt(0) == '.') { activityFieldContents = activityFieldContents.substring(1); } // Check it's a valid activity string IStatus status = JavaConventions.validateTypeVariableName(activityFieldContents, JDK_15, JDK_15); if (!status.isOK()) { return status; } // Check it's a valid package string if (packageName.length() > 0) { status = JavaConventions.validatePackageName(packageName, JDK_15, JDK_15); if (!status.isOK()) { return new Status(IStatus.ERROR, AdtPlugin.PLUGIN_ID, status.getMessage() + " (in the activity name)"); } } return null; }
From source file:com.android.ide.eclipse.adt.internal.wizards.newproject.NewProjectCreationPage.java
License:Open Source License
/** * Validates the activity name field.//w w w .j a va2 s .c o m * * @return The wizard message type, one of MSG_ERROR, MSG_WARNING or MSG_NONE. */ private int validateActivityField() { // Disregard if not creating an activity if (!mInfo.isCreateActivity()) { return MSG_NONE; } // Validate activity field String activityFieldContents = mInfo.getActivityName(); if (activityFieldContents.length() == 0) { return setStatus("Activity name must be specified.", MSG_ERROR); } // The activity field can actually contain part of a sub-package name // or it can start with a dot "." to indicates it comes from the parent package name. String packageName = ""; //$NON-NLS-1$ int pos = activityFieldContents.lastIndexOf('.'); if (pos >= 0) { packageName = activityFieldContents.substring(0, pos); if (packageName.startsWith(".")) { //$NON-NLS-1$ packageName = packageName.substring(1); } activityFieldContents = activityFieldContents.substring(pos + 1); } // the activity field can contain a simple java identifier, or a // package name or one that starts with a dot. So if it starts with a dot, // ignore this dot -- the rest must look like a package name. if (activityFieldContents.charAt(0) == '.') { activityFieldContents = activityFieldContents.substring(1); } // Check it's a valid activity string int result = MSG_NONE; IStatus status = JavaConventions.validateTypeVariableName(activityFieldContents, "1.5", "1.5"); //$NON-NLS-1$ $NON-NLS-2$ if (!status.isOK()) { result = setStatus(status.getMessage(), status.getSeverity() == IStatus.ERROR ? MSG_ERROR : MSG_WARNING); } // Check it's a valid package string if (result != MSG_ERROR && packageName.length() > 0) { status = JavaConventions.validatePackageName(packageName, "1.5", "1.5"); //$NON-NLS-1$ $NON-NLS-2$ if (!status.isOK()) { result = setStatus(status.getMessage() + " (in the activity name)", status.getSeverity() == IStatus.ERROR ? MSG_ERROR : MSG_WARNING); } } return result; }
From source file:com.android.ide.eclipse.adt.wizards.newproject.NewProjectCreationPage.java
License:Open Source License
/** * Validates the activity name field./*from w w w . ja v a 2 s . c o m*/ * * @return The wizard message type, one of MSG_ERROR, MSG_WARNING or MSG_NONE. */ private int validateActivityField() { // Disregard if not creating an activity if (!isCreateActivity()) { return MSG_NONE; } // Validate activity field String activityFieldContents = getActivityName(); if (activityFieldContents.length() == 0) { return setStatus("Activity name must be specified.", MSG_ERROR); } // The activity field can actually contain part of a sub-package name // or it can start with a dot "." to indicates it comes from the parent package name. String packageName = ""; int pos = activityFieldContents.lastIndexOf('.'); if (pos >= 0) { packageName = activityFieldContents.substring(0, pos); if (packageName.startsWith(".")) { //$NON-NLS-1$ packageName = packageName.substring(1); } activityFieldContents = activityFieldContents.substring(pos + 1); } // the activity field can contain a simple java identifier, or a // package name or one that starts with a dot. So if it starts with a dot, // ignore this dot -- the rest must look like a package name. if (activityFieldContents.charAt(0) == '.') { activityFieldContents = activityFieldContents.substring(1); } // Check it's a valid activity string int result = MSG_NONE; IStatus status = JavaConventions.validateTypeVariableName(activityFieldContents, "1.5", "1.5"); //$NON-NLS-1$ $NON-NLS-2$ if (!status.isOK()) { result = setStatus(status.getMessage(), status.getSeverity() == IStatus.ERROR ? MSG_ERROR : MSG_WARNING); } // Check it's a valid package string if (result != MSG_ERROR && packageName.length() > 0) { status = JavaConventions.validatePackageName(packageName, "1.5", "1.5"); //$NON-NLS-1$ $NON-NLS-2$ if (!status.isOK()) { result = setStatus(status.getMessage() + " (in the activity name)", status.getSeverity() == IStatus.ERROR ? MSG_ERROR : MSG_WARNING); } } return result; }
From source file:org.eclipse.andmore.internal.wizards.newproject.ApplicationInfoPage.java
License:Open Source License
/** * Validates the given activity name//w w w .j av a2 s .c o m * * @param activityFieldContents the activity name to validate * @return a status for whether the activity name is valid */ public static IStatus validateActivity(String activityFieldContents) { // Validate activity field if (activityFieldContents == null || activityFieldContents.length() == 0) { return new Status(IStatus.ERROR, AndmoreAndroidPlugin.PLUGIN_ID, "Activity name must be specified."); } else if (ACTIVITY_NAME_SUFFIX.equals(activityFieldContents)) { return new Status(IStatus.ERROR, AndmoreAndroidPlugin.PLUGIN_ID, "Enter a valid activity name"); } else if (activityFieldContents.contains("..")) { //$NON-NLS-1$ return new Status(IStatus.ERROR, AndmoreAndroidPlugin.PLUGIN_ID, "Package segments in activity name cannot be empty (..)"); } // The activity field can actually contain part of a sub-package name // or it can start with a dot "." to indicates it comes from the parent package // name. String packageName = ""; //$NON-NLS-1$ int pos = activityFieldContents.lastIndexOf('.'); if (pos >= 0) { packageName = activityFieldContents.substring(0, pos); if (packageName.startsWith(".")) { //$NON-NLS-1$ packageName = packageName.substring(1); } activityFieldContents = activityFieldContents.substring(pos + 1); } // the activity field can contain a simple java identifier, or a // package name or one that starts with a dot. So if it starts with a dot, // ignore this dot -- the rest must look like a package name. if (activityFieldContents.length() > 0 && activityFieldContents.charAt(0) == '.') { activityFieldContents = activityFieldContents.substring(1); } // Check it's a valid activity string IStatus status = JavaConventions.validateTypeVariableName(activityFieldContents, JDK_15, JDK_15); if (!status.isOK()) { return status; } // Check it's a valid package string if (packageName.length() > 0) { status = JavaConventions.validatePackageName(packageName, JDK_15, JDK_15); if (!status.isOK()) { return new Status(IStatus.ERROR, AndmoreAndroidPlugin.PLUGIN_ID, status.getMessage() + " (in the activity name)"); } } return null; }
From source file:org.eclipse.incquery.tooling.ui.wizards.NewEiqFileWizardContainerConfigurationPage.java
License:Open Source License
/** * Used to validate the page.//from w w w. j ava 2s .c o m * * Note that because of policy restrictions, a wizard must not come up with an error. * */ private void validatePage() { IStatus packageStatus = validatePackageName(getPackageText()); StatusInfo si = new StatusInfo(packageStatus.getSeverity(), packageStatus.getMessage()); String containerPath = getPackageFragmentRootText(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource containerResource = root.findMember(new Path(containerPath)); if (containerPath.matches("") || containerResource == null) { si.setError(SOURCE_FOLDER_ERROR); } if (fileText != null) { String fileName = fileText.getText(); String packageName = getPackageText().replaceAll("\\.", "/"); if (root.findMember(new Path(containerPath + "/" + packageName + "/" + fileText.getText())) != null) { si.setError(THE_GIVEN_FILE_ALREADY_EXISTS); } if (fileName.length() == 0) { si.setError(FILE_NAME_ERROR); } if (fileName.replace('\\', '/').indexOf('/', 1) > 0) { si.setError(FILE_NAME_NOT_VALID); } boolean wrongExtension = false; if (!fileName.contains(".")) { wrongExtension = true; } else { int dotLoc = fileName.lastIndexOf('.'); String ext = fileName.substring(dotLoc + 1); wrongExtension = !ext.equalsIgnoreCase("eiq"); String name = fileName.substring(0, dotLoc); IStatus nameValidatorStatus = JavaConventions.validateTypeVariableName(name, JavaCore.VERSION_1_6, JavaCore.VERSION_1_6); if (nameValidatorStatus.getSeverity() == IStatus.ERROR) { si.setError(String.format("Filename %s is not a valid Java type name.", name)); } } if (wrongExtension) { si.setError(FILE_EXTENSION_ERROR); } } if (si.getSeverity() == IStatus.OK) { si.setInfo(""); } if (si.isError()) { setErrorMessage(si.getMessage()); } updateStatus(si); }
From source file:org.eclipse.viatra.query.patternlanguage.emf.sirius.wizard.NewVgqlFileConfigurationPage.java
License:Open Source License
/** * Used to validate the page.//from w w w . j a v a 2 s . co m * * Note that because of policy restrictions, a wizard must not come up with an error. * */ private void validatePage() { IStatus packageStatus = validatePackageName(getPackageText()); StatusInfo si = new StatusInfo(packageStatus.getSeverity(), packageStatus.getMessage()); String containerPath = getPackageFragmentRootText(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource containerResource = root.findMember(new Path(containerPath)); if (containerPath.matches("") || containerResource == null) { si.setError(SOURCE_FOLDER_ERROR); } if (fileText != null) { String fileName = fileText.getText(); String packageName = getPackageText().replaceAll("\\.", "/"); if (root.findMember(new Path(containerPath + "/" + packageName + "/" + fileText.getText())) != null) { si.setError(THE_GIVEN_FILE_ALREADY_EXISTS); } if (fileName.length() == 0) { si.setError(FILE_NAME_ERROR); } if (fileName.replace('\\', '/').indexOf('/', 1) > 0) { si.setError(FILE_NAME_NOT_VALID); } IStatus nameValidatorStatus = JavaConventions.validateTypeVariableName(fileName, JavaCore.VERSION_1_8, JavaCore.VERSION_1_8); if (nameValidatorStatus.getSeverity() == IStatus.ERROR) { si.setError(String.format("Filename %s is not a valid Java type name.", fileName)); } } if (si.getSeverity() == IStatus.OK) { si.setInfo(""); } if (si.isError()) { setErrorMessage(si.getMessage()); } updateStatus(si); }
From source file:org.eclipse.viatra.query.tooling.ui.wizards.NewVqlFileWizardContainerConfigurationPage.java
License:Open Source License
/** * Used to validate the page.//from ww w . j a va 2 s .c o m * * Note that because of policy restrictions, a wizard must not come up with an error. * */ private void validatePage() { IStatus packageStatus = validatePackageName(getPackageText()); StatusInfo si = new StatusInfo(packageStatus.getSeverity(), packageStatus.getMessage()); String containerPath = getPackageFragmentRootText(); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IResource containerResource = root.findMember(new Path(containerPath)); if (containerPath.matches("") || containerResource == null) { si.setError(SOURCE_FOLDER_ERROR); } if (fileText != null) { String fileName = fileText.getText(); String packageName = getPackageText().replaceAll("\\.", "/"); if (root.findMember(new Path(containerPath + "/" + packageName + "/" + fileText.getText())) != null) { si.setError(THE_GIVEN_FILE_ALREADY_EXISTS); } if (fileName.length() == 0) { si.setError(FILE_NAME_ERROR); } if (fileName.replace('\\', '/').indexOf('/', 1) > 0) { si.setError(FILE_NAME_NOT_VALID); } boolean wrongExtension = false; if (!fileName.contains(".")) { wrongExtension = true; } else { int dotLoc = fileName.lastIndexOf('.'); String ext = fileName.substring(dotLoc + 1); wrongExtension = !ext.equalsIgnoreCase("vql"); String name = fileName.substring(0, dotLoc); IStatus nameValidatorStatus = JavaConventions.validateTypeVariableName(name, JavaCore.VERSION_1_7, JavaCore.VERSION_1_7); if (nameValidatorStatus.getSeverity() == IStatus.ERROR) { si.setError(String.format("Filename %s is not a valid Java type name.", name)); } } if (wrongExtension) { si.setError(FILE_EXTENSION_ERROR); } } if (si.getSeverity() == IStatus.OK) { si.setInfo(""); } if (si.isError()) { setErrorMessage(si.getMessage()); } updateStatus(si); }