use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.
the class JavaFileJDT method findServiceAPIs.
@Override
public List<SearchResult> findServiceAPIs(String[] serviceFQNPrefixes) {
List<SearchResult> searchResults = new ArrayList<>();
for (String prefix : serviceFQNPrefixes) {
for (String suffix : _SERVICE_API_SUFFIXES) {
String serviceFQN = prefix + suffix;
SearchResult importResult = findImport(serviceFQN);
if (importResult != null) {
searchResults.add(importResult);
}
String service = serviceFQN.substring(serviceFQN.lastIndexOf('.') + 1, serviceFQN.length());
searchResults.addAll(findMethodInvocations(null, service, "*", null));
searchResults.addAll(findMethodInvocations(service, null, "*", null));
}
}
return searchResults;
}
use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.
the class JavaFileJDT method findMethodDeclaration.
@Override
public List<SearchResult> findMethodDeclaration(String name, String[] params, String returnType) {
List<SearchResult> searchResults = new ArrayList<>();
_ast.accept(new ASTVisitor() {
@Override
public boolean visit(MethodDeclaration node) {
boolean sameParmSize = true;
boolean sameReturnType = true;
if (returnType != null) {
Type type = node.getReturnType2();
if (type != null) {
String returnTypeName = type.resolveBinding().getName();
if (!returnTypeName.equals(returnType)) {
sameReturnType = false;
}
} else {
sameReturnType = false;
}
}
String methodName = node.getName().toString();
List<?> parmsList = node.parameters();
if (name.equals(methodName) && (params.length == parmsList.size())) {
for (int i = 0; i < params.length; i++) {
Object x = parmsList.get(i);
if (!(params[i].trim().equals(x.toString().substring(0, params[i].trim().length())))) {
sameParmSize = false;
break;
}
}
} else {
sameParmSize = false;
}
if (sameParmSize && sameReturnType) {
int startLine = _ast.getLineNumber(node.getName().getStartPosition());
int startOffset = node.getName().getStartPosition();
node.accept(new ASTVisitor() {
@Override
public boolean visit(Block node) {
// SimpleName parent can not be MarkerAnnotation and
// SimpleType
// SingleVariableDeclaration node contains the
// parms's type
int endLine = _ast.getLineNumber(node.getStartPosition());
int endOffset = node.getStartPosition();
searchResults.add(createSearchResult(null, startOffset, endOffset, startLine, endLine, true));
return false;
}
});
}
return false;
}
});
return searchResults;
}
use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.
the class JavaFileJDT method findMethodInvocations.
/**
* find the method invocations for a particular method on a given type or
* expression
*
* @param typeHint
* the type hint to use when matching expressions
* @param expressionValue
* the expression only value (no type hint)
* @param methodName
* the method name
* @return search results
*/
@Override
@SuppressWarnings("unchecked")
public List<SearchResult> findMethodInvocations(String typeHint, String expressionValue, String methodName, String[] methodParamTypes) {
List<SearchResult> searchResults = new ArrayList<>();
_ast.accept(new ASTVisitor() {
@Override
public boolean visit(MethodInvocation node) {
String methodNameValue = node.getName().toString();
Expression expression = node.getExpression();
ITypeBinding type = null;
if (expression != null) {
try {
type = _typeCache.get(expression).orElse(null);
} catch (ExecutionException ee) {
}
}
if (((methodName.equals(methodNameValue)) || ("*".equals(methodName))) && ((typeHint != null && type != null && type.getName().endsWith(typeHint)) || (typeHint == null && expression != null && expression.toString().equals(expressionValue)))) {
boolean argumentsMatch = false;
if (methodParamTypes != null) {
Expression[] argExpressions = ((List<Expression>) node.arguments()).toArray(new Expression[0]);
if (argExpressions.length == methodParamTypes.length) {
// args number matched
boolean possibleMatch = true;
// assume all types will match until we find
// otherwise
boolean typeMatched = true;
boolean typeUnresolved = false;
for (int i = 0; i < argExpressions.length; i++) {
Expression arg = argExpressions[i];
ITypeBinding argType = arg.resolveTypeBinding();
if (argType != null) {
if (_typeMatch(methodParamTypes[i], argType.getQualifiedName())) {
continue;
} else {
// type unmatched
possibleMatch = false;
typeMatched = false;
break;
}
} else {
possibleMatch = false;
// there are two cases :
// typeUnresolved : means that all resolved
// type is matched and there is unsolved
// type , need to set fullMatch false
// typeUnmatched : means that some resolved
// type is unmatched , no need to add
// SearchResult
// do not add searchResults now, just record
// the state and continue
// because there maybe unmatched type later
// which will break this case
typeUnresolved = true;
}
}
if (typeMatched && typeUnresolved) {
int startOffset = expression.getStartPosition();
int startLine = _ast.getLineNumber(startOffset);
int endOffset = node.getStartPosition() + node.getLength();
int endLine = _ast.getLineNumber(endOffset);
// can't resolve the type but args number
// matched , note that the last param is false
searchResults.add(createSearchResult(null, startOffset, endOffset, startLine, endLine, false));
}
if (possibleMatch) {
argumentsMatch = true;
}
}
} else // any method args types is OK without setting
// methodParamTypes
{
argumentsMatch = true;
}
if (argumentsMatch) {
int startOffset = expression.getStartPosition();
int startLine = _ast.getLineNumber(startOffset);
int endOffset = node.getStartPosition() + node.getLength();
int endLine = _ast.getLineNumber(endOffset);
boolean fullMatch = true;
if ((typeHint != null) && (type != null) && type.getName().endsWith(typeHint) && !type.getName().equals(typeHint)) {
fullMatch = false;
}
searchResults.add(createSearchResult(null, startOffset, endOffset, startLine, endLine, fullMatch));
}
}
return true;
}
});
return searchResults;
}
use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.
the class JavaFileJDT method findSuperClass.
@Override
public List<SearchResult> findSuperClass(String superClassName) {
List<SearchResult> searchResults = new ArrayList<>();
_ast.accept(new ASTVisitor() {
@Override
public boolean visit(TypeDeclaration node) {
ITypeBinding superClass = null;
if (node.resolveBinding() != null) {
superClass = node.resolveBinding().getSuperclass();
if (superClass != null) {
String searchContext = superClass.getName();
if (searchContext.equals(superClassName)) {
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;
}
use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.
the class AbstractFileMigrator method analyze.
@Override
public List<Problem> analyze(File file) {
List<Problem> problems = new ArrayList<>();
String fileExtension = new Path(file.getAbsolutePath()).getFileExtension();
List<SearchResult> searchResults = searchFile(file, createFileChecker(type, file, fileExtension));
if (ListUtil.isNotEmpty(searchResults)) {
String sectionHtml = MarkdownParser.getSection("BREAKING_CHANGES.markdown", sectionKey);
if ((sectionHtml != null) && sectionHtml.equals("#legacy")) {
sectionHtml = problemSummary;
}
for (SearchResult searchResult : searchResults) {
if (searchResult != null) {
problems.add(new Problem(problemTitle, problemSummary, fileExtension, problemTickets, file, searchResult.startLine, searchResult.startOffset, searchResult.endOffset, sectionHtml, searchResult.autoCorrectContext, Problem.STATUS_NOT_RESOLVED, Problem.DEFAULT_MARKER_ID, Problem.MARKER_ERROR));
}
}
}
return problems;
}
Aggregations