本文整理汇总了Java中org.python.pydev.plugin.nature.PythonNature类的典型用法代码示例。如果您正苦于以下问题:Java PythonNature类的具体用法?Java PythonNature怎么用?Java PythonNature使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PythonNature类属于org.python.pydev.plugin.nature包,在下文中一共展示了PythonNature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doIt
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
private boolean doIt() {
IProject project = getProject();
if (project != null) {
PythonNature pythonNature = PythonNature.getPythonNature(project);
try {
String projectInterpreter = projectConfig.getProjectInterpreter();
if (projectInterpreter == null) {
return false;
}
pythonNature.setVersion(projectConfig.getSelectedPythonOrJythonAndGrammarVersion(), projectInterpreter);
} catch (CoreException e) {
Log.log(e);
}
}
return true;
}
示例2: onCreateActions
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
@Override
public void onCreateActions(ListResourceBundle resources, final BaseEditor baseEditor, IProgressMonitor monitor) {
PyEdit edit = (PyEdit) baseEditor;
edit.addOfflineActionListener("--internal-test-modules", new Action() {
@Override
public void run() {
List<IPythonNature> allPythonNatures = PythonNature.getAllPythonNatures();
StringBuffer buf = new StringBuffer();
try {
for (IPythonNature nature : allPythonNatures) {
buf.append(checkIntegrity(nature, new NullProgressMonitor(), true));
}
} catch (MisconfigurationException e) {
buf.append(e.getMessage());
}
UIUtils.showString(buf.toString());
}
}, "Used just for testing (do not use).", true);
}
示例3: getAdditionalInfoForProjectAndReferencing
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
/**
* @param project the project we want to get info on
* @return a list of the additional info for the project + referencing projects
* @throws MisconfigurationException
*/
public static List<AbstractAdditionalDependencyInfo> getAdditionalInfoForProjectAndReferencing(IPythonNature nature)
throws MisconfigurationException {
List<AbstractAdditionalDependencyInfo> ret = new ArrayList<AbstractAdditionalDependencyInfo>();
IProject project = nature.getProject();
if (project == null) {
return ret;
}
ret.add(getAdditionalInfoForProject(nature));
Set<IProject> referencingProjects = ProjectModulesManager.getReferencingProjects(project);
for (IProject p : referencingProjects) {
AbstractAdditionalDependencyInfo info2 = getAdditionalInfoForProject(PythonNature.getPythonNature(p));
if (info2 != null) {
ret.add(info2);
}
}
return ret;
}
示例4: doActionOnResource
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
@Override
protected int doActionOnResource(IResource next, IProgressMonitor monitor) {
List<IFile> filesToVisit = new ArrayList<IFile>();
if (next instanceof IContainer) {
List<IFile> l = PyFileListing.getAllIFilesBelow((IContainer) next);
for (Iterator<IFile> iter = l.iterator(); iter.hasNext();) {
IFile element = iter.next();
if (element != null) {
filesToVisit.add(element);
}
}
} else if (next instanceof IFile) {
filesToVisit.add((IFile) next);
}
PythonNature nature = PythonNature.getPythonNature(next);
forceCodeAnalysisOnFiles(nature, monitor, filesToVisit, filesVisited);
return 1;
}
示例5: setUpModule
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
private RefactoringRequest setUpModule(final int line, final int col, String str, String modName,
PythonNature natureToAdd) {
File f = new File(natureToAdd == nature2 ? baseDir2 : baseDir, modName +
".py");
Document doc = new Document(str);
PySelection ps = new PySelection(doc, line, col);
RefactoringRequest request = new RefactoringRequest(null, ps, natureToAdd);
request.moduleName = modName;
final SimpleNode ast = request.getAST();
FileUtils.writeStrToFile(str, f);
addModuleToNature(ast, modName, natureToAdd, f);
return request;
}
示例6: testInterceptAdd
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
/**
* Test if intercepting an add deep within the pythonpath structure will correctly return an object
* from the python model.
*/
public void testInterceptAdd() throws Exception {
PythonNature nature = createNature(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source/python");
project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature);
file = new FileStub(project, new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC
+ "projroot/source/python/pack1/pack2/mod2.py"));
provider = new PythonModelProvider();
HashSet<Object> files = new HashSet<Object>();
files.add(file);
files.add(null);
files.add("string");
provider.interceptAdd(new PipelinedShapeModification(file.getParent(), files));
assertEquals(2, files.size());
for (Object wrappedResource : files) {
assertTrue((wrappedResource instanceof IWrappedResource && ((IWrappedResource) wrappedResource)
.getActualObject() == file) || wrappedResource.equals("string"));
}
}
示例7: createNature
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
/**
* Creates a nature that has the given set as its underlying pythonpath paths. The reference
* is kept inside as a reference, so, changing that reference will affect the pythonpath
* that is set in the nature.
*/
private PythonNature createNature(final HashSet<String> pythonPathSet) {
PythonNature nature = new PythonNature() {
@Override
public IPythonPathNature getPythonPathNature() {
HashSet<String> hashSet = new HashSet<>();
IPath base = Path.fromOSString(TestDependent.TEST_PYSRC_NAVIGATOR_LOC);
for (String s : pythonPathSet) {
if (s.equals("invalid")) {
hashSet.add(s);
} else {
IPath p = Path.fromOSString(s);
Assert.isTrue(base.isPrefixOf(p), "Expected: " + base + " to be prefix of: " + p);
hashSet.add(p.makeRelativeTo(base).toString());
}
}
return new PythonPathNatureStub(hashSet);
}
};
return nature;
}
示例8: getResourcePythonPathMap
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
private static OrderedMap<String, String> getResourcePythonPathMap(
Map<IProject, OrderedMap<String, String>> projectSourcePathMapsCache, IResource resource) {
IProject project = resource.getProject();
OrderedMap<String, String> sourceMap = projectSourcePathMapsCache.get(project);
if (sourceMap == null) {
IPythonPathNature pythonPathNature = PythonNature.getPythonPathNature(project);
// Ignore resources that come from a non-Python project.
if (pythonPathNature == null) {
sourceMap = new OrderedMap<String, String>();
} else {
try {
sourceMap = pythonPathNature
.getProjectSourcePathResolvedToUnresolvedMap();
} catch (CoreException e) {
sourceMap = new OrderedMap<String, String>();
Log.log(e);
}
}
projectSourcePathMapsCache.put(project, sourceMap);
}
return sourceMap;
}
示例9: createNature
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
@Override
protected PythonNature createNature() {
return new PythonNature() {
@Override
public int getInterpreterType() throws CoreException {
return IInterpreterManager.INTERPRETER_TYPE_IRONPYTHON;
}
@Override
public int getGrammarVersion() {
return IPythonNature.LATEST_GRAMMAR_VERSION;
}
@Override
public String resolveModule(File file) throws MisconfigurationException {
if (isInTestFindDefinition) {
return null;
}
return super.resolveModule(file);
}
};
}
示例10: setLaunchAndRelatedInfo
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
public void setLaunchAndRelatedInfo(ILaunch launch) {
this.setLaunch(launch);
if (launch != null) {
IDebugTarget debugTarget = launch.getDebugTarget();
IInterpreterInfo projectInterpreter = null;
if (debugTarget instanceof PyDebugTarget) {
PyDebugTarget pyDebugTarget = (PyDebugTarget) debugTarget;
PythonNature nature = PythonNature.getPythonNature(pyDebugTarget.project);
if (nature != null) {
ArrayList<IPythonNature> natures = new ArrayList<>(1);
natures.add(nature);
this.setNaturesUsed(natures);
try {
projectInterpreter = nature.getProjectInterpreter();
this.setInterpreterInfo(projectInterpreter);
} catch (Throwable e1) {
Log.log(e1);
}
}
}
}
}
示例11: restoreProjectPythonPath2
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
/**
* A method that creates a project that references the project from the 'default' nature
* (and adds itself as a reference in the other project).
*
* @param force whether the creation of the new nature should be forced
* @param path the pythonpath for the new nature
* @param name the name for the project
* @return true if the creation was needed and false if it wasn't
*/
protected boolean restoreProjectPythonPath2(boolean force, String path, String name) {
PythonNature n = checkNewNature(name, force);
if (n != null) {
nature2 = n;
ProjectStub projectFromNature1 = (ProjectStub) nature.getProject();
//create a new project referencing the first one
ProjectStub projectFromNature2 = new ProjectStub(name, path, new IProject[] { projectFromNature1 },
new IProject[0]);
//as we're adding a reference, we also have to set the referencing...
projectFromNature1.referencingProjects = new IProject[] { projectFromNature2 };
setAstManager(path, projectFromNature2, nature2);
return true;
}
return false;
}
示例12: requestCompl
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
/**
* make a request for a code completion
*
* @param the file where we are doing the completion
* @param strDoc the document requesting the code completion
* @param documentOffset the offset of the document (if -1, the doc length is used)
* @param returned the number of completions expected (if -1 not tested)
* @param retCompl a string array specifying the expected completions that should be contained (may only be a
* subset of all completions.
* @return
*
* @throws CoreException
* @throws BadLocationException
* @throws MisconfigurationException
*/
public ICompletionProposal[] requestCompl(File file, String strDoc, int documentOffset, int returned,
String[] retCompl, PythonNature nature) throws Exception, MisconfigurationException {
if (documentOffset == -1) {
documentOffset = strDoc.length();
}
IDocument doc = new Document(strDoc);
CompletionRequest request = new CompletionRequest(file, nature, doc, documentOffset, codeCompletion, false);
List<Object> props = codeCompletion.getCodeCompletionProposals(null, request);
ICompletionProposal[] codeCompletionProposals = PyCodeCompletionUtils.onlyValid(props, request.qualifier,
request.isInCalltip, request.useSubstringMatchInCodeCompletion, null);
PyCodeCompletionUtils.sort(codeCompletionProposals, request.qualifier, null);
for (int i = 0; i < retCompl.length; i++) {
assertContains(retCompl[i], codeCompletionProposals);
}
if (returned > -1) {
StringBuffer buffer = getAvailableAsStr(codeCompletionProposals);
assertEquals("Expected " + returned + " received: " + codeCompletionProposals.length + "\n" + buffer,
returned, codeCompletionProposals.length);
}
return codeCompletionProposals;
}
示例13: createSourceFolder
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
/**
* Creates a source folder and configures the project to use it and the junit.jar
*
* @param addNature if false, no nature will be initially added to the project (if true, the nature will be added)
*/
protected IFolder createSourceFolder(IProgressMonitor monitor, IProject project, boolean addNature, boolean isJython)
throws CoreException {
IFolder sourceFolder = project.getFolder(new Path("src"));
if (!sourceFolder.exists()) {
sourceFolder.create(true, true, monitor);
}
if (addNature) {
String name = project.getName();
if (isJython) {
PythonNature.addNature(project, monitor, PythonNature.JYTHON_VERSION_2_1, "/" + name +
"/src|/" + name
+
"/grinder.jar", null, null, null);
} else {
PythonNature.addNature(project, monitor, PythonNature.PYTHON_VERSION_2_6, "/" + name +
"/src", null,
null, null);
}
}
return sourceFolder;
}
示例14: createNature
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
@Override
protected PythonNature createNature() {
return new PythonNature() {
@Override
public int getInterpreterType() throws CoreException {
return IInterpreterManager.INTERPRETER_TYPE_PYTHON;
}
@Override
public int getGrammarVersion() {
return IPythonNature.LATEST_GRAMMAR_VERSION;
}
@Override
public String resolveModule(File file) throws MisconfigurationException {
if (isInTestFindDefinition) {
return null;
}
return super.resolveModule(file);
}
};
}
示例15: getRunnerConfigRun
import org.python.pydev.plugin.nature.PythonNature; //导入依赖的package包/类
@Override
protected String getRunnerConfigRun(ILaunchConfiguration conf, String mode, ILaunch launch) {
try {
IProject project = PythonRunnerConfig.getProjectFromConfiguration(conf);
PythonNature nature = PythonNature.getPythonNature(project);
if (nature != null) {
switch (nature.getInterpreterType()) {
case IInterpreterManager.INTERPRETER_TYPE_JYTHON:
return PythonRunnerConfig.RUN_JYTHON;
case IInterpreterManager.INTERPRETER_TYPE_PYTHON:
return PythonRunnerConfig.RUN_REGULAR;
case IInterpreterManager.INTERPRETER_TYPE_IRONPYTHON:
return PythonRunnerConfig.RUN_IRONPYTHON;
}
throw new RuntimeException("Unable to get the run configuration for interpreter type: "
+ nature.getInterpreterType());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
throw new RuntimeException("Unable to get the run configuration");
}