use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.
the class JavaFileJDTTest method checkStaticMethodInvocation.
@Test
public void checkStaticMethodInvocation() throws Exception {
File file = new File("tests/files/JavaFileChecker.java");
final BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
final Collection<ServiceReference<JavaFile>> sr = context.getServiceReferences(JavaFile.class, "(file.extension=java)");
JavaFile javaFileChecker = context.getService(sr.iterator().next());
javaFileChecker.setFile(file);
List<SearchResult> searchResults = javaFileChecker.findMethodInvocations(null, "String", "valueOf", null);
assertNotNull(searchResults);
SearchResult searchResult = searchResults.get(0);
assertNotNull(searchResult);
if (Util.isWindows()) {
assertEquals(14, searchResult.startLine);
assertEquals(15, searchResult.endLine);
assertEquals(242, searchResult.startOffset);
assertEquals(265, searchResult.endOffset);
} else {
assertEquals(14, searchResult.startLine);
assertEquals(15, searchResult.endLine);
assertEquals(229, searchResult.startOffset);
assertEquals(251, searchResult.endOffset);
}
}
use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.
the class DeprecatedMethodsMigrator method searchFile.
@Override
protected List<SearchResult> searchFile(File file, JavaFile fileChecker) {
List<SearchResult> searchResults = new ArrayList<>();
String[] parameters = null;
JSONArray parameterJSONArray = _tempMethod.getJSONArray("parameters");
if (parameterJSONArray != null) {
parameters = new String[parameterJSONArray.length()];
for (int i = 0; i < parameterJSONArray.length(); i++) {
parameters[i] = parameterJSONArray.getString(i);
}
}
searchResults.addAll(fileChecker.findMethodInvocations(_tempMethod.getString("className"), null, _tempMethod.getString("methodName"), parameters));
searchResults.addAll(fileChecker.findMethodInvocations(null, _tempMethod.getString("className"), _tempMethod.getString("methodName"), parameters));
return searchResults;
}
use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.
the class DeprecatedMethodsMigrator method analyze.
@Override
public List<Problem> analyze(File file) {
List<Problem> problems = new ArrayList<>();
String fileExtension = new Path(file.getAbsolutePath()).getFileExtension();
for (JSONArray deprecatedMethodsArray : _deprecatedMethods) {
for (int j = 0; j < deprecatedMethodsArray.length(); j++) {
_tempMethod = deprecatedMethodsArray.getJSONObject(j);
List<SearchResult> searchResults = searchFile(file, createFileChecker(type, file, fileExtension));
if (searchResults != null) {
for (SearchResult searchResult : searchResults) {
int makerType = Problem.MARKER_ERROR;
if (_tempMethod.getString("deprecatedVersion").equals("7.0")) {
makerType = Problem.MARKER_WARNING;
}
problems.add(new Problem(_tempMethod.getString("javadoc"), _tempMethod.getString("javadoc"), fileExtension, "", file, searchResult.startLine, searchResult.startOffset, searchResult.endOffset, _tempMethod.getString("javadoc"), searchResult.autoCorrectContext, Problem.STATUS_NOT_RESOLVED, Problem.DEFAULT_MARKER_ID, makerType));
}
}
}
}
return problems;
}
use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.
the class JavaFileJDTTest method checkMethodInvocation.
@Test
public void checkMethodInvocation() throws Exception {
File file = new File("tests/files/JavaFileChecker.java");
final BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
final Collection<ServiceReference<JavaFile>> sr = context.getServiceReferences(JavaFile.class, "(file.extension=java)");
JavaFile javaFileChecker = context.getService(sr.iterator().next());
javaFileChecker.setFile(file);
List<SearchResult> searchResults = javaFileChecker.findMethodInvocations("Foo", null, "bar", null);
assertNotNull(searchResults);
assertEquals(4, searchResults.size());
SearchResult searchResult = searchResults.get(0);
assertNotNull(searchResult);
if (Util.isWindows()) {
assertEquals(10, searchResult.startLine);
assertEquals(11, searchResult.endLine);
assertEquals(190, searchResult.startOffset);
assertEquals(210, searchResult.endOffset);
} else {
assertEquals(10, searchResult.startLine);
assertEquals(11, searchResult.endLine);
assertEquals(181, searchResult.startOffset);
assertEquals(200, searchResult.endOffset);
}
}
use of com.liferay.blade.api.SearchResult in project liferay-ide by liferay.
the class JavaFileJDT method findImport.
@Override
public SearchResult findImport(String importName) {
List<SearchResult> searchResults = new ArrayList<>();
_ast.accept(new ASTVisitor() {
@Override
public boolean visit(ImportDeclaration node) {
String searchContext = node.getName().toString();
if (importName.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;
}
Aggregations