use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.
the class IOUtils method toString.
@Override
public String toString() {
synchronized (lock) {
FastStringBuffer buffer = new FastStringBuffer();
buffer.append("AdditionalInfo{");
buffer.append("topLevel=[");
entrySetToString(buffer, this.topLevelInitialsToInfo.entrySet());
buffer.append("]\n");
buffer.append("inner=[");
entrySetToString(buffer, this.innerInitialsToInfo.entrySet());
buffer.append("]");
buffer.append("}");
return buffer.toString();
}
}
use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.
the class InfoStrFactory method infoToString.
/**
* @param iInfo
* @return
*/
public static String infoToString(List<IInfo> iInfo) {
HashMap<String, Integer> map = new HashMap<String, Integer>();
FastStringBuffer infos = new FastStringBuffer();
int next = 0;
map.put(null, next);
next++;
for (Iterator<IInfo> it = iInfo.iterator(); it.hasNext(); ) {
IInfo info = it.next();
infos.append("&&");
// 0
infos.append(info.getType());
// 1
next = add(map, infos, next, info.getName());
// 2
next = add(map, infos, next, info.getDeclaringModuleName());
// 3
next = add(map, infos, next, info.getPath());
// 4
next = add(map, infos, next, info.getFile());
infos.append('|');
// 5
infos.append(info.getLine());
infos.append('|');
// 6
infos.append(info.getCol());
}
FastStringBuffer header = new FastStringBuffer("INFOS:", map.size() * 30);
Set<Entry<String, Integer>> entrySet = map.entrySet();
// null is always 0 (not written to header)
header.append(infos);
header.append('\n');
map.remove(null);
for (Entry<String, Integer> entry : entrySet) {
header.append(entry.getKey());
header.append("=");
header.append(entry.getValue());
header.append("\n");
}
return header.toString();
}
use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.
the class MypyAnalysis method afterRunProcess.
@Override
public void afterRunProcess(String output, String errors, IExternalCodeAnalysisStream out) {
boolean resourceIsContainer = resource instanceof IContainer;
IProject project = null;
IFile moduleFile = null;
if (resourceIsContainer) {
project = resource.getProject();
if (project == null) {
Log.log("Expected resource to have project for MyPyAnalysis.");
return;
}
if (!project.isAccessible()) {
Log.log("Expected project to be accessible for MyPyAnalysis.");
return;
}
} else if (resource instanceof IFile) {
moduleFile = (IFile) resource;
} else {
return;
}
output = output.trim();
errors = errors.trim();
Map<ModuleLineCol, MessageInfo> moduleLineColToMessage = new HashMap<>();
if (!output.isEmpty()) {
WriteToStreamHelper.write("Mypy: The stdout of the command line is:\n", out, output);
}
if (!errors.isEmpty()) {
WriteToStreamHelper.write("Mypy: The stderr of the command line is:\n", out, errors);
}
if (output.indexOf("Traceback (most recent call last):") != -1) {
Throwable e = new RuntimeException("Mypy ERROR: \n" + output);
Log.log(e);
return;
}
if (errors.indexOf("Traceback (most recent call last):") != -1) {
Throwable e = new RuntimeException("Mypy ERROR: \n" + errors);
Log.log(e);
return;
}
FastStringBuffer fileNameBuf = new FastStringBuffer();
String loc = this.location != null ? location.toString().toLowerCase() : null;
String res = null;
if (this.resource != null && resource.getFullPath() != null) {
res = this.resource.getFullPath().toString().toLowerCase();
}
Map<IResource, IDocument> resourceToDocCache = new HashMap<>();
for (String outputLine : StringUtils.iterLines(output)) {
if (monitor.isCanceled()) {
return;
}
try {
outputLine = outputLine.trim();
int column = -1;
Matcher m = MYPY_MATCH_PATTERN1.matcher(outputLine);
if (m.matches()) {
column = Integer.parseInt(outputLine.substring(m.start(3), m.end(3))) - 1;
} else {
m = MYPY_MATCH_PATTERN2.matcher(outputLine);
if (m.matches()) {
column = 0;
} else {
m = null;
}
}
if (m != null) {
IDocument document;
if (resourceIsContainer) {
String relativeFilename = outputLine.substring(m.start(1), m.end(1));
try {
moduleFile = project.getFile(new Path(relativeFilename));
} catch (Exception e) {
Log.log(e);
continue;
}
document = resourceToDocCache.get(moduleFile);
if (document == null) {
document = FileUtils.getDocFromResource(moduleFile);
if (document == null) {
continue;
}
resourceToDocCache.put(moduleFile, document);
}
} else {
document = fDocument;
// Must match the current file
fileNameBuf.clear();
fileNameBuf.append(outputLine.substring(m.start(1), m.end(1))).trim().replaceAll('\\', '/');
// Make all comparisons lower-case.
String fileName = fileNameBuf.toString().toLowerCase();
if (loc == null && res == null) {
// Proceed
} else if (loc != null && loc.contains(fileName)) {
// Proceed
} else if (res != null && res.contains(fileName)) {
// Proceed
} else {
// Bail out: it doesn't match the current file.
continue;
}
}
int line = -1;
String messageId = "";
String message = "";
int markerSeverity = -1;
String severityFound = outputLine.substring(m.start(4), m.end(4)).trim();
if (severityFound.equals("error")) {
markerSeverity = IMarker.SEVERITY_ERROR;
}
if (severityFound.equals("warning")) {
markerSeverity = IMarker.SEVERITY_WARNING;
}
if (severityFound.equals("note")) {
markerSeverity = IMarker.SEVERITY_INFO;
}
if (markerSeverity != -1) {
line = Integer.parseInt(outputLine.substring(m.start(2), m.end(2))) - 1;
String lineContents = PySelection.getLine(document, line);
if (CheckAnalysisErrors.isCodeAnalysisErrorHandled(lineContents, null)) {
continue;
}
messageId = "mypy";
message = outputLine.substring(m.start(5), m.end(5)).trim();
IRegion region = null;
try {
region = document.getLineInformation(line);
} catch (Exception e) {
}
if (region != null && document != null) {
ModuleLineCol moduleLineCol = new ModuleLineCol(moduleFile, line, column);
MessageInfo messageInfo = moduleLineColToMessage.get(moduleLineCol);
if (messageInfo == null) {
messageInfo = new MessageInfo(message, markerSeverity, messageId, line, column, document.get(region.getOffset(), region.getLength()), moduleFile, document);
moduleLineColToMessage.put(moduleLineCol, messageInfo);
} else {
messageInfo.addMessageLine(message);
}
}
} else {
continue;
}
} else {
continue;
}
} catch (Exception e) {
Log.log(e);
}
}
for (MessageInfo messageInfo : moduleLineColToMessage.values()) {
addToMarkers(messageInfo.message.toString(), messageInfo.markerSeverity, messageInfo.messageId, messageInfo.line, messageInfo.column, messageInfo.docLineContents, messageInfo.moduleFile, messageInfo.document);
}
}
use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.
the class AbstractPyCreateClassOrMethodOrField method createParametersList.
public static FastStringBuffer createParametersList(List<String> parametersAfterCall) {
FastStringBuffer params = new FastStringBuffer(parametersAfterCall.size() * 10);
AssistAssign assistAssign = new AssistAssign();
for (int i = 0; i < parametersAfterCall.size(); i++) {
String param = parametersAfterCall.get(i).trim();
if (params.length() > 0) {
params.append(", ");
}
String tok = null;
if (param.indexOf('=') != -1) {
List<String> split = StringUtils.split(param, '=');
if (split.size() > 0) {
String part0 = split.get(0).trim();
if (PyStringUtils.isPythonIdentifier(part0)) {
tok = part0;
}
}
}
if (tok == null) {
if (PyStringUtils.isPythonIdentifier(param)) {
tok = param;
} else {
tok = assistAssign.getTokToAssign(param);
if (tok == null || tok.length() == 0) {
tok = "param" + i;
}
}
}
boolean addTag = !(i == 0 && (tok.equals("cls") || tok.equals("self")));
if (addTag) {
params.append("${");
}
params.append(tok);
if (addTag) {
params.append("}");
}
}
return params;
}
use of org.python.pydev.shared_core.string.FastStringBuffer in project Pydev by fabioz.
the class PyCreateClass method createProposal.
/**
* Returns a proposal that can be used to generate the code.
*/
@Override
public ICompletionProposalHandle createProposal(RefactoringInfo refactoringInfo, String actTok, int locationStrategy, List<String> parametersAfterCall) {
PySelection pySelection = refactoringInfo.getPySelection();
ModuleAdapter moduleAdapter = refactoringInfo.getModuleAdapter();
String source;
if (parametersAfterCall == null || parametersAfterCall.size() == 0) {
source = StringUtils.format(baseClassStr, actTok);
} else {
FastStringBuffer params = createParametersList(parametersAfterCall);
source = StringUtils.format(baseClassWithInitStr, actTok, params);
}
Tuple<Integer, String> offsetAndIndent = getLocationOffset(locationStrategy, pySelection, moduleAdapter);
return createProposal(pySelection, source, offsetAndIndent);
}
Aggregations