Java 类com.intellij.lang.LanguageNamesValidation 实例源码

项目:intellij-ce-playground    文件:SpellCheckerDictionaryGenerator.java   
protected void addSeenWord(HashSet<String> seenNames, String word, Language language) {
  final String lowerWord = word.toLowerCase();
  if (globalSeenNames.contains(lowerWord)) {
    return;
  }

  final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(language);
  if (namesValidator != null && namesValidator.isKeyword(word, myProject)) {
    return;
  }

  globalSeenNames.add(lowerWord);
  if (mySpellCheckerManager.hasProblem(lowerWord)){
    seenNames.add(lowerWord);
  }
}
项目:intellij-ce-playground    文件:RenameUtil.java   
public static boolean isValidName(final Project project, final PsiElement psiElement, final String newName) {
  if (newName == null || newName.length() == 0) {
    return false;
  }
  final Condition<String> inputValidator = RenameInputValidatorRegistry.getInputValidator(psiElement);
  if (inputValidator != null) {
    return inputValidator.value(newName);
  }
  if (psiElement instanceof PsiFile || psiElement instanceof PsiDirectory) {
    return newName.indexOf('\\') < 0 && newName.indexOf('/') < 0;
  }
  if (psiElement instanceof PomTargetPsiElement) {
    return !StringUtil.isEmptyOrSpaces(newName);
  }

  final PsiFile file = psiElement.getContainingFile();
  final Language elementLanguage = psiElement.getLanguage();

  final Language fileLanguage = file == null ? null : file.getLanguage();
  Language language = fileLanguage == null ? elementLanguage : fileLanguage.isKindOf(elementLanguage) ? fileLanguage : elementLanguage;

  return LanguageNamesValidation.INSTANCE.forLanguage(language).isIdentifier(newName.trim(), project);
}
项目:intellij-ce-playground    文件:IntroduceParameterDialog.java   
public IntroduceParameterDialog(XPathExpression expression, int numberOfExpressions, boolean forceDefault) {
    super(expression.getProject(), LanguageNamesValidation.INSTANCE.forLanguage(expression.getLanguage()));
    myForceDefault = forceDefault;
    init(expression, numberOfExpressions, TITLE);

    getOKAction().addPropertyChangeListener(new PropertyChangeListener() {
        @SuppressWarnings({"AutoUnboxing"})
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("enabled")) {
                myPreviewAction.setEnabled(((Boolean)evt.getNewValue()) && !myCreateWithDefault.isSelected());
            }
        }
    });
    if (forceDefault) {
        myCreateWithDefault.setSelected(true);
        myCreateWithDefault.setVisible(false);
    } else {
        myCreateWithDefault.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                myPreviewAction.setEnabled(getOKAction().isEnabled() && !myCreateWithDefault.isSelected());
            }
        });
    }
    myPreviewAction.setEnabled(false);
}
项目:tools-idea    文件:SpellCheckerDictionaryGenerator.java   
protected void addSeenWord(HashSet<String> seenNames, String word, Language language) {
  final String lowerWord = word.toLowerCase();
  if (globalSeenNames.contains(lowerWord)) {
    return;
  }

  final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(language);
  if (namesValidator != null && namesValidator.isKeyword(word, myProject)) {
    return;
  }

  globalSeenNames.add(lowerWord);
  if (mySpellCheckerManager.hasProblem(lowerWord)){
    seenNames.add(lowerWord);
  }
}
项目:tools-idea    文件:RenameUtil.java   
public static boolean isValidName(final Project project, final PsiElement psiElement, final String newName) {
  if (newName == null || newName.length() == 0) {
    return false;
  }
  final Condition<String> inputValidator = RenameInputValidatorRegistry.getInputValidator(psiElement);
  if (inputValidator != null) {
    return inputValidator.value(newName);
  }
  if (psiElement instanceof PsiFile || psiElement instanceof PsiDirectory) {
    return newName.indexOf('\\') < 0 && newName.indexOf('/') < 0;
  }
  if (psiElement instanceof PomTargetPsiElement) {
    return !StringUtil.isEmptyOrSpaces(newName);
  }

  final PsiFile file = psiElement.getContainingFile();
  final Language elementLanguage = psiElement.getLanguage();

  final Language fileLanguage = file == null ? null : file.getLanguage();
  Language language = fileLanguage == null ? elementLanguage : fileLanguage.isKindOf(elementLanguage) ? fileLanguage : elementLanguage;

  return LanguageNamesValidation.INSTANCE.forLanguage(language).isIdentifier(newName.trim(), project);
}
项目:tools-idea    文件:IntroduceParameterDialog.java   
public IntroduceParameterDialog(XPathExpression expression, int numberOfExpressions, boolean forceDefault) {
    super(expression.getProject(), LanguageNamesValidation.INSTANCE.forLanguage(expression.getLanguage()));
    myForceDefault = forceDefault;
    init(expression, numberOfExpressions, TITLE);

    getOKAction().addPropertyChangeListener(new PropertyChangeListener() {
        @SuppressWarnings({"AutoUnboxing"})
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("enabled")) {
                myPreviewAction.setEnabled(((Boolean)evt.getNewValue()) && !myCreateWithDefault.isSelected());
            }
        }
    });
    if (forceDefault) {
        myCreateWithDefault.setSelected(true);
        myCreateWithDefault.setVisible(false);
    } else {
        myCreateWithDefault.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                myPreviewAction.setEnabled(getOKAction().isEnabled() && !myCreateWithDefault.isSelected());
            }
        });
    }
    myPreviewAction.setEnabled(false);
}
项目:consulo    文件:RenameUtil.java   
public static boolean isValidName(final Project project, final PsiElement psiElement, final String newName) {
  if (newName == null || newName.length() == 0) {
    return false;
  }
  final Condition<String> inputValidator = RenameInputValidatorRegistry.getInputValidator(psiElement);
  if (inputValidator != null) {
    return inputValidator.value(newName);
  }
  if (psiElement instanceof PsiFile || psiElement instanceof PsiDirectory) {
    return newName.indexOf('\\') < 0 && newName.indexOf('/') < 0;
  }
  if (psiElement instanceof PomTargetPsiElement) {
    return !StringUtil.isEmptyOrSpaces(newName);
  }

  final PsiFile file = psiElement.getContainingFile();
  final Language elementLanguage = psiElement.getLanguage();

  final Language fileLanguage = file == null ? null : file.getLanguage();
  Language language = fileLanguage == null ? elementLanguage : fileLanguage.isKindOf(elementLanguage) ? fileLanguage : elementLanguage;

  return LanguageNamesValidation.INSTANCE.forLanguage(language).isIdentifier(newName.trim(), project);
}
项目:consulo-xslt    文件:IntroduceParameterDialog.java   
public IntroduceParameterDialog(XPathExpression expression, int numberOfExpressions, boolean forceDefault) {
    super(expression.getProject(), LanguageNamesValidation.INSTANCE.forLanguage(expression.getLanguage()));
    myForceDefault = forceDefault;
    init(expression, numberOfExpressions, TITLE);

    getOKAction().addPropertyChangeListener(new PropertyChangeListener() {
        @SuppressWarnings({"AutoUnboxing"})
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("enabled")) {
                myPreviewAction.setEnabled(((Boolean)evt.getNewValue()) && !myCreateWithDefault.isSelected());
            }
        }
    });
    if (forceDefault) {
        myCreateWithDefault.setSelected(true);
        myCreateWithDefault.setVisible(false);
    } else {
        myCreateWithDefault.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                myPreviewAction.setEnabled(getOKAction().isEnabled() && !myCreateWithDefault.isSelected());
            }
        });
    }
    myPreviewAction.setEnabled(false);
}
项目:consulo-javascript    文件:JSReferenceExpressionImpl.java   
@RequiredReadAction
PsiElement handleElementRenameInternal(String newElementName) throws IncorrectOperationException
{
    final int i = newElementName.lastIndexOf('.');
    if(i != -1)
    {
        newElementName = newElementName.substring(0, i);
    }
    if(!LanguageNamesValidation.INSTANCE.forLanguage(JavaScriptLanguage.INSTANCE).isIdentifier(newElementName, null))
    {
        throw new IncorrectOperationException("Invalid javascript element name:" + newElementName);
    }
    final PsiElement parent = getParent();
    if(parent instanceof JSClass || parent instanceof JSFunction)
    {
        final PsiElement node = ((JSNamedElement) parent).getNameIdentifier();
        if(node != null && node == this)
        {
            return this; // JSNamedElement.setName will care of things
        }
    }
    JSChangeUtil.doIdentifierReplacement(this, getNameElement(), newElementName);
    return getParent();
}
项目:intellij-ce-playground    文件:RenameElementFix.java   
@Override
public boolean isAvailable(@NotNull Project project,
                           @NotNull PsiFile file,
                           @NotNull PsiElement startElement,
                           @NotNull PsiElement endElement) {
  if (!startElement.isValid()) {
    return false;
  }
  final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(file.getLanguage());
  return namesValidator != null && namesValidator.isIdentifier(myNewName, project);
}
项目:intellij-ce-playground    文件:IdManager.java   
/**
 * Assign a suitable new and unique id to the given component. The set of
 * existing id's is provided in the given list.
 */
@NotNull
public String assignId(RadViewComponent component, Collection<String> idList) {
  String idValue = StringUtil.decapitalize(component.getMetaModel().getTag());

  XmlTag tag = component.getTag();
  Module module = AndroidPsiUtils.getModuleSafely(tag);
  if (module != null) {
    idValue = ResourceHelper.prependResourcePrefix(module, idValue);
  }

  String nextIdValue = idValue;
  int index = 0;

  // Ensure that we don't create something like "switch" as an id, which won't compile when used
  // in the R class
  NamesValidator validator = LanguageNamesValidation.INSTANCE.forLanguage(JavaLanguage.INSTANCE);

  Project project = tag.getProject();
  while (idList.contains(nextIdValue) || validator != null && validator.isKeyword(nextIdValue, project)) {
    ++index;
    if (index == 1 && (validator == null || !validator.isKeyword(nextIdValue, project))) {
      nextIdValue = idValue;
    } else {
      nextIdValue = idValue + Integer.toString(index);
    }
  }

  String newId = NEW_ID_PREFIX + idValue + (index == 0 ? "" : Integer.toString(index));
  tag.setAttribute(ATTR_ID, ANDROID_URI, newId);
  return newId;
}
项目:intellij-ce-playground    文件:JavaFxUnresolvedFxIdReferenceInspection.java   
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder,
                                      final boolean isOnTheFly,
                                      @NotNull LocalInspectionToolSession session) {
  return new XmlElementVisitor() {
    @Override
    public void visitXmlFile(XmlFile file) {
      if (!JavaFxFileTypeFactory.isFxml(file)) return;
      super.visitXmlFile(file);
    }

    @Override
    public void visitXmlAttribute(XmlAttribute attribute) {
      if (FxmlConstants.FX_ID.equals(attribute.getName())) {
        final XmlAttributeValue valueElement = attribute.getValueElement();
        if (valueElement != null && valueElement.getTextLength() > 0) {
          final PsiClass controllerClass = JavaFxPsiUtil.getControllerClass(attribute.getContainingFile());
          if (controllerClass != null) {
            final PsiReference reference = valueElement.getReference();
            if (reference instanceof JavaFxFieldIdReferenceProvider.JavaFxControllerFieldRef && ((JavaFxFieldIdReferenceProvider.JavaFxControllerFieldRef)reference).isUnresolved()) {
              final PsiClass fieldClass =
                checkContext(((JavaFxFieldIdReferenceProvider.JavaFxControllerFieldRef)reference).getXmlAttributeValue());
              if (fieldClass != null) {
                final String text = reference.getCanonicalText();
                final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(fieldClass.getLanguage());
                boolean validName = namesValidator != null && namesValidator.isIdentifier(text, fieldClass.getProject());
                holder.registerProblem(reference.getElement(), reference.getRangeInElement(), "Unresolved fx:id reference",
                                       isOnTheFly && validName ? new LocalQuickFix[]{new CreateFieldFromUsageQuickFix(text)} : LocalQuickFix.EMPTY_ARRAY);
              }
            }
          }
        }
      }
    }
  };
}
项目:tools-idea    文件:RenameElementFix.java   
@Override
public boolean isAvailable(@NotNull Project project, @Nullable Editor editor, PsiFile file) {
  if (!myElement.isValid()) {
    return false;
  }
  final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(file.getLanguage());
  return namesValidator != null && namesValidator.isIdentifier(myNewName, project);
}
项目:tools-idea    文件:JavaFxUnresolvedFxIdReferenceInspection.java   
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder,
                                      final boolean isOnTheFly,
                                      @NotNull LocalInspectionToolSession session) {
  return new XmlElementVisitor() {
    @Override
    public void visitXmlFile(XmlFile file) {
      if (!JavaFxFileTypeFactory.isFxml(file)) return;
      super.visitXmlFile(file);
    }

    @Override
    public void visitXmlAttribute(XmlAttribute attribute) {
      if (FxmlConstants.FX_ID.equals(attribute.getName())) {
        final XmlAttributeValue valueElement = attribute.getValueElement();
        if (valueElement != null && valueElement.getTextLength() > 0) {
          final PsiClass controllerClass = JavaFxPsiUtil.getControllerClass(attribute.getContainingFile());
          if (controllerClass != null) {
            final PsiReference reference = valueElement.getReference();
            if (reference instanceof JavaFxFieldIdReferenceProvider.JavaFxControllerFieldRef && ((JavaFxFieldIdReferenceProvider.JavaFxControllerFieldRef)reference).isUnresolved()) {
              final PsiClass fieldClass =
                checkContext(((JavaFxFieldIdReferenceProvider.JavaFxControllerFieldRef)reference).getXmlAttributeValue());
              if (fieldClass != null) {
                final String text = reference.getCanonicalText();
                final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(fieldClass.getLanguage());
                boolean validName = namesValidator != null && namesValidator.isIdentifier(text, fieldClass.getProject());
                holder.registerProblem(reference.getElement(), reference.getRangeInElement(), "Unresolved fx:id reference",
                                       isOnTheFly && validName ? new LocalQuickFix[]{new CreateFieldFromUsageQuickFix(text)} : LocalQuickFix.EMPTY_ARRAY);
              }
            }
          }
        }
      }
    }
  };
}
项目:cordovastudio    文件:IdManager.java   
public String createId(RadViewComponent component) {
  String idValue = StringUtil.decapitalize(component.getMetaModel().getTag());

  XmlTag tag = component.getTag();
  Module module = CordovaPsiUtils.getModuleSafely(tag);

  String nextIdValue = idValue;
  int index = 0;

  // Ensure that we don't create something like "switch" as an id, which won't compile when used
  // in the R class
  NamesValidator validator = LanguageNamesValidation.INSTANCE.forLanguage(JavaLanguage.INSTANCE);

  Project project = tag.getProject();
  while (myIdList.contains(nextIdValue) || validator != null && validator.isKeyword(nextIdValue, project)) {
    ++index;
    if (index == 1 && (validator == null || !validator.isKeyword(nextIdValue, project))) {
      nextIdValue = idValue;
    } else {
      nextIdValue = idValue + Integer.toString(index);
    }
  }

  myIdList.add(nextIdValue);
  String newId = idValue + (index == 0 ? "" : Integer.toString(index));
  tag.setAttribute(ATTR_ID, CORDOVASTUDIO_URI, newId);
  return newId;
}
项目:consulo    文件:RenameElementFix.java   
@Override
public boolean isAvailable(@Nonnull Project project,
                           @Nonnull PsiFile file,
                           @Nonnull PsiElement startElement,
                           @Nonnull PsiElement endElement) {
  if (!startElement.isValid()) {
    return false;
  }
  final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(file.getLanguage());
  return namesValidator != null && namesValidator.isIdentifier(myNewName, project);
}
项目:consulo-javascript    文件:JSBaseIntroduceDialog.java   
private static boolean isValidIdentifier(String typeString, PsiElement context)
{
    if(typeString == null)
    {
        return false;
    }
    Language language = context.getContainingFile().getLanguage();
    return LanguageNamesValidation.INSTANCE.forLanguage(language).isIdentifier(typeString, context.getProject());
}
项目:intellij-ce-playground    文件:InplaceRefactoring.java   
protected boolean isIdentifier(final String newName, final Language language) {
  final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(language);
  return namesValidator == null || namesValidator.isIdentifier(newName, myProject);
}
项目:intellij-ce-playground    文件:PyChangeSignatureDialog.java   
public boolean isNameValid(final String name, final Project project) {
  final NamesValidator validator = LanguageNamesValidation.INSTANCE.forLanguage(PythonLanguage.getInstance());
  return (name != null) &&
         (validator.isIdentifier(name, project)) &&
         !(validator.isKeyword(name, project));
}
项目:intellij-ce-playground    文件:XsltDeclarationInspection.java   
public NamesValidator getNamesValidator() {
    if (myNamesValidator == null) {
        myNamesValidator = LanguageNamesValidation.INSTANCE.forLanguage(XPathFileType.XPATH.getLanguage());
    }
    return myNamesValidator;
}
项目:intellij-ce-playground    文件:XsltRenameInputValidator.java   
public boolean isInputValid(String newName, PsiElement element, ProcessingContext context) {
  return LanguageNamesValidation.INSTANCE.forLanguage(XPathFileType.XPATH.getLanguage())
    .isIdentifier(newName, element.getProject());
}
项目:intellij-ce-playground    文件:IntroduceVariableDialog.java   
public IntroduceVariableDialog(XPathExpression expression, int numberOfExpressions) {
    super(expression.getProject(), LanguageNamesValidation.INSTANCE.forLanguage(expression.getLanguage()));
    init(expression, numberOfExpressions, TITLE);
}
项目:tools-idea    文件:InplaceRefactoring.java   
protected boolean isIdentifier(final String newName, final Language language) {
  final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(language);
  return namesValidator == null || namesValidator.isIdentifier(newName, myProject);
}
项目:tools-idea    文件:XsltDeclarationInspection.java   
public NamesValidator getNamesValidator() {
    if (myNamesValidator == null) {
        myNamesValidator = LanguageNamesValidation.INSTANCE.forLanguage(XPathFileType.XPATH.getLanguage());
    }
    return myNamesValidator;
}
项目:tools-idea    文件:XsltRenameInputValidator.java   
public boolean isInputValid(String newName, PsiElement element, ProcessingContext context) {
  return LanguageNamesValidation.INSTANCE.forLanguage(XPathFileType.XPATH.getLanguage())
    .isIdentifier(newName, element.getProject());
}
项目:tools-idea    文件:IntroduceVariableDialog.java   
public IntroduceVariableDialog(XPathExpression expression, int numberOfExpressions) {
    super(expression.getProject(), LanguageNamesValidation.INSTANCE.forLanguage(expression.getLanguage()));
    init(expression, numberOfExpressions, TITLE);
}
项目:consulo-javafx    文件:JavaFxUnresolvedFxIdReferenceInspection.java   
@NotNull
@Override
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, final boolean isOnTheFly, @NotNull LocalInspectionToolSession session)
{
    return new XmlElementVisitor()
    {
        @Override
        public void visitXmlFile(XmlFile file)
        {
            if(!JavaFxFileTypeFactory.isFxml(file))
            {
                return;
            }
            super.visitXmlFile(file);
        }

        @Override
        public void visitXmlAttribute(XmlAttribute attribute)
        {
            if(FxmlConstants.FX_ID.equals(attribute.getName()))
            {
                final XmlAttributeValue valueElement = attribute.getValueElement();
                if(valueElement != null && valueElement.getTextLength() > 0)
                {
                    final PsiClass controllerClass = JavaFxPsiUtil.getControllerClass(attribute.getContainingFile());
                    if(controllerClass != null)
                    {
                        final PsiReference reference = valueElement.getReference();
                        if(reference instanceof JavaFxFieldIdReferenceProvider.JavaFxControllerFieldRef && ((JavaFxFieldIdReferenceProvider.JavaFxControllerFieldRef) reference).isUnresolved())
                        {
                            final PsiClass fieldClass = checkContext(((JavaFxFieldIdReferenceProvider.JavaFxControllerFieldRef) reference).getXmlAttributeValue());
                            if(fieldClass != null)
                            {
                                final String text = reference.getCanonicalText();
                                final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(fieldClass.getLanguage());
                                boolean validName = namesValidator != null && namesValidator.isIdentifier(text, fieldClass.getProject());
                                holder.registerProblem(reference.getElement(), reference.getRangeInElement(), "Unresolved fx:id reference", isOnTheFly && validName ? new LocalQuickFix[]{new
                                        CreateFieldFromUsageQuickFix(text)} : LocalQuickFix.EMPTY_ARRAY);
                            }
                        }
                    }
                }
            }
        }
    };
}
项目:consulo    文件:InplaceRefactoring.java   
protected boolean isIdentifier(final String newName, final Language language) {
  final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(language);
  return namesValidator == null || namesValidator.isIdentifier(newName, myProject);
}
项目:consulo    文件:AbstractParameterTablePanel.java   
public NameColumnInfo(Language lang, Project project) {
  super("Name");
  myNameValidator = (paramName) -> LanguageNamesValidation.INSTANCE.forLanguage(lang).isIdentifier(paramName, project);
}
项目:consulo-xslt    文件:XsltDeclarationInspection.java   
public NamesValidator getNamesValidator() {
    if (myNamesValidator == null) {
        myNamesValidator = LanguageNamesValidation.INSTANCE.forLanguage(XPathFileType.XPATH.getLanguage());
    }
    return myNamesValidator;
}
项目:consulo-xslt    文件:XsltRenameInputValidator.java   
public boolean isInputValid(String newName, PsiElement element, ProcessingContext context) {
  return LanguageNamesValidation.INSTANCE.forLanguage(XPathFileType.XPATH.getLanguage())
    .isIdentifier(newName, element.getProject());
}
项目:consulo-xslt    文件:IntroduceVariableDialog.java   
public IntroduceVariableDialog(XPathExpression expression, int numberOfExpressions) {
    super(expression.getProject(), LanguageNamesValidation.INSTANCE.forLanguage(expression.getLanguage()));
    init(expression, numberOfExpressions, TITLE);
}
项目:consulo-javascript    文件:JSBaseIntroduceDialog.java   
private boolean isValidName(final String name)
{
    final PsiFile containingFile = myMainOccurence.getContainingFile();
    return LanguageNamesValidation.INSTANCE.forLanguage(containingFile.getLanguage()).isIdentifier(name, myProject);
}