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

The following examples show how to use org.netbeans.modules.php.api.util.StringUtils#isEmpty() . 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: TableVisitor.java    From cakephp3-netbeans with Apache License 2.0 6 votes vote down vote up
private void handleMethod(FunctionInvocation method) {
    String methodName = CodeUtils.extractFunctionName(method);
    if (StringUtils.isEmpty(methodName)) {
        return;
    }
    Assosiation assosiation = Assosiation.get(methodName);
    if (assosiation != Assosiation.UNKNOWN) {
        addTable(method);
    }

    switch (methodName) {
        case ADD_BEHABIOR_METHOD:
            addBehavior(method);
            break;
        default:
            break;
    }
}
 
Example 2
Source File: ControllerVisitor.java    From cakephp3-netbeans with Apache License 2.0 6 votes vote down vote up
private void handleMethod(FunctionInvocation method) {
    String name = CodeUtils.extractFunctionName(method);
    if (StringUtils.isEmpty(name)) {
        return;
    }
    switch (name) {
        case LOAD_COMPONENT_METHOD:
            addComponent(method);
            break;
        case LOAD_MODEL_METHOD:
            addModel(method);
            break;
        case RENDER_METHOD:
            addTemplate(method);
            break;
        case SET_METHOD:
            // TODO
            break;
        default:
            break;
    }
}
 
Example 3
Source File: ImplementAbstractMethodsHintError.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static Set<String> toNames(Set<? extends PhpElement> elements) {
    Set<String> names = new HashSet<>();
    for (PhpElement elem : elements) {
        String name = elem.getName();
        if (!StringUtils.isEmpty(name)) {
            names.add(name);
        }
    }
    return names;
}
 
Example 4
Source File: FilePathParameter.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
private static Category getCategory(int position, String className, String methodName) {
    if (position < 0 || StringUtils.isEmpty(methodName)) {
        return Category.UNKNOWN;
    }
    List<String> elements = getElements(position, className, methodName);
    for (String element : elements) {
        element = element.toUpperCase();
        Category category = Category.valueOf(element);
        if (category != null) {
            return category;
        }
    }
    return Category.UNKNOWN;
}
 
Example 5
Source File: ViewVisitor.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
private void handleMethod(FunctionInvocation method) {
    String methodName = CodeUtils.extractFunctionName(method);
    if (StringUtils.isEmpty(methodName)) {
        return;
    }
    switch (methodName) {
        case LOAD_HELPER_METHOD:
            addHelper(method);
            break;
        default:
            break;
    }
}
 
Example 6
Source File: CakePHP3ModuleImpl.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
protected String getAppCssBaseUrl() {
    if (phpModule == null) {
        return ""; // NOI18N
    }
    String cssUrl = CakePHP3Preferences.getCssUrl(phpModule);
    if (StringUtils.isEmpty(cssUrl)) {
        cssUrl = DEFAULT_CSS_BASE_URL;
    }
    return cssUrl;
}
 
Example 7
Source File: CakePHP3ModuleImpl.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get a namespace for an app.
 *
 * @return a namespace, default namespace is App
 */
public String getAppNamespace() {
    if (phpModule == null) {
        return DEFAULT_NAMESPACE;
    }
    String namespace = CakePHP3Preferences.getNamespace(phpModule);
    if (!StringUtils.isEmpty(namespace)) {
        return namespace;
    }
    return DEFAULT_NAMESPACE;
}
 
Example 8
Source File: CakePHP3ModuleImpl.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get an extension of a template file for CakePHP.
 *
 * @return an extension of template, default is ctp
 */
public String getCtpExt() {
    if (phpModule != null) {
        String ctpExt = CakePHP3Preferences.getCtpExt(phpModule);
        if (!StringUtils.isEmpty(ctpExt)) {
            return ctpExt;
        }
    }
    return DEFAULT_CTP_EXT;
}
 
Example 9
Source File: CakePHP3ProjectGenerator.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Get default CakePHP3ProjectGenerator.
 *
 * @return
 * @throws InvalidPhpExecutableException
 */
@NbBundle.Messages({
    "CakePHP3ProjectGenerator.invalid.composer=Is not set composer path. Please set it to Options."
})
public static CakePHP3ProjectGenerator getDefault() throws InvalidPhpExecutableException {
    CakePHP3Options options = CakePHP3Options.getInstance();
    String composerPath = options.getComposerPath();
    if (!StringUtils.isEmpty(composerPath)) {
        return new CakePHP3ProjectGenerator(composerPath);
    }
    throw new InvalidPhpExecutableException(Bundle.CakePHP3ProjectGenerator_invalid_composer());
}
 
Example 10
Source File: Codecept.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public FileObject generateTest(PhpModule phpModule, FileObject fo, GenerateCommand command, String suite, String fqName) throws ExecutionException {
    String testPath = fullyQualifiedNameToPath(fqName);
    if (testPath.startsWith("/")) { // NOI18N
        testPath = testPath.substring(1);
    }
    PhpExecutable executable = getExecutable(phpModule);
    if (executable == null) {
        return null;
    }
    File workDir = getWorkingDirectory(phpModule);
    if (workDir != null) {
        executable.workDir(workDir);
    }
    List<String> params = createParams(true);
    params.add(command.getFullCommand());
    params.add(suite);
    params.add(testPath);
    executable.additionalParameters(params);
    GenerateTestOutputFactory generateTestOutputFactory = new GenerateTestOutputFactory();
    try {
        Integer status = executable.runAndWait(getDescriptor(false), generateTestOutputFactory, "Generating test..."); // NOI18N
        if (status != null && status == 0) {
            if (generateTestOutputFactory.isExists()) {
                return null;
            }
            String filePath = generateTestOutputFactory.getFilePath();
            if (StringUtils.isEmpty(filePath)) {
                return null;
            }
            File file = new File(filePath);
            return file.exists() ? FileUtil.toFileObject(file) : null;
        }
    } catch (CancellationException ex) {
        // canceled
        LOGGER.log(Level.FINE, "Test creating cancelled", ex); // NOI18N
    }
    return null;
}
 
Example 11
Source File: PHPDocCommentParser.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private List<PHPDocTypeNode> findTypes(String description, int startDescription, String originalComment, int originalCommentStart, boolean isReturnTag) {
    if (StringUtils.isEmpty(description)) {
        return Collections.emptyList();
    }

    List<PHPDocTypeNode> result = new ArrayList<>();
    for (String stype : getTypes(description, isReturnTag)) {
        stype = removeHTMLTags(stype);
        int startDocNode = findStartOfDocNode(originalComment, originalCommentStart, stype, startDescription);
        if (startDocNode == -1) {
            continue;
        }
        int index = stype.indexOf("::");    //NOI18N
        boolean isArray = (stype.indexOf('[') > 0 && stype.indexOf(']') > 0);
        if (isArray) {
            stype = stype.substring(0, stype.indexOf('[')).trim();
        }
        PHPDocTypeNode docType;
        if (index == -1) {
            docType = new PHPDocTypeNode(startDocNode, startDocNode + stype.length(), stype, isArray);
        } else {
            String className = stype.substring(0, index);
            String constantName = stype.substring(index + 2, stype.length());
            PHPDocNode classNameNode = new PHPDocNode(startDocNode, startDocNode + className.length(), className);
            PHPDocNode constantNode = new PHPDocNode(startDocNode + className.length() + 2, startDocNode + stype.length(), constantName);
            docType = new PHPDocStaticAccessType(startDocNode, startDocNode + stype.length(), stype, classNameNode, constantNode);
        }
        result.add(docType);
    }
    return result;
}
 
Example 12
Source File: AnalysisOptionsValidator.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private AnalysisOptionsValidator validatePHPStanConfiguration(String configuration) {
    if (!StringUtils.isEmpty(configuration)) {
        String warning = FileUtils.validateFile("Configuration file", configuration, false); // NOI18N
        if (warning != null) {
            result.addWarning(new ValidationResult.Message("phpStan.configuration", warning)); // NOI18N
        }
    }
    return this;
}
 
Example 13
Source File: CakePHP3Visitor.java    From cakephp3-netbeans with Apache License 2.0 5 votes vote down vote up
@CheckForNull
protected FileObject getEntityFile(Category category, String entityName, String pluginName) {
    CakePHP3Module module = CakePHP3Module.forPhpModule(phpModule);
    CakePHP3Module.Base base;
    if (!StringUtils.isEmpty(pluginName)) {
        base = CakePHP3Module.Base.PLUGIN;
    } else {
        base = CakePHP3Module.Base.APP;
    }
    String relativePath = module.toPhpFileName(category, entityName);
    return module.getFile(base, category, relativePath, pluginName);
}
 
Example 14
Source File: CakePHP3ModuleDefault.java    From cakephp3-netbeans with Apache License 2.0 4 votes vote down vote up
private FileObject getControllerOrViewCell(FileObject template, boolean isController, boolean forceApp) {
    if (template == null || template.isFolder()) {
        return null;
    }
    Category category = getCategory(template);
    if (isController) {
        if (category != Category.TEMPLATE) {
            return null;
        }
    } else {
        if (category != Category.TEMPLATE_CELL) {
            return null;
        }
    }

    Base base = getBase(template);
    // plugin
    String pluginName = ""; // NOI18N
    if (base == Base.PLUGIN) {
        pluginName = getPluginName(template);
    }

    List<FileObject> directories = getDirectories(base, category, pluginName);
    for (FileObject directory : directories) {
        String relativeFilePath = FileUtil.getRelativePath(directory, template);
        if (StringUtils.isEmpty(relativeFilePath)) {
            continue;
        }
        String relativeSubpath = relativeFilePath.replace(template.getNameExt(), ""); // NOI18N
        if (relativeSubpath.endsWith("/")) { // NOI18N
            relativeSubpath = relativeSubpath.substring(0, relativeSubpath.length() - 1);
        }
        Category c = category == Category.TEMPLATE ? Category.CONTROLLER : Category.VIEW_CELL;
        String controllerFilePath = toPhpFileName(c, relativeSubpath);
        if (forceApp) {
            base = Base.APP;
            pluginName = null;
        }
        FileObject controllerOrViewCell = getFile(base, c, controllerFilePath, pluginName);
        if (controllerOrViewCell != null) {
            return controllerOrViewCell;
        }
    }

    return null;
}
 
Example 15
Source File: CakePHP3ModuleImpl.java    From cakephp3-netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Get a namespace for a directory or file.
 *
 * @param fileObject a directroy or file
 * @return a namespace if it exists, otherwise empty string
 */
public String getNamespace(FileObject fileObject) {
    if (fileObject == null) {
        return ""; // NOI18N
    }
    Base base = getBase(fileObject);
    StringBuilder sb = new StringBuilder();
    String pluginName = null;
    if (base == Base.APP) {
        sb.append(getAppNamespace()).append("\\"); // NOI18N
    } else if (base == Base.CORE) {
        sb.append("Cake\\"); // NOI18N
    } else if (base == Base.PLUGIN) {
        pluginName = getPluginName(fileObject);
        if (StringUtils.isEmpty(pluginName)) {
            return sb.toString();
        }
        sb.append(pluginName).append("\\"); // NOI18N
    } else {
        return sb.toString();
    }

    // XXX not default directory structure
    FileObject srcDir = getSrcDir(base, pluginName);
    if (srcDir == null) {
        return ""; // NOI18N
    }
    FileObject target = fileObject;
    if (!fileObject.isFolder()) {
        target = fileObject.getParent();
        if (target == null) {
            return ""; // NOI18N
        }
    }

    String relativePath = FileUtil.getRelativePath(srcDir, target);
    if (relativePath == null) {
        return ""; // NOI18N
    }
    sb.append(relativePath.replace("/", "\\")); // NOI18N
    return sb.toString();
}
 
Example 16
Source File: ControllerVisitor.java    From cakephp3-netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void visit(ExpressionStatement node) {
    super.visit(node);
    if (StringUtils.isEmpty(currentMethodName)) {
        return;
    }

    Expression expression = node.getExpression();
    if (expression instanceof Assignment) {
        Assignment assignment = (Assignment) expression;
        Assignment.Type operator = assignment.getOperator();
        if (operator != Assignment.Type.EQUAL) {
            return;
        }

        VariableBase leftHandSide = assignment.getLeftHandSide();
        if (leftHandSide instanceof FieldAccess) {
            // e.g. $this->theme = 'Modern';
            // left
            FieldAccess f = (FieldAccess) leftHandSide;
            Variable v = f.getField();
            String variableName = CodeUtils.extractVariableName(v);
            if (!"theme".equals(variableName)) { // NOI18N
                return;
            }

            // right
            Expression rightHandSide = assignment.getRightHandSide();
            String rightValue = CakePHPCodeUtils.getStringValue(rightHandSide);
            if (rightValue.isEmpty()) {
                return;
            }

            if (currentMethodName.equals(templateName)) {
                themeNames.add(rightValue);
            } else {
                allThemeNames.add(rightValue);
            }
        }
    }
}
 
Example 17
Source File: TemplateVisitor.java    From cakephp3-netbeans with Apache License 2.0 4 votes vote down vote up
private void addElements(FunctionInvocation method) {
    String elementPath = getFirstParameter(method);
    if (!StringUtils.isEmpty(elementPath)) {
        elements.add(elementPath);
    }
}
 
Example 18
Source File: CakePHP3NewProjectPanelVisual.java    From cakephp3-netbeans with Apache License 2.0 4 votes vote down vote up
@NbBundle.Messages({
    "CakePHP3NewProjectPanelVisual.invalid.composer.path=Composer path is not set to Options.",
    "CakePHP3NewProjectPanelVisual.invalid.folder.name=Project Name is not a valid folder name.",
    "CakePHP3NewProjectPanelVisual.invalid.folder.path=Project Folder is not a valid path.",
    "CakePHP3NewProjectPanelVisual.invalid.folder.permission=Project Folder cannot be created.",
    "CakePHP3NewProjectPanelVisual.folder.not.empty=Project Folder already exists and is not empty."
})
boolean valid(WizardDescriptor wizardDescriptor) {
    // composer path
    CakePHP3Options options = CakePHP3Options.getInstance();
    String composerPath = options.getComposerPath();
    if (StringUtils.isEmpty(composerPath)) {
        wizardDescriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE,
                Bundle.CakePHP3NewProjectPanelVisual_invalid_composer_path());
        return false;
    }

    if (projectNameTextField.getText().length() == 0) {
        wizardDescriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE,
                Bundle.CakePHP3NewProjectPanelVisual_invalid_folder_name());
        return false; // Display name not specified
    }
    File f = FileUtil.normalizeFile(new File(projectLocationTextField.getText()).getAbsoluteFile());
    if (!f.isDirectory()) {
        wizardDescriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE,
                Bundle.CakePHP3NewProjectPanelVisual_invalid_folder_path());
        return false;
    }
    final File destFolder = FileUtil.normalizeFile(new File(createdFolderTextField.getText()).getAbsoluteFile());

    File projLoc = destFolder;
    while (projLoc != null && !projLoc.exists()) {
        projLoc = projLoc.getParentFile();
    }
    if (projLoc == null || !projLoc.canWrite()) {
        wizardDescriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE,
                Bundle.CakePHP3NewProjectPanelVisual_invalid_folder_permission());
        return false;
    }

    if (FileUtil.toFileObject(projLoc) == null) {
        wizardDescriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE,
                Bundle.CakePHP3NewProjectPanelVisual_invalid_folder_path());
        return false;
    }

    File[] kids = destFolder.listFiles();
    if (destFolder.exists() && kids != null && kids.length > 0) {
        // Folder exists and is not empty
        wizardDescriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE,
                Bundle.CakePHP3NewProjectPanelVisual_folder_not_empty());
        return false;
    }
    wizardDescriptor.putProperty(WizardDescriptor.PROP_ERROR_MESSAGE, ""); // NOI18N
    return true;
}
 
Example 19
Source File: ModuleUtils.java    From cakephp3-netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * Check whether a path is a child of specified directory.
 *
 * @param parent a directory
 * @param childPath a file path of FileObject
 * @return {@code true} if the path is a child the directory, otherwise
 * {@code false}
 */
public static boolean isChild(FileObject parent, String childPath) {
    if (parent == null || !parent.isFolder() || StringUtils.isEmpty(childPath)) {
        return false;
    }
    String parentPath = parent.getPath();
    return childPath.startsWith(parentPath);
}
 
Example 20
Source File: ModuleUtils.java    From cakephp3-netbeans with Apache License 2.0 3 votes vote down vote up
/**
 * Append a specified plugin name to a base name.
 *
 * @param pluginName a plugin name e.g. DebugKit
 * @param baseName a base name e.g. Toolbar
 * @return PluginName.basename e.g. DebugKit.Toolbar
 */
public static String appendPluignName(String pluginName, String baseName) {
    if (StringUtils.isEmpty(baseName)) {
        return baseName;
    }
    return StringUtils.isEmpty(pluginName) ? baseName : pluginName + "." + baseName; // NOI18N
}