Java Code Examples for org.netbeans.modules.php.api.util.FileUtils#isPhpFile()

The following examples show how to use org.netbeans.modules.php.api.util.FileUtils#isPhpFile() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CakePHP3GoToStatus.java    From cakephp3-netbeans with Apache License 2.0 6 votes vote down vote up
public List<GoToItem> getTestCases() {
    if (fileObject == null || !FileUtils.isPhpFile(fileObject)) {
        return Collections.emptyList();
    }
    CakePHP3Module cakeModule = CakePHP3Module.forFileObject(fileObject);
    ModuleInfo info = cakeModule.createModuleInfo(fileObject);
    if (ModuleUtils.isTemplate(info.getCategory())) {
        return Collections.emptyList();
    }

    List<GoToItem> items = new ArrayList<>();
    List<FileObject> directories = cakeModule.getDirectories(info.getBase(), null, info.getPluginName());
    for (FileObject directory : directories) {
        Set<ClassElement> classElements = getClassElements(directory, fileObject.getName() + "Test"); // NOI18N
        for (ClassElement classElement : classElements) {
            FileObject testcase = classElement.getFileObject();
            items.add(GoToItemFactory.create(Category.TEST_CASE, testcase, DEFAULT_OFFSET));
        }
    }
    return items;
}
 
Example 2
Source File: RunFileActionProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isActionEnabled(String command, Lookup context) {
    Project p = context.lookup(Project.class);
    if (p != null) {
        return false;
    }
    Collection<? extends DataObject> files = context.lookupAll(DataObject.class);
    if (files.isEmpty()) {
        return false;
    }
    for (DataObject d : files) {
        if (!FileUtils.isPhpFile(d.getPrimaryFile())) {
            return false;
        }
    }
    if (ActionProvider.COMMAND_DEBUG_SINGLE.equals(command)
            && DebugStarterFactory.getInstance() == null) {
        return false;
    }
    return true;
}
 
Example 3
Source File: ConfigActionTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isRunMethodEnabled(Lookup context) {
    SingleMethod singleMethod = CommandUtils.singleMethodForContext(context);
    if (singleMethod == null) {
        return false;
    }
    FileObject file = singleMethod.getFile();
    if (file == null) {
        return false;
    }
    if (!FileUtils.isPhpFile(file)) {
        return false;
    }
    PhpModule phpModule = project.getPhpModule();
    for (PhpTestingProvider testingProvider : project.getTestingProviders()) {
        if (testingProvider.isTestFile(phpModule, file)) {
            return true;
        }
    }
    return false;
}
 
Example 4
Source File: RunTestsCommand.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private FileObject findFolderWithTest(Lookup context) {
    FileObject[] files = CommandUtils.filesForContextOrSelectedNodes(context);
    if (files.length != 1) {
        return null;
    }
    FileObject file = files[0];
    if (!file.isFolder()) {
        return null;
    }
    Enumeration<? extends FileObject> children = file.getChildren(true);
    while (children.hasMoreElements()) {
        FileObject child = children.nextElement();
        if (child.isData()
                && isTestFile(child)
                && FileUtils.isPhpFile(child)) {
            return file;
        }
    }
    return null;
}
 
Example 5
Source File: PhpProjectConvertor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private FileObject detectSourceRoot() {
    // first check if there is any *.php file right in project dir
    for (FileObject child : projectDirectory.getChildren()) {
        if (FileUtils.isPhpFile(child)) {
            return projectDirectory;
        }
    }
    // now, check well known sources
    for (String dir : KNOWN_SOURCE_ROOTS) {
        FileObject srcDir = projectDirectory.getFileObject(dir);
        if (srcDir != null)  {
            return srcDir;
        }
    }
    return projectDirectory;
}
 
Example 6
Source File: CreateTestsSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void sanitizeFiles(List<FileObject> sanitizedFiles, List<FileObject> files, PhpModule phpModule, PhpVisibilityQuery phpVisibilityQuery) {
    for (FileObject fo : files) {
        if (fo.isData()
                && FileUtils.isPhpFile(fo)
                && !isUnderTests(phpModule, fo)
                // XXX no way to test selenium here
                //&& !isUnderSelenium(phpModule, fo)
                && phpVisibilityQuery.isVisible(fo)) {
            sanitizedFiles.add(fo);
        }
        FileObject[] children = fo.getChildren();
        if (children.length > 0) {
            sanitizeFiles(sanitizedFiles, Arrays.asList(children), phpModule, phpVisibilityQuery);
        }
    }
}
 
Example 7
Source File: ConfigurationFiles.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<FileInfo> getFiles() {
    FileObject sourceDir = getSourceDirectory();
    if (sourceDir == null) {
        // broken project
        return Collections.emptyList();
    }
    List<FileInfo> files = new ArrayList<>();
    FileObject configDir = sourceDir.getFileObject(CONFIG_DIRECTORY);
    if (configDir != null
            && configDir.isFolder()
            && configDir.isValid()) {
        Enumeration<? extends FileObject> children = configDir.getChildren(true);
        while (children.hasMoreElements()) {
            FileObject child = children.nextElement();
            if (child.isData()
                    && child.isValid()
                    && FileUtils.isPhpFile(child)) {
                files.add(new FileInfo(child));
            }
        }
        Collections.sort(files, FileInfo.COMPARATOR);
    }
    return files;
}
 
Example 8
Source File: AnalysisUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static int countPhpFiles(PhpVisibilityQuery visibilityQuery, FileObject fileObject, boolean recursive) {
    if (!visibilityQuery.isVisible(fileObject)) {
        LOGGER.log(Level.FINE, "Ignoring invisible file {0}", fileObject);
        return 0;
    }
    int count = 0;
    if (FileUtils.isPhpFile(fileObject)) {
        count++;
    }
    for (FileObject child : fileObject.getChildren()) {
        if (!visibilityQuery.isVisible(child)) {
            LOGGER.log(Level.FINE, "Ignoring invisible file {0}", child);
            continue;
        }
        if (FileUtils.isPhpFile(child)) {
            count++;
        }
        if (recursive
                && child.isFolder()) {
            count += countPhpFiles(visibilityQuery, child, recursive);
        }
    }
    return count;
}
 
Example 9
Source File: TesterTestingProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isTestFile(PhpModule phpModule, FileObject fileObj) {
    if (!FileUtils.isPhpFile(fileObj)) {
        return false;
    }
    for (FileObject testDirectory : phpModule.getTestDirectories()) {
        if (FileUtil.isParentOf(testDirectory, fileObj)) {
            return true;
        }
    }
    return false;
}
 
Example 10
Source File: AtoumTestLocator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<Locations.Offset> filterPhpFiles(FileObject sourceRoot, Collection<Pair<FileObject, Integer>> files) {
    List<Locations.Offset> results = new ArrayList<>(files.size());
    for (Pair<FileObject, Integer> pair : files) {
        FileObject fileObject = pair.first();
        if (FileUtils.isPhpFile(fileObject)
                && FileUtil.isParentOf(sourceRoot, fileObject)) {
            results.add(new Locations.Offset(fileObject, pair.second()));
        }
    }
    return results;
}
 
Example 11
Source File: CodeceptionTestLocator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<Locations.Offset> filterPhpFiles(FileObject sourceRoot, Collection<Pair<FileObject, Integer>> files) {
    List<Locations.Offset> results = new ArrayList<>(files.size());
    for (Pair<FileObject, Integer> pair : files) {
        FileObject fileObject = pair.first();
        if (FileUtils.isPhpFile(fileObject)
                && FileUtil.isParentOf(sourceRoot, fileObject)) {
            results.add(new Locations.Offset(fileObject, pair.second()));
        }
    }
    return results;
}
 
Example 12
Source File: ConfigurationFiles.java    From nb-ci-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Collection<ImportantFilesImplementation.FileInfo> getFiles() {
    List<FileObject> directories = getConfigDirectories();
    List<ImportantFilesImplementation.FileInfo> files = new ArrayList<ImportantFilesImplementation.FileInfo>();
    for (FileObject directory : directories) {
        FileObject[] children = directory.getChildren();
        for (FileObject child : children) {
            if (child.isFolder() || !FileUtils.isPhpFile(child)) {
                continue;
            }
            files.add(new ImportantFilesImplementation.FileInfo(child));
        }
    }
    return files;
}
 
Example 13
Source File: ConfigurationFiles.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<FileObject> getConfigFilesRecursively(FileObject parent) {
    List<FileObject> result = new ArrayList<>();
    for (FileObject child : parent.getChildren()) {
        if (VisibilityQuery.getDefault().isVisible(child)) {
            if (child.isData()
                    && (CONFIG_FILE_EXTENSIONS.contains(child.getExt().toLowerCase()) || FileUtils.isPhpFile(child))) {
                result.add(child);
            } else if (child.isFolder()) {
                result.addAll(getConfigFilesRecursively(child));
            }
        }
    }
    return result;
}
 
Example 14
Source File: DbgpLineBreakpointType.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isDefault() {
    JTextComponent lastFocusedComponent = EditorRegistry.lastFocusedComponent();
    if (lastFocusedComponent == null) {
        return false;
    }
    FileObject fileObject = NbEditorUtilities.getFileObject(lastFocusedComponent.getDocument());
    if (fileObject == null) {
        return false;
    }
    return FileUtils.isPhpFile(fileObject);
}
 
Example 15
Source File: DbgpFunctionBreakpointType.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isDefault() {
    JTextComponent lastFocusedComponent = EditorRegistry.lastFocusedComponent();
    if (lastFocusedComponent == null) {
        return false;
    }
    FileObject fileObject = NbEditorUtilities.getFileObject(lastFocusedComponent.getDocument());
    if (fileObject == null) {
        return false;
    }
    return FileUtils.isPhpFile(fileObject);
}
 
Example 16
Source File: PhpUnitTestLocator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<Locations.Offset> filterPhpFiles(FileObject sourceRoot, Collection<Pair<FileObject, Integer>> files) {
    List<Locations.Offset> results = new ArrayList<>(files.size());
    for (Pair<FileObject, Integer> pair : files) {
        FileObject fileObject = pair.first();
        if (FileUtils.isPhpFile(fileObject)
                && FileUtil.isParentOf(sourceRoot, fileObject)) {
            results.add(new Locations.Offset(fileObject, pair.second()));
        }
    }
    return results;
}
 
Example 17
Source File: NewFileNamespacePanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public synchronized void run() {
    final FileObject folder = targetFolder;
    // any selected namespace?
    final String selectedNamespace = panel.getSelectedNamespace();
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            panel.setPleaseWaitState();
        }
    });
    SortedSet<String> namespaces = new TreeSet<>();
    // add default namespace
    namespaces.add(""); // NOI18N
    EditorSupport editorSupport = Lookup.getDefault().lookup(EditorSupport.class);
    for (FileObject child : folder.getChildren()) {
        if (!folder.equals(targetFolder)) {
            // folder change => end
            return;
        }
        if (child.isFolder()) {
            continue;
        }
        if (FileUtils.isPhpFile(child)) {
            for (PhpType phpType : editorSupport.getTypes(child)) {
                String name = phpType.getName();
                String fqn = phpType.getFullyQualifiedName();
                if (fqn == null
                        || name.length() + 1 == fqn.length()) {
                    // fqn not known or default namespace
                    continue;
                }
                // remove leading "\", class name itself and trailing "\"
                String namespace = fqn.substring(1, fqn.length() - name.length() - 1);
                if (StringUtils.hasText(namespace)) {
                    namespaces.add(namespace);
                }
            }
        }
    }
    if (!folder.equals(targetFolder)) {
        // folder change => end
        return;
    }
    if (selectedNamespace != null) {
        namespaces.add(selectedNamespace);
    }
    final List<String> namespacesCopy = new CopyOnWriteArrayList<>(namespaces);
    EventQueue.invokeLater(new Runnable() {
        @Override
        public void run() {
            panel.setNamespaces(namespacesCopy);
            if (StringUtils.hasText(selectedNamespace)) {
                panel.setSelectedNamespace(selectedNamespace);
            } else if (namespacesCopy.size() == 2) {
                // exactly one namespace in the whole folder => preselect it
                panel.setSelectedNamespace(namespacesCopy.get(1));
            }
        }
    });
}
 
Example 18
Source File: GoToTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean appliesTo(FileObject fo) {
    return FileUtils.isPhpFile(fo);
}
 
Example 19
Source File: ConfigActionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRunFileEnabled(Lookup context) {
    FileObject file = CommandUtils.fileForContextOrSelectedNodes(context);
    return file != null && FileUtils.isPhpFile(file);
}
 
Example 20
Source File: ConfigActionScript.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public boolean isRunFileEnabled(Lookup context) {
    FileObject file = CommandUtils.fileForContextOrSelectedNodes(context, sourceRoot);
    return file != null && FileUtils.isPhpFile(file);
}