mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
javafx: disable create field from usage when the reference name is empty (IDEA-105237)
This commit is contained in:
@@ -59,6 +59,13 @@ public class JavaFXQuickfixTest extends LightCodeInsightFixtureTestCase {
|
||||
doTest("Create Field 'btn'", ".java");
|
||||
}
|
||||
|
||||
public void testCreateFieldEmptyName() throws Exception {
|
||||
String path = getTestName(true) + ".fxml";
|
||||
final IntentionAction intention =
|
||||
myFixture.getAvailableIntention("Create Field 'btn'", path, getTestName(false) + ".java");
|
||||
assertNull(intention);
|
||||
}
|
||||
|
||||
public void testRegisterPageLanguage() throws Exception {
|
||||
myFixture.configureByFile(getTestName(true) + ".fxml");
|
||||
final IntentionAction intention = myFixture.findSingleIntention("Specify page language");
|
||||
|
||||
@@ -23,6 +23,8 @@ import com.intellij.codeInsight.daemon.QuickFixBundle;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateFieldFromUsageFix;
|
||||
import com.intellij.codeInsight.daemon.impl.quickfix.CreateFieldFromUsageHelper;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.lang.LanguageNamesValidation;
|
||||
import com.intellij.lang.refactoring.NamesValidator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -67,8 +69,11 @@ public class JavaFxUnresolvedFxIdReferenceInspection extends XmlSuppressableInsp
|
||||
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 ? new LocalQuickFix[]{new CreateFieldFromUsageQuickFix(reference.getCanonicalText())} : LocalQuickFix.EMPTY_ARRAY);
|
||||
isOnTheFly && validName ? new LocalQuickFix[]{new CreateFieldFromUsageQuickFix(text)} : LocalQuickFix.EMPTY_ARRAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
public class CreateControllerMethod {}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?import javafx.scene.layout.GridPane?>
|
||||
<?import javafx.scene.control.Button?>
|
||||
<GridPane xmlns:fx="http://javafx.com/fxml" fx:controller="CreateFieldEmptyName">
|
||||
<Button fx:id="<caret>"/>
|
||||
</GridPane>
|
||||
Reference in New Issue
Block a user