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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations