List of usage examples for org.eclipse.jdt.core JavaConventions validateFieldName
public static IStatus validateFieldName(String name, String sourceLevel, String complianceLevel)
From source file:com.google.gdt.eclipse.designer.uibinder.model.util.NameSupport.java
License:Open Source License
/** * @return the error message if given name is not valid, or <code>null</code> if this name can be * used.//from w ww. j a v a 2 s .co m */ private String validateName(String name) throws Exception { // check that identifier is valid { IJavaProject javaProject = m_object.getContext().getJavaProject(); String sourceLevel = javaProject.getOption(JavaCore.COMPILER_SOURCE, true); String complianceLevel = javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); IStatus status = JavaConventions.validateFieldName(name, sourceLevel, complianceLevel); if (status.matches(IStatus.ERROR)) { return status.getMessage(); } } // check that name is unique { Set<String> existingNames = getExistingNames(); if (existingNames.contains(name)) { return "Field '" + name + "' already exists."; } } // OK return null; }
From source file:com.liferay.ide.layouttpl.core.operation.NewLayoutTplDataModelProvider.java
License:Open Source License
@Override public IStatus validate(String propertyName) { if (LAYOUT_TEMPLATE_ID.equals(propertyName)) { // first check to see if an existing property exists. LayoutTplDescriptorHelper helper = new LayoutTplDescriptorHelper(getTargetProject()); if (helper.hasTemplateId(getStringProperty(propertyName))) { return LayoutTplCore.createErrorStatus(Msgs.templateIdExists); }//from w w w .j ava 2s . c o m // to avoid marking text like "this" as bad add a z to the end of the string String idValue = getStringProperty(propertyName) + "z"; //$NON-NLS-1$ if (CoreUtil.isNullOrEmpty(idValue)) { return super.validate(propertyName); } IStatus status = JavaConventions.validateFieldName(idValue, CompilerOptions.VERSION_1_7, CompilerOptions.VERSION_1_7); if (!status.isOK()) { return LayoutTplCore.createErrorStatus(Msgs.templateIdInvalid); } String idText = getStringProperty(propertyName); if (CoreUtil.isNullOrEmpty(idText)) { return LayoutTplCore.createErrorStatus("Id can't be empty."); } } else if (LAYOUT_TEMPLATE_FILE.equals(propertyName)) { String filename = getStringProperty(propertyName); if (!checkoutDocrootFileNameCorrect(filename, "tpl")) { return LayoutTplCore.createErrorStatus("Template file name is invalid."); } final IPath filePath = new Path(getStringProperty(LAYOUT_TEMPLATE_FILE)); if (checkDocrootFileExists(filePath)) { return LayoutTplCore.createWarningStatus(Msgs.templateFileExists); } } else if (LAYOUT_WAP_TEMPLATE_FILE.equals(propertyName)) { String filename = getStringProperty(propertyName); if (!checkoutDocrootFileNameCorrect(filename, "tpl")) { return LayoutTplCore.createErrorStatus("WAP template file name is invalid."); } final IPath filePath = new Path(getStringProperty(LAYOUT_WAP_TEMPLATE_FILE)); if (checkDocrootFileExists(filePath)) { return LayoutTplCore.createWarningStatus(Msgs.wapTemplateFileExists); } } else if (LAYOUT_THUMBNAIL_FILE.equals(propertyName)) { String filename = getStringProperty(propertyName); if (!checkoutDocrootFileNameCorrect(filename, "")) { return LayoutTplCore.createErrorStatus("Thumbnail file name is invalid."); } final IPath filePath = new Path(getStringProperty(LAYOUT_THUMBNAIL_FILE)); if (checkDocrootFileExists(filePath)) { return LayoutTplCore.createWarningStatus(Msgs.thumbnailFileExists); } } return super.validate(propertyName); }
From source file:com.worldline.awltech.i18ntools.editor.ui.ResourceBundleEditor.java
License:Open Source License
@Override public void createPartControl(Composite parent) { Composite background = new Composite(parent, SWT.NONE); background.setLayout(new FormLayout()); Group optionsGroup = new Group(background, SWT.NONE); optionsGroup.setText(ResourceBundleEditorMessages.LABEL_OPTIONSGROUP.value()); optionsGroup.setLayout(new FormLayout()); FormDataBuilder.on(optionsGroup).horizontal().bottom(); Group tableGroup = new Group(background, SWT.NONE); tableGroup.setText(ResourceBundleEditorMessages.LABEL_TABLEGROUP.value()); tableGroup.setLayout(new FormLayout()); FormDataBuilder.on(tableGroup).horizontal().top().bottom(optionsGroup); Label localeSelectionLabel = new Label(optionsGroup, SWT.NONE); localeSelectionLabel.setText(ResourceBundleEditorMessages.LABEL_LOCALECOMBO.value()); FormDataBuilder.on(localeSelectionLabel).left().top(0, 8).width(100); Button localeSelectionButton = new Button(optionsGroup, SWT.PUSH); localeSelectionButton.setText(ResourceBundleEditorMessages.LABEL_LOCALEBUTTON.value()); FormDataBuilder.on(localeSelectionButton).right().width(120).height(25).top(); Combo localSelectionCombo = new Combo(optionsGroup, SWT.READ_ONLY); FormDataBuilder.on(localSelectionCombo).left(localeSelectionLabel).top().right(localeSelectionButton); Label addLiteralLabel = new Label(optionsGroup, SWT.NONE); addLiteralLabel.setText(ResourceBundleEditorMessages.LABEL_NEWKEYLABEL.value()); FormDataBuilder.on(addLiteralLabel).left().bottom().width(100).top(localSelectionCombo, 8); Button addLiteralButton = new Button(optionsGroup, SWT.PUSH); addLiteralButton.setText(ResourceBundleEditorMessages.LABEL_NEWKEYBUTTON.value()); FormDataBuilder.on(addLiteralButton).right().width(120).height(25).bottom().top(localSelectionCombo); final Text addLiteralText = new Text(optionsGroup, SWT.BORDER); FormDataBuilder.on(addLiteralText).left(addLiteralLabel).right(addLiteralButton).bottom() .top(localSelectionCombo);/*from ww w.j a v a 2 s . c o m*/ Table table = new Table(tableGroup, SWT.BORDER); FormDataBuilder.on(table).fill(); table.setHeaderVisible(true); table.setLinesVisible(true); TableColumn keyColumn = new TableColumn(table, SWT.NONE); keyColumn.setText(ResourceBundleEditorMessages.LABEL_KEYCOLUMN.value()); TableColumn defaultColumn = new TableColumn(table, SWT.NONE); defaultColumn.setText(ResourceBundleEditorMessages.LABEL_DEFAULTCOLUMN.value()); TableColumn localeColumn = new TableColumn(table, SWT.NONE); localeColumn.setText(ResourceBundleEditorMessages.LABEL_LOCALECOLUMN.value()); this.tableResizeListener = new TableResizeListener(); table.addControlListener(tableResizeListener); tableResizeListener.register(keyColumn, 20); tableResizeListener.register(defaultColumn, 40); tableResizeListener.register(localeColumn, 40); this.comboViewer = new ComboViewer(localSelectionCombo); this.comboViewer.setContentProvider(new EditorComboContentProvider()); this.comboViewer.setLabelProvider(new EditorComboLabelProvider()); this.comboViewer.setInput(this.resourceBundle); this.tableViewer = new TableViewer(table) { @Override public void update(Object element, String[] properties) { super.update(element, properties); firePropertyChange(PROP_DIRTY); } }; TableViewerColumn defaultColumnViewer = new TableViewerColumn(tableViewer, defaultColumn); TableViewerColumn localizedColumnViewer = new TableViewerColumn(tableViewer, localeColumn); defaultColumnViewer.setEditingSupport(new EditorDefaultMessageEditingSupport(tableViewer)); this.editorLocalizedMessageEditingSupport = new EditorLocalizedMessageEditingSupport(tableViewer); localizedColumnViewer.setEditingSupport(this.editorLocalizedMessageEditingSupport); this.comboViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { ISelection selection = event.getSelection(); Object first = ((IStructuredSelection) selection).getFirstElement(); if (first instanceof Locale) { currentLocale = (Locale) first; tableViewer.setLabelProvider(new EditorTableLabelProvider(currentLocale)); editorLocalizedMessageEditingSupport.setLocale(currentLocale); tableViewer.setInput(resourceBundle); } } }); this.tableViewer.setContentProvider(new EditorTableContentProvider()); this.tableViewer.setLabelProvider(new EditorTableLabelProvider(null)); this.tableViewer.setInput(this.resourceBundle); localeSelectionButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { ElementListSelectionDialog dialog = new ElementListSelectionDialog(new Shell(), new EditorComboLabelProvider()); dialog.setMessage(ResourceBundleEditorMessages.LOCALEDIALOG_MESSAGE.value()); dialog.setTitle(ResourceBundleEditorMessages.LOCALEDIALOG_TITLE.value()); dialog.setImage(Activator.getDefault().getImage("/icons/i18neditor.png")); dialog.setMultipleSelection(false); dialog.setElements(Locale.getAvailableLocales()); if (dialog.open() == Window.OK && dialog.getResult().length > 0) { Locale newLocale = (Locale) dialog.getFirstResult(); resourceBundle.addLocale(newLocale); comboViewer.setInput(resourceBundle); comboViewer.setSelection(new StructuredSelection(newLocale)); ResourceBundleEditor.this.firePropertyChange(PROP_DIRTY); } } }); addLiteralButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String value = addLiteralText.getText().trim(); if (JavaConventions.validateFieldName(value, "1.7", "1.7").getSeverity() == IStatus.OK) { resourceBundle.addLiteral(value); tableViewer.setInput(resourceBundle); addLiteralText.setText(""); addLiteralText.update(); ResourceBundleEditor.this.firePropertyChange(PROP_DIRTY); } } }); }
From source file:com.worldline.awltech.i18ntools.wizard.core.ui.validation.FieldTextValidator.java
License:Open Source License
@Override public IStatus validate(final String input) { return JavaConventions.validateFieldName(input, FieldTextValidator.JAVA_VERSION, FieldTextValidator.JAVA_VERSION); }
From source file:org.bonitasoft.studio.businessobject.ui.wizard.validator.FieldNameCellEditorValidator.java
License:Open Source License
protected IStatus doValidate(Object value) { IStatus status = JavaConventions.validateFieldName((String) value, JavaCore.VERSION_1_6, JavaCore.VERSION_1_6);// ww w .ja v a 2s. c o m if (!status.isOK()) { return status; } status = new InputLengthValidator(value.toString(), MAX_COLUMN_NAME_LENGTH).validate(value); if (!status.isOK()) { return status; } if (sqlNameValidator.isSQLKeyword(value.toString())) { return ValidationStatus.error(Messages.bind(Messages.reservedKeyWord, value.toString())); } if (!sqlNameValidator.isValid(value.toString())) { return ValidationStatus.error(Messages.bind(Messages.invalidSQLIdentifier, value.toString())); } if (value.toString().equalsIgnoreCase(Field.PERSISTENCE_ID)) { return ValidationStatus.error(Messages.bind(Messages.reservedKeyWord, Field.PERSISTENCE_ID)); } else if (value.toString().equalsIgnoreCase(Field.PERSISTENCE_VERSION)) { return ValidationStatus.error(Messages.bind(Messages.reservedKeyWord, Field.PERSISTENCE_VERSION)); } for (Field field : bo.getFields()) { if (field.getName().equalsIgnoreCase(value.toString()) && !this.field.equals(field)) { return ValidationStatus.error(Messages.fieldNameAlreadyExists); } } return ValidationStatus.ok(); }
From source file:org.bonitasoft.studio.businessobject.ui.wizard.validator.IndexNameCellEditorValidator.java
License:Open Source License
protected IStatus doValidate(final Object value) { IStatus status = JavaConventions.validateFieldName((String) value, JavaCore.VERSION_1_6, JavaCore.VERSION_1_6);//from w w w. ja v a 2 s .co m if (!status.isOK()) { return status; } status = new InputLengthValidator(value.toString(), MAX_INDEX_NAME_LENGTH).validate(value); if (!status.isOK()) { return status; } if (sqlNameValidator.isSQLKeyword(value.toString())) { return ValidationStatus.error(Messages.bind(Messages.reservedKeyWord, value.toString())); } if (!sqlNameValidator.isValid(value.toString())) { return ValidationStatus.error(Messages.bind(Messages.invalidSQLIdentifier, value.toString())); } for (final BusinessObject bo : bom.getBusinessObjects()) { for (final Index index : bo.getIndexes()) { if (index.getName().equalsIgnoreCase(value.toString()) && !this.index.equals(index)) { return ValidationStatus.error(Messages.indexNameAlreadyExists); } } } return ValidationStatus.ok(); }
From source file:org.bonitasoft.studio.businessobject.ui.wizard.validator.QueryParameterNameCellEditorValidator.java
License:Open Source License
protected IStatus doValidate(Object value) { IStatus status = JavaConventions.validateFieldName((String) value, JavaCore.VERSION_1_6, JavaCore.VERSION_1_6);/*from ww w.j a va2 s. c o m*/ if (!status.isOK()) { return status; } if (value.toString().equalsIgnoreCase(BDMQueryUtil.START_INDEX_PARAM_NAME) || value.toString().equalsIgnoreCase(BDMQueryUtil.MAX_RESULTS_PARAM_NAME)) { return ValidationStatus .error(Messages.bind(Messages.queryParameterNameReservedForPagination, value.toString())); } for (QueryParameter parameter : query.getQueryParameters()) { if (parameter.getName().equalsIgnoreCase(value.toString()) && !this.param.equals(parameter)) { return ValidationStatus .error(Messages.bind(Messages.queryParameterNameAlreadyExists, value.toString())); } } return ValidationStatus.ok(); }
From source file:org.bonitasoft.studio.businessobject.ui.wizard.validator.UniqueConstraintNameCellEditorValidator.java
License:Open Source License
protected IStatus doValidate(Object value) { IStatus status = JavaConventions.validateFieldName((String) value, JavaCore.VERSION_1_6, JavaCore.VERSION_1_6);//w w w. j av a 2 s. co m if (!status.isOK()) { return status; } status = new InputLengthValidator(value.toString(), MAX_CONSTRAINT_NAME_LENGTH).validate(value); if (!status.isOK()) { return status; } if (sqlNameValidator.isSQLKeyword(value.toString())) { return ValidationStatus.error(Messages.bind(Messages.reservedKeyWord, value.toString())); } if (!sqlNameValidator.isValid(value.toString())) { return ValidationStatus.error(Messages.bind(Messages.invalidSQLIdentifier, value.toString())); } for (UniqueConstraint uConstraint : bo.getUniqueConstraints()) { if (uConstraint.getName().equalsIgnoreCase(value.toString()) && !this.uConstraint.equals(uConstraint)) { return ValidationStatus.error(Messages.constraintNameAlreadyExists); } } return ValidationStatus.ok(); }
From source file:org.bonitasoft.studio.common.jface.databinding.validator.GroovyReferenceValidator.java
License:Open Source License
@Override public IStatus validate(Object value) { if (checkEmptyField) { final IStatus s = new EmptyInputValidator(fieldName).validate(value); if (!s.isOK()) { return s; }// w w w. j av a2 s. c o m } else { if (value == null || value.toString().isEmpty()) { return ValidationStatus.ok(); } } if (forceLowerCaseFirst && !value.toString().isEmpty()) { if (Character.isUpperCase(value.toString().charAt(0))) { return ValidationStatus.error(Messages.nameMustStartWithLowerCase); } } if (!value.toString().isEmpty()) { if (value.toString().contains(" ")) { return ValidationStatus.error(Messages.bind(Messages.nameCantHaveAWhitespace, value.toString())); } } if (value.toString() != null && !value.toString().isEmpty() && Arrays.asList(KEYWORDS).contains(value.toString())) { return ValidationStatus.error(Messages.reservedKeyword); } final IStatus javaConventionNameStatus = JavaConventions.validateFieldName(value.toString(), JavaCore.VERSION_1_6, JavaCore.VERSION_1_6); if (!javaConventionNameStatus.isOK()) { return ValidationStatus.error(javaConventionNameStatus.getMessage()); } return ValidationStatus.ok(); }
From source file:org.codehaus.groovy.eclipse.refactoring.core.rename.renameLocal.GroovyRenameLocalVariableProcessor.java
License:Apache License
public RefactoringStatus checkNewElementName(String newName) throws CoreException { if (localVariable.getElementName().equals(newName)) { return RefactoringStatus.createErrorStatus("New name must be different from old name"); } else {/*from w w w .j ava2s .c o m*/ return RefactoringStatus.create(JavaConventions.validateFieldName(newName, CompilerOptions.VERSION_1_6, CompilerOptions.VERSION_1_6)); } }