Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Bas Leijdekkers
2011-04-06 22:44:45 +02:00
90 changed files with 1164 additions and 428 deletions
@@ -247,6 +247,8 @@ public class JavaCompletionContributor extends CompletionContributor {
if (reference instanceof PsiJavaReference) {
final ElementFilter filter = getReferenceFilter(position);
if (filter != null) {
boolean filterVoid = JavaSmartCompletionContributor.getExpectedTypes(parameters).length > 0 && parameters.getInvocationCount() < 2;
final boolean isSwitchLabel = SWITCH_LABEL.accepts(position);
final PsiFile originalFile = parameters.getOriginalFile();
for (LookupElement element : JavaCompletionUtil.processJavaReference(position,
@@ -268,6 +270,11 @@ public class JavaCompletionContributor extends CompletionContributor {
item.setTailType(TailType.NONE);
}
Object object = element.getObject();
if (filterVoid && object instanceof PsiMethod && PsiType.VOID.equals(((PsiMethod)object).getReturnType())) {
continue;
}
result.addElement(element);
}
}
@@ -13,10 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @author max
*/
package com.intellij.psi.impl.compiled;
import com.intellij.openapi.vfs.VirtualFile;
@@ -26,6 +22,9 @@ import com.intellij.psi.stubs.BinaryFileStubBuilder;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.cls.ClsFormatException;
/**
* @author max
*/
public class ClassFileStubBuilder implements BinaryFileStubBuilder {
public boolean acceptsFile(final VirtualFile file) {
return !isInner(file.getNameWithoutExtension(), new ParentDirectory(file));
@@ -37,8 +36,7 @@ public class ClassFileStubBuilder implements BinaryFileStubBuilder {
private static boolean isInner(final String name, final int from, final Directory directory) {
final int index = name.indexOf('$', from);
return index == -1 ? false
: containsPart(directory, name, index) ? true : isInner(name, index + 1, directory);
return index != -1 && (containsPart(directory, name, index) || isInner(name, index + 1, directory));
}
private static boolean containsPart(Directory directory, String name, int endIndex) {
@@ -55,7 +53,7 @@ public class ClassFileStubBuilder implements BinaryFileStubBuilder {
}
public int getStubVersion() {
return JavaFileElementType.STUB_VERSION;
return JavaFileElementType.STUB_VERSION + 1;
}
@@ -74,7 +72,7 @@ public class ClassFileStubBuilder implements BinaryFileStubBuilder {
public boolean contains(final String name) {
final String fullName = myExtension == null ? name : name + "." + myExtension;
return myDirectory == null ? false : myDirectory.findChild(fullName) != null;
return myDirectory != null && myDirectory.findChild(fullName) != null;
}
}
}
@@ -44,7 +44,7 @@ public class ClsAnnotationImpl extends ClsRepositoryPsiElement<PsiAnnotationStub
super(stub);
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append("@").append(getReferenceElement().getCanonicalText());
((ClsAnnotationParameterListImpl)getParameterList()).appendMirrorText(indentLevel, buffer);
}
@@ -110,7 +110,7 @@ public class ClsAnnotationImpl extends ClsRepositoryPsiElement<PsiAnnotationStub
}
public String getText() {
final StringBuffer buffer = new StringBuffer();
final StringBuilder buffer = new StringBuilder();
appendMirrorText(0, buffer);
return buffer.toString();
}
@@ -39,7 +39,7 @@ public class ClsAnnotationParameterListImpl extends ClsElementImpl implements Ps
}
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
if (myAttributes.length != 0) {
buffer.append("(");
for (int i = 0; i < myAttributes.length; i++) {
@@ -48,7 +48,7 @@ public abstract class ClsAnnotationValueImpl extends ClsElementImpl implements P
protected abstract ClsJavaCodeReferenceElementImpl createReference();
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append("@").append(myReferenceElement.getCanonicalText());
myParameterList.appendMirrorText(indentLevel, buffer);
}
@@ -107,7 +107,7 @@ public abstract class ClsAnnotationValueImpl extends ClsElementImpl implements P
}
public String getText() {
final StringBuffer buffer = new StringBuffer();
final StringBuilder buffer = new StringBuilder();
appendMirrorText(0, buffer);
return buffer.toString();
}
@@ -35,12 +35,12 @@ public class ClsArrayInitializerMemberValueImpl extends ClsElementImpl implement
}
public String getText() {
StringBuffer buffer = new StringBuffer();
final StringBuilder buffer = new StringBuilder();
appendMirrorText(0, buffer);
return buffer.toString();
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append('{');
for (int i = 0; i < myInitializers.length; i++) {
if (i > 0) buffer.append(", ");
@@ -319,7 +319,7 @@ public class ClsClassImpl extends ClsRepositoryPsiElement<PsiClassStub<?>> imple
return getStub().isEnum();
}
public void appendMirrorText(final int indentLevel, @NonNls final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, @NonNls final StringBuilder buffer) {
ClsDocCommentImpl docComment = (ClsDocCommentImpl)getDocComment();
if (docComment != null) {
docComment.appendMirrorText(indentLevel, buffer);
@@ -41,7 +41,7 @@ public class ClsClassObjectAccessExpressionImpl extends ClsElementImpl implement
myTypeElement = new ClsTypeElementImpl(this, canonicalClassText, ClsTypeElementImpl.VARIANCE_NONE);
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
myTypeElement.appendMirrorText(0, buffer);
buffer.append(CLASS_ENDING);
}
@@ -81,7 +81,7 @@ public class ClsClassObjectAccessExpressionImpl extends ClsElementImpl implement
}
public String getText() {
StringBuffer buffer = new StringBuffer();
final StringBuilder buffer = new StringBuilder();
appendMirrorText(0, buffer);
return buffer.toString();
}
@@ -36,7 +36,7 @@ class ClsDocCommentImpl extends ClsElementImpl implements PsiDocComment, JavaTok
myTags = tags;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append("/**");
for (PsiDocTag tag : getTags()) {
goNextLine(indentLevel + 1, buffer);
@@ -41,7 +41,7 @@ class ClsDocTagImpl extends ClsElementImpl implements PsiDocTag {
myNameElement = new NameElement(name);
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append(myNameElement.getText());
}
@@ -129,7 +129,7 @@ class ClsDocTagImpl extends ClsElementImpl implements PsiDocTag {
return PsiElement.EMPTY_ARRAY;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
}
public void setMirror(@NotNull TreeElement element) {
@@ -104,9 +104,9 @@ public abstract class ClsElementImpl extends PsiElementBase implements PsiCompil
protected static final String CAN_NOT_MODIFY_MESSAGE = PsiBundle.message("psi.error.attempt.to.edit.class.file");
public abstract void appendMirrorText(final int indentLevel, final StringBuffer buffer);
public abstract void appendMirrorText(final int indentLevel, final StringBuilder buffer);
protected static void goNextLine(int indentLevel, StringBuffer buffer) {
protected static void goNextLine(int indentLevel, StringBuilder buffer) {
buffer.append('\n');
for (int i = 0; i < indentLevel; i++) buffer.append(' ');
}
@@ -32,7 +32,7 @@ public class ClsEnumConstantImpl extends ClsFieldImpl implements PsiEnumConstant
super(stub);
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
ClsDocCommentImpl docComment = (ClsDocCommentImpl)getDocComment();
if (docComment != null) {
docComment.appendMirrorText(indentLevel, buffer);
@@ -183,7 +183,7 @@ public class ClsFieldImpl extends ClsRepositoryPsiElement<PsiFieldStub> implemen
public void normalizeDeclaration() throws IncorrectOperationException {
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
ClsDocCommentImpl docComment = (ClsDocCommentImpl)getDocComment();
if (docComment != null) {
docComment.appendMirrorText(indentLevel, buffer);
@@ -209,7 +209,7 @@ public class ClsFileImpl extends ClsRepositoryPsiElement<PsiClassHolderFileStub>
return false;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append(PsiBundle.message("psi.decompiled.text.header"));
goNextLine(indentLevel, buffer);
goNextLine(indentLevel, buffer);
@@ -358,7 +358,7 @@ public class ClsFileImpl extends ClsRepositoryPsiElement<PsiClassHolderFileStub>
psiFile = new ClsFileImpl((PsiManagerImpl)manager, new ClassFileViewProvider(manager, file), true);
}
StringBuffer buffer = new StringBuffer();
final StringBuilder buffer = new StringBuilder();
psiFile.appendMirrorText(0, buffer);
return buffer.toString();
}
@@ -50,7 +50,7 @@ class ClsIdentifierImpl extends ClsElementImpl implements PsiIdentifier, PsiJava
return myParent;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer){
public void appendMirrorText(final int indentLevel, final StringBuilder buffer){
buffer.append(getText());
}
@@ -234,7 +234,7 @@ public class ClsJavaCodeReferenceElementImpl extends ClsElementImpl implements P
return false;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append(getCanonicalText());
}
@@ -53,7 +53,7 @@ public class ClsLiteralExpressionImpl extends ClsElementImpl implements PsiLiter
return null;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append(getText());
}
@@ -242,7 +242,7 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement<PsiMethodStub> implem
return MethodSignatureBackedByPsiMethod.create(this, substitutor);
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
appendMethodHeader(buffer, indentLevel);
if (hasModifierProperty(PsiModifier.ABSTRACT) || hasModifierProperty(PsiModifier.NATIVE)) {
@@ -255,7 +255,7 @@ public class ClsMethodImpl extends ClsRepositoryPsiElement<PsiMethodStub> implem
}
}
private void appendMethodHeader(@NonNls StringBuffer buffer, final int indentLevel) {
private void appendMethodHeader(@NonNls StringBuilder buffer, final int indentLevel) {
ClsDocCommentImpl docComment = (ClsDocCommentImpl)getDocComment();
if (docComment != null) {
docComment.appendMirrorText(indentLevel, buffer);
@@ -84,30 +84,33 @@ public class ClsModifierListImpl extends ClsRepositoryPsiElement<PsiModifierList
|| element instanceof PsiField;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
PsiAnnotation[] annotations = getAnnotations();
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
final PsiAnnotation[] annotations = getAnnotations();
final boolean formattingAllowed = isAnnotationFormattingAllowed();
for (PsiAnnotation annotation : annotations) {
((ClsAnnotationImpl)annotation).appendMirrorText(indentLevel, buffer);
if (formattingAllowed) {
goNextLine(indentLevel, buffer);
} else {
}
else {
buffer.append(' ');
}
}
PsiElement parent = getParent();
final PsiElement parent = getParent();
//TODO : filtering & ordering modifiers can go to CodeStyleManager
boolean isInterface = parent instanceof PsiClass && ((PsiClass)parent).isInterface();
boolean isInterfaceMethod = parent instanceof PsiMethod && parent.getParent() instanceof PsiClass && ((PsiClass)parent.getParent()).isInterface();
boolean isInterfaceField = parent instanceof PsiField && parent.getParent() instanceof PsiClass && ((PsiClass)parent.getParent()).isInterface();
boolean isInterfaceClass = parent instanceof PsiClass && parent.getParent() instanceof PsiClass && ((PsiClass)parent.getParent()).isInterface();
if (hasModifierProperty(PsiModifier.PUBLIC)) {
if (!isInterfaceMethod && !isInterfaceField && !isInterfaceClass) {
buffer.append(PsiModifier.PUBLIC);
buffer.append(' ');
}
final boolean isClass = parent instanceof PsiClass;
final boolean isInterface = isClass && ((PsiClass)parent).isInterface();
final boolean isInterfaceClass = isClass && parent.getParent() instanceof PsiClass && ((PsiClass)parent.getParent()).isInterface();
final boolean isMethod = parent instanceof PsiMethod;
final boolean isInterfaceMethod = isMethod && parent.getParent() instanceof PsiClass && ((PsiClass)parent.getParent()).isInterface();
final boolean isField = parent instanceof PsiField;
final boolean isInterfaceField = isField && parent.getParent() instanceof PsiClass && ((PsiClass)parent.getParent()).isInterface();
if (hasModifierProperty(PsiModifier.PUBLIC) && !isInterfaceMethod && !isInterfaceField && !isInterfaceClass) {
buffer.append(PsiModifier.PUBLIC);
buffer.append(' ');
}
if (hasModifierProperty(PsiModifier.PROTECTED)) {
buffer.append(PsiModifier.PROTECTED);
@@ -117,23 +120,17 @@ public class ClsModifierListImpl extends ClsRepositoryPsiElement<PsiModifierList
buffer.append(PsiModifier.PRIVATE);
buffer.append(' ');
}
if (hasModifierProperty(PsiModifier.STATIC)) {
if (!isInterfaceField) {
buffer.append(PsiModifier.STATIC);
buffer.append(' ');
}
if (hasModifierProperty(PsiModifier.STATIC) && !isInterfaceField) {
buffer.append(PsiModifier.STATIC);
buffer.append(' ');
}
if (hasModifierProperty(PsiModifier.ABSTRACT)) {
if (!isInterface && !isInterfaceMethod) {
buffer.append(PsiModifier.ABSTRACT);
buffer.append(' ');
}
if (hasModifierProperty(PsiModifier.ABSTRACT) && !isInterface && !isInterfaceMethod) {
buffer.append(PsiModifier.ABSTRACT);
buffer.append(' ');
}
if (hasModifierProperty(PsiModifier.FINAL)) {
if (!isInterfaceField) {
buffer.append(PsiModifier.FINAL);
buffer.append(' ');
}
if (hasModifierProperty(PsiModifier.FINAL) && !isInterfaceField) {
buffer.append(PsiModifier.FINAL);
buffer.append(' ');
}
if (hasModifierProperty(PsiModifier.NATIVE)) {
buffer.append(PsiModifier.NATIVE);
@@ -151,16 +148,20 @@ public class ClsModifierListImpl extends ClsRepositoryPsiElement<PsiModifierList
buffer.append(PsiModifier.VOLATILE);
buffer.append(' ');
}
if (hasModifierProperty(PsiModifier.STRICTFP)) {
buffer.append(PsiModifier.STRICTFP);
buffer.append(' ');
}
}
public void setMirror(@NotNull TreeElement element) {
setMirrorCheckingType(element, JavaElementType.MODIFIER_LIST);
PsiElement[] mirrorAnnotations = ((PsiModifierList)SourceTreeToPsiMap.treeElementToPsi(element)).getAnnotations();
PsiElement[] mirrorAnnotations = SourceTreeToPsiMap.<PsiModifierList>treeToPsiNotNull(element).getAnnotations();
PsiAnnotation[] annotations = getAnnotations();
LOG.assertTrue(annotations.length == mirrorAnnotations.length);
for (int i = 0; i < annotations.length; i++) {
((ClsElementImpl)annotations[i]).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirrorAnnotations[i]));
((ClsElementImpl)annotations[i]).setMirror(SourceTreeToPsiMap.psiToTreeNotNull(mirrorAnnotations[i]));
}
}
@@ -37,7 +37,7 @@ public class ClsNameValuePairImpl extends ClsElementImpl implements PsiNameValue
myMemberValue = ClsParsingUtil.getMemberValue(value, this);
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
if (myNameIdentifier.getText() != null) {
myNameIdentifier.appendMirrorText(0, buffer);
buffer.append(" = ");
@@ -68,7 +68,7 @@ class ClsPackageStatementImpl extends ClsElementImpl implements PsiPackageStatem
return myPackageName;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append("package ");
buffer.append(getPackageName());
buffer.append(";");
@@ -125,7 +125,7 @@ public class ClsParameterImpl extends ClsRepositoryPsiElement<PsiParameterStub>
public void normalizeDeclaration() throws IncorrectOperationException {
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
PsiAnnotation[] annotations = getModifierList().getAnnotations();
for (PsiAnnotation annotation : annotations) {
((ClsAnnotationImpl)annotation).appendMirrorText(indentLevel, buffer);
@@ -49,7 +49,7 @@ public class ClsParameterListImpl extends ClsRepositoryPsiElement<PsiParameterLi
return getParameters().length;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append('(');
PsiParameter[] parameters = getParameters();
for (int i = 0; i < parameters.length; i++) {
@@ -63,7 +63,7 @@ public class ClsPrefixExpressionImpl extends ClsElementImpl implements PsiPrefix
return "-" + myOperand.getText();
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append(getText());
}
@@ -98,7 +98,7 @@ public class ClsPrefixExpressionImpl extends ClsElementImpl implements PsiPrefix
return ClsPrefixExpressionImpl.this;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append("-");
}
@@ -159,7 +159,7 @@ public class ClsReferenceExpressionImpl extends ClsElementImpl implements PsiRef
return false;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
buffer.append(getText());
}
@@ -62,7 +62,7 @@ public class ClsReferenceListImpl extends ClsRepositoryPsiElement<PsiClassRefere
return getStub().getRole();
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
final String[] names = getStub().getReferencedNames();
if (names.length != 0) {
final Role role = getStub().getRole();
@@ -36,7 +36,7 @@ public class ClsReferenceParametersListImpl extends ClsElementImpl implements Ps
myTypeElements = typeElements;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
if (myTypeElements.length != 0) {
buffer.append('<');
for (int i = 0; i < myTypeElements.length; i++) {
@@ -13,10 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @author max
*/
package com.intellij.psi.impl.compiled;
import com.intellij.lexer.JavaLexer;
@@ -25,6 +21,7 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.CommonClassNames;
import com.intellij.psi.JavaTokenType;
import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.PsiReferenceList;
@@ -51,12 +48,14 @@ import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
/**
* @author max
*/
@SuppressWarnings({"HardCodedStringLiteral"})
public class ClsStubBuilder {
private static final Pattern REGEX_PATTERN = Pattern.compile("(?<=[^\\$])\\${1}(?=[^\\$])");
private ClsStubBuilder() {
}
private ClsStubBuilder() { }
@Nullable
public static PsiFileStub build(final VirtualFile vFile, byte[] bytes) throws ClsFormatException {
@@ -102,7 +101,7 @@ public class ClsStubBuilder {
private final StubElement myParent;
private final int myAccess;
private final VirtualFile myVFile;
private PsiModifierListStub myModlist;
private PsiModifierListStub myModList;
private PsiClassStub myResult;
@NonNls private static final String SYNTHETIC_CLINIT_METHOD = "<clinit>";
@NonNls private static final String SYNTHETIC_INIT_METHOD = "<init>";
@@ -143,7 +142,7 @@ public class ClsStubBuilder {
myLexer = new JavaLexer(languageLevel);
((PsiClassStubImpl)myResult).setLanguageLevel(languageLevel);
myModlist = new PsiModifierListStubImpl(myResult, packModlistFlags(flags));
myModList = new PsiModifierListStubImpl(myResult, packClassFlags(flags));
CharacterIterator signatureIterator = signature != null ? new StringCharacterIterator(signature) : null;
if (signatureIterator != null) {
@@ -177,7 +176,7 @@ public class ClsStubBuilder {
new PsiClassReferenceListStubImpl(JavaStubElementTypes.IMPLEMENTS_LIST, myResult, ArrayUtil.EMPTY_STRING_ARRAY,
PsiReferenceList.Role.IMPLEMENTS_LIST);
} else {
if (convertedSuper != null && !"java.lang.Object".equals(convertedSuper)) {
if (convertedSuper != null && !CommonClassNames.JAVA_LANG_OBJECT.equals(convertedSuper)) {
new PsiClassReferenceListStubImpl(JavaStubElementTypes.EXTENDS_LIST, myResult, new String[]{convertedSuper},
PsiReferenceList.Role.EXTENDS_LIST);
} else {
@@ -226,36 +225,66 @@ public class ClsStubBuilder {
return LanguageLevel.HIGHEST;
}
private static int packModlistFlags(final int access) {
private static int packCommonFlags(final int access) {
int flags = 0;
if ((access & Opcodes.ACC_PRIVATE) != 0) {
flags |= ModifierFlags.PRIVATE_MASK;
} else if ((access & Opcodes.ACC_PROTECTED) != 0) {
}
else if ((access & Opcodes.ACC_PROTECTED) != 0) {
flags |= ModifierFlags.PROTECTED_MASK;
} else if ((access & Opcodes.ACC_PUBLIC) != 0) {
}
else if ((access & Opcodes.ACC_PUBLIC) != 0) {
flags |= ModifierFlags.PUBLIC_MASK;
} else {
}
else {
flags |= ModifierFlags.PACKAGE_LOCAL_MASK;
}
if ((access & Opcodes.ACC_ABSTRACT) != 0) {
flags |= ModifierFlags.ABSTRACT_MASK;
if ((access & Opcodes.ACC_STATIC) != 0) {
flags |= ModifierFlags.STATIC_MASK;
}
if ((access & Opcodes.ACC_FINAL) != 0) {
flags |= ModifierFlags.FINAL_MASK;
}
if ((access & Opcodes.ACC_NATIVE) != 0) {
flags |= ModifierFlags.NATIVE_MASK;
return flags;
}
private static int packClassFlags(final int access) {
int flags = packCommonFlags(access);
if ((access & Opcodes.ACC_ABSTRACT) != 0) {
flags |= ModifierFlags.ABSTRACT_MASK;
}
if ((access & Opcodes.ACC_STATIC) != 0) {
flags |= ModifierFlags.STATIC_MASK;
return flags;
}
private static int packFieldFlags(final int access) {
int flags = packCommonFlags(access);
if ((access & Opcodes.ACC_VOLATILE) != 0) {
flags |= ModifierFlags.VOLATILE_MASK;
}
if ((access & Opcodes.ACC_TRANSIENT) != 0) {
flags |= ModifierFlags.TRANSIENT_MASK;
}
if ((access & Opcodes.ACC_VOLATILE) != 0) {
flags |= ModifierFlags.VOLATILE_MASK;
return flags;
}
private static int packMethodFlags(final int access) {
int flags = packCommonFlags(access);
if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) {
flags |= ModifierFlags.SYNCHRONIZED_MASK;
}
if ((access & Opcodes.ACC_NATIVE) != 0) {
flags |= ModifierFlags.NATIVE_MASK;
}
if ((access & Opcodes.ACC_ABSTRACT) != 0) {
flags |= ModifierFlags.ABSTRACT_MASK;
}
if ((access & Opcodes.ACC_STRICT) != 0) {
flags |= ModifierFlags.STRICTFP_MASK;
@@ -274,7 +303,7 @@ public class ClsStubBuilder {
public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
return new AnnotationTextCollector(desc, new AnnotationResultCallback() {
public void callback(final String text) {
new PsiAnnotationStubImpl(myModlist, text);
new PsiAnnotationStubImpl(myModList, text);
}
});
}
@@ -287,11 +316,11 @@ public class ClsStubBuilder {
if (!isCorrectName(innerName)) return;
if (innerName != null && outerName != null && getClassName(outerName).equals(myResult.getQualifiedName())) {
final String basename = myVFile.getNameWithoutExtension();
final String baseName = myVFile.getNameWithoutExtension();
final VirtualFile dir = myVFile.getParent();
assert dir != null;
final VirtualFile innerFile = dir.findChild(basename + "$" + innerName + ".class");
final VirtualFile innerFile = dir.findChild(baseName + "$" + innerName + ".class");
if (innerFile != null) {
try {
buildClass(innerFile, innerFile.contentsToByteArray(), myResult, access);
@@ -318,8 +347,8 @@ public class ClsStubBuilder {
final byte flags = PsiFieldStubImpl.packFlags((access & Opcodes.ACC_ENUM) != 0, (access & Opcodes.ACC_DEPRECATED) != 0, false);
PsiFieldStub stub = new PsiFieldStubImpl(myResult, name, fieldType(desc, signature), constToString(value), flags);
final PsiModifierListStub modlist = new PsiModifierListStubImpl(stub, packModlistFlags(access));
return new AnnotationCollectingVisitor(stub, modlist);
final PsiModifierListStub modList = new PsiModifierListStubImpl(stub, packFieldFlags(access));
return new AnnotationCollectingVisitor(stub, modList);
}
@NotNull
@@ -346,7 +375,6 @@ public class ClsStubBuilder {
return new TypeInfo(StringRef.fromString(getTypeText(type)), (byte)dim, false, Collections.<PsiAnnotationStub>emptyList()); //todo read annos from .class file
}
@Nullable
public MethodVisitor visitMethod(final int access,
final String name,
@@ -372,7 +400,7 @@ public class ClsStubBuilder {
PsiMethodStubImpl stub = new PsiMethodStubImpl(myResult, StringRef.fromString(canonicalMethodName), flags, null);
final PsiModifierListStub modlist = new PsiModifierListStubImpl(stub, packMethodFlags(access));
final PsiModifierListStub modList = new PsiModifierListStubImpl(stub, packMethodFlags(access));
boolean parsedViaGenericSignature = false;
String returnType;
if (signature == null) {
@@ -392,7 +420,7 @@ public class ClsStubBuilder {
final boolean isNonStaticInnerClassConstructor =
isConstructor && !(myParent instanceof PsiFileStub) && (myModlist.getModifiersMask() & Opcodes.ACC_STATIC) == 0;
isConstructor && !(myParent instanceof PsiFileStub) && (myModList.getModifiersMask() & Opcodes.ACC_STATIC) == 0;
final boolean shouldSkipFirstParamForNonStaticInnerClassConstructor = !parsedViaGenericSignature && isNonStaticInnerClassConstructor;
final PsiParameterListStubImpl parameterList = new PsiParameterListStubImpl(stub);
@@ -420,7 +448,7 @@ public class ClsStubBuilder {
localVarIgnoreCount += 2;
}
final int paramIgnoreCount = isEnumConstructor? 2 : isNonStaticInnerClassConstructor ? 1 : 0;
return new AnnotationParamCollectingVisitor(stub, modlist, localVarIgnoreCount, paramIgnoreCount, paramCount, paramStubs);
return new AnnotationParamCollectingVisitor(stub, modList, localVarIgnoreCount, paramIgnoreCount, paramCount, paramStubs);
}
private static String[] buildThrowsList(String[] exceptions, List<String> throwables, boolean parsedViaGenericSignature) {
@@ -445,15 +473,6 @@ public class ClsStubBuilder {
}
}
private static int packMethodFlags(final int access) {
int commonFlags = packModlistFlags(access);
if ((access & Opcodes.ACC_SYNCHRONIZED) != 0) {
commonFlags |= ModifierFlags.SYNCHRONIZED_MASK;
}
return commonFlags;
}
private static String parseMethodViaDescription(final String desc, final PsiMethodStubImpl stub, final List<String> args) {
final String returnType = getTypeText(Type.getReturnType(desc));
final Type[] argTypes = Type.getArgumentTypes(desc);
@@ -691,10 +710,10 @@ public class ClsStubBuilder {
private static String getTypeText(final Type type) {
final String raw = type.getClassName();
// As the '$' char is a valid java identifier and is actively used by bytecode genarators, the problem is
// As the '$' char is a valid java identifier and is actively used by byte code generators, the problem is
// which occurrences of this char should be replaced and which should not.
// Heuristic: replace only those $ occurrences that are surrounded non-"$" chars
// (most likely generated by javac to separate inner or anonymoys class name)
// (most likely generated by javac to separate inner or anonymous class name)
// Leading and trailing $ chars should be left unchanged.
return raw.contains("$")? REGEX_PATTERN.matcher(raw).replaceAll("\\.") : raw;
}
@@ -84,7 +84,7 @@ public class ClsTypeElementImpl extends ClsElementImpl implements PsiTypeElement
return decorateTypeText(myTypeText);
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer){
public void appendMirrorText(final int indentLevel, final StringBuilder buffer){
buffer.append(decorateTypeText(myTypeText));
}
@@ -266,7 +266,7 @@ public class ClsTypeParameterImpl extends ClsRepositoryPsiElement<PsiTypeParamet
return "PsiTypeParameter";
}
public void appendMirrorText(final int indentLevel, @NonNls final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, @NonNls final StringBuilder buffer) {
buffer.append(getName());
PsiJavaCodeReferenceElement[] bounds = getExtendsList().getReferenceElements();
if (bounds.length > 0) {
@@ -156,7 +156,7 @@ public class ClsTypeParameterReferenceImpl extends ClsElementImpl implements Psi
return false;
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer){
public void appendMirrorText(final int indentLevel, final StringBuilder buffer){
buffer.append(getCanonicalText());
}
@@ -37,7 +37,7 @@ public class ClsTypeParametersListImpl extends ClsRepositoryPsiElement<PsiTypePa
super(stub);
}
public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
public void appendMirrorText(final int indentLevel, final StringBuilder buffer) {
final PsiTypeParameter[] params = getTypeParameters();
if (params.length != 0) {
buffer.append('<');
@@ -15,6 +15,7 @@
*/
package com.intellij.psi.impl.source.tree.injected;
import com.intellij.psi.PsiLanguageInjectionHost;
import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl;
import com.intellij.psi.LiteralTextEscaper;
import com.intellij.openapi.util.TextRange;
@@ -24,10 +25,10 @@ import org.jetbrains.annotations.NotNull;
/**
* @author cdr
*/
public class StringLiteralEscaper extends LiteralTextEscaper<PsiLiteralExpressionImpl> {
public class StringLiteralEscaper<T extends PsiLanguageInjectionHost> extends LiteralTextEscaper<T> {
private int[] outSourceOffsets;
public StringLiteralEscaper(PsiLiteralExpressionImpl host) {
public StringLiteralEscaper(T host) {
super(host);
}
@@ -547,7 +547,7 @@ public class PsiLiteralExpressionImpl
@NotNull
public LiteralTextEscaper<PsiLiteralExpressionImpl> createLiteralTextEscaper() {
return new StringLiteralEscaper(this);
return new StringLiteralEscaper<PsiLiteralExpressionImpl>(this);
}
public void processInjectedPsi(@NotNull InjectedPsiVisitor visitor) {
@@ -23,8 +23,9 @@ public abstract class OutputObjectRegistry {
private int myLastIndex = 0;
private PacketProcessor myMainTransport;
public OutputObjectRegistry(PacketProcessor transport) {
myMainTransport = transport;
protected OutputObjectRegistry(PacketProcessor mainTransport, int lastIndex) {
myLastIndex = lastIndex;
myMainTransport = mainTransport;
}
public String referenceTo(Object test) {
@@ -97,4 +98,12 @@ public abstract class OutputObjectRegistry {
public void forget(Object test) {
myKnownKeys.remove(test);
}
public int getKnownObject(Object description) {
final Object o = myKnownKeys.get(description);
if (o instanceof String) {
return Integer.parseInt((String)o);
}
return 0;
}
}
@@ -24,7 +24,12 @@ public class SegmentedOutputStream extends OutputStream implements PacketProcess
private boolean myStarted = false;
public SegmentedOutputStream(PrintStream transportStream) {
this(transportStream, false);
}
public SegmentedOutputStream(PrintStream transportStream, boolean started) {
myPrintStream = transportStream;
myStarted = started;
try {
flush();
}
@@ -75,4 +80,8 @@ public class SegmentedOutputStream extends OutputStream implements PacketProcess
writeNext(SegmentedStream.STARTUP_MESSAGE);
myStarted = true;
}
public PrintStream getPrintStream() {
return myPrintStream;
}
}
@@ -8,4 +8,6 @@ public class Foo {
});
}
boolean fefefef() {}
}
@@ -0,0 +1,5 @@
public class Foo {
Object foo(){
return noti<caret>
}
}
@@ -0,0 +1,5 @@
public class Foo {
Object foo(){
return notify<caret>
}
}
@@ -1,5 +1,5 @@
class Foo {
boolean zoo(String s) {
return f<caret>
return f<caret>x
}
}
@@ -23,7 +23,7 @@ PsiJavaFileStub []
PsiModifierListStub[mask=0]
PsiRefListStub[THROWS_LIST:]
PsiMethodStub[cons varargs AnnotatedEnumConstructor:void]
PsiModifierListStub[mask=130]
PsiModifierListStub[mask=2]
PsiTypeParameterListStub
PsiParameterListStub
PsiParameterStub[names:java.lang.String...]
@@ -0,0 +1,27 @@
PsiJavaFileStub [pack]
PsiClassStub[name=Modifiers fqn=pack.Modifiers]
PsiModifierListStub[mask=1]
PsiTypeParameterListStub
PsiRefListStub[EXTENDS_LIST:]
PsiRefListStub[IMPLEMENTS_LIST:]
PsiFieldStub[f1:int]
PsiModifierListStub[mask=130]
PsiFieldStub[f2:int]
PsiModifierListStub[mask=66]
PsiMethodStub[cons Modifiers:void]
PsiModifierListStub[mask=1]
PsiTypeParameterListStub
PsiParameterListStub
PsiRefListStub[THROWS_LIST:]
PsiMethodStub[varargs m1:void]
PsiModifierListStub[mask=2]
PsiTypeParameterListStub
PsiParameterListStub
PsiParameterStub[i:int...]
PsiModifierListStub[mask=0]
PsiRefListStub[THROWS_LIST:]
PsiMethodStub[m2:void]
PsiModifierListStub[mask=34]
PsiTypeParameterListStub
PsiParameterListStub
PsiRefListStub[THROWS_LIST:]
@@ -2289,7 +2289,7 @@ PsiJavaFileStub [java.util]
PsiModifierListStub[mask=0]
PsiRefListStub[THROWS_LIST:]
PsiMethodStub[varargs addAll:boolean]
PsiModifierListStub[mask=137]
PsiModifierListStub[mask=9]
PsiTypeParameterListStub
PsiTypeParameter[T]
PsiRefListStub[EXTENDS_BOUNDS_LIST:]
@@ -46,7 +46,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
}
public void testReturnF() throws Throwable {
checkPreferredItems(0, "false", "finalize");
checkPreferredItems(0, "false");
}
public void testPreferDefaultTypeToExpected() throws Throwable {
@@ -84,7 +84,10 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
}
public void testClassStaticMembersInBooleanContext() throws Throwable {
checkPreferredItems(0, "booleanMethod", "voidMethod", "BOOLEAN", "AN_OBJECT", "class");
final String path = getTestName(false) + ".java";
myFixture.configureByFile(path);
myFixture.complete(CompletionType.BASIC, 2);
assertPreferredItems(0, "booleanMethod", "voidMethod", "registerNatives", "BOOLEAN", "AN_OBJECT");
}
public void testDispreferDeclared() throws Throwable {
@@ -5,6 +5,7 @@ import com.intellij.JavaTestUtil
import com.intellij.codeInsight.CodeInsightSettings
import com.intellij.codeInsight.lookup.Lookup
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.codeInsight.lookup.LookupManager
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.fileTypes.StdFileTypes
@@ -14,7 +15,6 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.PsiMethod
import com.intellij.psi.codeStyle.CodeStyleSettings
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.codeInsight.lookup.LookupElementPresentation
public class NormalCompletionTest extends LightFixtureCompletionTestCase {
@Override
@@ -677,7 +677,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
public void testDoubleFalse() throws Throwable {
configureByFile(getTestName(false) + ".java");
assertStringItems("false", "finalize");
assertStringItems("false", "fefefef");
}
public void testSameNamedVariableInNestedClasses() throws Throwable {
@@ -822,6 +822,16 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
public void testMethodParameterAnnotationClass() throws Throwable { doTest(); }
public void testVoidMethodsInNonVoidContext() throws Throwable {
configure()
checkResultByFile(getTestName(false) + ".java")
assertEmpty(myItems)
assertNull(getLookup());
myFixture.complete(CompletionType.BASIC, 2)
checkResult()
}
public void testEnumConstantFromEnumMember() throws Throwable { doTest(); }
public void testPrimitiveMethodParameter() throws Throwable { doTest(); }
@@ -892,9 +902,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
}
public void testClassNameInsideIdentifierInIf() throws Throwable {
configure()
type '\n'
checkResult()
doTest '\n'
}
public void testSuggestMembersOfStaticallyImportedClasses() throws Exception {
@@ -61,15 +61,23 @@ public class ClsBuilderTest extends LightIdeaTestCase {
doTestFromTestData();
}
public void testModifiers() throws Exception {
final String clsFilePath = JavaTestUtil.getJavaTestDataPath() + "/psi/repositoryUse/cls/pack/" + getTestName(false) + ".class";
final VirtualFile clsFile = LocalFileSystem.getInstance().findFileByPath(clsFilePath);
assert clsFile != null : clsFilePath;
doTest(clsFile, getTestName(false) + ".txt");
}
private void doTestFromTestData() throws ClsFormatException, IOException {
final String clsFilePath = JavaTestUtil.getJavaTestDataPath() + "/psi/cls/stubBuilder/" + getTestName(false) + ".class";
VirtualFile clsFile = LocalFileSystem.getInstance().findFileByPath(clsFilePath);
final VirtualFile clsFile = LocalFileSystem.getInstance().findFileByPath(clsFilePath);
assert clsFile != null : clsFilePath;
doTest(clsFile, getTestName(false) + ".txt");
}
private void doTest(final String className) throws IOException, ClsFormatException {
VirtualFile vFile = findFile(className);
doTest(vFile, getTestName(false)+".txt");
final VirtualFile clsFile = findFile(className);
doTest(clsFile, getTestName(false) + ".txt");
}
private static void doTest(VirtualFile vFile, String goldFile) throws ClsFormatException, IOException {
@@ -752,4 +752,20 @@ public class ClsRepositoryUseTest extends PsiTestCase{
assertTrue(substitution instanceof PsiWildcardType);
assertEquals(PsiWildcardType.createUnbounded(myPsiManager), substitution);
}
public void testModifiers() throws Exception {
final PsiClass psiClass = myJavaFacade.findClass("pack.Modifiers", RESOLVE_SCOPE);
assertNotNull(psiClass);
assertEquals("public class Modifiers {\n" +
" private transient int f1;\n" +
" private volatile int f2;\n" +
" \n" +
" public Modifiers() { /* compiled code */ }\n" +
" \n" +
" private void m1(int... i) { /* compiled code */ }\n" +
" \n" +
" private synchronized void m2() { /* compiled code */ }\n" +
"}",
psiClass.getText().trim());
}
}
@@ -569,9 +569,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
}
public void addWatchedPrefix(int startOffset, ElementPattern<String> restartCondition) {
if (isAutopopupCompletion()) {
myRestartingPrefixConditions.add(Pair.create(startOffset, restartCondition));
}
myRestartingPrefixConditions.add(Pair.create(startOffset, restartCondition));
}
public void prefixUpdated() {
@@ -27,6 +27,7 @@ import com.intellij.codeInsight.intention.impl.config.IntentionActionWrapper;
import com.intellij.codeInsight.intention.impl.config.IntentionManagerSettings;
import com.intellij.codeInspection.ex.QuickFixWrapper;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.*;
@@ -47,6 +48,8 @@ import java.util.*;
* @author cdr
*/
class IntentionListStep implements ListPopupStep<IntentionActionWithTextCaching>, SpeedSearchFilter<IntentionActionWithTextCaching> {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.intention.impl.IntentionListStep");
private final Set<IntentionActionWithTextCaching> myCachedIntentions = new THashSet<IntentionActionWithTextCaching>(ACTION_TEXT_AND_CLASS_EQUALS);
private final Set<IntentionActionWithTextCaching> myCachedErrorFixes = new THashSet<IntentionActionWithTextCaching>(ACTION_TEXT_AND_CLASS_EQUALS);
private final Set<IntentionActionWithTextCaching> myCachedInspectionFixes = new THashSet<IntentionActionWithTextCaching>(ACTION_TEXT_AND_CLASS_EQUALS);
@@ -311,7 +314,11 @@ class IntentionListStep implements ListPopupStep<IntentionActionWithTextCaching>
@NotNull
public String getTextFor(final IntentionActionWithTextCaching action) {
return action.getAction().getText();
final String text = action.getAction().getText();
if (text.startsWith("<html>")) {
LOG.info("IntentionAction.getText() returned HTML: action=" + action + " text=" + text);
}
return text;
}
public Icon getIconFor(final IntentionActionWithTextCaching value) {
@@ -15,98 +15,100 @@
*/
package com.intellij.codeInsight.lookup.impl;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.ui.Animator;
import com.google.common.collect.ImmutableMap;
import com.intellij.util.ui.GridBag;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.font.TextAttribute;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* @author peter
*/
public class Advertiser implements Disposable {
private static final int ourScrollingResolution = 15;
public class Advertiser {
private final List<String> myTexts = new CopyOnWriteArrayList<String>();
private final JPanel myComponent = new JPanel() {
private final JPanel myComponent = new JPanel(new GridBagLayout()) {
@Override
public Dimension getPreferredSize() {
List<String> texts = getTexts();
if (texts.isEmpty()) return new Dimension(0, 0);
FontMetrics fm = getFontMetrics(adFont());
int w = 0;
for (String text : texts) {
w = Math.max(w, fm.stringWidth(text));
if (texts.isEmpty()) {
return new Dimension(-1, 0);
}
Insets insets = getBorder().getBorderInsets(this);
return new Dimension(w + insets.left + insets.right, fm.getHeight() + insets.top + insets.bottom);
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int currentItem = myCurrentItem;
List<String> texts = getTexts();
if (texts.isEmpty() || currentItem >= texts.size()) return;
Font font = adFont();
FontMetrics metrics = g.getFontMetrics(font);
g.setFont(font);
int height = getHeight();
int y = (height - metrics.getHeight()) / 2 + metrics.getAscent() - (myScrollingOffset * height / ourScrollingResolution);
int x = getBorder().getBorderInsets(this).left;
if (currentItem >= 0) {
g.drawString(texts.get(currentItem), x, y);
}
if (myScrollingOffset != 0) {
g.drawString(texts.get((currentItem + 1) % texts.size()), x, y + height);
int maxSize = 0;
for (String label : texts) {
maxSize = Math.max(maxSize, createLabel(label).getPreferredSize().width);
}
Dimension sup = super.getPreferredSize();
return new Dimension(maxSize + sup.width - myTextPanel.getPreferredSize().width, sup.height);
}
};
private int myCurrentItem = 0;
private int myScrollingOffset = 0;
private volatile int myCurrentItem = 0;
private JPanel myTextPanel;
private JLabel myNextLabel;
public Advertiser(Disposable parentDisposable) {
Disposer.register(parentDisposable, this);
int interCycleGap = 4000;
Animator animator = new Animator("completion ad", ourScrollingResolution, 800, true, interCycleGap, -1) {
public Advertiser() {
myTextPanel = new JPanel(new BorderLayout());
myNextLabel = new JLabel(">>");
myNextLabel.setFont(adFont().deriveFont(ImmutableMap.<TextAttribute, Object>builder().put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON).build()));
myNextLabel.setForeground(Color.blue);
myNextLabel.addMouseListener(new MouseAdapter() {
@Override
public void paintNow(float frame, float totalFrames, float cycle) {
int adCount = getTexts().size();
if (adCount <= 1) {
myCurrentItem = myScrollingOffset = 0;
myComponent.repaint();
return;
}
myScrollingOffset = ((int)frame + 1) % ourScrollingResolution;
if (myScrollingOffset == 0) {
myCurrentItem = (myCurrentItem + 1) % adCount;
}
myComponent.paintImmediately(0, 0, myComponent.getWidth(), myComponent.getHeight());
public void mouseClicked(MouseEvent e) {
myCurrentItem++;
updateAdvertisements();
}
};
animator.resume();
Disposer.register(this, animator);
});
myNextLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
GridBag gb = new GridBag();
myComponent.add(myTextPanel, gb.next());
myComponent.add(myNextLabel, gb.next());
myComponent.add(new JPanel(), gb.next().fillCellHorizontally().weightx(1));
}
private void updateAdvertisements() {
List<String> texts = getTexts();
myNextLabel.setVisible(texts.size() > 1);
myTextPanel.removeAll();
if (!texts.isEmpty()) {
String text = texts.get(myCurrentItem % texts.size());
myTextPanel.add(createLabel(text));
}
myComponent.revalidate();
myComponent.repaint();
}
private static JLabel createLabel(String text) {
JLabel label = new JLabel(text + " ");
label.setFont(adFont());
return label;
}
private synchronized List<String> getTexts() {
return new ArrayList<String>(myTexts);
}
public void showRandomText() {
int count = myTexts.size();
myCurrentItem = count > 0 ? new Random().nextInt(count) : 0;
updateAdvertisements();
}
public synchronized void clearAdvertisements() {
myTexts.clear();
myCurrentItem = 0;
updateAdvertisements();
}
private static Font adFont() {
@@ -116,18 +118,16 @@ public class Advertiser implements Disposable {
public synchronized void addAdvertisement(@NotNull String text) {
myTexts.add(text);
if (myTexts.size() == 2) {
if (!myComponent.isShowing()) {
myCurrentItem = -1;
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
updateAdvertisements();
}
}
});
}
public JComponent getAdComponent() {
return myComponent;
}
@Override
public void dispose() {
}
}
@@ -338,6 +338,11 @@ public class LookupCellRenderer implements ListCellRenderer {
setFocusBorderAroundIcon(true);
setBorderInsets(new Insets(0, 0, 0, 0));
}
@Override
protected void applyAdditionalHints(Graphics g) {
UISettings.setupAntialiasing(g);
}
}
private class LookupPanel extends JPanel {
@@ -346,7 +351,6 @@ public class LookupCellRenderer implements ListCellRenderer {
}
public void paint(Graphics g){
UISettings.setupAntialiasing(g);
if (!myLookup.isFocused() && myLookup.isCompletion()) {
((Graphics2D)g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f));
}
@@ -159,7 +159,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
getComponent().add(myScrollPane, BorderLayout.NORTH);
myScrollPane.setBorder(null);
myAdComponent = new Advertiser(this);
myAdComponent = new Advertiser();
JComponent adComponent = myAdComponent.getAdComponent();
adComponent.setBorder(new EmptyBorder(0, 1, 1, 2 + relevanceSortIcon.getIconWidth()));
getComponent().add(adComponent, BorderLayout.SOUTH);
@@ -581,7 +581,7 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
public Point calculatePosition(final JComponent component) {
Dimension dim = component.getPreferredSize();
int lookupStart = getLookupStart();
if (lookupStart < 0 || lookupStart >= myEditor.getDocument().getTextLength()) {
if (lookupStart < 0 || lookupStart > myEditor.getDocument().getTextLength()) {
LOG.error(lookupStart + "; offset=" + myEditor.getCaretModel().getOffset() + "; element=" +
getPsiElement());
}
@@ -706,12 +706,16 @@ public class LookupImpl extends LightweightHint implements Lookup, Disposable {
if (ApplicationManager.getApplication().isUnitTestMode()) return;
myAdComponent.showRandomText();
getComponent().setBorder(null);
updateScrollbarVisibility();
Point p = calculatePosition(getComponent());
HintManagerImpl.getInstanceImpl().showEditorHint(this, myEditor, p, HintManagerImpl.HIDE_BY_ESCAPE | HintManagerImpl.UPDATE_BY_SCROLLING, 0, false,
HintManagerImpl.createHintHint(myEditor, p, this, HintManager.UNDER).setAwtTooltip(false));
LOG.assertTrue(isVisible(), "!visible, disposed=" + myDisposed);
LOG.assertTrue(myList.isShowing(), "!showing, disposed=" + myDisposed);
final JLayeredPane layeredPane = getComponent().getRootPane().getLayeredPane();
layeredPane.add(myIconPanel, 42, 0);
@@ -46,6 +46,6 @@ public class RenameToIgnoredDirectoryFileInputValidator implements RenameInputVa
@Override
public boolean isInputValid(String newName, PsiElement element, ProcessingContext context) {
return newName != null && newName.length() > 0;
return newName != null && newName.length() > 0 && newName.indexOf('\\') < 0 && newName.indexOf('/') < 0;
}
}
@@ -405,8 +405,8 @@ public class SimpleColoredComponent extends JComponent implements Accessible {
final List<Object[]> searchMatches = new ArrayList<Object[]>();
// Paint text
applyAdditionalHints(g);
UIUtil.applyRenderingHints(g);
applyAdditionalHints(g);
for (int i = 0; i < myFragments.size(); i++) {
final SimpleTextAttributes attributes = myAttributes.get(i);
Font font = g.getFont();
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.keymap.impl;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
@@ -187,6 +188,7 @@ public final class IdeMouseEventDispatcher {
}
private static boolean doHorizontalScrolling(Component c, MouseWheelEvent me) {
FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.horizontal.scrolling");
final JScrollBar scrollBar = findHorizontalScrollBar(c);
if (scrollBar != null) {
scrollBar.setValue(scrollBar.getValue() + getScrollAmount(c, me, scrollBar));
@@ -77,6 +77,7 @@ refactoring.rename=Rename
refactoring.copyClass=Copy Class refactoring
ui.tree.speedsearch=Speed search in trees
ui.scheme.quickswitch=Quick switch scheme
ui.horizontal.scrolling=Horizontal Scrolling
# suppress inspection "UnusedProperty"
ui.recentchanges=Recent changes
@@ -0,0 +1,9 @@
<html>
<body style="font-family: Verdana; font-size: 13;" LEFTMARGIN="25" TOPMARGIN="25">
<table cellpadding="15" width="98%" border="0">
<tr>
<td>Enable Horizontal Scrolling with mouse wheel by holding <font style="font-family: Verdana; font-weight:bold; size=4; color=#993300;">SHIFT</font> button</td>
</tr>
</table>
</body>
</html>
@@ -21,6 +21,7 @@ import com.intellij.util.concurrency.JBReentrantReadWriteLock;
import com.intellij.util.concurrency.LockFactory;
public abstract class FieldCache<T, Owner,AccessorParameter,Parameter> {
private static final RecursionGuard ourGuard = RecursionManager.createGuard("fieldCache");
private final JBLock r;
private final JBLock w;
@@ -46,8 +47,11 @@ public abstract class FieldCache<T, Owner,AccessorParameter,Parameter> {
try {
result = getValue(owner, a);
if (result == null) {
RecursionGuard.StackStamp stamp = ourGuard.markStack();
result = compute(owner, p);
putValue(result, owner, a);
if (stamp.mayCacheNow()) {
putValue(result, owner, a);
}
}
}
finally {
@@ -19,6 +19,7 @@ package com.intellij.openapi.util;
import org.jetbrains.annotations.NonNls;
public abstract class UserDataCache<T, Owner extends UserDataHolder, Param> extends FieldCache<T, Owner, Key<T>, Param> {
private static final RecursionGuard ourGuard = RecursionManager.createGuard("userDataCache");
private final Key<T> myKey;
protected UserDataCache() {
@@ -49,8 +50,11 @@ public abstract class UserDataCache<T, Owner extends UserDataHolder, Param> exte
public T get(Key<T> a, Owner owner, Param p) {
T value = owner.getUserData(a);
if (value == null) {
RecursionGuard.StackStamp stamp = ourGuard.markStack();
value = compute(owner, p);
value = ((UserDataHolderEx)owner).putUserDataIfAbsent(a, value);
if (stamp.mayCacheNow()) {
value = ((UserDataHolderEx)owner).putUserDataIfAbsent(a, value);
}
}
return value;
}
@@ -45,6 +45,7 @@ import com.intellij.xdebugger.impl.XDebugSessionImpl;
import com.intellij.xdebugger.impl.XSourcePositionImpl;
import com.intellij.xdebugger.impl.actions.ViewBreakpointsAction;
import com.intellij.xdebugger.ui.DebuggerColors;
import com.intellij.xdebugger.ui.DebuggerIcons;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -124,6 +125,8 @@ public class XLineBreakpointImpl<P extends XBreakpointProperties> extends XBreak
@NotNull
private Icon calculateIcon() {
if (!isEnabled()) {
// disabled icon takes precedence to other to visually distinguish it and provide feedback then it is enabled/disabled
// (e.g. in case of mute-mode we would like to differentiate muted but enabled breakpoints from simply disabled ones)
return myType.getDisabledIcon();
}
@@ -135,7 +138,7 @@ public class XLineBreakpointImpl<P extends XBreakpointProperties> extends XBreak
}
else {
if (session.areBreakpointsMuted()) {
return myType.getDisabledIcon();
return DebuggerIcons.MUTED_BREAKPOINT_ICON;
}
if (session.isDisabledSlaveBreakpoint(this)) {
return myType.getDisabledDependentIcon();
@@ -1871,3 +1871,7 @@ try.finally.can.be.try.with.resources.problem.descriptor=<code>#ref</code> can u
try.finally.can.be.try.with.resources.quickfix=Replace with 'try' with resources
array.comparison.display.name=Array comparison using '==', instead of 'Arrays.equals()'
array.comparison.problem.descriptor=Array objects are compared using <code>#ref</code>, not 'Arrays.equals()' #loc
array.hash.code.display.name='hashCode()' called on array
array.hash.code.problem.descriptor=<code>#ref()</code> called on array should probably be 'Arrays.hashCode()' #loc
arrays.deep.hash.code.quickfix=Replace with 'Arrays.deepHashCode()'
arrays.hash.code.quickfix=Replace with 'Arrays.hashCode()'
@@ -518,6 +518,7 @@ public class InspectionGadgetsPlugin implements ApplicationComponent,
m_inspectionClasses.add(ArchaicSystemPropertyAccessInspection.class);
m_inspectionClasses.add(ArrayEqualityInspection.class);
m_inspectionClasses.add(ArrayEqualsInspection.class);
m_inspectionClasses.add(ArrayHashCodeInspection.class);
m_inspectionClasses.add(AssertWithSideEffectsInspection.class);
m_inspectionClasses.add(ConstantAssertConditionInspection.class);
m_inspectionClasses.add(CastConflictsWithInstanceofInspection.class);
@@ -19,6 +19,7 @@ import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.HardcodedMethodConstants;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
@@ -120,14 +121,15 @@ public class ArrayEqualsInspection extends BaseInspection {
@Override public void visitMethodCallExpression(
@NotNull PsiMethodCallExpression expression){
super.visitMethodCallExpression(expression);
if(!MethodCallUtils.isEqualsCall(expression)){
return;
}
final PsiReferenceExpression methodExpression =
expression.getMethodExpression();
final String methodName = methodExpression.getReferenceName();
if (!HardcodedMethodConstants.EQUALS.equals(methodName)) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length == 0) {
if (arguments.length != 1) {
return;
}
final PsiExpression argument = arguments[0];
@@ -150,4 +152,4 @@ public class ArrayEqualsInspection extends BaseInspection {
registerMethodCallError(expression, qualifierType);
}
}
}
}
@@ -0,0 +1,145 @@
/*
* Copyright 2011 Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.siyeh.ig.bugs;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.util.IncorrectOperationException;
import com.siyeh.HardcodedMethodConstants;
import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.InspectionGadgetsFix;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
public class ArrayHashCodeInspection extends BaseInspection {
@Nls
@NotNull
@Override
public String getDisplayName() {
return InspectionGadgetsBundle.message("array.hash.code.display.name");
}
@NotNull
@Override
protected String buildErrorString(Object... infos) {
return InspectionGadgetsBundle.message(
"array.hash.code.problem.descriptor");
}
@Override
public boolean isEnabledByDefault() {
return true;
}
@Override
protected InspectionGadgetsFix buildFix(Object... infos) {
final PsiArrayType type = (PsiArrayType) infos[0];
if (type.getComponentType() instanceof PsiArrayType) {
return new ArrayHashCodeFix(true);
}
return new ArrayHashCodeFix(false);
}
private static class ArrayHashCodeFix extends InspectionGadgetsFix {
private final boolean deepHashCode;
public ArrayHashCodeFix(boolean deepHashCode) {
this.deepHashCode = deepHashCode;
}
@NotNull
public String getName() {
if (deepHashCode) {
return InspectionGadgetsBundle.message(
"arrays.deep.hash.code.quickfix");
} else {
return InspectionGadgetsBundle.message(
"arrays.hash.code.quickfix");
}
}
@Override
protected void doFix(Project project, ProblemDescriptor descriptor)
throws IncorrectOperationException {
final PsiElement element = descriptor.getPsiElement();
final PsiElement parent = element.getParent();
final PsiElement grandParent = parent.getParent();
if (!(grandParent instanceof PsiMethodCallExpression)) {
return;
}
final PsiMethodCallExpression methodCallExpression =
(PsiMethodCallExpression) grandParent;
final PsiReferenceExpression methodExpression =
methodCallExpression.getMethodExpression();
final PsiExpression qualifier =
methodExpression.getQualifierExpression();
if (qualifier == null) {
return;
}
@NonNls final StringBuilder newExpressionText = new StringBuilder();
if (deepHashCode) {
newExpressionText.append("java.util.Arrays.deepHashCode(");
} else {
newExpressionText.append("java.util.Arrays.hashCode(");
}
newExpressionText.append(qualifier.getText());
newExpressionText.append(')');
replaceExpressionAndShorten(methodCallExpression,
newExpressionText.toString());
}
}
@Override
public BaseInspectionVisitor buildVisitor() {
return new ArrayHashCodeVisitor();
}
private static class ArrayHashCodeVisitor extends BaseInspectionVisitor {
@Override
public void visitMethodCallExpression(
PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
final PsiReferenceExpression methodExpression =
expression.getMethodExpression();
final String methodName = methodExpression.getReferenceName();
if (!HardcodedMethodConstants.HASH_CODE.equals(methodName)) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
final PsiExpression[] arguments = argumentList.getExpressions();
if (arguments.length != 0) {
return;
}
final PsiExpression qualifier =
methodExpression.getQualifierExpression();
if (qualifier == null) {
return;
}
final PsiType type = qualifier.getType();
if (!(type instanceof PsiArrayType)) {
return;
}
registerMethodCallError(expression, type);
}
}
}
@@ -1,11 +1,12 @@
<html>
<body>
This inspection reports <b>.equals()</b> being called
to compare two arrays. Calling <b>.equals()</b> on an array
This inspection reports <b>equals()</b> being called
to compare two arrays. Calling <b>equals()</b> on an array
compares identity and is equivalent to using <b>==</b>. Use
<b>==</b> to see if two references reference the same array and
<b>Arrays.equals()</b> to compare the contents of two arrays.
<b>Arrays.equals()</b> to compare the contents of two arrays
or <b>Arrays.deepEquals()</b> to compare the content of two
multi-dimensional arrays.
<p>
<small>Powered by InspectionGadgets</small>
</body>
</html>
</html>
@@ -0,0 +1,11 @@
<html>
<body>
This inspection reports <b>hashCode()</b> being called
on an array. To get the same hash code for two arrays
with identical contents call <b>Arrays.hashCode()</b>.
Use <b>Arrays.deepHashCode()</b> to calculate the hash
code of a multi-dimensional array.
<p>
<small>New in 10.5, Powered by InspectionGadgets</small>
</body>
</html>
@@ -16,32 +16,14 @@
package org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.literals;
import com.intellij.psi.LiteralTextEscaper;
import com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.ProperTextRange;
import org.jetbrains.annotations.NotNull;
import com.intellij.psi.impl.source.tree.injected.StringLiteralEscaper;
public class GrLiteralEscaper extends LiteralTextEscaper<GrLiteralImpl> {
private int[] outSourceOffsets;
public class GrLiteralEscaper extends StringLiteralEscaper<GrLiteralImpl> {
public GrLiteralEscaper(final GrLiteralImpl literal) {
super(literal);
}
public boolean decode(@NotNull final TextRange rangeInsideHost, @NotNull StringBuilder outChars) {
ProperTextRange.assertProperRange(rangeInsideHost);
String subText = rangeInsideHost.substring(myHost.getText());
outSourceOffsets = new int[subText.length() + 1];
return PsiLiteralExpressionImpl.parseStringCharacters(subText, outChars, outSourceOffsets);
}
public int getOffsetInHost(int offsetInDecoded, @NotNull final TextRange rangeInsideHost) {
int result = offsetInDecoded < outSourceOffsets.length ? outSourceOffsets[offsetInDecoded] : -1;
if (result == -1) return -1;
return (result <= rangeInsideHost.getLength() ? result : rangeInsideHost.getLength()) + rangeInsideHost.getStartOffset();
}
public boolean isOneLine() {
final Object value = myHost.getValue();
return value instanceof String && ((String)value).indexOf('\n') < 0;
@@ -322,6 +322,14 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
}
}
public void setForkMode(String forkMode) {
myData.FORK_MODE = forkMode;
}
public String getForkMode() {
return myData.FORK_MODE;
}
public static class Data implements Cloneable {
public String PACKAGE_NAME;
public String MAIN_CLASS_NAME;
@@ -330,6 +338,7 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
public String VM_PARAMETERS;
public String PARAMETERS;
public String WORKING_DIRECTORY;
public String FORK_MODE;
private Set<String> myPattern = new LinkedHashSet<String>();
//iws/ipr compatibility
@@ -349,7 +358,8 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
Comparing.equal(getWorkingDirectory(), second.getWorkingDirectory()) &&
Comparing.equal(VM_PARAMETERS, second.VM_PARAMETERS) &&
Comparing.equal(PARAMETERS, second.PARAMETERS) &&
Comparing.equal(myPattern, second.myPattern);
Comparing.equal(myPattern, second.myPattern) &&
Comparing.equal(FORK_MODE, second.FORK_MODE) ;
}
public int hashCode() {
@@ -360,7 +370,8 @@ public class JUnitConfiguration extends ModuleBasedConfiguration<JavaRunConfigur
Comparing.hashcode(getWorkingDirectory()) ^
Comparing.hashcode(VM_PARAMETERS) ^
Comparing.hashcode(PARAMETERS) ^
Comparing.hashcode(myPattern);
Comparing.hashcode(myPattern) ^
Comparing.hashcode(FORK_MODE);
}
public TestSearchScope getScope() {
@@ -44,13 +44,17 @@ import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JavaSdk;
import com.intellij.openapi.projectRoots.JavaSdkType;
import com.intellij.openapi.projectRoots.ex.JavaSdkUtil;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Getter;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.CharsetToolkit;
import com.intellij.openapi.vfs.encoding.EncodingManager;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
@@ -61,12 +65,12 @@ import com.intellij.rt.execution.junit.JUnitStarter;
import com.intellij.util.Function;
import com.intellij.util.IJSwingUtilities;
import com.intellij.util.PathUtil;
import com.intellij.util.lang.UrlClassLoader;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.*;
public abstract class TestObject implements JavaCommandLine {
@@ -349,7 +353,40 @@ public abstract class TestObject implements JavaCommandLine {
}
protected JUnitProcessHandler createHandler() throws ExecutionException {
return JUnitProcessHandler.runJava(getJavaParameters(), myProject);
appendForkInfo();
return JUnitProcessHandler.runCommandLine(CommandLineBuilder.createFromJavaParameters(myJavaParameters, myProject, true));
}
private void appendForkInfo() throws ExecutionException {
final String forkMode = myConfiguration.getForkMode();
if (Comparing.strEqual(forkMode, "none")) return;
File tempFile = null;
try {
tempFile = FileUtil.createTempFile("command.line", "");
myJavaParameters.getProgramParametersList().add("@@@" + tempFile.getAbsolutePath());
}
catch (IOException e) {
LOG.error(e);
}
final JavaParameters javaParameters = getJavaParameters();
try {
final PrintWriter writer = new PrintWriter(tempFile, "UTF-8");
try {
writer.print(GeneralCommandLine
.quoteParameter(((JavaSdkType)javaParameters.getJdk().getSdkType()).getVMExecutablePath(javaParameters.getJdk())) + " ");
writer.print(javaParameters.getVMParametersList().getParametersString() + " ");
writer.print("-classpath ");
writer.print(GeneralCommandLine.quoteParameter(javaParameters.getClassPath().getPathsString()));
writer.print("\n" + forkMode);
}
finally {
writer.close();
}
tempFile.deleteOnExit();
}
catch (Exception e) {
LOG.error(e);
}
}
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.intellij.execution.junit2.configuration.JUnitConfigurable">
<grid id="ece1c" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="5">
<grid id="ece1c" binding="myWholePanel" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="5">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="28" y="28" width="660" height="531"/>
@@ -69,7 +69,7 @@
<grid id="1c9c1" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="1" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@@ -84,15 +84,6 @@
<properties/>
<border type="etched" title-resource-bundle="messages/ExecutionBundle" title-key="junit.configuration.test.border"/>
<children>
<component id="89ba4" class="com.intellij.openapi.ui.LabeledComponent" binding="myClass">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.openapi.ui.TextFieldWithBrowseButton"/>
<text resource-bundle="messages/ExecutionBundle" key="junit.configuration.class.label"/>
</properties>
</component>
<component id="b109" class="com.intellij.openapi.ui.LabeledComponent" binding="myMethod">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
@@ -181,6 +172,15 @@
<visible value="true"/>
</properties>
</component>
<component id="89ba4" class="com.intellij.openapi.ui.LabeledComponent" binding="myClass">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<componentClass value="com.intellij.openapi.ui.TextFieldWithBrowseButton"/>
<text resource-bundle="messages/ExecutionBundle" key="junit.configuration.class.label"/>
</properties>
</component>
</children>
</grid>
</children>
@@ -193,7 +193,7 @@
<grid id="92997" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="10">
<margin top="5" left="0" bottom="5" right="0"/>
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@@ -223,6 +223,35 @@
</component>
</children>
</grid>
<grid id="ca987" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="bafba" class="com.intellij.ui.components.JBLabel">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&amp;Fork mode:"/>
</properties>
</component>
<component id="73c49" class="javax.swing.JComboBox" binding="myForkCb" default-binding="true">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<hspacer id="82483">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</hspacer>
</children>
</grid>
</children>
</grid>
</form>
@@ -45,6 +45,7 @@ import com.intellij.psi.PsiPackage;
import com.intellij.psi.search.SearchScope;
import com.intellij.util.Icons;
import gnu.trove.TIntArrayList;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -92,6 +93,11 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> {
private final BrowseModuleValueActionListener[] myBrowsers;
private AlternativeJREPanel myAlternativeJREPanel;
private JComboBox myForkCb;
@NonNls private static final String NONE = "none";
@NonNls private static final String METHOD = "method";
private static final String[] FORK_MODE_ALL = {NONE, METHOD, "class"};
private static final String[] FORK_MODE = {NONE, METHOD};
public JUnitConfigurable(final Project project) {
myModel = new JUnitConfigurationModel(project);
@@ -142,8 +148,8 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> {
myModel.setType(i);
break;
}
changePanel();
}
changePanel();
}
});
myModel.setType(JUnitConfigurationModel.CLASS);
@@ -175,6 +181,7 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> {
configuration.setAlternativeJrePathEnabled(myAlternativeJREPanel.isPathEnabled());
myCommonJavaParameters.applyTo(configuration);
configuration.setForkMode((String)myForkCb.getSelectedItem());
}
public void resetEditorFrom(final JUnitConfiguration configuration) {
@@ -192,7 +199,7 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> {
myWholeProjectScope.setSelected(true);
}
myAlternativeJREPanel.init(configuration.getAlternativeJrePath(), configuration.isAlternativeJrePathEnabled());
myForkCb.setSelectedItem(configuration.getForkMode());
}
private void changePanel () {
@@ -201,23 +208,34 @@ public class JUnitConfigurable extends SettingsEditor<JUnitConfiguration> {
myPattern.setVisible(false);
myClass.setVisible(false);
myMethod.setVisible(false);
myForkCb.setEnabled(true);
myForkCb.setModel(new DefaultComboBoxModel(FORK_MODE_ALL));
myForkCb.setSelectedItem(NONE);
}
else if (myClassButton.isSelected()){
myPackagePanel.setVisible(false);
myPattern.setVisible(false);
myClass.setVisible(true);
myMethod.setVisible(false);
myForkCb.setEnabled(true);
myForkCb.setModel(new DefaultComboBoxModel(FORK_MODE));
myForkCb.setSelectedItem(NONE);
}
else if (myTestMethodButton.isSelected()){
myPackagePanel.setVisible(false);
myPattern.setVisible(false);
myClass.setVisible(true);
myMethod.setVisible(true);
myForkCb.setEnabled(false);
myForkCb.setSelectedItem(NONE);
} else {
myPackagePanel.setVisible(false);
myPattern.setVisible(true);
myClass.setVisible(false);
myMethod.setVisible(false);
myForkCb.setEnabled(true);
myForkCb.setModel(new DefaultComboBoxModel(FORK_MODE_ALL));
myForkCb.setSelectedItem(NONE);
}
}
@@ -56,11 +56,12 @@ public class JUnitConfigurationModel {
myProject = project;
}
public void setType(int type) {
if (type == myType) return;
public boolean setType(int type) {
if (type == myType) return false;
if (type < 0 || type >= ourTestObjects.size()) type = CLASS;
myType = type;
fireTypeChanged(type);
return true;
}
private void fireTypeChanged(final int newType) {
@@ -15,28 +15,37 @@
*/
package com.intellij.junit3;
import com.intellij.rt.execution.junit.DeafStream;
import com.intellij.rt.execution.junit.IdeaTestRunner;
import com.intellij.rt.execution.junit.IDEAJUnitListener;
import com.intellij.rt.execution.junit.segments.PoolOfDelimiters;
import com.intellij.rt.execution.junit.*;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
import junit.framework.*;
import junit.textui.ResultPrinter;
import junit.textui.TestRunner;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
private TestListener myTestsListener;
private JUnit3OutputObjectRegistry myRegistry;
private ArrayList myListeners;
private boolean mySendTree;
public JUnit3IdeaTestRunner() {
super(DeafStream.DEAF_PRINT_STREAM);
}
public int startRunnerWithArgs(String[] args, ArrayList listeners) {
public int startRunnerWithArgs(String[] args, ArrayList listeners, boolean sendTree) {
myListeners = listeners;
mySendTree = sendTree;
if (sendTree) {
setPrinter(new TimeSender(myRegistry));
}
else {
setPrinter(new MockResultPrinter());
}
try {
Test suite = TestRunnerUtil.getTestSuite(this, args);
if (suite == null) return -1;
@@ -60,12 +69,31 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
super.runFailed(message);
}
public void setStreams(SegmentedOutputStream segmentedOut, SegmentedOutputStream segmentedErr) {
setPrinter(new TimeSender());
myRegistry = new JUnit3OutputObjectRegistry(segmentedOut);
public void setStreams(SegmentedOutputStream segmentedOut, SegmentedOutputStream segmentedErr, int lastIdx) {
myRegistry = new JUnit3OutputObjectRegistry(segmentedOut, lastIdx);
myTestsListener = new TestResultsSender(myRegistry);
}
public Object getTestToStart(String[] args) {
return TestRunnerUtil.getTestSuite(this, args);
}
public List getChildTests(Object description) {
return getTestCasesOf((Test)description);
}
public OutputObjectRegistry getRegistry() {
return myRegistry;
}
public String getStartDescription(Object child) {
final Test test = (Test)child;
if (test instanceof TestCase) {
return test.getClass().getName() + "," + ((TestCase)test).getName();
}
return test.toString();
}
protected TestResult createTestResult() {
TestResult testResult = super.createTestResult();
testResult.addListener(myTestsListener);
@@ -97,31 +125,40 @@ public class JUnit3IdeaTestRunner extends TestRunner implements IdeaTestRunner {
return testResult;
}
public TestResult doRun(Test suite, boolean wait) {
try {
TreeSender.sendSuite(myRegistry, suite);
}
catch (Exception e) {
//noinspection HardCodedStringLiteral
System.err.println("Internal Error occured.");
e.printStackTrace(System.err);
public TestResult doRun(Test suite, boolean wait) { //todo
if (mySendTree) {
try {
TreeSender.sendTree(this, suite);
}
catch (Exception e) {
//noinspection HardCodedStringLiteral
System.err.println("Internal Error occured.");
e.printStackTrace(System.err);
}
}
return super.doRun(suite, wait);
}
static Vector getTestCasesOf(Test test) {
Vector testCases = new Vector();
if (test instanceof TestRunnerUtil.SuiteMethodWrapper) {
test = ((TestRunnerUtil.SuiteMethodWrapper)test).getSuite();
}
if (test instanceof TestSuite) {
TestSuite testSuite = (TestSuite)test;
for (Enumeration each = testSuite.tests(); each.hasMoreElements();) {
Object childTest = each.nextElement();
if (childTest instanceof TestSuite && !((TestSuite)childTest).tests().hasMoreElements()) continue;
testCases.addElement(childTest);
}
}
return testCases;
}
public static class MockResultPrinter extends ResultPrinter {
public MockResultPrinter() {
super(DeafStream.DEAF_PRINT_STREAM);
}
}
private class TimeSender extends ResultPrinter {
public TimeSender() {
super(DeafStream.DEAF_PRINT_STREAM);
}
protected void printHeader(long runTime) {
myRegistry.createPacket().addString(PoolOfDelimiters.TESTS_DONE).addLong(runTime).send();
}
}
}
@@ -28,8 +28,9 @@ import junit.framework.TestCase;
import junit.framework.TestSuite;
public class JUnit3OutputObjectRegistry extends OutputObjectRegistry {
public JUnit3OutputObjectRegistry(PacketProcessor mainTransport) {
super(mainTransport);
public JUnit3OutputObjectRegistry(PacketProcessor mainTransport, int lastIndex) {
super(mainTransport, lastIndex);
}
protected int getTestCont(Object test) {
@@ -1,64 +0,0 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.junit3;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import com.intellij.rt.execution.junit.segments.PoolOfDelimiters;
import com.intellij.rt.execution.junit.segments.Packet;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.util.*;
public class TreeSender {
private static void sendNode(Test test, Packet packet, Collection objects) {
Vector testCases = getTestCasesOf(test);
packet.addObject(test, objects).addLong(testCases.size());
for (int i = 0; i < testCases.size(); i++) {
Test nextTest = (Test)testCases.get(i);
sendNode(nextTest, packet, objects);
}
}
private static Vector getTestCasesOf(Test test) {
Vector testCases = new Vector();
if (test instanceof TestRunnerUtil.SuiteMethodWrapper) {
test = ((TestRunnerUtil.SuiteMethodWrapper)test).getSuite();
}
if (test instanceof TestSuite) {
TestSuite testSuite = (TestSuite)test;
for (Enumeration each = testSuite.tests(); each.hasMoreElements();) {
Object childTest = each.nextElement();
if (childTest instanceof TestSuite && !((TestSuite)childTest).tests().hasMoreElements()) continue;
testCases.addElement(childTest);
}
}
return testCases;
}
public static void sendSuite(OutputObjectRegistry registry, Test suite) {
Packet packet = registry.createPacket();
packet.addString(PoolOfDelimiters.TREE_PREFIX);
Collection objects = new ArrayList();
sendNode(suite, packet, objects);
for (Iterator iterator = objects.iterator(); iterator.hasNext();) {
((Packet)iterator.next()).send();
}
packet.addString("\n");
packet.send();
}
}
@@ -15,14 +15,9 @@
*/
package com.intellij.junit4;
import com.intellij.rt.execution.junit.DeafStream;
import com.intellij.rt.execution.junit.IDEAJUnitListener;
import com.intellij.rt.execution.junit.IdeaTestRunner;
import com.intellij.rt.execution.junit.*;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import com.intellij.rt.execution.junit.segments.Packet;
import com.intellij.rt.execution.junit.segments.PoolOfDelimiters;
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
import junit.textui.ResultPrinter;
import org.junit.internal.requests.ClassRequest;
import org.junit.internal.requests.FilterRequest;
import org.junit.runner.*;
@@ -37,49 +32,28 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
private RunListener myTestsListener;
private OutputObjectRegistry myRegistry;
private static void sendNode(Description test, Packet packet, Collection objectPackets) {
final ArrayList children = test.getChildren();
packet.addObject(test, objectPackets).addLong(children.size());
for (int i = 0; i < children.size(); i++) {
sendNode((Description)children.get(i), packet, objectPackets);
}
}
public int startRunnerWithArgs(String[] args, ArrayList listeners, boolean sendTree) {
public void sendTree(OutputObjectRegistry registry, Description suite) {
Packet packet = registry.createPacket();
packet.addString(PoolOfDelimiters.TREE_PREFIX);
Set objects = new HashSet();
sendNode(suite, packet, objects);
for (Iterator iterator = objects.iterator(); iterator.hasNext();) {
((Packet)iterator.next()).send();
final Request request = JUnit4TestRunnerUtil.buildRequest(args);
final Runner testRunner = request.getRunner();
try {
Description description = testRunner.getDescription();
if (request instanceof ClassRequest) {
description = getSuiteMethodDescription(request, description);
}
else if (request instanceof FilterRequest) {
description = getFilteredDescription(request, description);
}
if (sendTree) TreeSender.sendTree(this, description);
}
catch (Exception e) {
//noinspection HardCodedStringLiteral
System.err.println("Internal Error occured.");
e.printStackTrace(System.err);
}
packet.addString("\n");
packet.send();
}
public int startRunnerWithArgs(String[] args, ArrayList listeners) {
try {
final JUnitCore runner = new JUnitCore();
final Request request = JUnit4TestRunnerUtil.buildRequest(args);
final Runner testRunner = request.getRunner();
try {
Description description = testRunner.getDescription();
if (request instanceof ClassRequest) {
description = getSuiteMethodDescription(request, description);
}
else if (request instanceof FilterRequest) {
description = getFilteredDescription(request, description);
}
sendTree(myRegistry, description);
}
catch (Exception e) {
//noinspection HardCodedStringLiteral
System.err.println("Internal Error occured.");
e.printStackTrace(System.err);
}
runner.addListener(myTestsListener);
for (Iterator iterator = listeners.iterator(); iterator.hasNext();) {
final IDEAJUnitListener junitListener = (IDEAJUnitListener)Class.forName((String)iterator.next()).newInstance();
@@ -101,7 +75,7 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
})*/);
long endTime = System.currentTimeMillis();
long runTime = endTime - startTime;
new TimeSender().printHeader(runTime);
if (sendTree) new TimeSender(myRegistry).printHeader(runTime);
if (!result.wasSuccessful()) {
return -1;
@@ -152,18 +126,43 @@ public class JUnit4IdeaTestRunner implements IdeaTestRunner {
}
public void setStreams(SegmentedOutputStream segmentedOut, SegmentedOutputStream segmentedErr) {
myRegistry = new JUnit4OutputObjectRegistry(segmentedOut);
public void setStreams(SegmentedOutputStream segmentedOut, SegmentedOutputStream segmentedErr, int lastIdx) {
myRegistry = new JUnit4OutputObjectRegistry(segmentedOut, lastIdx);
myTestsListener = new JUnit4TestResultsSender(myRegistry);
}
private class TimeSender extends ResultPrinter {
public TimeSender() {
super(DeafStream.DEAF_PRINT_STREAM);
public Object getTestToStart(String[] args) {
final Request request = JUnit4TestRunnerUtil.buildRequest(args);
final Runner testRunner = request.getRunner();
Description description = null;
try {
description = testRunner.getDescription();
if (request instanceof ClassRequest) {
description = getSuiteMethodDescription(request, description);
}
else if (request instanceof FilterRequest) {
description = getFilteredDescription(request, description);
}
}
catch (Exception e) {
//noinspection HardCodedStringLiteral
System.err.println("Internal Error occured.");
e.printStackTrace(System.err);
}
return description;
}
protected void printHeader(long runTime) {
myRegistry.createPacket().addString(PoolOfDelimiters.TESTS_DONE).addLong(runTime).send();
}
public List getChildTests(Object description) {
return ((Description)description).getChildren();
}
public OutputObjectRegistry getRegistry() {
return myRegistry;
}
public String getStartDescription(Object child) {
final Description description = (Description)child;
final String methodName = description.getMethodName();
return methodName != null ? description.getClassName() + "," + methodName : description.getClassName();
}
}
@@ -27,8 +27,9 @@ import org.junit.runner.Description;
public class JUnit4OutputObjectRegistry extends OutputObjectRegistry {
public JUnit4OutputObjectRegistry(PacketProcessor mainTransport) {
super(mainTransport);
public JUnit4OutputObjectRegistry(PacketProcessor mainTransport, int lastIndex) {
super(mainTransport, lastIndex);
}
protected int getTestCont(Object test) {
@@ -0,0 +1,117 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit;
import java.io.*;
/**
* User: anna
* Date: 4/6/11
*/
class ForkedVMWrapper extends DataOutputStream {
private FileOutputStream myOutputStream;
private boolean myError;
public ForkedVMWrapper(FileOutputStream outputStream, boolean error) throws FileNotFoundException {
super(outputStream);
myOutputStream = outputStream;
myError = error;
}
public synchronized void write(int b) throws IOException {
printPrefix();
myOutputStream.write(b);
}
private void printPrefix() throws IOException {
myOutputStream.write("/K".getBytes());
if (myError) {
myOutputStream.write("e".getBytes());
}
else {
myOutputStream.write("o".getBytes());
}
}
public void write(byte[] b) throws IOException {
printPrefix();
myOutputStream.write(b);
}
public synchronized void write(byte[] b, int off, int len) throws IOException {
printPrefix();
myOutputStream.write(b, off, len);
}
public void close() throws IOException {
myOutputStream.close();
}
public void flush() throws IOException {
myOutputStream.flush();
}
public static void readWrapped(String path, PrintStream out, PrintStream err) throws IOException {
FileInputStream stream = new FileInputStream(path);
try {
boolean error = false;
boolean afterSymbol = false;
boolean afterM = false;
while (stream.available() > 0) {
char read = (char)stream.read();
if (read == '/') {
afterSymbol = true;
continue;
}
if (afterSymbol) {
if (afterM) {
error = read == 'e';
afterSymbol = false;
afterM = false;
continue;
}
if (read != 'K') {
if (error) {
err.write("/".getBytes());
err.write(read);
}
else {
out.write("/".getBytes());
out.write(read);
}
afterSymbol = false;
afterM = false;
continue;
}
else {
afterM = true;
continue;
}
}
if (error) {
err.write(read);
}
else {
out.write(read);
}
}
}
finally {
if (stream != null) stream.close();
}
}
}
@@ -20,12 +20,22 @@
*/
package com.intellij.rt.execution.junit;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
import org.junit.runner.Description;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public interface IdeaTestRunner {
int startRunnerWithArgs(String[] args, ArrayList listeners);
void setStreams(SegmentedOutputStream segmentedOut, SegmentedOutputStream segmentedErr);
int startRunnerWithArgs(String[] args, ArrayList listeners, boolean sendTree);
void setStreams(SegmentedOutputStream segmentedOut, SegmentedOutputStream segmentedErr, int lastIdx);
Object getTestToStart(String[] args);
List getChildTests(Object description);
String getStartDescription(Object child);
OutputObjectRegistry getRegistry();
}
@@ -0,0 +1,132 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit;
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* User: anna
* Date: 4/6/11
*/
public class JUnitForkedStarter {
private JUnitForkedStarter() {
}
public static void main(String[] args) throws Exception {
final String testOutputPath = args[0];
final int lastIdx = Integer.parseInt(args[1]);
final boolean isJUnit4 = args[2].equalsIgnoreCase("true");
final String[] childTestDescription = {args[3]};
final ArrayList listeners = new ArrayList();
for (int i = 4, argsLength = args.length; i < argsLength; i++) {
listeners.add(args[i]);
}
final File file = new File(testOutputPath);
if (!file.exists()) {
if (!file.createNewFile()) return;
}
final FileOutputStream stream = new FileOutputStream(testOutputPath);
PrintStream oldOut = System.out;
PrintStream oldErr = System.err;
try {
final PrintStream out = new PrintStream(new ForkedVMWrapper(stream, false));
final PrintStream err = new PrintStream(new ForkedVMWrapper(stream, true));
System.setOut(out);
System.setErr(err);
IdeaTestRunner testRunner = (IdeaTestRunner)JUnitStarter.getAgentClass(isJUnit4).newInstance();
testRunner.setStreams(new SegmentedOutputStream(out, true), new SegmentedOutputStream(err, true), lastIdx);
System.exit(testRunner.startRunnerWithArgs(childTestDescription, listeners, false));
} finally {
System.setOut(oldOut);
System.setErr(oldErr);
stream.close();
}
}
static int startForkedVMs(String[] args,
boolean isJUnit4,
ArrayList listeners,
SegmentedOutputStream out,
SegmentedOutputStream err, String path) throws Exception {
final BufferedReader reader = new BufferedReader(new FileReader(path));
final String commandline = reader.readLine();
final String forkMode = reader.readLine();
reader.close();
IdeaTestRunner testRunner = (IdeaTestRunner)JUnitStarter.getAgentClass(isJUnit4).newInstance();
testRunner.setStreams(out, err, 0);
final Object description = testRunner.getTestToStart(args);
TreeSender.sendTree(testRunner, description);
long startTime = System.currentTimeMillis();
final List children = testRunner.getChildTests(description);
final boolean forkTillMethod = forkMode.equalsIgnoreCase("method");
int result = processChildren(isJUnit4, listeners, out, err, commandline, testRunner, children, 0, forkTillMethod);
long endTime = System.currentTimeMillis();
long runTime = endTime - startTime;
new TimeSender(testRunner.getRegistry()).printHeader(runTime);
return result;
}
private static int processChildren(boolean isJUnit4,
ArrayList listeners,
SegmentedOutputStream out,
SegmentedOutputStream err,
String commandline, IdeaTestRunner testRunner, List children, int result, boolean forkTillMethod)
throws IOException, InterruptedException {
for (int i = 0, argsLength = children.size(); i < argsLength; i++) {
final Object child = children.get(i);
final List childTests = testRunner.getChildTests(child);
if (childTests.isEmpty() || !forkTillMethod) {
result = Math.min(runChild(child, isJUnit4, listeners, out, err, commandline, testRunner, forkTillMethod), result);
} else {
result = Math.min(processChildren(isJUnit4, listeners, out, err, commandline, testRunner, childTests, result, forkTillMethod), result);
}
}
return result;
}
private static int runChild(Object child,
boolean isJUnit4,
ArrayList listeners,
SegmentedOutputStream out,
SegmentedOutputStream err,
String commandline, IdeaTestRunner testRunner,
boolean forkTillMethod)
throws IOException, InterruptedException {
final File tempFile = File.createTempFile("fork", "test");
final String testOutputPath = tempFile.getAbsolutePath();
final int knownObject = testRunner.getRegistry().getKnownObject(child);
String command = commandline + " " + JUnitForkedStarter.class.getName()+ " " + testOutputPath + " " + (knownObject + (forkTillMethod ? 0 : 1)) + " " +
isJUnit4 + " " + testRunner.getStartDescription(child) ;
for (Iterator iterator = listeners.iterator(); iterator.hasNext(); ) {
command += " " + iterator.next();
}
final Process exec = Runtime.getRuntime().exec(command);
int result = exec.waitFor();
ForkedVMWrapper.readWrapped(testOutputPath, out.getPrintStream(), err.getPrintStream());
// tempFile.deleteOnExit();
return result;
}
}
@@ -16,6 +16,7 @@
package com.intellij.rt.execution.junit;
import com.intellij.rt.execution.junit.segments.SegmentedOutputStream;
import java.io.*;
import java.net.InetAddress;
import java.net.Socket;
@@ -33,6 +34,7 @@ public class JUnitStarter {
public static final String IDE_VERSION = "-ideVersion";
public static final String JUNIT4_PARAMETER = "-junit4";
private static final String SOCKET = "-socket";
private static String ourCommandLine;
public static void main(String[] args) throws IOException {
SegmentedOutputStream out = new SegmentedOutputStream(System.out);
@@ -74,7 +76,10 @@ public class JUnitStarter {
isJunit4 = true;
}
else {
if (arg.startsWith("@@")) {
if (arg.startsWith("@@@")) {
ourCommandLine = arg.substring(3);
continue;
} else if (arg.startsWith("@@")) {
if (new File(arg.substring(2)).exists()) {
try {
final BufferedReader reader = new BufferedReader(new FileReader(arg.substring(2)));
@@ -183,26 +188,27 @@ public class JUnitStarter {
SegmentedOutputStream err) {
PrintStream oldOut = System.out;
PrintStream oldErr = System.err;
int result;
try {
System.setOut(new PrintStream(out));
System.setErr(new PrintStream(err));
if (ourCommandLine != null) {
return JUnitForkedStarter.startForkedVMs(args, isJUnit4, listeners, out, err, ourCommandLine);
}
IdeaTestRunner testRunner = (IdeaTestRunner)getAgentClass(isJUnit4).newInstance();
testRunner.setStreams(out, err);
result = testRunner.startRunnerWithArgs(args, listeners);
testRunner.setStreams(out, err, 0);
return testRunner.startRunnerWithArgs(args, listeners, true);
}
catch (Exception e) {
e.printStackTrace(System.err);
result = -2;
return -2;
}
finally {
System.setOut(oldOut);
System.setErr(oldErr);
}
return result;
}
private static Class getAgentClass(boolean isJUnit4) throws ClassNotFoundException {
static Class getAgentClass(boolean isJUnit4) throws ClassNotFoundException {
return isJUnit4
? Class.forName("com.intellij.junit4.JUnit4IdeaTestRunner")
: Class.forName("com.intellij.junit3.JUnit3IdeaTestRunner");
@@ -0,0 +1,37 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit;
import com.intellij.rt.execution.junit.segments.OutputObjectRegistry;
import com.intellij.rt.execution.junit.segments.PoolOfDelimiters;
import junit.textui.ResultPrinter;
/**
* User: anna
* Date: 4/5/11
*/
public class TimeSender extends ResultPrinter {
private final OutputObjectRegistry myRegistry;
public TimeSender(OutputObjectRegistry registry) {
super(DeafStream.DEAF_PRINT_STREAM);
myRegistry = registry;
}
public void printHeader(long runTime) {
myRegistry.createPacket().addString(PoolOfDelimiters.TESTS_DONE).addLong(runTime).send();
}
}
@@ -0,0 +1,47 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.rt.execution.junit;
import com.intellij.rt.execution.junit.segments.Packet;
import com.intellij.rt.execution.junit.segments.PoolOfDelimiters;
import java.util.*;
public class TreeSender {
private TreeSender() {
}
public static void sendTree(IdeaTestRunner runner, Object suite) {
Packet packet = runner.getRegistry().createPacket();
packet.addString(PoolOfDelimiters.TREE_PREFIX);
Set objects = new HashSet();
sendNode(runner, suite, packet, objects);
for (Iterator iterator = objects.iterator(); iterator.hasNext();) {
((Packet)iterator.next()).send();
}
packet.addString("\n");
packet.send();
}
private static void sendNode(IdeaTestRunner runner, Object test, Packet packet, Collection objectPackets) {
final List children = runner.getChildTests(test);
packet.addObject(test, objectPackets).addLong(children.size());
for (int i = 0; i < children.size(); i++) {
sendNode(runner, children.get(i), packet, objectPackets);
}
}
}
@@ -29,8 +29,12 @@ public class MavenWorkspaceMap implements Serializable {
private final THashMap<MavenId, Data> myMapping = new THashMap<MavenId, Data>();
public void register(@NotNull MavenId id, @NotNull File file) {
register(id, file, null);
}
public void register(@NotNull MavenId id, @NotNull File file, @Nullable File outputFile) {
for (MavenId each : getAllIDs(id)) {
myMapping.put(each, new Data(id, file));
myMapping.put(each, new Data(id, file, outputFile));
}
}
@@ -70,11 +74,17 @@ public class MavenWorkspaceMap implements Serializable {
public static class Data implements Serializable {
public final MavenId originalId;
public final File file;
private final File file;
private final File outputFile;
private Data(MavenId originalId, File file) {
private Data(MavenId originalId, File file, File outputFile) {
this.originalId = originalId;
this.file = file;
this.outputFile = outputFile;
}
public File getFile(String type) {
return outputFile == null || MavenConstants.POM_EXTENSION.equalsIgnoreCase(type) ? file : outputFile;
}
}
}
@@ -76,9 +76,9 @@ public class CustomArtifactResolver extends DefaultArtifactResolver {
if (resolved == null) return false;
a.setResolved(true);
a.setFile(resolved.file);
a.setFile(resolved.getFile(a.getType()));
a.selectVersion(resolved.originalId.getVersion());
return true;
}
}
}
@@ -78,7 +78,7 @@ public class CustomMaven3ArtifactResolver extends DefaultArtifactResolver {
if (resolved == null) return false;
a.setResolved(true);
a.setFile(resolved.file);
a.setFile(resolved.getFile(a.getType()));
a.selectVersion(resolved.originalId.getVersion());
return true;
@@ -414,6 +414,13 @@
successive-show="5"
min-usage-count="1"
/>
<feature
id="ui.horizontal.scrolling"
tip-file="HorizontalScrolling.html"
first-show="1"
successive-show="1"
min-usage-count="1"
/>
<!-- TODO: Uncomment usage in InsertPathAction when FeatureUsageTracker goes to OpenApi
<feature
id="ui.commandLine.insertPath"