use of org.python.pydev.shared_core.image.IImageCache in project Pydev by fabioz.
the class AnalysisImages method getImageForTypeInfo.
public static IImageHandle getImageForTypeInfo(IInfo info) {
switch(info.getType()) {
case IInfo.CLASS_WITH_IMPORT_TYPE:
if (classWithImportType == null) {
synchronized (lock) {
IImageCache imageCache = SharedUiPlugin.getImageCache();
classWithImportType = imageCache.get(UIConstants.CLASS_ICON);
}
}
return classWithImportType;
case IInfo.METHOD_WITH_IMPORT_TYPE:
if (methodWithImportType == null) {
synchronized (lock) {
IImageCache imageCache = SharedUiPlugin.getImageCache();
methodWithImportType = imageCache.get(UIConstants.METHOD_ICON);
}
}
return methodWithImportType;
case IInfo.ATTRIBUTE_WITH_IMPORT_TYPE:
if (attributeWithImportType == null) {
synchronized (lock) {
IImageCache imageCache = SharedUiPlugin.getImageCache();
attributeWithImportType = imageCache.get(UIConstants.PUBLIC_ATTR_ICON);
}
}
return attributeWithImportType;
case IInfo.MOD_IMPORT_TYPE:
if (modImportType == null) {
synchronized (lock) {
IImageCache imageCache = SharedUiPlugin.getImageCache();
modImportType = imageCache.get(UIConstants.FOLDER_PACKAGE_ICON);
}
}
return modImportType;
default:
throw new RuntimeException("Undefined type.");
}
}
use of org.python.pydev.shared_core.image.IImageCache in project Pydev by fabioz.
the class AnalysisImages method getImageForAutoImportTypeInfo.
public static IImageHandle getImageForAutoImportTypeInfo(int infoType) {
switch(infoType) {
case IInfo.CLASS_WITH_IMPORT_TYPE:
if (autoImportClassWithImportType == null) {
synchronized (lock) {
IImageCache imageCache = SharedUiPlugin.getImageCache();
autoImportClassWithImportType = imageCache.getImageDecorated(UIConstants.CLASS_ICON, UIConstants.CTX_INSENSITIVE_DECORATION_ICON, IImageCache.DECORATION_LOCATION_BOTTOM_RIGHT);
}
}
return autoImportClassWithImportType;
case IInfo.METHOD_WITH_IMPORT_TYPE:
if (autoImportMethodWithImportType == null) {
synchronized (lock) {
IImageCache imageCache = SharedUiPlugin.getImageCache();
autoImportMethodWithImportType = imageCache.getImageDecorated(UIConstants.METHOD_ICON, UIConstants.CTX_INSENSITIVE_DECORATION_ICON, IImageCache.DECORATION_LOCATION_BOTTOM_RIGHT);
}
}
return autoImportMethodWithImportType;
case IInfo.ATTRIBUTE_WITH_IMPORT_TYPE:
if (autoImportAttributeWithImportType == null) {
synchronized (lock) {
IImageCache imageCache = SharedUiPlugin.getImageCache();
autoImportAttributeWithImportType = imageCache.getImageDecorated(UIConstants.PUBLIC_ATTR_ICON, UIConstants.CTX_INSENSITIVE_DECORATION_ICON, IImageCache.DECORATION_LOCATION_BOTTOM_RIGHT);
}
}
return autoImportAttributeWithImportType;
case IInfo.MOD_IMPORT_TYPE:
if (autoImportModImportType == null) {
synchronized (lock) {
IImageCache imageCache = SharedUiPlugin.getImageCache();
autoImportModImportType = imageCache.getImageDecorated(UIConstants.FOLDER_PACKAGE_ICON, UIConstants.CTX_INSENSITIVE_DECORATION_ICON, IImageCache.DECORATION_LOCATION_BOTTOM_RIGHT);
}
}
return autoImportModImportType;
case IInfo.USE_PACKAGE_ICON:
IImageCache imageCache = SharedUiPlugin.getImageCache();
return imageCache.get(UIConstants.COMPLETION_PACKAGE_ICON);
default:
throw new RuntimeException("Undefined type.");
}
}
use of org.python.pydev.shared_core.image.IImageCache in project Pydev by fabioz.
the class PackageTab method createPackageControlTab.
/**
* @param exeOrJarOfInterpretersToRestore if the info is changed, the executable should be added to exeOrJarOfInterpretersToRestore.
*/
public void createPackageControlTab(TabFolder tabFolder, Set<String> exeOrJarOfInterpretersToRestore, IInterpreterManager interpreterManager) {
Composite parent;
GridData gd;
TabItem tabItem = new TabItem(tabFolder, SWT.None);
tabItem.setText("Packages");
IImageCache imageCache = SharedUiPlugin.getImageCache();
tabItem.setImage(ImageCache.asImage(imageCache.get(UIConstants.FOLDER_PACKAGE_ICON)));
Composite composite = new Composite(tabFolder, SWT.None);
parent = composite;
GridLayout layout = new GridLayout(2, false);
composite.setLayout(layout);
tree = new Tree(parent, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
tree.setHeaderVisible(true);
createColumn("Library", 300);
createColumn("Version", 100);
createColumn("", 100);
gd = new GridData(GridData.FILL_BOTH);
gd.horizontalSpan = 1;
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
tree.setLayoutData(gd);
// buttons at the side of the tree
Composite control = getButtonBoxPackage(parent, interpreterManager);
gd = new GridData();
gd.verticalAlignment = GridData.BEGINNING;
control.setLayoutData(gd);
tabItem.setControl(composite);
}
use of org.python.pydev.shared_core.image.IImageCache in project Pydev by fabioz.
the class PyCodeCompletion method createOverrideCodeCompletions.
private void createOverrideCodeCompletions(CompletionRequest request, ArrayList<ICompletionProposalHandle> ret, PySelection ps) throws BadLocationException {
IImageCache imageCache = SharedCorePlugin.getImageCache();
IImageHandle imageOverride = imageCache != null ? imageCache.get(UIConstants.METHOD_ICON) : null;
String lineContentsToCursor = ps.getLineContentsToCursor();
LineStartingScope scopeStart = ps.getPreviousLineThatStartsScope(PySelection.CLASS_TOKEN, false, PySelection.getFirstCharPosition(lineContentsToCursor));
String className = null;
if (scopeStart != null) {
className = PySelection.getClassNameInLine(scopeStart.lineStartingScope);
if (className != null && className.length() > 0) {
Tuple<List<String>, Integer> insideParensBaseClasses = ps.getInsideParentesisToks(true, scopeStart.iLineStartingScope);
if (insideParensBaseClasses != null) {
// representation -> token and base class
OrderedMap<String, ImmutableTuple<IToken, String>> map = new OrderedMap<String, ImmutableTuple<IToken, String>>();
for (String baseClass : insideParensBaseClasses.o1) {
try {
ICompletionState state = new CompletionState(-1, -1, null, request.nature, baseClass);
state.setActivationToken(baseClass);
state.setIsInCalltip(false);
IPythonNature pythonNature = request.nature;
checkPythonNature(pythonNature);
ICodeCompletionASTManager astManager = pythonNature.getAstManager();
if (astManager == null) {
// we're probably still loading it.
return;
}
// Ok, looking for a token in globals.
IModule module = request.getModule();
if (module == null) {
continue;
}
TokensList comps = astManager.getCompletionsForModule(module, state, true, true);
for (IterTokenEntry entry : comps) {
IToken iToken = entry.getToken();
String representation = iToken.getRepresentation();
ImmutableTuple<IToken, String> curr = map.get(representation);
if (curr != null && curr.o1 instanceof SourceToken) {
// source tokens are never reset!
continue;
}
int type = iToken.getType();
if (iToken instanceof SourceToken && ((SourceToken) iToken).getAst() instanceof FunctionDef) {
map.put(representation, new ImmutableTuple<IToken, String>(iToken, baseClass));
} else if (type == IToken.TYPE_FUNCTION || type == IToken.TYPE_UNKNOWN || type == IToken.TYPE_BUILTIN) {
map.put(representation, new ImmutableTuple<IToken, String>(iToken, baseClass));
}
}
} catch (Exception e) {
Log.log(e);
}
}
for (ImmutableTuple<IToken, String> tokenAndBaseClass : map.values()) {
FunctionDef functionDef = null;
// No checkings needed for type (we already did that above).
if (tokenAndBaseClass.o1 instanceof SourceToken) {
SourceToken sourceToken = (SourceToken) tokenAndBaseClass.o1;
SimpleNode ast = sourceToken.getAst();
if (ast instanceof FunctionDef) {
functionDef = (FunctionDef) ast;
} else {
functionDef = sourceToken.getAliased().createCopy();
NameTok t = (NameTok) functionDef.name;
t.id = sourceToken.getRepresentation();
}
} else {
// unfortunately, for builtins we usually cannot trust the parameters.
String representation = tokenAndBaseClass.o1.getRepresentation();
PyAstFactory factory = new PyAstFactory(new AdapterPrefs(ps.getEndLineDelim(), request.nature));
functionDef = factory.createFunctionDef(representation);
functionDef.args = factory.createArguments(true);
functionDef.args.vararg = new NameTok("args", NameTok.VarArg);
functionDef.args.kwarg = new NameTok("kwargs", NameTok.KwArg);
if (!representation.equals("__init__")) {
// signal that the return should be added
functionDef.body = new stmtType[] { new Return(null) };
}
}
if (functionDef != null) {
ret.add(CompletionProposalFactory.get().createOverrideMethodCompletionProposal(request, ps, ps.getAbsoluteCursorOffset(), 0, 0, imageOverride, functionDef, tokenAndBaseClass.o2, className));
}
}
}
}
}
}
use of org.python.pydev.shared_core.image.IImageCache in project Pydev by fabioz.
the class PythonCorrectionProcessor method computeQuickAssistProposals.
@Override
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
int offset = invocationContext.getOffset();
PySelection base = edit.createPySelection();
if (!(this.edit instanceof PyEdit) || base == null) {
return new ICompletionProposal[0];
}
PyEdit editor = (PyEdit) this.edit;
List<ICompletionProposalHandle> results = new ArrayList<>();
String sel = PyAction.getLineWithoutComments(base);
List<IAssistProps> assists = new ArrayList<IAssistProps>();
synchronized (PythonCorrectionProcessor.additionalAssists) {
for (IAssistProps prop : additionalAssists.values()) {
assists.add(prop);
}
}
assists.add(new AssistSurroundWith());
assists.add(new AssistImport());
assists.add(new AssistDocString());
assists.add(new AssistAssign());
assists.add(new AssistPercentToFormat());
assists.add(new AssistImportToLocal());
assists.add(new AssistFString());
assists.addAll(ExtensionHelper.getParticipants(ExtensionHelper.PYDEV_CTRL_1));
IImageCache imageCache = SharedUiPlugin.getImageCache();
File editorFile = edit.getEditorFile();
IPythonNature pythonNature = null;
try {
pythonNature = edit.getPythonNature();
} catch (MisconfigurationException e1) {
Log.log(e1);
}
for (IAssistProps assist : assists) {
// Always create a new for each assist, as any given assist may change it.
PySelection ps = new PySelection(base);
try {
if (assist.isValid(ps, sel, editor, offset)) {
try {
results.addAll(assist.getProps(ps, imageCache, editorFile, pythonNature, editor, offset));
} catch (Exception e) {
Log.log(e);
}
}
} catch (Exception e) {
Log.log(e);
}
}
Collections.sort(results, new ProposalsComparator("", new ProposalsComparator.CompareContext(pythonNature)));
try {
// handling spelling... (we only want to show spelling fixes if a spell problem annotation is found at the current location).
// we'll only show some spelling proposal if there's some spelling problem (so, we don't have to check the preferences at this place,
// as no annotations on spelling will be here if the spelling is not enabled).
ICompletionProposal[] spellProps = null;
IAnnotationModel annotationModel = editor.getPySourceViewer().getAnnotationModel();
Iterator<Annotation> it = annotationModel.getAnnotationIterator();
while (it.hasNext()) {
Annotation annotation = it.next();
if (annotation instanceof SpellingAnnotation) {
SpellingAnnotation spellingAnnotation = (SpellingAnnotation) annotation;
SpellingProblem spellingProblem = spellingAnnotation.getSpellingProblem();
int problemOffset = spellingProblem.getOffset();
int problemLen = spellingProblem.getLength();
if (problemOffset <= offset && problemOffset + problemLen >= offset) {
SpellingCorrectionProcessor spellingCorrectionProcessor = new SpellingCorrectionProcessor();
spellProps = spellingCorrectionProcessor.computeQuickAssistProposals(invocationContext);
break;
}
}
}
if (spellProps == null || (spellProps.length == 1 && spellProps[0] instanceof NoCompletionsProposal)) {
// no proposals from the spelling
return results.toArray(new ICompletionProposal[results.size()]);
}
// ok, add the spell problems and return...
ICompletionProposal[] ret = results.toArray(new ICompletionProposal[results.size() + spellProps.length]);
System.arraycopy(spellProps, 0, ret, results.size(), spellProps.length);
return ret;
} catch (Throwable e) {
if (e instanceof ClassNotFoundException || e instanceof LinkageError || e instanceof NoSuchMethodException || e instanceof NoSuchMethodError || e instanceof NoClassDefFoundError) {
// Eclipse 3.2 support
return results.toArray(new ICompletionProposal[results.size()]);
}
throw new RuntimeException(e);
}
}
Aggregations