use of com.intellij.lang.refactoring.NamesValidator in project intellij-community by JetBrains.
the class GotoDeclarationAction method invoke.
@Override
public void invoke(@NotNull final Project project, @NotNull Editor editor, @NotNull PsiFile file) {
DumbService.getInstance(project).setAlternativeResolveEnabled(true);
try {
int offset = editor.getCaretModel().getOffset();
PsiElement[] elements = underModalProgress(project, "Resolving Reference...", () -> findAllTargetElements(project, editor, offset));
FeatureUsageTracker.getInstance().triggerFeatureUsed("navigation.goto.declaration");
if (elements.length != 1) {
if (elements.length == 0 && suggestCandidates(TargetElementUtil.findReference(editor, offset)).isEmpty()) {
PsiElement element = findElementToShowUsagesOf(editor, editor.getCaretModel().getOffset());
if (startFindUsages(editor, element)) {
return;
}
//disable 'no declaration found' notification for keywords
final PsiElement elementAtCaret = file.findElementAt(offset);
if (elementAtCaret != null) {
final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(elementAtCaret.getLanguage());
if (namesValidator != null && namesValidator.isKeyword(elementAtCaret.getText(), project)) {
return;
}
}
}
chooseAmbiguousTarget(editor, offset, elements, file);
return;
}
PsiElement element = elements[0];
if (element == findElementToShowUsagesOf(editor, editor.getCaretModel().getOffset()) && startFindUsages(editor, element)) {
return;
}
PsiElement navElement = element.getNavigationElement();
navElement = TargetElementUtil.getInstance().getGotoDeclarationTarget(element, navElement);
if (navElement != null) {
gotoTargetElement(navElement, editor, file);
}
} catch (IndexNotReadyException e) {
DumbService.getInstance(project).showDumbModeNotification("Navigation is not available here during index update");
} finally {
DumbService.getInstance(project).setAlternativeResolveEnabled(false);
}
}
use of com.intellij.lang.refactoring.NamesValidator in project intellij-plugins by JetBrains.
the class AnnotationBackedDescriptorImpl method validateValue.
@Override
@Nullable
public String validateValue(final XmlElement context, String value) {
final PsiElement parent = context instanceof XmlAttributeValue ? context.getParent() : null;
if (parent instanceof XmlAttribute && FlexMxmlLanguageAttributeNames.ID.equals(((XmlAttribute) parent).getName())) {
final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(JavaScriptSupportLoader.JAVASCRIPT.getLanguage());
return // ok
namesValidator.isIdentifier(value, context.getProject()) ? // ok
null : JSBundle.message("invalid.identifier.value");
}
// dynamic values
if (value.indexOf('{') != -1)
return null;
if (value.trim().startsWith("@Resource"))
return null;
if (myAnnotationName != null && CLEAR_DIRECTIVE.equals(value)) {
return checkClearDirectiveContext(context);
}
if (isAllowsPercentage() && value.endsWith("%")) {
value = value.substring(0, value.length() - 1);
}
boolean uint = false;
if ("int".equals(type) || (uint = "uint".equals(type))) {
try {
boolean startWithSharp;
if ((startWithSharp = value.startsWith("#")) || value.startsWith("0x")) {
if (uint) {
final long l = Long.parseLong(value.substring(startWithSharp ? 1 : 2), 16);
if (l < 0 || l > 0xFFFFFFFFL) {
throw new NumberFormatException("value out of range");
}
} else {
Integer.parseInt(value.substring(startWithSharp ? 1 : 2), 16);
}
} else {
if ("Color".equals(format) && !StringUtil.isEmptyOrSpaces(value) && !Character.isDigit(value.charAt(0))) {
return checkColorAlias(value);
}
if (uint) {
final long l = Long.parseLong(value);
if (l < 0 || l > 0xFFFFFFFFL) {
throw new NumberFormatException("value out of range");
}
} else {
Integer.parseInt(value);
}
}
} catch (NumberFormatException ex) {
return FlexBundle.message("flex.invalid.integer.value");
}
} else if ("Number".equals(type)) {
try {
boolean startWithSharp;
if (value != null && ((startWithSharp = value.startsWith("#")) || value.startsWith("0x"))) {
Integer.parseInt(value.substring(startWithSharp ? 1 : 2), 16);
} else {
Double.parseDouble(value);
}
} catch (NumberFormatException ex) {
return FlexBundle.message("flex.invalid.number.value");
}
}
return null;
}
use of com.intellij.lang.refactoring.NamesValidator in project intellij-plugins by JetBrains.
the class ChoosePackageDialog method doOKAction.
protected void doOKAction() {
final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(JavascriptLanguage.INSTANCE);
final String packageName = getPackageName();
for (final String s : StringUtil.split(packageName, ".")) {
if (!namesValidator.isIdentifier(s, null)) {
setErrorText(JSBundle.message("invalid.package", packageName), myPackageCombo);
return;
}
}
myPackageCombo.updateRecents();
myTargetDirectory = JSRefactoringUtil.chooseOrCreateDirectoryForClass(myModule.getProject(), myModule, getPackageScope(), packageName, null, myContextFile.getParent(), ThreeState.UNSURE);
if (myTargetDirectory != null) {
super.doOKAction();
}
}
use of com.intellij.lang.refactoring.NamesValidator in project intellij-community by JetBrains.
the class InvertBooleanDialog method doAction.
protected void doAction() {
Project project = myElement.getProject();
final String name = myNameField.getText().trim();
final NamesValidator namesValidator = LanguageNamesValidation.INSTANCE.forLanguage(myElement.getLanguage());
if (namesValidator != null && !namesValidator.isIdentifier(name, myProject)) {
CommonRefactoringUtil.showErrorMessage(InvertBooleanHandler.REFACTORING_NAME, RefactoringBundle.message("please.enter.a.valid.name.for.inverted.element", UsageViewUtil.getType(myElement)), InvertBooleanHandler.INVERT_BOOLEAN_HELP_ID, project);
return;
}
invokeRefactoring(new InvertBooleanProcessor(myElement, name));
}
use of com.intellij.lang.refactoring.NamesValidator in project intellij-community by JetBrains.
the class JavaFxUnresolvedFxIdReferenceInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
if (!JavaFxFileTypeFactory.isFxml(session.getFile()))
return PsiElementVisitor.EMPTY_VISITOR;
return new XmlElementVisitor() {
@Override
public void visitXmlAttribute(XmlAttribute attribute) {
super.visitXmlAttribute(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);
}
}
}
}
}
}
};
}
Aggregations