Javafx: "Wrap field with JavaFx property" intention - use ArtifactManager's modification tracker for caching presence of JavaFX artifacts (IDEA-102430)

This commit is contained in:
Pavel Dolgov
2016-10-27 14:43:53 +03:00
parent 270ab5e85f
commit a2b040e170
3 changed files with 15 additions and 22 deletions
@@ -1,34 +1,21 @@
package org.jetbrains.plugins.javaFX;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ContentEntry;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.testFramework.fixtures.DefaultLightProjectDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.javaFX.fxml.AbstractJavaFXTestCase;
/**
* Same as the base test, but detects the presence of JavaFX using imports and FXMLs, not artifacts
* @author Pavel.Dolgov
*/
public class JavaFxFieldToPropertyNoArtifactTest extends JavaFxFieldToPropertyTest {
public static final DefaultLightProjectDescriptor JAVA_FX_DESCRIPTOR_NO_ARTIFACT = new DefaultLightProjectDescriptor() {
@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
AbstractJavaFXTestCase.addJavaFxJarAsLibrary(module, model);
super.configureModule(module, model, contentEntry);
}
};
@Override
protected void setUpModule() {
super.setUpModule();
}
public void testArtifactPresenceFieldToProperty() throws Exception {
final IntentionAction intentionAction = getIntentionAction(getTestName(false) + ".java");
// no artifact, no fxml, no javafx.* imports: the intention shoudn't be available
assertNull(intentionAction);
}
@Override
protected boolean isArtifactNeeded() {
return false;
}
}
@@ -35,7 +35,9 @@ public class JavaFxFieldToPropertyTest extends DaemonAnalyzerTestCase {
protected void setUpModule() {
super.setUpModule();
AbstractJavaFXTestCase.addJavaFxJarAsLibrary(getModule());
ArtifactManager.getInstance(getProject()).addArtifact("fake-javafx", JavaFxApplicationArtifactType.getInstance(), null);
if (isArtifactNeeded()) {
ArtifactManager.getInstance(getProject()).addArtifact("fake-javafx", JavaFxApplicationArtifactType.getInstance(), null);
}
}
public void testIntFieldToProperty() throws Exception {
@@ -98,6 +100,10 @@ public class JavaFxFieldToPropertyTest extends DaemonAnalyzerTestCase {
return findIntentionAction(infos, actionName, editor, file);
}
protected boolean isArtifactNeeded() {
return true;
}
@NotNull
@Override
protected String getTestDataPath() {
@@ -69,9 +69,9 @@ public class JavaFxModuleUtil {
private static boolean hasJavaFxArtifacts(@NotNull Project project) {
return CachedValuesManager.getManager(project).getCachedValue(
project, () -> {
final Collection<? extends Artifact> artifacts =
ArtifactManager.getInstance(project).getArtifactsByType(JavaFxApplicationArtifactType.getInstance());
return CachedValueProvider.Result.create(!artifacts.isEmpty(), ProjectRootManager.getInstance(project));
final ArtifactManager artifactManager = ArtifactManager.getInstance(project);
final Collection<? extends Artifact> artifacts = artifactManager.getArtifactsByType(JavaFxApplicationArtifactType.getInstance());
return CachedValueProvider.Result.create(!artifacts.isEmpty(), artifactManager.getModificationTracker());
});
}