Search in sources :

Example 1 with PsiNameHelper

use of com.intellij.psi.PsiNameHelper in project intellij-community by JetBrains.

the class GroovyCreateClassDialog method createCenterPanel.

@Override
@Nullable
protected JComponent createCenterPanel() {
    myPackageTextField.getDocument().addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            PsiNameHelper nameHelper = PsiNameHelper.getInstance(myProject);
            String packageName = getPackageName();
            getOKAction().setEnabled(nameHelper.isQualifiedName(packageName) || packageName != null && packageName.isEmpty());
        }
    });
    new AnAction() {

        @Override
        public void actionPerformed(AnActionEvent e) {
            myPackageChooseButton.doClick();
        }
    }.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_DOWN_MASK)), myPackageTextField);
    return myContentPane;
}
Also used : PsiNameHelper(com.intellij.psi.PsiNameHelper) CustomShortcutSet(com.intellij.openapi.actionSystem.CustomShortcutSet) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with PsiNameHelper

use of com.intellij.psi.PsiNameHelper in project intellij-community by JetBrains.

the class ClassPatternsPanel method getValidationError.

public String getValidationError(Project project) {
    TableUtil.stopEditing(myTable);
    final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
    final ClassPatternValidator validator = new ClassPatternValidator(nameHelper);
    for (EntryPointsManagerBase.ClassPattern pattern : myModifiedPatterns) {
        final String errorText = validator.getErrorText(pattern.pattern);
        if (errorText != null) {
            return errorText;
        }
        final String subst = pattern.method.replace("*", "");
        if (!subst.isEmpty()) {
            if (!nameHelper.isIdentifier(subst)) {
                return "Method pattern '" + pattern.method + "' must be a valid java identifier, only '*' are accepted as placeholders";
            }
        }
    }
    return null;
}
Also used : PsiNameHelper(com.intellij.psi.PsiNameHelper)

Example 3 with PsiNameHelper

use of com.intellij.psi.PsiNameHelper in project intellij-community by JetBrains.

the class CreatePackageInfoAction method isAvailable.

private static boolean isAvailable(DataContext dataContext) {
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
    if (project == null || view == null) {
        return false;
    }
    final PsiDirectory[] directories = view.getDirectories();
    if (directories.length == 0) {
        return false;
    }
    final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    final JavaDirectoryService directoryService = JavaDirectoryService.getInstance();
    final PsiNameHelper nameHelper = PsiNameHelper.getInstance(project);
    for (PsiDirectory directory : directories) {
        if (projectFileIndex.isUnderSourceRootOfType(directory.getVirtualFile(), JavaModuleSourceRootTypes.SOURCES) && PsiUtil.isLanguageLevel5OrHigher(directory)) {
            final PsiPackage aPackage = directoryService.getPackage(directory);
            if (aPackage != null) {
                final String qualifiedName = aPackage.getQualifiedName();
                if (StringUtil.isEmpty(qualifiedName) || nameHelper.isQualifiedName(qualifiedName)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : PsiNameHelper(com.intellij.psi.PsiNameHelper) Project(com.intellij.openapi.project.Project) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) IdeView(com.intellij.ide.IdeView) JavaDirectoryService(com.intellij.psi.JavaDirectoryService)

Example 4 with PsiNameHelper

use of com.intellij.psi.PsiNameHelper in project intellij-community by JetBrains.

the class BindToNewBeanStep method _commit.

public void _commit(boolean finishChosen) throws CommitStepException {
    // Stop editing if any
    final TableCellEditor cellEditor = myTable.getCellEditor();
    if (cellEditor != null) {
        cellEditor.stopCellEditing();
    }
    // Check that all included fields are bound to valid bean properties
    final PsiNameHelper nameHelper = PsiNameHelper.getInstance(myData.myProject);
    for (int i = 0; i < myData.myBindings.length; i++) {
        final FormProperty2BeanProperty binding = myData.myBindings[i];
        if (binding.myBeanProperty == null) {
            continue;
        }
        if (!nameHelper.isIdentifier(binding.myBeanProperty.myName)) {
            throw new CommitStepException(UIDesignerBundle.message("error.X.is.not.a.valid.property.name", binding.myBeanProperty.myName));
        }
    }
    myData.myGenerateIsModified = myChkIsModified.isSelected();
}
Also used : PsiNameHelper(com.intellij.psi.PsiNameHelper) CommitStepException(com.intellij.ide.wizard.CommitStepException) TableCellEditor(javax.swing.table.TableCellEditor)

Example 5 with PsiNameHelper

use of com.intellij.psi.PsiNameHelper in project liferay-ide by liferay.

the class LiferayModuleWizardStep method validate.

@Override
public boolean validate() throws ConfigurationException {
    String validationTitle = "Validation Error";
    if (CoreUtil.isNullOrEmpty(getSelectedType())) {
        throw new ConfigurationException("Please click one of the items to select a template", validationTitle);
    }
    ProjectManager projectManager = ProjectManager.getInstance();
    Project workspaceProject = projectManager.getOpenProjects()[0];
    String packageNameValue = getPackageName();
    String classNameValue = getClassName();
    PsiDirectoryFactory psiDirectoryFactory = PsiDirectoryFactory.getInstance(workspaceProject);
    PsiNameHelper psiNameHelper = PsiNameHelper.getInstance(workspaceProject);
    if (!CoreUtil.isNullOrEmpty(packageNameValue) && !psiDirectoryFactory.isValidPackageName(packageNameValue)) {
        throw new ConfigurationException(packageNameValue + " is not a valid package name", validationTitle);
    }
    if (!CoreUtil.isNullOrEmpty(classNameValue) && !psiNameHelper.isQualifiedName(classNameValue)) {
        throw new ConfigurationException(classNameValue + " is not a valid java class name", validationTitle);
    }
    return true;
}
Also used : PsiNameHelper(com.intellij.psi.PsiNameHelper) Project(com.intellij.openapi.project.Project) ConfigurationException(com.intellij.openapi.options.ConfigurationException) PsiDirectoryFactory(com.intellij.psi.impl.file.PsiDirectoryFactory) ProjectManager(com.intellij.openapi.project.ProjectManager)

Aggregations

PsiNameHelper (com.intellij.psi.PsiNameHelper)5 Project (com.intellij.openapi.project.Project)2 IdeView (com.intellij.ide.IdeView)1 CommitStepException (com.intellij.ide.wizard.CommitStepException)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 CustomShortcutSet (com.intellij.openapi.actionSystem.CustomShortcutSet)1 DocumentAdapter (com.intellij.openapi.editor.event.DocumentAdapter)1 DocumentEvent (com.intellij.openapi.editor.event.DocumentEvent)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 ProjectManager (com.intellij.openapi.project.ProjectManager)1 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)1 JavaDirectoryService (com.intellij.psi.JavaDirectoryService)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiPackage (com.intellij.psi.PsiPackage)1 PsiDirectoryFactory (com.intellij.psi.impl.file.PsiDirectoryFactory)1 TableCellEditor (javax.swing.table.TableCellEditor)1 Nullable (org.jetbrains.annotations.Nullable)1