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); } }
@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); }
/** * 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; }
@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); } } } } } } }; }
@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); }
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; }
@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); }
public MyTokenConsumer(SpellCheckerManager manager, ProblemsHolder holder, NamesValidator namesValidator) { myManager = manager; myHolder = holder; myNamesValidator = namesValidator; }
protected boolean isIdentifier(final String newName, final Language language) { final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(language); return namesValidator == null || namesValidator.isIdentifier(newName, myProject); }
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)); }
public NamesValidator getNamesValidator() { if (myNamesValidator == null) { myNamesValidator = LanguageNamesValidation.INSTANCE.forLanguage(XPathFileType.XPATH.getLanguage()); } return myNamesValidator; }
public NameValidator(Project project, NamesValidator namesValidator) { myProject = project; myNamesValidator = namesValidator; }
public BaseIntroduceDialog(Project project, NamesValidator validator) { super(project, false); myInputValidator = new NameValidator(project, validator); }
@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); } } } } } } }; }