Java Code Examples for org.openide.util.Utilities#isJavaIdentifier()

The following examples show how to use org.openide.util.Utilities#isJavaIdentifier() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OrderingItemPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void check() {
    if (desc == null)
        return;

    NotificationLineSupport supp = desc.getNotificationLineSupport();
    if (rbName.isSelected()) {
        String s = tfNameRef.getText();
        if (s == null || s.length() < 1) {
            supp.setInformationMessage(NbBundle.getMessage(OrderingItemPanel.class, "ERR_NO_NAME"));
            desc.setValid(false);
            return;
        }
        if (!Utilities.isJavaIdentifier(s)) {
            supp.setErrorMessage(NbBundle.getMessage(OrderingItemPanel.class, "ERR_WRONG_NAME"));
            desc.setValid(false);
            return;
        }
    }
    supp.clearMessages();
    desc.setValid(true);
}
 
Example 2
Source File: NameAndPackagePanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private boolean isValidPackageName(String str) {
    if (str.length() > 0 && str.charAt(0) == '.') {
        return false;
    }
    StringTokenizer tukac = new StringTokenizer(str, ".");
    while (tukac.hasMoreTokens()) {
        String token = tukac.nextToken();
        if ("".equals(token)) {
            return false;
        }
        if (!Utilities.isJavaIdentifier(token)) {
            return false;
        }
    }
    return true;
}
 
Example 3
Source File: WizardUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns true for valid package name.
 */
public static boolean isValidPackageName(String str) {
    if (str.length() > 0 && str.charAt(0) == '.') {
        return false;
    }
    StringTokenizer tukac = new StringTokenizer(str, "."); // NOI18N
    while (tukac.hasMoreTokens()) {
        String token = tukac.nextToken();
        if ("".equals(token)) {
            return false;
        }
        if (!Utilities.isJavaIdentifier(token)) {
            return false;
        }
    }
    return true;
}
 
Example 4
Source File: EventSetPatternNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Tests if the given string is valid name for associated pattern and if not, notifies
* the user.
* @return true if it is ok.
*/
boolean testNameValidity( String name ) {

    if (! Utilities.isJavaIdentifier( name ) ) {
        DialogDisplayer.getDefault().notify(
            new NotifyDescriptor.Message(getString("MSG_Not_Valid_Identifier"),
                                         NotifyDescriptor.ERROR_MESSAGE) );
        return false;
    }

    if (name.indexOf( "Listener" ) <= 0 ) { // NOI18N
        String msg = MessageFormat.format( getString("FMT_InvalidEventSourceName"),
                                           new Object[] { name } );
        DialogDisplayer.getDefault().notify( new NotifyDescriptor.Message(msg, NotifyDescriptor.ERROR_MESSAGE) );
        return false;
    }

    return true;
}
 
Example 5
Source File: NameAndLocationPanel.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkValidity() {
//        if (!checkPlatformValidity()) {
//            return false;
//        }
        if (txtName.getText().trim().length() == 0) {
            setError(getMessage("ERR_Name_Prefix_Empty"));
            return false;
        }
        if (!Utilities.isJavaIdentifier(txtName.getText().trim())) {
            setError(getMessage("ERR_Name_Prefix_Invalid"));
            return false;
        }
        String packageName = comPackageName.getEditor().getItem().toString().trim();
        if (packageName.length() == 0 || !UIUtil.isValidPackageName(packageName)) {
            setError(getMessage("ERR_Package_Invalid"));
            return false;
        }

        markValid();
        return true;
    }
 
Example 6
Source File: NameAndLocationPanel.java    From visualvm with GNU General Public License v2.0 6 votes vote down vote up
private boolean checkValidity() {
//        if (!checkPlatformValidity()) {
//            return false;
//        }
        if (txtName.getText().trim().length() == 0) {
            setError(getMessage("ERR_Name_Prefix_Empty"));
            return false;
        }
        if (!Utilities.isJavaIdentifier(txtName.getText().trim())) {
            setError(getMessage("ERR_Name_Prefix_Invalid"));
            return false;
        }
        String packageName = comPackageName.getEditor().getItem().toString().trim();
        if (packageName.length() == 0 || !UIUtil.isValidPackageName(packageName)) {
            setError(getMessage("ERR_Package_Invalid"));
            return false;
        }

        markValid();
        return true;
    }
 
Example 7
Source File: ProjectServerPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean isMainClassValid(String mainClassName) {
    StringTokenizer tk = new StringTokenizer(mainClassName, "."); //NOI18N
    boolean valid = tk.countTokens() > 0;
    while (tk.hasMoreTokens()) {
        String token = tk.nextToken();
        if (token.length() == 0 || !Utilities.isJavaIdentifier(token)) {
            valid = false;
            break;
        }
    }
    return valid;
}
 
Example 8
Source File: FileUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static void processFolder(FileObject file, NameObtainer nameObtainer, SortedSet<String> result, boolean onlyRoots) {
    Enumeration<? extends FileObject> dataFiles = file.getData(false);
    Enumeration<? extends FileObject> folders = file.getFolders(false);

    if (dataFiles.hasMoreElements()) {
        while (dataFiles.hasMoreElements()) {
            FileObject kid = dataFiles.nextElement();
            if ((kid.hasExt("java") || kid.hasExt("class")) && Utilities.isJavaIdentifier(kid.getName())) {
                // at least one java or class inside directory -> valid package
                String packageName = nameObtainer.getPackageName(file);
                if (packageName == null) {
                    continue;
                }
                result.add(packageName);
                if (onlyRoots) {
                    // don't recurse into subfolders
                    return;
                } else {
                    // recurse inot subfolders
                    break;
                }
            }
        }
    }

    while (folders.hasMoreElements()) {
        processFolder(folders.nextElement(), nameObtainer, result, onlyRoots);
    }
}
 
Example 9
Source File: JavaUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isValidPackageName(String str) {
    if (str.length() > 0 && (str.charAt(0) == '.' || str.endsWith("."))) {
        return false;
    }
    StringTokenizer tukac = new StringTokenizer(str, ".");
    while (tukac.hasMoreTokens()) {
        String token = tukac.nextToken();
        if ("".equals(token))
            return false;
        if (!Utilities.isJavaIdentifier(token))
            return false;
    }
    return true;
}
 
Example 10
Source File: CreateRelationshipPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public NameStatus checkName(String name){
    if (!Utilities.isJavaIdentifier(name)){
        return NameStatus.ILLEGAL_JAVA_ID;
    }
    
    if (JavaPersistenceQLKeywords.isKeyword(name)){
        return NameStatus.ILLEGAL_SQL_KEYWORD;
    }
    
    if (existingFieldNames != null && existingFieldNames.contains(name)){
        return NameStatus.DUPLICATE;
    }
    
    return NameStatus.VALID;
}
 
Example 11
Source File: EncapsulateFieldRefactoringPlugin.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Problem fastCheckParameters(String getter, String setter,
        Set<Modifier> methodModifier, Set<Modifier> fieldModifier,
        boolean alwaysUseAccessors) {

    if ((getter != null && !Utilities.isJavaIdentifier(getter))
            || (setter != null && !Utilities.isJavaIdentifier(setter))
            || (getter == null && setter == null)) {
        // user doesn't use valid java identifier, it cannot be used
        // as getter/setter name
        return new Problem(true, NbBundle.getMessage(EncapsulateFieldRefactoringPlugin.class, "ERR_EncapsulateMethods"));
    } else {
        // we have no problem :-)
        return null;
    }
}
 
Example 12
Source File: FxXmlSymbols.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isQualifiedIdentifier(String qn) {
    StringTokenizer tukac = new StringTokenizer(qn, ".");
    if (!tukac.hasMoreTokens()) {
        return false;
    }
    while (tukac.hasMoreTokens()) {
        if (!Utilities.isJavaIdentifier(tukac.nextToken())) {
            return false;
        }
    }
    return true;
}
 
Example 13
Source File: SingletonSetupPanelVisual.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean valid(WizardDescriptor wizard) {
    AbstractPanel.clearErrorMessage(wizard);
    String resourceUri = uriTextField.getText().trim();
    String packageName = getPackage();
    String className = classTextField.getText().trim();
    SourceGroup[] groups = SourceGroupSupport.getJavaSourceGroups(project);

    if (groups == null || groups.length < 1) {
        AbstractPanel.setErrorMessage(wizard, "MSG_NoJavaSourceRoots");
        return false;
    } else if (className.length() == 0 || !Utilities.isJavaIdentifier(className)) {
        AbstractPanel.setErrorMessage(wizard, "MSG_InvalidResourceClassName");
        return false;
    } else if (resourceUri.length() == 0) {
        AbstractPanel.setErrorMessage(wizard, "MSG_EmptyUriTemplate");
        return false;
    } else if (!Util.isValidPackageName(packageName)) {
        AbstractPanel.setErrorMessage(wizard, "MSG_InvalidPackageName");
        return false;
    } else if (getResourceClassFile() != null) {
        AbstractPanel.setErrorMessage(wizard, "MSG_ExistingClass");
        return false;
    } else if (!Util.isValidUri(resourceUri)) {
        AbstractPanel.setErrorMessage(wizard, "MSG_IncorrectUriTemplate");
        return false;
    }
    return true;
}
 
Example 14
Source File: Util.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static boolean isValidUri(String uri) {
    StringTokenizer segments = new StringTokenizer(uri, "/ "); //NOI18N
    Set<String> uriParts = new HashSet<String>();
    while (segments.hasMoreTokens()) {
        String segment = segments.nextToken();
        if (segment.startsWith("{")) { //NOI18N
            if (segment.length() > 2 && segment.endsWith("}")) { //NOI18N
                String uriPart = segment.substring(1, segment.length() - 1);
                if (!Utilities.isJavaIdentifier(uriPart)) {
                    return false;
                }
                if (uriParts.contains(uriPart)) {
                    return false;
                } else {
                    uriParts.add(uriPart);
                }

            } else {
                return false;
            }
        } else {
            if (segment.contains("{") || segment.contains("}")) { //NOI18N
                return false;
            }
        }
    }
    return true;
}
 
Example 15
Source File: SelectedTables.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Set<Problem> validateClassName(String className) {
        Set<Problem> problems = EnumSet.noneOf(Problem.class);
        if (!Utilities.isJavaIdentifier(className)) {
            problems.add(Problem.NO_JAVA_IDENTIFIER);
        }
        if (JavaPersistenceQLKeywords.isKeyword(className)) {
            problems.add(Problem.JPA_QL_IDENTIFIER);
        }
/* commented to have an ability to update entity classes
        if (targetFolder != null && targetFolder.getFileObject(className, "java") != null) { // NOI18N
            problems.add(Problem.ALREADY_EXISTS);
        }
 */
        return problems;
    }
 
Example 16
Source File: NameAndLocationPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private boolean checkValidity() {
    if (txtPrefix.getText().trim().length() == 0) {
        setInfo(getMessage("ERR_Name_Prefix_Empty"), false);
        return false;
    }        
    if (!Utilities.isJavaIdentifier(txtPrefix.getText().trim())) {
        setError(getMessage("ERR_Name_Prefix_Invalid"));
        return false;
    }
    String path = txtIcon.getText().trim();
    if (path.length() != 0) {
        File fil = new File(path);
        if (!fil.exists()) {
            setError(NbBundle.getMessage(getClass(), "ERR_Icon_Invalid"));
            return false;
        }
    }
    String packageName = comPackageName.getEditor().getItem().toString().trim();
    
    if (packageName.length() == 0 || !WizardUtils.isValidPackageName(packageName)) { //NOI18N
        setError(NbBundle.getMessage(getClass(), "ERR_Package_Invalid"));
        return false;
    }
    
    File icon = (path.length() == 0) ? null : new File(path);
    if (icon == null || !icon.exists()) {
        setWarning(WizardUtils.getNoIconSelectedWarning(16,16), !useMultiView.isSelected());
    } else if (!WizardUtils.isValidIcon(icon,16,16)) {
        setWarning(WizardUtils.getIconDimensionWarning(icon,16,16), !useMultiView.isSelected());
    } else {
        markValid();
    }
    return true;
}
 
Example 17
Source File: EjbFacadeWizardPanel2.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean isValidPackageName(String str) {
    if (str.length() > 0 && str.charAt(0) == '.') {         //NOI18N
        return false;
    }
    StringTokenizer tukac = new StringTokenizer(str, ".");  //NOI18N
    while (tukac.hasMoreTokens()) {
        String token = tukac.nextToken();
        if ("".equals(token)) {                             //NOI18N
            return false;
        } else if (!Utilities.isJavaIdentifier(token)) {
            return false;
        }
    }
    return true;
}
 
Example 18
Source File: DataSourceReferencePanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean verifyComponents() {
    // reference name
    String refName = dsReferenceText.getText();
    if (refName == null || refName.trim().length() == 0) {
        setInfo("ERR_NO_REFNAME"); // NOI18N
        return false;
    } else {
        refName = refName.trim();
        if (!Utilities.isJavaIdentifier(refName)){
            setError("ERR_INVALID_REFNAME"); // NOI18N
            return false;
        }
        if (refNames.contains(refName)) {
            setError("ERR_DUPLICATE_REFNAME"); // NOI18N
            return false;
        }
    }
    
    // data sources (radio + combo)
    if (dsGroup.getSelection() == null) {
        setInfo("ERR_NO_DATASOURCE_SELECTED"); // NOI18N
        return false;
    } else if (projectDsRadio.isSelected()) {
        if (projectDsCombo.getItemCount() == 0
                || projectDsCombo.getSelectedIndex() == -1) {
            setInfo("ERR_NO_DATASOURCE_SELECTED"); // NOI18N
            return false;
        }
    } else if (serverDsRadio.isSelected()) {
        if (serverDsCombo.getItemCount() == 0
                || serverDsCombo.getSelectedIndex() == -1) {
            setInfo("ERR_NO_DATASOURCE_SELECTED"); // NOI18N
            return false;
        }
    }

    if (!isDsApiSupportedByServerPlugin) {
        // DS API is not supported by the server plugin
        statusLine.setWarningMessage(NbBundle.getMessage(DataSourceReferencePanel.class, "LBL_DSC_Warning"));
        return true;
    }
    
    // no errors
    statusLine.clearMessages();
    return true;
}
 
Example 19
Source File: NameChangeSupport.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@NbBundle.Messages({
    "ERR_NameIsEmpty=Name is empty",
    "ERR_NameIsNotValid=Name is not a vallid java identifier"
})
@Override
public void run() {
    TreePathHandle t;
    MemberValidator v;
    synchronized (this) {
        if (validateName == null) {
            return;
        }
        if (validator == null) {
            return;
        }
        t = target;
        v = validator;
    }
    boolean nv = false;
    Modifier mod = null;
    final ChangeListener l;
    
    if (validateName.isEmpty()) {
        notifyNameError(Bundle.ERR_NameIsEmpty());
        nv = false;
    } else if (!Utilities.isJavaIdentifier(validateName)) {
        notifyNameError(Bundle.ERR_NameIsNotValid());
        nv = false;
    } else {
        MemberSearchResult res = v.validateName(t, control.getText().trim());
        nv = updateUI(res);
        mod = res == null ? null : res.getRequiredModifier();
    }
    synchronized (this) {
        if (minAccess == mod && nv == valid) {
            return;
        }
        this.valid = nv;
        if (nv) {
            minAccess = mod;
        }
        l = listener;
    }
    if (l != null) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                l.stateChanged(new ChangeEvent(this));
            }
        });
    }
}
 
Example 20
Source File: QuickSearchPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private boolean checkValidity() {
    final String fileName = classNameTextField.getText().trim();
    if (fileName.length() == 0) {
        setWarning(getMessage("ERR_FN_EMPTY"), false);
        return false;
    }

    if (!Utilities.isJavaIdentifier(normalize(fileName))) {
        setError(getMessage("ERR_FN_INVALID"));
        return false;
    }

    String packName = packageCombo.getEditor().getItem().toString();
    if (packName.equals("")) {
        setWarning(getMessage("EMPTY_PACKAGE"), false);
        return false;
    }

    if (categoryNameTextField.getText().equals("")) {
        setWarning(getMessage("EMPTY_CATEGORY"), false);
        return false;
    }

    if (commandPrefixTextField.getText().trim().equals("")) {
        setWarning(getMessage("ERR_EMPTY_PREFIX"), false);
    }

    if (!commandPrefixTextField.getText().trim().matches("\\w*")) {//alfanumeric only
        setError(getMessage("ERR_PREFIX_INVALID"));
        return false;
    }

    if (positionTextField.getText().equals("")) {
        setWarning(getMessage("ERR_POSITION_EMPTY"), false);
        return false;
    }

    if (!positionTextField.getText().trim().matches("\\d*")) {
        setError(getMessage("ERR_POSITION_INVALID"));
        return false;
    }

    markValid();
    return true;
}