我已经开始使用IntelliJ而且我非常喜欢它,但是有一些我想念的功能与Eclipse相比.其中之一是在{},()或[]之间选择块,或者在块的打开/关闭之间跳转.例如,在eclipse中,如果在开始括号后双击,它将选择匹配的右括号中的所有内容,如下所示:
method(item1, method2(itemA), item3,
item4, item5);
Run Code Online (Sandbox Code Playgroud)
如果你在开括号后双击method(|,那么它将在第5项之后选择截止括号的所有内容.我发现当你双击时,IntelliJ会选择方法体,但不会选择括号内的区域而不是类体.
此外,在eclipse中,您可以在块打开/关闭后按Ctrl + Shift + P在块的结束和开始之间跳转.在IntelliJ中(使用eclipse键映射),Ctrl + Shift + P只选择方法的结束大括号'}'.我发现Ctrl + Shift +}的工作方式与我期望的方式相同,但仅适用于花括号{},它还可以选择块之间的所有内容,无论是方法还是类,而不仅仅是移动光标.
我可以说IntelliJ是相当复杂和可定制的,但我无法弄清楚如何从Eclipse复制此功能.在使用此功能时,我们将不胜感激.
提前致谢!克雷格
我正在我的公司创建一个新的dataexchange服务.我们想扩展在我们的core.xsd定义文件中定义的现有对象.这是我需要做的一个例子:
<xs:complexType name="parentType">
<xs:sequence>
<xs:element name="departmentName" type="core:DEPARTMENT_NAME"
minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="childType">
<xs:complexContent>
<xs:extension base="parentType">
<xs:sequence>
<xs:element name="departmentName"
type="core:DEPARTMENT_NAME"
minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)
我觉得这很有道理.我想覆盖父元素并使其成为必需.但是,有效的xml文件就是这样.现在有一个额外的部门名称!?
<childType>
<departmentName>HR</departmentName>
<departmentName>IT</departmentName>
</childType>
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能使XML文件成为:
<childType>
<departmentName>IT</departmentName>
</childType>
Run Code Online (Sandbox Code Playgroud)
谢谢,克雷格
我想精确计算从给定日期开始一周的时间,但我得到的输出提前一小时.
码:
long DURATION = 7 * 24 * 60 * 60 * 1000;
System.out.println(" now: " + new Date(System.currentTimeMillis()));
System.out.println("next week: " + new Date(System.currentTimeMillis() + DURATION));
Run Code Online (Sandbox Code Playgroud)
输出:
now: Wed Sep 16 09:52:36 IRDT 2015
next week: Wed Sep 23 08:52:36 IRST 2015
Run Code Online (Sandbox Code Playgroud)
我怎样才能正确计算出来?
我正在处理 XML 模式,我想将生成的类中的字段名称从“值”更改为“名称”。我希望我的 StackOverflow.xsd 文件如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:StackOverflow="http://stackoverflow.com"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
targetNamespace="http://stackoverflow.com"
attributeFormDefault="unqualified"
elementFormDefault="qualified"
jaxb:version="2.1">
<element name="toolbar">
<complexType>
<sequence>
<element name="action" type="StackOverflow:action" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
<attribute type="string" name="id" use="required"/>
</complexType>
</element>
<simpleType name="actionName">
<restriction base="string">
<enumeration value="Start"/>
<enumeration value="Stop"/>
<enumeration value="Cancel"/>
</restriction>
</simpleType>
<complexType name="action">
<simpleContent>
<extension base="StackOverflow:actionName">
<annotation>
<appinfo>
<!--This ensures that the field in the Action class will be called 'name' rather than 'value'-->
<jaxb:property name="name"/>
</appinfo>
</annotation>
<attribute name="isActive" type="boolean" default="false"/>
</extension>
</simpleContent>
</complexType>
</schema>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我尝试添加 …
我想模拟 os.path.exists 方法的行为,以便在 os.path.exists 报告文件/文件夹不存在时验证我的脚本是否行为正确。
@when("Service starts with input file that does not exist")
def step_impl(context):
"""
:type context: behave.runner.Context
"""
json_file_path = "fake_file_path"
mock_os_path = mock.Mock()
mock_os_path.exists.return_value = False
context.returncode = dicom_send_service.launch(json_file_path)
mock_os_path.exists.assert_called_once_with(json_file_abspath)
Run Code Online (Sandbox Code Playgroud)
如何将模拟注入到我的脚本中?我尝试使用
@mock.patch("mymodule.os.path")
@when("Service starts with input file that does not exist")
def step_impl(context, mock_os_path):
Run Code Online (Sandbox Code Playgroud)
但是,当我运行该方法时,python 返回:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/behave/model.py", line 1456, in run
match.run(runner.context)
File "/usr/local/lib/python2.7/dist-packages/behave/model.py", line 1903, in run
self.func(context, *args, **kwargs)
TypeError: step_impl() takes exactly 2 arguments (1 given)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,step_impl …
我正在使用Eclipse的Find/Replace将一些sql代码格式化为Java字符串.我想将sql查询的每一行放在引号之间,并在末尾添加换行符.
这是我在查找字段中添加的内容:
(.*)
Run Code Online (Sandbox Code Playgroud)
这是我放在替换字段中的内容
\t\t+ "\1\\n"
Run Code Online (Sandbox Code Playgroud)
这是一个简单的例子(我的实际sql查询大约是200行)
SELECT *
FROM User
WHERE User.Id = 1232164
Run Code Online (Sandbox Code Playgroud)
这就是我期望看到的
+ "SELECT *\n"
+ "\n"
+ "FROM User\n"
+ "WHERE User.Id = 1232164\n"
Run Code Online (Sandbox Code Playgroud)
但是,查找在遇到空行时失败,它表示没有更多匹配的结果并终止(或者如果标记了"Wrapped Search"选项,则跳转到文件的顶部)
我也尝试在find regex中使用以下内容
^(.*)
^(.*)$
Run Code Online (Sandbox Code Playgroud)
结果相同
任何人都知道我做错了什么,或者这是Eclipse中的一个错误.
它的价值在于它在我最初编写它时在Emacs中运行良好.
根据http://nose.readthedocs.io/en/latest的所有测试
...应考虑使用Nose2,py.test或仅使用unittest / unittest2。
但是,我似乎无法让Pycharm代替鼻子使用它。我可以配置一些设置,以便它使用鼻子2而不是鼻子进行测试吗?
我有一个比较两个字符串的JUnit测试:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = CDPlayerConfig.class)
public class CDPlayerTest {
@Rule
public final SystemOutRule log = new SystemOutRule().enableLog();
@Autowired
private CompactDisc cd;
@Autowired
private MediaPlayer player;
@Test
public void cdShouldNotBeNull() {
assertNotNull(cd);
}
@Test
public void play() {
player.play();
assertEquals("Playing title Sgt. Pepper's Lonely Hearts Club Band by artist The Beatles\n",
log.getLog());
}
}
Run Code Online (Sandbox Code Playgroud)
我org.junit.ComparisonFailure在第二次测试时遇到异常.但是,IntelliJ显示的内容是相同的.我错过了什么?
编辑:添加回预期字符串末尾的\n.
我有一个带有私有静态方法的final类,它在另一个静态方法中调用
public final class GenerateResponse{
private static Map<String, String> getErrorDetails(JSONObject jsonObject) {
// implementation
}
public static String method1(params...){
Map<String, String> map = getErrorDetails(new JsonObject());
// implementation
}
}
Run Code Online (Sandbox Code Playgroud)
我需要模拟私有静态方法调用getErrorDetails(),但我的测试是调用实际方法.这是我的代码:
@RunWith(PowerMockRunner.class)
@PrepareForTest(GenerateResponse.class)
public class GenerateResponseTest{
@Test
public void testFrameQtcErrorResponse() throws Exception {
Map<String, String> errorDtls = new HashMap<String, String>();
PowerMockito.spy(GenerateResponse.class);
PowerMockito.doReturn(errorDtls).when(GenerateResponse.class, "getErrorDetails", JSONObject.class);
String response = GenerateResponse.method1(params...);
}
Run Code Online (Sandbox Code Playgroud) 我将以下内容设置为bg的编辑文本:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<solid android:color="#A4A4A4" />
</shape>
</item>
<!-- main color -->
<item
android:bottom="1dp"
android:left="0dp"
android:right="0dp">
<shape>
<solid android:color="@android:color/transparent" />
</shape>
</item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)
我的编辑文本嵌套在android.support.design.widget.TextInputLayout:
<android.support.design.widget.TextInputLayout
android:id="@+id/wrapper_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@drawable/bg_edit_txt"
android:hint="@string/reg_email"
android:imeOptions="actionNext"
android:inputType="textEmailAddress"
android:paddingBottom="10dp"
android:paddingEnd="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:textCursorDrawable="@drawable/edit_text_cursor"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
这呈现如下:
所需的行为是仅在底部渲染一条线,该线覆盖此元素的整个宽度.