Search in sources :

Example 1 with SearchResult

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

the class JSPFileWTP method findJSPTags.

@Override
public List<SearchResult> findJSPTags(String tagName, String[] attrNames) {
    if ((tagName == null) || tagName.isEmpty() || ListUtil.isEmpty(attrNames)) {
        throw new IllegalArgumentException("tagName can not be null or empty");
    }
    List<SearchResult> searchResults = new ArrayList<>();
    NodeList nodeList = _getTagNodes(tagName);
    for (int i = 0; i < nodeList.getLength(); i++) {
        IDOMNode domNode = (IDOMNode) nodeList.item(i);
        for (String attrName : attrNames) {
            IDOMNode attrNode = (IDOMNode) domNode.getAttributes().getNamedItem(attrName);
            if (attrNode != null) {
                int startOffset = attrNode.getStartOffset();
                int endOffset = startOffset + attrName.length();
                int jspStartLine = _getJspLine(startOffset);
                int jspEndLine = _getJspLine(endOffset);
                searchResults.add(super.createSearchResult(null, startOffset, endOffset, jspStartLine, jspEndLine, true));
            }
        }
    }
    return searchResults;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult)

Example 2 with SearchResult

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

the class JSPFileWTP method findJSPTags.

@Override
public List<SearchResult> findJSPTags(String tagName) {
    if ((tagName == null) || tagName.isEmpty()) {
        throw new IllegalArgumentException("tagName can not be null or empty");
    }
    List<SearchResult> searchResults = new ArrayList<>();
    NodeList nodeList = _getTagNodes(tagName);
    for (int i = 0; i < nodeList.getLength(); i++) {
        IDOMNode domNode = (IDOMNode) nodeList.item(i);
        int startOffset = domNode.getStartOffset();
        int endOffset = domNode.getEndOffset();
        int jspStartLine = _getJspLine(startOffset);
        int jspEndLine = _getJspLine(endOffset);
        searchResults.add(super.createSearchResult(null, startOffset, endOffset, jspStartLine, jspEndLine, true));
    }
    return searchResults;
}
Also used : IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) NodeList(org.w3c.dom.NodeList) ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult)

Example 3 with SearchResult

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

the class JavaFileJDT method findCatchExceptions.

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

        @Override
        public boolean visit(CatchClause node) {
            SingleVariableDeclaration exception = node.getException();
            String exceptionTypeName = exception.getType().toString();
            boolean retVal = false;
            for (String exceptionType : exceptions) {
                if (exceptionTypeName.equals(exceptionType)) {
                    int startLine = _ast.getLineNumber(exception.getStartPosition());
                    int startOffset = exception.getStartPosition();
                    int endLine = _ast.getLineNumber(exception.getStartPosition() + exception.getLength());
                    int endOffset = exception.getStartPosition() + exception.getLength();
                    searchResults.add(createSearchResult(exceptionTypeName, startOffset, endOffset, startLine, endLine, true));
                    retVal = true;
                }
            }
            return retVal;
        }
    });
    return searchResults;
}
Also used : SingleVariableDeclaration(org.eclipse.jdt.core.dom.SingleVariableDeclaration) ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult) CatchClause(org.eclipse.jdt.core.dom.CatchClause) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor)

Example 4 with SearchResult

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

the class JavaFileJDT method findPackage.

@Override
public SearchResult findPackage(String packageName) {
    List<SearchResult> searchResults = new ArrayList<>();
    _ast.accept(new ASTVisitor() {

        @Override
        public boolean visit(PackageDeclaration node) {
            String searchContext = node.getName().toString();
            if (packageName.equals(searchContext)) {
                int startLine = _ast.getLineNumber(node.getName().getStartPosition());
                int startOffset = node.getName().getStartPosition();
                int endLine = _ast.getLineNumber(node.getName().getStartPosition() + node.getName().getLength());
                int endOffset = node.getName().getStartPosition() + node.getName().getLength();
                searchResults.add(createSearchResult(searchContext, startOffset, endOffset, startLine, endLine, true));
            }
            return false;
        }
    });
    if (ListUtil.isNotEmpty(searchResults)) {
        return searchResults.get(0);
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult) PackageDeclaration(org.eclipse.jdt.core.dom.PackageDeclaration) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor)

Example 5 with SearchResult

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

the class JavaFileJDT method findImplementsInterface.

@Override
public List<SearchResult> findImplementsInterface(String interfaceName) {
    List<SearchResult> searchResults = new ArrayList<>();
    _ast.accept(new ASTVisitor() {

        @Override
        public boolean visit(TypeDeclaration node) {
            ITypeBinding[] superInterfaces = null;
            if (node.resolveBinding() != null) {
                superInterfaces = node.resolveBinding().getInterfaces();
                if (ListUtil.isNotEmpty(superInterfaces)) {
                    String searchContext = superInterfaces[0].getName();
                    if (searchContext.equals(interfaceName)) {
                        int startLine = _ast.getLineNumber(node.getName().getStartPosition());
                        int startOffset = node.getName().getStartPosition();
                        int endLine = _ast.getLineNumber(node.getName().getStartPosition() + node.getName().getLength());
                        int endOffset = node.getName().getStartPosition() + node.getName().getLength();
                        searchResults.add(createSearchResult(searchContext, startOffset, endOffset, startLine, endLine, true));
                    }
                }
            }
            return true;
        }
    });
    return searchResults;
}
Also used : ArrayList(java.util.ArrayList) SearchResult(com.liferay.blade.api.SearchResult) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) ASTVisitor(org.eclipse.jdt.core.dom.ASTVisitor)

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