Java Code Examples for org.netbeans.modules.php.api.util.StringUtils#hasText()

The following examples show how to use org.netbeans.modules.php.api.util.StringUtils#hasText() . 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: LatteControlCompletionProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void findControls(PHPParseResult parseResult) {
    Set<MethodScope> controlFactories = new HashSet<>();
    String realPrefix = StringUtils.hasText(controlPrefix) ? CREATE_COMPONENT_PREFIX + StringUtils.capitalize(controlPrefix) : CREATE_COMPONENT_PREFIX;
    NameKind.Prefix nameKindPrefix = NameKind.prefix(realPrefix);
    Model model = parseResult.getModel(Model.Type.COMMON);
    Collection<? extends ClassScope> declaredClasses = ModelUtils.getDeclaredClasses(model.getFileScope());
    for (ClassScope classScope : declaredClasses) {
        Collection<? extends MethodScope> methods = classScope.getMethods();
        controlFactories = ElementFilter.forName(nameKindPrefix).filter(new HashSet<>(methods));
    }
    for (MethodScope methodScope : controlFactories) {
        String methodName = methodScope.getName();
        String controlName = methodName.substring(CREATE_COMPONENT_PREFIX.length());
        result.add(StringUtils.decapitalize(controlName));
    }
}
 
Example 2
Source File: PHP5ErrorHandlerImpl.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages("SE_After=after")
public String createAfterText() {
    String result;
    String afterText = null;
    if (isValuableToken(token)) {
        afterText = getTokenTextForm(token.sym) + " '" + String.valueOf(token.value) + "'";
    } else {
        if (!isNodeToken()) {
            String previousText = getTokenTextForm(token.sym);
            if (StringUtils.hasText(previousText)) {
                afterText = previousText.trim();
            }
        }
    }
    if (afterText == null) {
        result = ""; //NOI18N
    } else {
        result = "\n " + Bundle.SE_After() + ":\t" + afterText; //NOI18N
    }
    return result;
}
 
Example 3
Source File: RunConfigInternalValidator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages("RunConfigInternalValidator.router.label=Router")
private static String validate(RunConfigInternal config, boolean validateRouter) {
    String error;
    error = RemoteValidator.validateHost(config.getHostname());
    if (error != null) {
        return error;
    }
    error = RemoteValidator.validatePort(config.getPort());
    if (error != null) {
        return error;
    }
    if (validateRouter) {
        String routerRelativePath = config.getRouterRelativePath();
        if (StringUtils.hasText(routerRelativePath)) {
            error = BaseRunConfigValidator.validateRelativeFile(config.getWorkDir(), routerRelativePath, Bundle.RunConfigInternalValidator_router_label());
            if (error != null) {
                return error;
            }
        }
    }
    return null;
}
 
Example 4
Source File: RunConfigScriptValidator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private static String validate(RunConfigScript config, boolean validateIndex) {
    String error;
    error = validateInterpreter(config.getInterpreter());
    if (error != null) {
        return error;
    }
    error = validateWorkDir(config.getWorkDir(), true);
    if (error != null) {
        return error;
    }
    if (validateIndex) {
        String indexRelativePath = config.getIndexRelativePath();
        if (StringUtils.hasText(indexRelativePath)) {
            error = BaseRunConfigValidator.validateIndexFile(config.getIndexParentDir(), indexRelativePath, false);
            if (error != null) {
                return error;
            }
        }
    }
    return null;
}
 
Example 5
Source File: OccurenceBuilder.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void buildDocTagsForClasses(ElementInfo nodeCtxInfo, FileScopeImpl fileScope, final List<Occurence> occurences) {
    Set<? extends PhpElement> elements = nodeCtxInfo.getDeclarations();
    for (PhpElement phpElement : elements) {
        for (Entry<PhpDocTypeTagInfo, Scope> entry : docTags.entrySet()) {
            if (CancelSupport.getDefault().isCancelled()) {
                return;
            }
            PhpDocTypeTagInfo nodeInfo = entry.getKey();
            final QualifiedName qualifiedName = VariousUtils.getFullyQualifiedName(nodeInfo.getQualifiedName(), nodeInfo.getOriginalNode().getStartOffset(), entry.getValue());
            final String name = CodeUtils.removeNullableTypePrefix(nodeInfo.getName());
            if (StringUtils.hasText(name) && NameKind.exact(name).matchesName(PhpElementKind.CLASS, phpElement.getName())
                    && NameKind.exact(qualifiedName).matchesName(phpElement)) {
                if (qualifiedName.getKind().isUnqualified()) {
                    occurences.add(new OccurenceImpl(ElementFilter.forFiles(fileScope.getFileObject()).prefer(elements), nodeInfo.getRange()));
                } else {
                    occurences.add(new OccurenceImpl(phpElement, nodeInfo.getRange()));
                }
            }
        }
    }
}
 
Example 6
Source File: SourceRoots.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the display names of source roots.
 * The returned array has the same length as an array returned by the {@link #getRootProperties()}.
 * It may contain empty {@link String}s but not <code>null</code>.
 * @return an array of source roots names.
 */
@NbBundle.Messages({
    "# {0} - display name of the source root",
    "# {1} - directory of the source root",
    "SourceRoots.displayName={0} ({1})",
})
public String[] getRootNames() {
    String[] pureRootNames = getPureRootNames();
    if (pureRootNames.length == 0) {
        return new String[0];
    }
    String[] names = new String[pureRootNames.length];
    for (int i = 0; i < names.length; i++) {
        String pureName = pureRootNames[i];
        String name;
        if (StringUtils.hasText(pureName)) {
            name = Bundle.SourceRoots_displayName(displayName, pureName);
        } else {
            name = displayName;
        }
        names[i] = name;
    }
    return names;
}
 
Example 7
Source File: RemoteValidator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@NbBundle.Messages({
    "RemoteValidator.error.uploadDirectory.missing=Upload directory must be specified.",
    "# {0} - remote path separator",
    "RemoteValidator.error.uploadDirectory.start=Upload directory must start with \"{0}\".",
    "# {0} - invalid path separator",
    "RemoteValidator.error.uploadDirectory.content=Upload directory cannot contain \"{0}\"."
})
public static String validateUploadDirectory(String uploadDirectory) {
    if (!StringUtils.hasText(uploadDirectory)) {
        return Bundle.RemoteValidator_error_uploadDirectory_missing();
    } else if (!uploadDirectory.startsWith(TransferFile.REMOTE_PATH_SEPARATOR)) {
        return Bundle.RemoteValidator_error_uploadDirectory_start(TransferFile.REMOTE_PATH_SEPARATOR);
    } else if (uploadDirectory.contains(INVALID_SEPARATOR)) {
        return Bundle.RemoteValidator_error_uploadDirectory_content(INVALID_SEPARATOR);
    }
    return null;
}
 
Example 8
Source File: PhpModuleGenerator.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Validate given create properties.
 * @param properties properties to be validated
 * @return self
 */
@NbBundle.Messages({
    "CreatePropertiesValidator.error.name=Invalid name.",
    "CreatePropertiesValidator.error.sourcesDirectory=No sources directory.",
    "CreatePropertiesValidator.error.phpVersion=No PHP version.",
    "CreatePropertiesValidator.error.charset=No charset.",
})
public CreatePropertiesValidator validate(@NonNull CreateProperties properties) {
    Parameters.notNull("properties", properties); // NOI18N
    if (!StringUtils.hasText(properties.getName())) {
        result.addError(new ValidationResult.Message("name", Bundle.CreatePropertiesValidator_error_name())); // NOI18N
    }
    if (properties.getSourcesDirectory() == null) {
        result.addError(new ValidationResult.Message("sourcesDirectory", Bundle.CreatePropertiesValidator_error_sourcesDirectory())); // NOI18N
    }
    if (properties.getPhpVersion() == null) {
        result.addError(new ValidationResult.Message("phpVersion", Bundle.CreatePropertiesValidator_error_phpVersion())); // NOI18N
    }
    if (properties.getCharset() == null) {
        result.addError(new ValidationResult.Message("charset", Bundle.CreatePropertiesValidator_error_charset())); // NOI18N
    }
    return this;
}
 
Example 9
Source File: RunAsWebAdvanced.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public boolean isLastServerPathFilled() {
    int rowCount = getRowCount();
    if (rowCount == 0) {
        return true;
    }
    return StringUtils.hasText((String) getValueAt(rowCount - 1, COLUMN_REMOTE_PATH));
}
 
Example 10
Source File: PhpProjectUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Resolve local file.
 * @param parentDir parent directory
 * @param relativeFilePath relative path ("/" expected as a separator), can be {@link StringUtils#hasText(String) empty}
 * @return resolved file
 */
public static File resolveFile(File parentDir, String relativeFilePath) {
    if (parentDir == null) {
        throw new NullPointerException("Parameter 'parentDir' must be set");
    }
    if (StringUtils.hasText(relativeFilePath)) {
        return new File(parentDir, relativeFilePath.replace('/', File.separatorChar)); // NOI18N
    }
    return parentDir;
}
 
Example 11
Source File: RemoteConfiguration.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Read value of the given key as a number. If number is not found in the given configuration
 * (or value is not a number), the default value is returned (and set in the configuration).
 * @param key key of the number
 * @param defaultValue default value if any error occurs
 * @return value of the given key as a number or defaultValue if any error occurs
 */
protected int readNumber(String key, int defaultValue) {
    String currentValue = cfg.getValue(key);
    if (StringUtils.hasText(currentValue)) {
        try {
            return Integer.parseInt(currentValue);
        } catch (NumberFormatException nfe) {
            LOGGER.log(Level.INFO, "Exception while parsing number of '" + key + "'", nfe);
        }
    }
    cfg.putValue(key, String.valueOf(defaultValue));
    return defaultValue;
}
 
Example 12
Source File: ApiGenScript.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void addConfig(PhpModule phpModule, List<String> params) {
    String config = ApiGenPreferences.get(phpModule, ApiGenPreferences.CONFIG);
    if (StringUtils.hasText(config)) {
        params.add(CONFIG_PARAM);
        params.add(config);
    }
}
 
Example 13
Source File: TesterPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String relativizePath(PhpModule phpModule, String filePath) {
    if (!StringUtils.hasText(filePath)) {
        return ""; // NOI18N
    }
    File file = new File(filePath);
    String path = PropertyUtils.relativizeFile(FileUtil.toFile(phpModule.getProjectDirectory()), file);
    if (path == null) {
        // sorry, cannot be relativized
        path = file.getAbsolutePath();
    }
    return path;
}
 
Example 14
Source File: ProjectPropertiesSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static boolean getBoolean(PhpProject project, String property, boolean defaultValue) {
    String boolValue = project.getEvaluator().getProperty(property);
    if (StringUtils.hasText(boolValue)) {
        return Boolean.parseBoolean(boolValue);
    }
    return defaultValue;
}
 
Example 15
Source File: ProjectPropertiesSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static File getSubdirectory(PhpProject project, FileObject rootDirectory, String subdirectoryPath) {
    File rootDir = FileUtil.toFile(rootDirectory);
    if (!StringUtils.hasText(subdirectoryPath)) {
        return rootDir;
    }
    // first try to resolve fileobject
    FileObject fo = rootDirectory.getFileObject(subdirectoryPath);
    if (fo != null) {
        return FileUtil.toFile(fo);
    }
    // fallback for OS specific paths (should be changed everywhere, my fault, sorry)
    return PropertyUtils.resolveFile(FileUtil.toFile(rootDirectory), subdirectoryPath);
}
 
Example 16
Source File: ProjectUpgrader.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void upgradePhpUnit(EditableProperties properties) {
    Map<String, String> newlyEnabledProperties = new HashMap<>();
    newlyEnabledProperties.put(PHP_UNIT_BOOTSTRAP, "auxiliary.org-netbeans-modules-php-phpunit.bootstrap_2e_enabled"); // NOI18N
    newlyEnabledProperties.put(PHP_UNIT_CONFIGURATION, "auxiliary.org-netbeans-modules-php-phpunit.configuration_2e_enabled"); // NOI18N
    newlyEnabledProperties.put(PHP_UNIT_SUITE, "auxiliary.org-netbeans-modules-php-phpunit.customSuite_2e_enabled"); // NOI18N
    newlyEnabledProperties.put(PHP_UNIT_SCRIPT, "auxiliary.org-netbeans-modules-php-phpunit.phpUnit_2e_enabled"); // NOI18N
    for (Map.Entry<String, String> entry : newlyEnabledProperties.entrySet()) {
        if (StringUtils.hasText(properties.get(entry.getKey()))) {
            properties.setProperty(entry.getValue(), "true"); // NOI18N
        }
    }
}
 
Example 17
Source File: CodeceptionPreferences.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String relativizePath(PhpModule phpModule, String filePath) {
    if (!StringUtils.hasText(filePath)) {
        return ""; // NOI18N
    }
    File file = new File(filePath);
    String path = PropertyUtils.relativizeFile(FileUtil.toFile(phpModule.getProjectDirectory()), file);
    if (path == null) {
        // sorry, cannot be relativized
        path = file.getAbsolutePath();
    }
    return path;
}
 
Example 18
Source File: RemoteValidator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public static String validateUser(String username) {
    if (!StringUtils.hasText(username)) {
        return NbBundle.getMessage(RemoteValidator.class, "MSG_NoUserName");
    }
    return null;
}
 
Example 19
Source File: FunctionScopeImpl.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private synchronized void updateReturnTypesIfNotChanged(String oldTypes, String newTypes) {
    if (oldTypes.equals(getReturnType()) && StringUtils.hasText(newTypes)) {
        returnType = newTypes;
    }
}
 
Example 20
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));
            }
        }
    });
}