Search in sources :

Example 6 with SearchResult

use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.

the class JavaFileJDT method findImports.

@Override
public List<SearchResult> findImports(String[] imports) {
    List<SearchResult> searchResults = new ArrayList<>();
    _ast.accept(new ASTVisitor() {

        @Override
        public boolean visit(ImportDeclaration node) {
            Name name = node.getName();
            String searchContext = name.getFullyQualifiedName();
            for (String importName : imports) {
                if (searchContext.startsWith(importName)) {
                    List<String> importsList = new ArrayList<>(Arrays.asList(imports));
                    String greedyImport = importName;
                    importsList.remove(importName);
                    for (String anotherImport : importsList) {
                        if (name.toString().contains(anotherImport) && (anotherImport.length() > importName.length())) {
                            greedyImport = anotherImport;
                        }
                    }
                    int startLine = _ast.getLineNumber(name.getStartPosition());
                    int startOffset = name.getStartPosition();
                    int endLine = _ast.getLineNumber(name.getStartPosition() + name.getLength());
                    int endOffset = name.getStartPosition() + greedyImport.length();
                    searchResults.add(createSearchResult(searchContext, startOffset, endOffset, startLine, endLine, true));
                }
            }
            return false;
        }
    });
    return searchResults;
}
Also used : ArrayList(java.util.ArrayList) ImportDeclaration(org.eclipse.jdt.core.dom.ImportDeclaration) SearchResult(com.liferay.blade.api.SearchResult) ArrayList(java.util.ArrayList) List(java.util.List) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor) Name(org.eclipse.jdt.core.dom.Name)

Example 7 with SearchResult

use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.

the class SSEXMLFile method findElement.

@Override
public List<SearchResult> findElement(String tagName, String value) {
    List<SearchResult> results = new ArrayList<>();
    IFile xmlFile = getIFile(file);
    IDOMModel domModel = null;
    try {
        domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForRead(xmlFile);
        IDOMDocument document = domModel.getDocument();
        NodeList elements = document.getElementsByTagName(tagName);
        if (elements != null) {
            for (int i = 0; i < elements.getLength(); i++) {
                IDOMElement element = (IDOMElement) elements.item(i);
                String textContent = element.getTextContent();
                if ((textContent != null) && value.trim().equals(textContent.trim())) {
                    int startOffset = element.getStartOffset();
                    int endOffset = element.getEndOffset();
                    int startLine = document.getStructuredDocument().getLineOfOffset(startOffset) + 1;
                    int endLine = document.getStructuredDocument().getLineOfOffset(endOffset) + 1;
                    SearchResult result = new SearchResult(file, "startOffset:" + startOffset, startOffset, endOffset, startLine, endLine, true);
                    results.add(result);
                }
            }
        }
    } catch (Exception e) {
    } finally {
        if (domModel != null) {
            domModel.releaseFromRead();
        }
    }
    return results;
}
Also used : IFile(org.eclipse.core.resources.IFile) IDOMModel(org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult) IDOMDocument(org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument) IDOMElement(org.eclipse.wst.xml.core.internal.provisional.document.IDOMElement)

Example 8 with SearchResult

use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.

the class ImportStatementMigrator method searchFile.

@Override
public List<SearchResult> searchFile(File file, JavaFile javaFile) {
    List<SearchResult> searchResults = new ArrayList<>();
    for (String importName : _importFixes.keySet()) {
        SearchResult importResult = javaFile.findImport(importName);
        if (importResult != null) {
            importResult.autoCorrectContext = _PREFIX + importName;
            searchResults.add(importResult);
        }
    }
    return searchResults;
}
Also used : ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult)

Example 9 with SearchResult

use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.

the class PropertiesFileChecker method findProperties.

public List<SearchResult> findProperties(String key) {
    List<SearchResult> retval = new ArrayList<>();
    List<KeyInfo> infos = _keyInfos.get(key);
    if (infos != null) {
        for (KeyInfo info : infos) {
            retval.add(new SearchResult(_file, info.offset, info.offset + info.length, info.lineNumber, info.lineNumber, true));
        }
    }
    return retval;
}
Also used : ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult)

Example 10 with SearchResult

use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.

the class LiferayVersionsProperties method analyze.

@Override
public List<Problem> analyze(File file) {
    List<Problem> problems = new ArrayList<>();
    if (file.getName().equals("liferay-plugin-package.properties")) {
        PropertiesFileChecker propertiesFileChecker = new PropertiesFileChecker(file);
        List<KeyInfo> keys = propertiesFileChecker.getInfos("liferay-versions");
        if (ListUtil.isNotEmpty(keys)) {
            String versions = keys.get(0).value;
            if (!versions.matches(".*7\\.[0-9]\\.[0-9].*")) {
                List<SearchResult> results = propertiesFileChecker.findProperties("liferay-versions");
                if (results != null) {
                    String sectionHtml = problemSummary;
                    for (SearchResult searchResult : results) {
                        searchResult.autoCorrectContext = _PREFIX + "liferay-versions";
                        problems.add(new Problem(problemTitle, problemSummary, problemType, problemTickets, file, searchResult.startLine, searchResult.startOffset, searchResult.endOffset, sectionHtml, searchResult.autoCorrectContext, Problem.STATUS_NOT_RESOLVED, Problem.DEFAULT_MARKER_ID, Problem.MARKER_ERROR));
                    }
                }
            }
        }
    }
    return problems;
}
Also used : PropertiesFileChecker(com.liferay.blade.upgrade.liferay70.PropertiesFileChecker) KeyInfo(com.liferay.blade.upgrade.liferay70.PropertiesFileChecker.KeyInfo) ArrayList(java.util.ArrayList) Problem(com.liferay.blade.api.Problem) SearchResult(com.liferay.blade.api.SearchResult)

Aggregations

SearchResult (com.liferay.blade.api.SearchResult)29 ArrayList (java.util.ArrayList)25 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)8 JavaFile (com.liferay.blade.api.JavaFile)4 Problem (com.liferay.blade.api.Problem)4 File (java.io.File)4 Test (org.junit.Test)4 BundleContext (org.osgi.framework.BundleContext)4 ServiceReference (org.osgi.framework.ServiceReference)4 NodeList (org.w3c.dom.NodeList)3 PropertiesFileChecker (com.liferay.blade.upgrade.liferay70.PropertiesFileChecker)2 List (java.util.List)2 Path (org.eclipse.core.runtime.Path)2 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)2 ImportDeclaration (org.eclipse.jdt.core.dom.ImportDeclaration)2 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)2 IDOMNode (org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode)2 JSONArray (org.json.JSONArray)2 KeyInfo (com.liferay.blade.upgrade.liferay70.PropertiesFileChecker.KeyInfo)1 ExecutionException (java.util.concurrent.ExecutionException)1