2 * Copyright 2000-2010 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.javafx;
18 import com.intellij.facet.FacetManager;
19 import com.intellij.facet.ModifiableFacetModel;
20 import com.intellij.openapi.module.Module;
21 import com.intellij.openapi.project.Project;
22 import com.intellij.openapi.projectRoots.Sdk;
23 import com.intellij.openapi.roots.CompilerModuleExtension;
24 import com.intellij.openapi.roots.ModuleRootManager;
25 import com.intellij.openapi.vfs.LocalFileSystem;
26 import com.intellij.openapi.vfs.VirtualFile;
27 import com.intellij.psi.PsiFile;
28 import com.intellij.psi.PsiManager;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 import org.jetbrains.javafx.facet.JavaFxFacet;
32 import org.jetbrains.javafx.lang.psi.JavaFxFile;
33 import org.jetbrains.javafx.lang.psi.JavaFxPackageDefinition;
36 * Created by IntelliJ IDEA.
38 * @author: Alexey.Ivanov
40 public class JavaFxUtil {
41 private JavaFxUtil() {
45 public static String getCompilerOutputPath(@NotNull final Module module) {
46 final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
47 if (compilerModuleExtension != null) {
48 final VirtualFile outputPath = compilerModuleExtension.getCompilerOutputPath();
49 if (outputPath != null) {
50 return outputPath.getPath();
57 public static String scriptNameToClassName(final Project project, final String scriptName) {
58 final VirtualFile virtualFile = LocalFileSystem.getInstance().findFileByPath(scriptName);
59 if (virtualFile != null) {
60 final PsiFile psiFile = PsiManager.getInstance(project).findFile(virtualFile);
61 if (psiFile != null && psiFile instanceof JavaFxFile) {
62 final JavaFxPackageDefinition packageDefinition = ((JavaFxFile)psiFile).getPackageDefinition();
63 final String nameWithoutExtension = virtualFile.getNameWithoutExtension();
64 if (packageDefinition != null) {
65 final String packageName = packageDefinition.getName();
66 if (!"".equals(packageName)) {
67 return packageName + "." + nameWithoutExtension;
70 return nameWithoutExtension;
76 public static JavaFxFacet addFacet(final Module module, final @Nullable Sdk sdk) {
77 final ModifiableFacetModel facetModel = FacetManager.getInstance(module).createModifiableModel();
78 final JavaFxFacet javaFxFacet = JavaFxFacet.FACET_TYPE
79 .createFacet(module, JavaFxFacet.FACET_TYPE.getDefaultFacetName(), JavaFxFacet.FACET_TYPE.createDefaultConfiguration(), null);
80 facetModel.addFacet(javaFxFacet);
83 javaFxFacet.getConfiguration().setJavaFxSdk(sdk);
89 public static VirtualFile[] getModuleSourceRoots(final Module module) {
90 return ModuleRootManager.getInstance(module).getSourceRoots();