diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AbstractMethods.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AbstractMethods.java new file mode 100644 index 000000000000..986e6f391d9b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AbstractMethods.java @@ -0,0 +1,109 @@ +// abstract methods +public class a { + void f(); + +} +abstract class c1 { + abstract void f1(); + int f2(); +} + +interface ff { + abstract void f1(); + void f2(); +} + +class x { + void f() { + RuntimeException(); + throw RuntimeException(); + } +} + +// ------------------------------------------------------------- +class c2 { + abstract void f(); +} + +class c3 extends c4 { + +} + +abstract class c4 { + abstract void iif(); +} + +class c5 extends c6 implements i7 { public void ff(){} } +abstract class c6 {} +interface i7 { void ff(); } + +class c7 implements i7 { +} + +class callabstract extends c4 { + void iif() { + super.iif(); + } +} + + +abstract class c8 { + public abstract boolean equals(Object other); +} + +final class c9 extends c8 { +} + + + +//------- if only Bottom were in other package, it should have been abstract -------------------------- +public abstract class AbstractTest { + + abstract String getName(); + + abstract static class Middle extends AbstractTest { + + } + + static class Bottom extends Middle { + String getName() { + return null; + } + } +} + +/////////// +abstract class cc1 { + abstract void f(int i); +} +abstract class cc2 extends cc1 { + abstract protected void f(int i); +} +class cc3 extends cc2 { + public void f(int i) {} +} +/////////////// +interface MyComparator { + int compare(Object t, Object t1); + + boolean equals(java.lang.Object object); +} +class MyComparatorImpl implements MyComparator { + public int compare(Object o, Object o1) { + new MyComparator() { + public int compare(Object o, Object o1) { + return 0; + } + }; + return 0; + } +} +//////////////// IDEADEV-6050 +interface Comparable {} + +interface PublicCloneable extends Cloneable { + Object clone() throws CloneNotSupportedException; +} + +interface PublicCloneableExtension extends Comparable, PublicCloneable { +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AccessLevelClash.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AccessLevelClash.java new file mode 100644 index 000000000000..7fa62b8aa01e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AccessLevelClash.java @@ -0,0 +1,87 @@ +// access level clashes +interface i { + void ff(); +} + +public class a implements i { + void ff() {} +} +class ai implements i { + public int ff() { return 0;} +} + +class c2 implements i { + public c2() {} + public void ff() {} + protected void g() {} + private int fff(String s) { return 0; } +} + +class c3 extends c2 { + protected c3() {} + private int g(int k) { return 2;} + private char fff(String s) { return 0; } +} + +class c4 extends c3 { + private c4() {} + private void g() {} + private String fff(String s) throws java.io.IOException { return null; } +} +class c4i extends c3 { + protected Object g() {return null;} +} + +// sibling inheritance +abstract class c5 { abstract public int ff(); } +interface i5 { void ff(); } +abstract class c6 extends c5 implements i5 { +} + +class c7 { public String ff() { return null;} } +class c8 extends c7 implements i5 { +} + +// interface should not clash with Object +interface A { + Object clone() throws CloneNotSupportedException; + void finalize(); + + void hashCode(); + void equals(Object o); + void toString(); +} + +interface ConflictWithObject { + Object clone() throws CloneNotSupportedException; +} +class s implements ConflictWithObject { + +} + +// parallel overriding methods from Object +interface InderFace { + Object clone() throws CloneNotSupportedException; +} + +interface SubInderFace extends InderFace { +} + +class Implementation implements SubInderFace { +} + + + +//SCR20002 +abstract class SCR20002A extends Object implements Runnable { + protected abstract int getSome(); + private final Inner getInner() { return null; } + private class Inner { } +} + +abstract class SCR20002B extends SCR20002A implements Runnable { + private final Inner getInner() { return null; } + private class Inner { } +} +abstract class SCR20002C extends SCR20002B implements Runnable { +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AmbiguousMethodCall.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AmbiguousMethodCall.java new file mode 100644 index 000000000000..4155ee049f7b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AmbiguousMethodCall.java @@ -0,0 +1,35 @@ +// Ambiguous method call + +class C61 { + public void foo(String s) {} + public void foo(Integer i) {} + public void foo2() { + foo(null); + } +} + +class D61 extends C61 { + public void foo(Integer i) {} + public void foo2() { + foo(null); + foo(1); + } +} +class ex { + void f(String name, String[] i){} + void f(String name, ex i){} + + void g() { + f("",null); + } +} + +class XX { + XX() {} + void XX() {} + + { + new XX().XX(); + } +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AnonBaseRef.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AnonBaseRef.java new file mode 100644 index 000000000000..bef2526fc89e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AnonBaseRef.java @@ -0,0 +1,11 @@ +class A{ + { + class Local{ + void foo(){} + } + + new Local(){ + void foo(){} + }; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AnonInAnon.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AnonInAnon.java new file mode 100644 index 000000000000..298668e4a615 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AnonInAnon.java @@ -0,0 +1,21 @@ +public class QQQ { + { + new Outer(){ + void foo(){ + new Inner(){ + void method() { + super.method(); + } + }; + } + }; + } +} + +class Outer{ + class Inner{ + void method(){ + + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AssignToFinal.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AssignToFinal.java new file mode 100644 index 000000000000..2049abc9a56b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/AssignToFinal.java @@ -0,0 +1,72 @@ +// assign to final +import java.io.*; +import java.net.*; +public class a21 { + final int fi; + { + fi = 4; + } + void f1(int i) { + final int j = 4; + j = 3; + + } + void f2(final int i) { + final int j = 4; + i = 3; + + } + void f3( int ip) { + fi = 3; + for (final int i = 0; i<3; i++) { + int k = 4; + } + final int i1 = 0; + i1++; + --i1; + int i2 = -i1 + ~i1; + final int j = (j=0) == 1 || j==0 ? 9 : j; + } + + static final boolean DEBUG = false; + void f4() { + if (DEBUG && (fi < 3 || fi >4)) return; + } +} +class B extends a21 { + public B() { + fi = 0; + } + void f() { + final Integer i; + new Runnable() { + public void run() { + i = new Integer(4); + } + }; + } +} + +class a21_2 { + final int i; + a21_2() { + i = 0; + new Runnable() { + public void run() { + i = 0; + } + }; + } +} + +class Foo { + private final Foo next; + + public Foo(Foo previous) { + this.next = null; + + if (previous != null) { + previous.next = this; + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/BreakOutside.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/BreakOutside.java new file mode 100644 index 000000000000..f2fd05be2786 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/BreakOutside.java @@ -0,0 +1,50 @@ +// break outside of +public class a { + + void f() { + break; + while (true) { + break; + } + do { break; } while (true); + switch (1) { + case 1: break; + } + for (;;) { + break; + } + + for (;;) { + new ff() { + void f() { + break; + } + }; + break; + } + + + while (true) { + class s { + { + break; + } + } + break; + } + + do { + class s { + { + break; + } + } + break; + } while (true); + + } +} + +class ff { + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CanHaveBody.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CanHaveBody.java new file mode 100644 index 000000000000..cdb7d19fdd21 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CanHaveBody.java @@ -0,0 +1,16 @@ +abstract public class a1 { + abstract void f() {} + native void ff() {} + + void f2() { + new ii() { + public int iif(int i) { + return 0; + } + }; + } +} + +interface ii { + int iif(int i) throws Exception { return 2; } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CastFromVoid.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CastFromVoid.java new file mode 100644 index 000000000000..49ea9c93f1da --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CastFromVoid.java @@ -0,0 +1,8 @@ +class K { + public K foo() { + return (K) bar(); + } + + private void bar() { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CatchUnknownMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CatchUnknownMethod.java new file mode 100644 index 000000000000..da90b8b2e68b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CatchUnknownMethod.java @@ -0,0 +1,11 @@ +public class MyClass { + + public static void main(String[] args) { + try { + unknownMethod(); /* Red code - as expected */ + } catch (java.io.IOException e) { /* Unwanted red squiggly line */ + e.printStackTrace(); + } + } + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ComputeConstant.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ComputeConstant.java new file mode 100644 index 000000000000..43a794dc58d9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ComputeConstant.java @@ -0,0 +1,20 @@ +class A_CR{ + public static final int CONST = CONSTX; + + { + switch(0){ + case CONST: + } + } +} + +class AClass { + private static final String SPACE = " "; + class s { + private static final String RET_VAL = + "Roger" + + SPACE + + SPACE + // comment and uncomment this line + " Dodger"; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CtrCallIsFirst.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CtrCallIsFirst.java new file mode 100644 index 000000000000..53059fbdc06b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/CtrCallIsFirst.java @@ -0,0 +1,63 @@ +// call to super must be first +public class a { + a() {} + a(int i) {} +} + +class b extends a { + b() { + int i = 3; + super(); + } + b(int i) { + this(); + super(2); + } + b(char i) { + super(4); + this(); + } + + b(String s) { + try { + super(2); + } + finally { + } + } + b(String s, int i) { + { + super(2); + } + } + + void f() { + super(); + } + void g() { + this(); + } + +} +class O extends A.B +{ + public O(A a) + { + int i = 0; + a.super(); + } + public O(A a,int i) + { + a.super(); + i = 0; + } +} + +class A +{ + class B + { + class C{} + } + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Deprecated.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Deprecated.java new file mode 100644 index 000000000000..ef2978975183 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Deprecated.java @@ -0,0 +1,62 @@ +// deprecated + +class a { + /** + * @deprecated + */ + void f() {} + + /** + * @deprecated + */ + int dep; + int notdep; + + /** + * @deprecated + */ + a(int i,int j,int k) { + new a(k+i+j,dep,notdep); + } +} + +class b extends a { + void f() { + super.f(); + } + + b() { + this(1); + } + + /** + * @deprecated + */ + b(int i) { + super(0,0,i); + System.out.print(i); + } +} + +class c extends b { + // b.f is not deprecated + void f() {} +} + +interface i1 { + /** + * @deprecated + */ + void f(); +} +abstract class ac1 { + /** + * @deprecated + */ + public abstract void f(); +} + +class ci1 extends ac1 implements i1 { + // no chance not to implement it + public void f() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DotBeforeDecl.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DotBeforeDecl.java new file mode 100644 index 000000000000..058b40565ab4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DotBeforeDecl.java @@ -0,0 +1,7 @@ +public class A_DBD { + { + int field = 0; + field. + String s = null; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateClassMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateClassMethod.java new file mode 100644 index 000000000000..6908ad8db5dc --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateClassMethod.java @@ -0,0 +1,75 @@ +public class a { + void f(int i) { } + void f(int i) { + + new c1() { + public void f1() {} + public void f1() {} + }; + } +} +abstract class c1 { + abstract void f1(); +} + +interface ii { + abstract void f1(); + void f2(); +} + +class a { +} + +class Foo { + void f() { + class Bar { + } + class Bar { + } + } +} + + +class c2 { + class c3 { + void f() { + class c2 { + } + } + } +} + + +class cont { + class B { + } + { + class B { + } + } + class B { + } +} +class cont2 { + { + class B { + } + } + class B { + } +} +class ok { + class Local{}; + class AnotherLocal { + class Local {}; + void bar() { + class Local {}; + Local l; + } + } +} + +class ok2 { + public ok2() {} + public void ok2() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateClassMethodTop.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateClassMethodTop.java new file mode 100644 index 000000000000..642e3501231b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateClassMethodTop.java @@ -0,0 +1,75 @@ +public class a { + void f(int i) { } + void f(int i) { + + new c1() { + public void f1() {} + public void f1() {} + }; + } +} +abstract class c1 { + abstract void f1(); +} + +interface ii { + abstract void f1(); + void f2(); +} + +class a { +} + +class Foo { + void f() { + class Bar { + } + class Bar { + } + } +} + + +class c2 { + class c3 { + void f() { + class c2 { + } + } + } +} + + +class cont { + class B { + } + { + class B { + } + } + class B { + } +} +class cont2 { + { + class B { + } + } + class B { + } +} +class ok { + class Local{}; + class AnotherLocal { + class Local {}; + void bar() { + class Local {}; + Local l; + } + } +} + +class ok2 { + public ok2() {} + public void ok2() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateSwitchLabels.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateSwitchLabels.java new file mode 100644 index 000000000000..d2f7c626be46 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/DuplicateSwitchLabels.java @@ -0,0 +1,66 @@ +// duplicate labels +import java.io.*; +import java.net.*; + +public class a { + + final int FI = 4; + + void f(final int i) { + switch (i) { + default: break; + case 1: break; + default: break; + } + + switch (i) { + case 1: break; + case 1: break; + } + + switch (i) { + case FI/2 - 1: break; + case (1 + 35/16)%2: break; + case FI - 8: break; + } + + final byte b = 127; + + switch(i) { + case b: + System.out.println("b=" + b + ";"); + case 127: + System.out.println("MySwitch.MySwitch"); + } + + + // internalize strings + switch (0) { + case 0: + case "\410" == "!0" ? 1 : 0: + case ""==""+"" ? 3 : 0: + } + + switch (0) { + case 0: + //case 1./0 == Double.POSITIVE_INFINITY ? 1 : 0: + + //case 1./0 == Float.POSITIVE_INFINITY ? 2 : 0: + + // commented out ref + // does not work when running under JRE + //case -1./0 == Double.NEGATIVE_INFINITY ? 3 : 0: + //case -1./0 == Float.NEGATIVE_INFINITY ? 4 : 0: + //case Double.POSITIVE_INFINITY == Float.POSITIVE_INFINITY ? 5 : 0: + //case Double.NEGATIVE_INFINITY == Float.NEGATIVE_INFINITY ? 6 : 0: + //case Double.NaN != Float.NaN ? 7 : 0: + //case Integer.MIN_VALUE == -2.147483648e9 ? 8 : 0: + //case Integer.MIN_VALUE == -2.14748365e9f ? 9 : 0: + //case Long.MIN_VALUE == -9.223372036854776e18 ? 10 : 0: + //case Long.MIN_VALUE == -9.223372e18f ? 11 : 0: + + + + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/EnclosingInstance.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/EnclosingInstance.java new file mode 100644 index 000000000000..d77559a024ac --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/EnclosingInstance.java @@ -0,0 +1,88 @@ +// no enclosing instance when inheriting inner class + + +class A57 { + class X { + } + void f() { + class XL extends A57.X { + } + + } + class XXL extends A57.X { + } +} +class B57 { + class X extends A57.X { + } +} +class C57 extends B57.X { +} + + +class inner_holder { + class inner {} +} + +public class C1_57 extends inner_holder { + // inner instance available through inheritance + protected class c extends inner { + private class iii extends inner {} + } +} + +///////////////////////////////////// +class ParentA { + class InnerA { + + } +} + +class ParentB extends ParentA { + static class InnerB extends InnerA { + + } + class InnerC extends InnerA { + + } +} +//////////////////////// +class c { + static class s { + void f() { + Object o = this; + } + } + void f() {} +} + +class cc { + static class sc extends c { + void f() { + super.f(); + } + } +} +/////////////////////////// +class A +{ + class B + { + class C{} + } +} +class AB extends A.B { + AB(A a) { + a.super(); + } + AB() { + this(new A()); + } +} +class ABIllegal extends A.B { + ABIllegal(A a) { + } + ABIllegal() { + this(new A()); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ExceptionNeverThrown.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ExceptionNeverThrown.java new file mode 100644 index 000000000000..5158a74fb0e6 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ExceptionNeverThrown.java @@ -0,0 +1,105 @@ +// Exception is never thrown in method + +import java.io.*; +import java.sql.*; + +class a { + private void f() throws IOException { + } + public void usef() throws Exception { + f(); //avoid unused f() + } + + private void f2() throws IOException { + try { + throw new IOException(); + } + finally { + return; + } + } + public final void f3() throws IOException { + } + public static void f4() throws IOException { + } + + public void usef2() throws Exception { + f2(); //avoid unused f() + } + public void usef3() throws Exception { + f3(); //avoid unused f() + } + public void usef4() throws Exception { + f4(); //avoid unused f() + } + +} + +final class Final { + { + new Object() { + void f() throws IOException {} + }; + } + + void f() throws IOException {} + public void f1() throws IOException {} + protected void f2() throws IOException {} +} + + + +class a1 { + a1() throws java.io.IOException, SQLException{ + } + +} + +class b1 extends a1 { + b1() throws IOException, SQLException { + } +} + +//////////////////////////////// +public class FooThrow +{ + final Foo foo = new Foo(); // Can throw FooException + FooThrow() throws Foo { + } +} +class Foo extends Exception { + public Foo() throws Foo { + throw new Foo(); + } +} +////////////// +class H { + public H() throws FileNotFoundException { + } + + { + if(true) { + throw new FileNotFoundException(); + } + } +} + +class PossibleIdeaBugs implements java.io.Serializable { + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + } + + private void readObject(java.io.ObjectInputStream in) + throws java.io.IOException, ClassNotFoundException { + } + + + private Object writeReplace() throws java.io.ObjectStreamException { + return this; + } + + private Object readResolve() throws java.io.ObjectStreamException { + return null; + } +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ExceptionNeverThrownInTry.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ExceptionNeverThrownInTry.java new file mode 100644 index 000000000000..38782c3bd933 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ExceptionNeverThrownInTry.java @@ -0,0 +1,13 @@ +import java.io.*; +import java.sql.*; + +//////////// +class x { + void f() { + try { + int i = 0; + } + catch (IOException e) { + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ExtendsClause.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ExtendsClause.java new file mode 100644 index 000000000000..a436f1ee38af --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ExtendsClause.java @@ -0,0 +1,4 @@ +class s { + int i; + class inn extends i {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/FinalFieldInit.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/FinalFieldInit.java new file mode 100644 index 000000000000..17bd29a20846 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/FinalFieldInit.java @@ -0,0 +1,223 @@ +// final Fields initialization +import java.io.*; +import java.net.*; +import java.awt.event.*; + +public class a { + /** + * javadoc should not be highlighted + */ + final int javaDoced; + + static final int sfi1; + static final int sfi2; + final int fi1; + final int fi2; + + class inner { + final int fii; + } + final int fi3; + final int fi4; + + + static final int csfi1 = 0; + static final int csfi2 = csfi1 + 13 / 5; + static final int csfi3; + static { + if (csfi1 < 13) { + csfi3 = csfi2 + (csfi1 == 4 ? 5 : csfi2/13); + } + else { + csfi3 = 0; + sfi2 = 2; + } + } + + + final int cifi1 = 1; + final int cifi2 = ff(); + final int cifi3; + + int ff() { + int i = cifi1 + cifi2 + cifi3 + fi3 + fi4; + return i; + } + + { + switch (cifi1) { + case 2: cifi3 = 2; break; + case 1: cifi3 = 20; break; + case 0: cifi3 = 21; break; + default: cifi3 = 22; break; + } + } + + final int cifi4; + a() { + cifi4 = 4; + int i = fi3; + fi3 = 3; + a ainst = null; + fi4 = ainst.fi4; + } + a(int i) { + this.cifi4 = i; + fi2 = 3; + fi3 = 3; + a ainst = null; + fi4 = ainst.fi4; + } + a(String s) { + this(0); + int i = fi3; + + } +} + +class Test { + // access from within inner class OK + final boolean FB; + { + class s { + boolean b = FB; + } + FB = true; + + } + private final String text; + public Test() { + new ActionListener() { + public void actionPerformed(ActionEvent e) { + doSomething(text);//// + } + }; + text = "Hello world"; + } + + private void doSomething(String value) { + } +} + +// multiple initalizers +class c1 { + private final String x; + { + x = "Hello"; + } + + private final String y; + { + y = x; + } + void f() { + String s = x+y; + } +} + +class c2 { + static { + } + private static final int limit; + static { + limit = 5; + } + final String s; + int k = s.length(); + final String c; + int k2 = c.length(); + { + s = ""; + } + + public c2() { + c = ""; + } + // its ok + int k3 = c.length(); + + c2(int i) { + this(); + } +} + +class UninitializedFinal2 { + private final String s; + + UninitializedFinal2(){ + try { + } + finally { + } + } +} +class UninitedFinalFied { + + private final String string; + + public UninitedFinalFied() throws IOException { + init(); + } + + private void init() throws IOException {} +} +class AssertFinalFied { + private final String string; + + public AssertFinalFied(boolean b) throws Exception { + assert b; + string = null; + } +} + +class a20Exotic { + int n=k=0; + final int k; + final int k2; + int n2 = k==0 ? (k2=9) : (k2=0); +} + +public class cX { + final int i; + cX() { + this(1); + int k = i; + } + cX(int d) { + i = d; + } +} + +// http://www.intellij.net/tracker/idea/viewSCR?publicId=20097 +class Lemma { + public Lemma() { + name.hashCode(); + } + private final String name; + { name = "Andy"; + } +} + +class correct { + void f() { + final Object o; + o = new Object(); + new Object() { + { o.toString(); } + }; + } +} + +public class X { + final int i; + X() { + try { + i = 0; + } + finally { + + } + } +} + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV11877.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV11877.java new file mode 100644 index 000000000000..7dfc0024180f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV11877.java @@ -0,0 +1,7 @@ +interface MyCloneable { + + //protected method from java.lang.Object is not implicitly declared in interface with no base interfaces + int clone(); + + int toString(); +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV11919.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV11919.java new file mode 100644 index 000000000000..8181b03009c5 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV11919.java @@ -0,0 +1,55 @@ +interface Bar { + void DoBar(); +} + +abstract class Foo { + public Foo(Bar b) { + } +} + +class Inh extends Foo { + public Integer myField = new Integer(0); + + public Inh() { + super(new Bar() { + public void DoBar() { + Inh.this.myField.toString(); + } + }); + + class E extends Foo { + E() { + super(new Bar() { + public void DoBar() { + Inh.this.myField.toString(); + } + }); + } + + public void DoBar() { + Inh.this.myField.toString(); + } + } + Inh.this.myField.toString(); + } + + public Inh(Bar b) { + super(b); + } +} + +//IDEADEV-14306 +class Base { + protected String field; + + public Base(final String field, int l) { + this.field = field; + } +} + +class Inhertior extends Base { + public Inhertior() { + super("", field.length()); + } +} +//end of IDEADEV-14306 \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV13249.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV13249.java new file mode 100644 index 000000000000..3adc15d65c9d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV13249.java @@ -0,0 +1,22 @@ +class TestSuper { + public static class A { + private String s = "A"; + + public void foo() { + System.out.println("A::foo"); + } + } + + public static class B extends A { + + public void foo() { + super.foo(); + System.out.println("B::foo " + super.s); + System.out.println("B::foo " + ((A) this).s); + } + } + + public static void main(String[] args) { + new B().foo(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV25784.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV25784.java new file mode 100644 index 000000000000..99b6bc53b1b1 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV25784.java @@ -0,0 +1,13 @@ +public class X extends Y {} +public class Y { + + private static int x = 0; + + public static int getX() { + return x; + } + + public static void setX(int x) { + X.x = x; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV8822.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV8822.java new file mode 100644 index 000000000000..23347d6f9719 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV8822.java @@ -0,0 +1,8 @@ +class S extends S3 { + String XXX; //should correctly resolve to java.lang.String +} + +class S3 { + private class String { + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV9201.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV9201.java new file mode 100644 index 000000000000..322079a1b327 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IDEADEV9201.java @@ -0,0 +1,6 @@ +class YouAreNotMyType { + + String[][] oldLady() { + return new String[][]{new Integer[]{}}; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IllegalModifiersCombination.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IllegalModifiersCombination.java new file mode 100644 index 000000000000..d682ba31f65d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IllegalModifiersCombination.java @@ -0,0 +1,74 @@ +// illegal modifier combinations + +abstract public class a { + //////////////////// fields //////////////////////////////// + public static + protected int f1 = 0; + + public volatile + private int f2 = 0; + + protected final + private int f3 = 0; + + final + volatile private int f4 = 0; + + public + public + int f5 = 0; + + public static final int cf1 = 0; + static volatile private int cf2; + transient public static final int cf3 = 0; + protected volatile transient int cf4; + private static final int cf5 = 1; + + + + ///////////////////// methods /////////////////////////////////// + + abstract + native void m1(); + + static public + abstract void m2(); + + final + abstract void m3(); + + private static + public void m4() {} + + protected final + private void m5() {} + + public + public void m6() {}; + + public abstract void cm1(); + protected static synchronized native void cm2(); + public static final void cm3() {} + + + ///////////////////////// classes ////////////////////////////////// + final static strictfp protected + abstract class c1 {} + + private final + public class c2 {} + + final + final class c3 {} + + abstract protected static strictfp class cc1 {} + final private static class cc2 {} + class cc3 {} + static class cc4 {} + + ///////////////////////// locals + void f() { + final + final int loc; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IllegalType.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IllegalType.java new file mode 100644 index 000000000000..1fd25c89716b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IllegalType.java @@ -0,0 +1,8 @@ + + class Foo { + int k; + Class c=k.class; + void f() { + java.io javaio; + } + } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IllegalVoidType.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IllegalVoidType.java new file mode 100644 index 000000000000..206be9026ba0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IllegalVoidType.java @@ -0,0 +1,18 @@ +class s { + void f() { + // illegal type + void[] va; + void vv; + class loc { + void f(void i) {} + } + Object o = new void[1]; + + // this is the only valid void usage + Class voidClass = void.class; + } + + { + Object o = f(); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ImplicitConstructor.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ImplicitConstructor.java new file mode 100644 index 000000000000..1402dec5d7c4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ImplicitConstructor.java @@ -0,0 +1,9 @@ +class A_I extends B_I{ + public A_I() { + super(); + new B_I(); + } +} + +class B_I{ +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IncompatibleTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IncompatibleTypes.java new file mode 100644 index 000000000000..18f8b36cbb62 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/IncompatibleTypes.java @@ -0,0 +1,80 @@ +class c { + void f() { + //---- switch -------------------------------------------------------- + switch ("s") + {default:} + byte bt = 0; + switch (bt) { + case "S": break; + case 10L: break; + case true: break; + case 0xdfffffff: break; + case '\udede': break; + case 1280: break; + // assignable compatible to byte + case 0: break; + case 'c': break; + case -1: break; + case 127: break; + } + char ch = 'd'; + switch (ch) { + case "S": break; + case 10L: break; + case true: break; + case 0xafffffff: break; + // assignable compatible to char + case 0: break; + case '\u4567': break; + case 0xffff: break; + case 255: break; + } + switch ('d') {default:} + + /// --------- incompatible types inside array initializer ---------- + + + int[] ia = new int[] { + "String" + , 3.4 + }; + + String[] sa = { "s", + false + , 'S' + }; + + String[] vas = null; + Object o = new int[vas[0]]; + + int[] weird={{0}}; + int[][] arrayInitializers = {{ }}; + int[][][] arrayInitializers2 = {{ }, {{}} }; + double[][] i2d = {{1}}; + char[][] i2c = {{1}}; + char foo = 0x0000; /* okay */ + char[] bar = { 1,2,3 }; /* still okay */ + char[][] baz = { { 1,2,3 } }; /* not okay in 4.5, okay in 4.0.x and for javac */ + + + /// -------- conditional operator + int i8 = "ff" + true ? 1 : 2; + int i9 = 1==2 ? 1 : "ff" + true; + i9 = 1==2 ? 3 : null; + Object o9 = true ? 0 : new Object(); + + + + final char ccons='0'; + short ssss=ccons; + byte bbbbbb=ccons; + // too big char to fit in short + final char bigchar='\uffff'; + short sbig = bigchar; + } + + void g(boolean f, byte b) { + byte c = '\n'; + byte next = f ? b : '\n'; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InheritFinal.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InheritFinal.java new file mode 100644 index 000000000000..56e1265fe7da --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InheritFinal.java @@ -0,0 +1,10 @@ +// inherit from final +public class a extends ff { + + void f() { + Object o = new ff() { void gg(){} }; + } +} + +final class ff { +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InitializerCompletion.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InitializerCompletion.java new file mode 100644 index 000000000000..2e270c0db875 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InitializerCompletion.java @@ -0,0 +1,134 @@ +/// initalizers completion +import java.io.*; +import java.net.*; + +public class a { + + { + throw new RuntimeException(); + } + + static { + try { + throw new RuntimeException(); + } + finally { + throw new NullPointerException(); + } + } + + +} +class a2 { + { + if (1==2) throw new IOException(); + } + + a2() {} +} +class a3 { + { + if (1==2) throw new SocketException(); + } + + a3() throws ConnectException {} +} + +class b { + + { if (1==2) throw new SocketException(); } + + b() throws IOException {} +} + +class a4 { + { + if (true) { + throw new Exception(); + } + } + a4() throws Exception { + } +} + +class a5 { + int i = f(); + + int f() throws ClassNotFoundException { + return 0; + } +} +class a6 { + int i = f(); + + int f() throws ClassNotFoundException { + return 0; + } + + a6() throws ClassNotFoundException { + } +} + +class a7 { +{ + try { + throw new RuntimeException(); + } finally { + } + } +} + +class MyRuntimeException extends RuntimeException {} + +class GUIBase { + GUIBase () throws MyRuntimeException {} +} + +class GUI extends GUIBase { + +} + + +class a8 { + { + assert true; + } + { + assert false; + } + +} + +class a9 { + + private static interface AnInterface {} + + public AnInterface getAnInterface() { + return new AnInterface() { + { + new java.io.FileInputStream("somefile"); + } + }; + } +} + +//////////////////////////////// +class BadStatic { + static String f() throws ClassNotFoundException { + return null; + } + private static final String FOO = f(); + + public BadStatic() throws ClassNotFoundException { + } +} +class H { + public H() throws FileNotFoundException { + } + + static { + if(true) { + throw new FileNotFoundException(); + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InjectedAnnotator.xml b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InjectedAnnotator.xml new file mode 100644 index 000000000000..8efde915514e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InjectedAnnotator.xml @@ -0,0 +1,5 @@ +aaa="dddd"> + +   + + \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InstantiateAbstract.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InstantiateAbstract.java new file mode 100644 index 000000000000..2a7456ec8de0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InstantiateAbstract.java @@ -0,0 +1,37 @@ +// instantiate abstract +public class a { + void f() { + new ii(); + + new c1(); + + new c1() { + public void f2() {} + }; + + new c1() { + public void f1() {} + }; + + new c1() { + public void f1(int i) {} + public abstract void f2(); + }; + + + new c1() { + public void f1(int i) {} + }; + new ii() { public void f1(){} public void f2(){} }; + + } +} +abstract class c1 { + abstract public void f1(int i); +} + +interface ii { + abstract void f1(); + void f2(); +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Interface.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Interface.java new file mode 100644 index 000000000000..1dc6b8c535c7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Interface.java @@ -0,0 +1,20 @@ +interface i implements Runnable {} + +interface ii {} +class cs extends ii {} +interface is extends ii {} + +class cs2 implements cs {} +interface is3 extends cs {} + +abstract class Exercis { + public static void main() { + Object o = java.lang.this; + + new Runnable() { + public void run() { + Runnable.this.run(); /// + } + }; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InvalidExpressions.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InvalidExpressions.java new file mode 100644 index 000000000000..e676de4441ef --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/InvalidExpressions.java @@ -0,0 +1,104 @@ +// invalid expressions +public class a12 { + static int i; + + int f(int i) { + 1; + 1==2; + 1==2 ? 1 : 3; + f(1) == 3; + 1,2; + ~1; + !(1==2); + new int[0]; + new a12[10]; + new a12[]{}; + new int[]{1}; + new String[]{new String()}; + if (i==1) + String s00 = ""; + for (;;) + String s01 = ""; + + + for (1==2,i=3; i<3; !(1==2)); + + label2: + int ksdfgdf; + + + int i1=3, g=5; + g++; + ++g; + for (int k=1,l=3; k<3; k++,l--) {;}; + class s {} + new s() { void f(){}}; + return 3; + } + + + + ////////////////////////// + void f() { + a12 a[] = new a12[4]; + int[] ai = null; + + 5 = 5; + 5++; + ++5; + 5 += 5; + + foo123Unresolved(String); + foo123Unresolved(xxxx); + + // incomplete code should not cause 'expr expected' + Object + + + 4[1] = 5; + a["d"] = null; + + a[0][1] = 5; + i[0] = 5; + i = ai[a[1]]; + + final a12[] a12a = new a12[{null}]; + int[] iarr = new int[{0}]; + + + new String["d"]; + new String[1.1] + [this]; + + a[0] = null; + (a)[(1)].i = 3; + (( i) ) = (5); + a12.i = 0; + arr()[0] = 1; + new int[] { 1,3} [0] = 2; + Object[] var = null; + i = var.length; + + // array initializers + var = { null, null }; + Object var1 = { null, null }; + int[] var2 = { 1,2 }; + var2 = new int[] { 2, 4}; + int[][] ii2 = { { 1,2}, {4} }; + + } + void[] fv() { + if (1==2) return new void[0]; + return null; + } + + int[] arr() { return new int[0]; } + + public foo() { + } + + // do not warn about illegal type in incomplete declarations (http://www.intellij.net/tracker/idea/viewSCR?publicId=9586) + void foo +} + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Javadoc.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Javadoc.java new file mode 100644 index 000000000000..4a73ec289aa0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Javadoc.java @@ -0,0 +1,39 @@ +class a { + /**period. + * @return x + */ + int f() { + return 0; + } + /**period. + * @return x wtf ? + */ + int f2() { + return 0; + } + + /**period. + * @return + * true if someone wants + */ + int f3() { + return 0; + } + + + /**period. + * @param i description goes here + * @return + */ + int f(int i) { + return i; + } + + + /** + * @see localVar + */ + static String KEY_FOR_VAR="index.localVar"; + String localVar; +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/LocalVariableInitialization.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/LocalVariableInitialization.java new file mode 100644 index 000000000000..3c7be47387fe --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/LocalVariableInitialization.java @@ -0,0 +1,418 @@ +import java.io.*; +import java.net.*; +import java.util.*; + +public class a { + static final a ai; + int ii; + + static { + ai.ii = 4; + ai = null; + } + + void f1(int i) { + int j; + i = j; + } + void f2(int i) { + int j; + if (i ==2) j = 4; + i = j; + } + void f3(int i) { + int j; + if (i==3 && (j=i) != 9) { + i = j+2; + } + else { + i -= -1 - j; + } + } + void f4(int i) { + + final int dd; + + Runnable r = new Runnable() { + public void run() { + int j = dd; + } + }; + + if (i == 3) dd = 5; + else dd = 6; + } + void f5(int i) { + final int k; + class inner { + void f() { + int j = k; + } + } + + } + void f6(int a){ + Object[] var; + if (a > 0){ + } + else{ + var = new Object[1]; + } + System.out.println(var); + } + + + void f7() { + int k; + try { + k=0; + } finally { + if (k==0) { + } + } + } + + void f8(int n) + { + int k; + while (n < 4) { + k = n; + break; + } + // k is not "definitely assigned" before this + System.out.println(k); + } + + void f9() { + final int k; + k+=1; + } + void f10() { + final int k; + k++; + int i = i + 1; + int j = (j=2) == 1 || j==0 ? 1 : j; + } + + void f11() { + int x = 0; + switch (x) { + case 0: + int y = 1; + System.out.println(y); + break; + case 1: + int z = y; + System.out.println(z); + break; + } + } + void f12() { + switch (0) { + case 0: + int k=0; + case 1: + System.out.println(k); + } + } + + public class AInner { + class AI2 {} + private AI2 myTitleRenderer = new AI2() { + private String myLabel = ""; + + public String getTreeCellRendererComponent(String value) { + if (value instanceof String) { + int i = myLabel.length(); + } + return null; + } + }; + } + + void f13() { + int i ; + try { + i = 0; + if (i==0) throw new IOException(); + } + catch (IOException e) { + if (i==0) return; + } + } + + abstract class X { + class XException extends Exception{} + class YException extends Exception{} + class ZException extends Exception{} + public void test() throws XException { + final Object obj; + try { + obj = test1(); + } + catch (YException fnf) { + } + finally { + try { + test2(); + } + catch (ZException eof) { + } + } + obj.hashCode(); //can stay uninitialized + } + + public abstract Object test1() throws YException, XException; + + public abstract void test2() throws XException, ZException; + } + + public static int test(List aList) { + List list2; + int counter = 0; + for (int i=0; ilist2.add(aList.get(i)); + } + return counter; + } + + void forEachParam(java.io.File x) { + for (java.io.File f: f.listFiles()) { + forEachParam(f); + } + } + + // all code below is correct + int cf1(int i) { + return i; + } + + void cf2(int i) { + int j; + if (i == 0 && (j=i) != 2) { + i = j; + } + if (i == 0 || (j=i) != 2 || j>3) { + i = 2; + } + } + + boolean cf3(int i) { + final int j; + if (i<3 || i>33) j = i; + else j = 4; + i = j; + + return i==3 && i==5; + } + void cf33(int i) { + final int j2; + while (true) { + j2 = 5; + break; + } + i = j2; + } + + void cf4() { + final int i1; + int i2; + final Object o1; + } + void cf5() { + final int dialog = 3; + + final int dd; + if (dialog == 3) dd = 5; + else dd = 6; + + Runnable r = new Runnable() { + public void run() { + int i = dialog; + int j = dd; + } + }; + + } + void cf6() { + class inner extends a { + void fi() { + int i = ii; + } + } + a ainst = new a() { + void fi() { + int i = ii; + } + }; + } + a() { + int i = ai.ii; + } + void cf7() { + for(int i = 0; i < 3; i++){ + Object element; + if (i==0){ + element = null; + } + else if (i==3){ + element = null; + } + else{ + continue; + } + Object newe = element; + } + } + void cf8(int n) + { + int i; + while (true) { + if (false) { + i = 0; + break; + } + } + i++; + + } + final boolean FB = true; + + void cf9() { + int k; + if (FB) { + k = 4; + } + int j = k; + } + + + void cf10() { + for (String line; (line = "") != null; ) { + line.indexOf(" "); + } + } + + void cf11(boolean d) { + boolean b; + boolean c = true; + if (c && (false && true)) { + c = b; + } + } + void cf12() { + boolean booleanVar = true; + boolean stringVar; + if (!(booleanVar && (stringVar = true))) { + stringVar = false; + } + if (stringVar) { + + } + } + + void cfxx(boolean a, boolean b) { + int n; + if ((a || b) && (n = 0) >= 2) { + n++; // + } + } + void cfxx1(boolean a, int b) { + final int i; + if ((true || false) && (i = b) != 0) { + System.out.println(i); // i gets highlighted } + } + } + void cfx3() { + boolean b; + boolean c;// = true; + if (c && false) { + c = b; + } + } + void cfx4() + { + final int k; + if (false) { + k = 0; + k = 1; + System.out.println(k); + } + } +} + + +class Main { + void f() { + final int x; + x = 0; + class C { + void m () { + int y = x; + } + } + } +} + + +// continue in finally +class QuartzSchedulerThread { + public void run() throws IOException { + while (true) { + try { + } finally { + try { + run(); + } catch (IOException e) { + e.printStackTrace(); + } + continue; + } + } + } + +} +class ExceptionProblems { + + private boolean bad() { + final boolean succeeded; + try { + new FileInputStream("test"); + succeeded = true; + } catch (IOException e) { + succeeded = false; // should warn here + } + return succeeded; + } +} +class ImGood { + int foo() { //IDEADEV-7446 + int foo; + if (true) { + foo = 42; + } + return foo; + } + } + +class SwitchTest +{ + public static String method() + { + int a = 0; + switch (a) + { + case 0: + return null; + case 4: + String description; + return description; + default: + return ""; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Loop.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Loop.java new file mode 100644 index 000000000000..600bae3ca7db --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Loop.java @@ -0,0 +1,67 @@ +// continue outside of.../loop label +public class a { + + void f() { + continue; + while (true) { + continue; + } + do { continue; } while (true); + switch (1) { + case 1: continue; + } + for (;;) { + continue; + } + + for (;;) { + new ff() { + void f() { + continue; + } + }; + continue; + } + + + while (true) { + class s { + { + continue; + } + } + continue; + } + + do { + class s { + { + continue; + } + } + continue; + } while (true); + + + + a: + if (2==4) { + for (;;) { + continue a; + } + } + + a: + b: + for (;;) { + continue a; + } + + + + } +} + +class ff { + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MethodCalls.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MethodCalls.java new file mode 100644 index 000000000000..c6fc37d77092 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MethodCalls.java @@ -0,0 +1,104 @@ +// illegal method calls + +class A { + private class B { + Object o = super; + } + private B b = null; + A(A a) + { + new A(a).new B(); + B b = new A(a).b; + AA aa = (AA) a; + AA.SAA saa = aa.new SAA(); + AA.SAA saa1 = new AA.SAA(); + } +} + +class AA extends A { + private AA aa; + AA(A a) { + super(a); + } + class SAA {} + + void f() { + new AA.SAA(); + new SAA(); + AA.this.aa.new SAA(); + + class MyAA extends AA { + public MyAA(A a) { + super(a); + } + } + } +} + +class AX { + class B { + } +} +class CX { + { + new AX.B(); + } +} + + + +class c { + c() { + + } + class inner { + class ininner {} + } + + + static void f() { + new inner(); + } + + static { + new inner(); + } +} + + +class A1 { + void f() {} +} +class B1 { + void f() { + A1.f(); + } +} + +class AAAA implements java.io.Serializable +{ + public AAAA () + { + super(); // here + } +} + +class DCC { + public DCC(int i) { + } + + public DCC(int i, int z) { + DCC(i); + } + void f() { + DCC(1); + new DCC(1); + } +} + +class ThisExpression { + static String foo() { + System.out.println(this); + return this.toString(); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MethodCannotBeApplied.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MethodCannotBeApplied.java new file mode 100644 index 000000000000..6191dc926344 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MethodCannotBeApplied.java @@ -0,0 +1,7 @@ +class A {{ + String.valueOf(chars, 0, 10); // all arguments are highlighted when only chars has a problemij + new String(chars, 0, 10); // highlighting is good here. + + String.valueOf(0, 0, 10); + new String(0, 0, 10); +}} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ModifierAllowed.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ModifierAllowed.java new file mode 100644 index 000000000000..99b79745b48e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ModifierAllowed.java @@ -0,0 +1,68 @@ +// not allowed modifiers +private +static +volatile +class a { + + static + private + public + abstract { + int i = 4; + } + synchronized Object x; + + + private class c1 { + private void ff() {} + } + static strictfp class c2 {} + + private static interface ii { + private int f1 = 2; + protected int f2 = 2; + public int f3 = 3; + + + private int f1(); + protected int f2(); + public int f3(); + void f4(); + + } + + void f1(final String i) { + final int ii = 3; + private int i2; + static int i3; + + try { + throw new Exception(); + } catch (final static Exception e) { + } + } + +} + +interface ff { + static class cc {} +} + +abstract class c { + abstract c(); + static c(int i) {} + native c(boolean b); + final c(char c) {} + strictfp c(String s) {} + synchronized c(Object o) {} +} + +interface i3 { + strictfp int f1; + transient int f2; + synchronized int f3; + + strictfp int m1() { return 0; } + transient int m2() { return 0; } + synchronized int m3() { return 0; } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeBoolean.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeBoolean.java new file mode 100644 index 000000000000..ff5afd5677ad --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeBoolean.java @@ -0,0 +1,20 @@ +class c { + void f() { + Object o = null; + if (o) { + return; + } + + String str1 = ""; + String str2 = ""; + do {} + while (str1 = str2); + + int i8 = "ff" + true ? 1 : 2; + + assert 0; + assert 'a'; + assert ""; + assert f(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeFinal.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeFinal.java new file mode 100644 index 000000000000..f2a914b6ff60 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeFinal.java @@ -0,0 +1,12 @@ +class m { + int i; + void f() { + int r = 0; + new Runnable() { + public void run() { + int k = r; + int ii = i; + } + }; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeThrowable.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeThrowable.java new file mode 100644 index 000000000000..bd4e59b434db --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/MustBeThrowable.java @@ -0,0 +1,46 @@ +class c { + void f1() { + try { + } catch (Error[] e) { + } + try { + } catch (Error e[]) { + } + try { + } catch (Error[] []e[] []) { + } + catch(int e) { + } + + } + +} + +class MyException // does not extend Throwable +{} + +class a60 +{ + public void test() throws MyException + { + throw new MyException(); + } + public void test(int i) { + switch (i) { + case 1: throw false; + case 2: throw 1; + case 3: throw 1.0; + case 4: throw 'a'; + case 5: throw 1L; + case 6: throw 1.0f; + } + } +} + + class Contest { + short midget; + + void strongMan() throws midget { + } +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/NamesHighlighting.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/NamesHighlighting.java new file mode 100644 index 000000000000..1cab6140cb63 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/NamesHighlighting.java @@ -0,0 +1,59 @@ +import java.io.*; // highlight on demand import as class name + +class a { + void method() { + method(); + + new Exception(); + new java.lang.Exception(); + } + a() { + new a(); + } + + /** + * @see itf#method(double) + */ + static void f() { + Integer.parseInt(""); + java.lang.Integer.parseInt(""); + f(); + } + + interface itf{ + int CONST = 0; + /** . + * @param d Important param + */ + void method(double d); + } + void ff(Runnable r) { + ff( + new java.lang.Runnable() + { + public void run() {} + int instance = 0; + } + ); + + int i = java.lang.Integer.MIN_VALUE; + int j = itf.CONST; + } +} + +class NoCtrClass { + { + // default constructor call looks like class + new NoCtrClass(); + } + void ff(int param) { + int i = 1; + i ++; + + param = 0; + } +} + +class Generic<TT extends Runnable> { + TT field; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/NumericLiterals.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/NumericLiterals.java new file mode 100644 index 000000000000..86ac91d25e03 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/NumericLiterals.java @@ -0,0 +1,64 @@ +/// assignment compatible types +import java.io.*; +import java.net.*; +public class a { + final int FI = 2; + final int FIBIG = 200000000; + + + void f() { + int i1=-2147483649; + int i2=2147483648; + int i3 = -2147483648; + int i4 = -0x7fffffff; + int i5 = -017777777777; + int i6 = 0x; + int i7 = 0xdeadbeef; + int i8 = 0xffffffff; + int i9=0xffffffff9; + int i10= 0x80000000; + int i11=0000000000000+0x000000000; + int i12=0x00000000000000000000000; + int i13= 040000000000; + int i14= 020000000000; + int i15 = 0xf044332211; + int octale = 017777777777; // negative + + + + long l1=-9223372036854775809L; + long l2=9223372036854775808L; + long l3=-9223372036854775808L; + long l4=-2147483649; + long l5=2147483648; + long l6 = 0xL; + long l7= 0xdeadbeefffffffffL; + long l8= 0xffffffffffffffffL; + long l9=0xffffffffffffffff9L; + long l10=0x8000000000000000L; + long octalValue = 01777777777777777777600L; + long octalValua = 01777777777777777777777L; + + float f1= 1e-46f; + float f2=1e39f; + float f3=0E1F; + + double dd1=1e-324; + double dd2=1e309; + double dd3=0E1; + + double d1=1.E; + double d2=1.e; + double d3=1.E+; + double d4=1.E-; + double d5=.1eD; + double d6=.1e+D; + double d7=1e+D; + double d8=1e-D; + double d9=1e-d; + double d10=1e-F; + double d11=1e-f; + + + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/NumericOverflow.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/NumericOverflow.java new file mode 100644 index 000000000000..742d5fe9d2cc --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/NumericOverflow.java @@ -0,0 +1,88 @@ +// overflows in const expressions + + +class c { + // @*#$& ! references do not work in JRE + static final long LONG_MIN_VALUE = 0x8000000000000000L; + static final long LONG_MAX_VALUE = 0x7fffffffffffffffL; + static final int INTEGER_MIN_VALUE = 0x80000000; + static final int INTEGER_MAX_VALUE = 0x7fffffff; + static final float FLOAT_MIN_VALUE = 1.4e-45f; + static final float FLOAT_MAX_VALUE = 3.4028235e+38f; + static final double DOUBLE_MIN_VALUE = 4.9e-324; + static final double DOUBLE_MAX_VALUE = 1.7976931348623157e+308; + + void f() { + float f1 = 1.0f / 0.0f; + f1 = FLOAT_MAX_VALUE + FLOAT_MAX_VALUE; + f1 = FLOAT_MAX_VALUE * 2; + f1 = 2 / FLOAT_MIN_VALUE; + f1 = FLOAT_MIN_VALUE + 1; + f1 = - FLOAT_MIN_VALUE; + f1 = -FLOAT_MAX_VALUE; + System.out.println(f1); + + double d1 = DOUBLE_MAX_VALUE - -DOUBLE_MAX_VALUE; + d1 = DOUBLE_MAX_VALUE + 1; + d1 = 2 * DOUBLE_MAX_VALUE; + d1 = 2 / DOUBLE_MIN_VALUE; + d1 = 2 / 0.0d; + d1 = 2 / 0.0; + System.out.println(d1); + + + int i1 = INTEGER_MAX_VALUE + 1; + i1 = INTEGER_MAX_VALUE - 1 + 2; + i1 = INTEGER_MAX_VALUE - INTEGER_MIN_VALUE; + i1 = -INTEGER_MIN_VALUE; + i1 = INTEGER_MIN_VALUE - 1; + i1 = INTEGER_MIN_VALUE - INTEGER_MAX_VALUE; + i1 = INTEGER_MIN_VALUE + INTEGER_MAX_VALUE; + i1 = - INTEGER_MAX_VALUE; + i1 = - -INTEGER_MAX_VALUE; + i1 = INTEGER_MIN_VALUE * -1; + i1 = INTEGER_MIN_VALUE * 2; + i1 = INTEGER_MAX_VALUE * -2; + i1 = INTEGER_MAX_VALUE * -1; + i1 = 2 / 0; + i1 = INTEGER_MIN_VALUE / -1; + System.out.println(i1); + + long l1 = LONG_MAX_VALUE + 1; + l1 = LONG_MAX_VALUE - 1 + 2; + l1 = LONG_MAX_VALUE - LONG_MIN_VALUE; + l1 = -LONG_MIN_VALUE; + l1 = LONG_MIN_VALUE - 1; + l1 = LONG_MIN_VALUE - LONG_MAX_VALUE; + l1 = LONG_MIN_VALUE + LONG_MAX_VALUE; + l1 = - LONG_MAX_VALUE; + l1 = - -LONG_MAX_VALUE; + l1 = -INTEGER_MIN_VALUE; + l1 = -1L + INTEGER_MIN_VALUE; + l1 = LONG_MIN_VALUE * INTEGER_MIN_VALUE; + l1 = LONG_MIN_VALUE * -1; + l1 = LONG_MIN_VALUE * 2; + l1 = LONG_MAX_VALUE * -2; + l1 = INTEGER_MIN_VALUE * -1L; + l1 = 2 / 0L; + l1 = 2 % 0L; + l1 = LONG_MIN_VALUE / -1; + + l1 = 30 * 24 * 60 * 60 * 1000; + l1 = 30000000 * 243232323 + * (LONG_MAX_VALUE +3) / 5; + System.out.println(l1); + + + + } + + private static final long MILLIS_PER_DAY = 24 * 3600 * 1000; + private static final long _7DAYS = 7 * MILLIS_PER_DAY; + private static final long _30DAYS = 30 * MILLIS_PER_DAY; + private static final long _1000DAYS = 1000 * MILLIS_PER_DAY; + { + System.out.println(_1000DAYS + _30DAYS + _7DAYS); + } + int iii = 2 % 0; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OperatorApplicability.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OperatorApplicability.java new file mode 100644 index 000000000000..8b577ba54a7d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OperatorApplicability.java @@ -0,0 +1,70 @@ +// operators applicability +public class a { + + int f(int ik) { + if (1 < null) {} + if (null == 'c') {} + Object o = null; + if (1.2 >= o) {} + if (1L != "null") {} + if ((1==2) == 3) {} + + int i = (1 + null); + i = o/o; + i = null - 1.2; + i = true % 4; + + i = i << o; + i = (i==2) >> null; + i = i >>> 2.2; + + i = i & o; + i = true | 2.1; + i = 2 && 3; + i = 3.8 || 2L; + i = null || o; + + i |= null; + double d = 0; + d &= i; + o /= 3; + + + String sss2 = "" + fvoid(); + int sss1 = fvoid() + 2; + + int ia[] = null; + boolean b = 1==3 || 3 < '4' && (1>3.5) == (o == null) || false || (o == "d"); + b = (1 != 'f') == (3.4 >= 'x') && o!=null & (b | (3<4)); + i = i & 2 | i>>i ^ 15>>>4 & ~ia[i-- + (int)d] - (int)d; + + b |= (i &= 7) == 5 | (null == null); + d *= (i -= 3) / 13.4; + ia[0]++; + ia[~i | (i+=(!b?2:i))] -= i + 3.3; + + // Object += String + o += o + "string"; + + return 0; + } + + void fvoid() {} + +} + +class Test +{ + public void test(TestB a) + { + if(a == this) + { + System.out.println("a is equals to this"); + } + } + + public static interface TestB + { + public void bla(); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OverriddenMethodIsFinal.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OverriddenMethodIsFinal.java new file mode 100644 index 000000000000..b1c3dd44e3a6 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OverriddenMethodIsFinal.java @@ -0,0 +1,14 @@ + +interface ConflictWithObject { + public void notify(); +} + +//--override final------------------------------------------------------------------------- +class base { + final void f() {} +} +class derived extends base { + + void f() {} + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OverrideConflicts.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OverrideConflicts.java new file mode 100644 index 000000000000..3aaa540d2a0c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/OverrideConflicts.java @@ -0,0 +1,88 @@ +// throws conflicts on overriding/ override final +import java.io.*; +import java.net.*; +public class a extends c3 { + public void f() throws Exception { + } +} + +interface i { + void f() throws java.net.SocketException; +} +class c2 implements i { + public void f() throws java.io.IOException {} +} +class c2i implements i { + public void f() throws Exception {} +} + +class c3 implements i { + public void f() throws java.net.ConnectException {} +} + +class c4 extends c3 { + public void f() throws java.net.ConnectException {} +} + +interface MethodsFromObject { + Object clone(); +} +interface im extends MethodsFromObject { +} +class cm implements MethodsFromObject { +} + +// sibling inheritance +class c5 { public void f() throws Exception {} } +interface i5 { void f(); } +class c6 extends c5 implements i5 { +} + +// overriding method does not throw exception, its OK +class c { + protected Object clone() { + return null; + } +} +interface i6 { + +} +class b extends c implements i6 { + +} + + +//-------------- methods with same signature +interface AContract +{ + void invoke () throws Exception; +} + +class A implements AContract +{ + public void invoke () throws Exception { } +} + +interface BContract +{ + void invoke (); +} + +class B extends A implements BContract +{ + public void invoke () { } +} + +class C extends B +{ +} + + +////////////////////// +class Bug extends AbstrColl implements java.io.Serializable { +} +interface Coll { + boolean equals(Object f); +} +class AbstrColl implements Coll {} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/QualifiedNew.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/QualifiedNew.java new file mode 100644 index 000000000000..28ed2c23d5e9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/QualifiedNew.java @@ -0,0 +1,19 @@ +// Qualified new of static class + +class A { + b b; + A() { + b.new c(); + b.new inner(); + } + class inner {} + + void f() { + char[] c = b.new char[0]; + } +} + +class b extends A { + static class c {} +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/QualifiedSuper.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/QualifiedSuper.java new file mode 100644 index 000000000000..24c34449db3e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/QualifiedSuper.java @@ -0,0 +1,48 @@ +class Outer { + class Inner1 extends Outer { + Inner1() {} + Inner1(Outer o) {} + } + + class Inner2 extends Inner1 { + public Inner2(Object o) { + o.super(); + } + public Inner2(int o) { + Outer.this.super(); + } + public Inner2(Outer o) { + o.super(Outer.this); + } + public Inner2(Outer o, int par) { + o.super(this); + } + public Inner2(Outer o, Object par) { + this.super(o); + } + } + + class BadInner extends Inner1 { + BadInner() {} + } + class BadInner2 extends Inner1 { + } + + class s { + void f(Object o) { + new s(); + Outer.this.new s(); + } + } +} + +class Outer2 { + class Inner {} +} +class Ext extends Outer2 { + class ExtInner extends Inner { + ExtInner() { + super(); + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/QualifierBeforeClassName.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/QualifierBeforeClassName.java new file mode 100644 index 000000000000..1edd34fe5247 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/QualifierBeforeClassName.java @@ -0,0 +1,14 @@ +class E { + class Outer { + class S { + public static final int SS = 0; + } + } + + Outer f() { + int s = f().S.SS; + int s1 = this.Outer.S.SS; + int s2 = Outer.S.SS; + return null; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ReferenceMemberBeforeCtrCalled.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ReferenceMemberBeforeCtrCalled.java new file mode 100644 index 000000000000..149f62c06438 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/ReferenceMemberBeforeCtrCalled.java @@ -0,0 +1,154 @@ +// reference before ctr called +import java.io.*; +import java.net.*; + +class a { + a(int i) {} + a(a a) {} + int f() { return 0; } + int fi; +} + +class b extends a { + int bi; + b(int h) { + super(bi); + } + b() { + this(bi); + } + + b(String s) { + super(db(1) ); + } + + b(int i, int j) { + super(f()); + } + b(int i, int j, int k) { + super(super.f()); + } + + b(String s, int i) { + super(s.length()); + } + + b(int s, int i, char j) { + super(super.fi ); + } + + b(double d) { + super(new inner() ); + } + class inner extends a {inner(){super(1);}} + + int db(int j) { + return 0; + } +} + + +class enc { + int ienc; + class bb extends a { + int ibb; + bb() { super(ienc); } + bb(int i) { + super(i); + } + + bb(int i, int j) { + super(enc.bb.this.ibb ); + } + + bb(int i, String s) { + super(enc.this.ienc); + } + + bb(int i, char j) { + super(this ); + } + + + } + + enc() { + this(new bb()); + } + enc(bb b) {} +} + +// static are OK +class c2 extends a { + static final int fi = 4; + c2() { + super(fi); + } + c2(int i) { + super(sf()); + } + static int sf() { return 0; } + + c2(int i, int j) { + super(new sc().i); + } + static class sc { + int i; + } + +} + +interface Callback { + void call(); +} + +class Base { + Callback callback; + + public Base(final Callback callback) { + this.callback = callback; + } +} + +class YellinBug extends Base { + + public YellinBug() { + super(new Callback() { + + public void call() { + YellinBug.this.f(); + } + }); + } + + private void f() {} + + { + new Callback() { + + public void call() { + YellinBug.this.f(); + } + }; + } +} + +class Outer { + class Inner extends Outer{} + class UseIt extends Inner{ + Outer o; + UseIt() { + o.super(); + } + + Outer geto() { + return null; + } + UseIt(int x) { + geto().super(); + } + UseIt(Outer x) { + this.super(); + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Return.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Return.java new file mode 100644 index 000000000000..f75c60247282 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Return.java @@ -0,0 +1,20 @@ +class s { + void f() { + return 0; + } + void f2() { + return; + } + + int f3() { + return; + } + int f4() { + return 0; + } + + { + return; + + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/SerializableStuff.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/SerializableStuff.java new file mode 100644 index 000000000000..d339899e8e20 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/SerializableStuff.java @@ -0,0 +1,77 @@ +// Serializable/externalizable specific + +import java.io.*; +class a implements Serializable { + private void readObject(ObjectInputStream stream) + throws IOException, ClassNotFoundException { + if (stream == null) throw new IOException(); + if (stream == null) throw new ClassNotFoundException(); + } + + private void readObjectNoData() throws ObjectStreamException { + if (this == null) throw new ObjectStreamException(){}; + } + + + private Object readResolve() + throws ObjectStreamException { + if (this == null) throw new ObjectStreamException(){}; + return null; + } + + private Object writeReplace() { return null; } + private void writeObject(ObjectOutputStream stream) { if (stream==null) return; } + + +} + +class b { + private void readObject(ObjectInputStream stream) + throws IOException, ClassNotFoundException { + if (stream == null) throw new IOException(); + if (stream == null) throw new ClassNotFoundException(); + } + + private void readObjectNoData() throws ObjectStreamException { + if (this == null) throw new ObjectStreamException(){}; + } + + + private Object readResolve() + throws ObjectStreamException { + if (this == null) throw new ObjectStreamException(){}; + return null; + } + + private Object writeReplace() { return null; } + private void writeObject(ObjectOutputStream stream) { if (stream==null) return; } +} + +//////////////////////////// +abstract class e implements Externalizable { +} +class eImpl extends e { + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + } + + public void writeExternal(ObjectOutput out) throws IOException { + } +} +class eImpl1 extends e { + private eImpl1() {} + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + } + + public void writeExternal(ObjectOutput out) throws IOException { + } +} +class eImpl2 extends e { + public eImpl2(int i) { + System.out.print(i); + } + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + } + + public void writeExternal(ObjectOutput out) throws IOException { + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/SillyAssignment.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/SillyAssignment.java new file mode 100644 index 000000000000..8c270c2198e3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/SillyAssignment.java @@ -0,0 +1,37 @@ +// silly asignment +import javax.swing.*; + +class a { + int f; + JPanel fpanel; + + void f(int i) { + + i = i; + } + + void f2() { + this.f = f; + a.this.f = f; + f = this.f; + } + + void f3(Object o) { + int i = 0; + i = i; + i = (int)i; + o = ((Object)(o)); + } + void f4() { + fpanel.getSize().height = this.fpanel.getSize().height; // not silly. Are you sure you can bet getSize() has no side effects? + } + + void cf1() { + JPanel a = new JPanel(), b = new JPanel(); + a.getSize().height = b.getSize().height; // not silly! + } + + void cf2(a aa) { + aa.f = f; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/StaticOverride.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/StaticOverride.java new file mode 100644 index 000000000000..2229311ad290 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/StaticOverride.java @@ -0,0 +1,132 @@ +// method override +import java.io.*; +import java.net.*; + +public class a extends a1 { + public static void f() { } + public void f1() { } +} +class a1 { + public void f() {} + public static void f1() {} +} + +interface i { + void f1(); +} + +class c_a1_i extends a1 implements i { +} + +interface ii { + int f(); +} + +abstract class c_a1_ii extends a1 implements ii { +} + +interface i2 { + int f1(); +} +interface i3 extends i, i2 { +} + +class weak { + void f1() {} +} +class a2 extends weak implements i { +} + +class a3 { + protected void f1() {} +} +class a4 extends a3 implements i { +// public void f1() {} +} +class a5 extends a3 implements i { + // if we override suspicious method, its OK + public void f1() {} +} + + + +// deep inherit +class da1 { void f() {} } +class da2 extends da1 { void f() {} } +class da3 extends da2 {} + + + + +interface MyInterface +{ + public void myMethod(); +} +class MyInterfaceImpl implements MyInterface +{ + public static void myMethod() { /* implementation goes here */ } + + private static String toString() { + return null; + } + +} + + + +// Sun-style inheritance +public class Sunc { + protected void f() {} +} +public class Suncc extends Sunc { + public void f() {} +} +public interface Suni { + public void f(); +} +class Sunccc extends Suncc implements Suni { +} + +// override static +class StA { + public static StA createInstance() { + return new StA(); + } +} +class StB extends StA { + public static String createInstance() { + return null; + } +} + +//////// +class Foo { + protected static void foo(String s) {} +} +public class Bar extends Foo{ + private static void foo(String s) {} +} + + +///////////// IDEADEV-41779 +class A { + public static C C() { return new C(); } +} +class B extends A { +} +class C extends B { + public C() {} +} +/////////////////////////// +class Z1 { + public static final void doItBaby() { + System.out.println("Hello, diar A"); + } +} + +class Z2 extends Z1 { + public static void doItBaby() { + System.out.println("Hello, diar B"); + } +} +/////////////////// \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/StringSwitchLabels.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/StringSwitchLabels.java new file mode 100644 index 000000000000..9b8f99b1946d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/StringSwitchLabels.java @@ -0,0 +1,23 @@ +public class Test { + private static final String BAZ = "baz"; + + private void stringSwitch() { + final String bar = "bar"; + String key = "key"; + switch (key) { + case "": { + System.out.println("Nothing"); + break; + } + case "foo": + case bar: + case BAZ: { + System.out.println("Matched key"); + break; + } + default: + break; + } + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Suppressed.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Suppressed.java new file mode 100644 index 000000000000..9ee533fa0faf --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Suppressed.java @@ -0,0 +1,8 @@ +public class Suppressed { + private static final String UNUSED_DECLARATION = "UnusedDeclaration"; + + @java.lang.SuppressWarnings(UNUSED_DECLARATION) + public static void main(String[] args) { + int i = 0; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnhandledMessingWithFinally.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnhandledMessingWithFinally.java new file mode 100644 index 000000000000..de6502774d09 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnhandledMessingWithFinally.java @@ -0,0 +1,84 @@ +// unhandled exception when messing with finally block + +import java.io.*; +class a { + void f1(int i) { + try { + new FileReader(""); + } + finally { + throw new ClassNotFoundException(); + } + } + + void f2(int i) { + try { + new FileReader(""); + } + finally { + if (i==4) throw new ClassNotFoundException(); + } + } + + void f3(int i) { + try { + new FileReader(""); + } + finally { + if (i==1) return; + } + } + + void f4(int i) { + try { + new FileReader(""); + } + finally { + if (i==1) throw new FileNotFoundException(); + } + } + + void cf1(int i) { + try { + new FileReader(""); + } + catch (FileNotFoundException e) { + } + finally { + if (1==1) return; + } + } + + void cf2(int i) { + try { + new FileReader(""); + } + finally { + while (1==1) return; + } + } + void foo(OutputStream out, byte[] data) throws IOException { + out.write(data); + } + + public void swallow() { + try { + throw new Exception("Hello World! I'm Checked Exception and must be declared!"); + } catch (Exception e) { + throw e; + } finally { + return; + } + } + public void spitout() { + try { + throw new Exception("Hello World! I'm Checked Exception and must be declared!"); + } catch (Exception e) { + throw e; + } finally { + //return; + } + } + +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Unreachable.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Unreachable.java new file mode 100644 index 000000000000..9b419b3b4b08 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Unreachable.java @@ -0,0 +1,359 @@ +// unreachables +import java.io.*; +import java.net.*; +public class a { +interface ii {} + + { // initializer + try { + throw new Exception(); + int i = 5; + } + catch (Exception e) { + } + } + + + int f1() throws Exception { + return 2; + return 5; + } + int f2(int i) throws Exception { + if (i==2) return 2; + throw new Exception(); + return 5; + } + int f3(int i) throws Exception { + for (;;) return 2; + return 5; + } + int f4(int i) throws Exception { + try { + if (i==3) throw new Exception(); + return 4; + } finally { + if (i==6) return 9; + } + return 5; + } + + void f5() + { + try { + } catch (Error e) { + throw e; + ; + } + } + + void f6() { + try { + } + finally { + return; + ; + } + } + + void f7(RuntimeException e) { + for (;;) { + if (e==null) { + return; + break; + } + } + } + void f8(RuntimeException e,int i,int j,int k,int l) { + for (;;) { + if (e==null) { + return; + f8(e,i,j,k,l); + } + } + } + void f9(RuntimeException e,int i,int j,int k,int l) { + for (;;) { + if (e==null) { + return; + throw e; + } + } + } + class Af10 { + int f() { + return 0; + new Af10(); + } + + } + class Af11 { + int f() { + return 0; + int k; + } + void test() { + int i; + return; + assert i == i; + } + } + + + + int cf1(int i) throws Exception { + if (i==2) return 2; + for (int k=0;1==1;k++) break; + try { + i = 5; + } + catch (Error e) { + if (i==5) return 2; + } + catch (RuntimeException e) { + } + catch (Throwable e) { + } + + return 5; + } + + int cf2(int i) throws Exception { + switch (i) { + case 1: return 4; + } + return 5; + } + void cf3() { + if (false) { + int i = 5; + } + while (true) { break; } + if (true) { + int i = 4; + } + else { + int i = 6; + } + } + void cf4() throws java.net.SocketException { + try { + bind(); + } catch (java.net.SocketException se) { + throw se; + } catch(java.io.IOException e) { + throw new java.net.SocketException(e.getMessage()); + } + } + void bind() throws java.net.SocketException {} + + + void cf5() { + try { + } catch(Exception e) { + + } + } + + void cf6() { + if (true || true) { + } else { + System.out.println("hi"); + } + } + + + static boolean g() { + return true; + } + public static void main(String[] args) { + boolean b=false && g(); + System.out.println("b = "+b); + } + + + + void cf7() { + try { + } finally { + try { + } finally { + } + try { + } finally { + try { + } finally { + } + try { + } finally { + try { + } finally { + try { + } finally { + try { + } finally { + try { + } finally { + } + } + } + } + try { + try { + } finally { + } + } finally { + } + } + } + } + ; + } + + void cf8() { + class Test01 + { + + public int testMethod() + { + try + { + throw new Exception("test"); + } + catch(Exception e) + { + try + { + throw new Exception("test"); + } + catch(Exception ee) + {} + finally + {} + } + finally + { + + try + { + throw new Exception("test"); + } + catch(Exception e) + {} + finally + {} + } + return 0; + } + } + } + + void cf9() { + // should not try to compute constant expression within assert + // since assertions can be disabled/enabled at any moment via JVM flags + assert true; + assert false; + final int i; + if (0==1) { + i = 9; + } + else { + i = 0; + } + } + + void cf10() { + int k = 0; + switch (k) { + } + } + + + private Exception getException() + { + return new java.io.IOException(); + } + + public void cf11() + { + try { + throw getException(); + } + catch (java.io.IOException e) { + e.printStackTrace(); // IDEA claims this to be "Unreachable statement"// + } + catch (Exception e) { + e.printStackTrace(); + } + } + + ////////////////////////// + public void cf12() { + try { + try { + } finally { + doit(); + } + } catch (Excep1 e) { + String error = "RollbackException"; + } catch (Excep2 e) { + String error = "HeuristicRollbackException"; + } catch (Excep3 e) { + String error = "SystemException"; + } catch (IllegalStateException e) { + String error = "IllegalStateException"; + } catch (RuntimeException e) { + String error = "RuntimeException"; + } + } + + private void doit() throws Excep1, Excep2, Excep3{ + //To change body of created methods use Options | File Templates. + } + + class Excep1 extends Exception {} + class Excep2 extends Exception {} + class Excep3 extends Exception {} + + + + + public void cf13() throws Exception { + while (true) { + try { + cf13(); + } finally { + continue; + } + } + } + +} + + +class NestedFinallyTest { + void ftest4() { + try { + } + finally { + try { + } + finally { + try { + } + finally { + try { + } + catch (Throwable t4) { + } + } + } + } + ftest4(); + } +} + + + + + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Unused.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Unused.java new file mode 100644 index 000000000000..bcbcd279de6d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/Unused.java @@ -0,0 +1,46 @@ +public class a extends Exception { + private a(String s) { + super(s); + } +} + +class s extends Exception { + private s(String s) { + super(s); + } + public s create() { + return new s(""); + } +} + +class PrivateClassTest { + private static class Test1 { + // Complains that this constructor is never used + private Test1 () {} + + private Test1 (String s) { + System.out.println(s); + } + } + + private static class Test2 extends Test1 { + // Complains that no default constructor is available + public Test2 () { + } + + // Complains that the relevant constructor has private access + public Test2 (String s) { + super (s); + } + } + public static void main(String[] args) { + System.out.println(new Test2()); + } + + private void f(boolean b, + int param) { + if (b) { + f(b, param); + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedNonPrivateMembers.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedNonPrivateMembers.java new file mode 100644 index 000000000000..9f3a7b47cbb8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedNonPrivateMembers.java @@ -0,0 +1,19 @@ +public class XXX { + void fffff(){} + public void asdfaffffff(){} + protected void dasklfjhsad(){} + + String asdfadsf; + public String asdasdfadsf; + static class sasdfasdfasd {} + + public XXX() {} + + + // overloaded + void fffff(String i){i.hashCode();} + { + fffff(null); + } +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedNonPrivateMembers2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedNonPrivateMembers2.java new file mode 100644 index 000000000000..b7ae475f9e66 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedNonPrivateMembers2.java @@ -0,0 +1,9 @@ +public class WithMain { + + public static void main(String[] args){ + + } + + public void myTestMethod(){} +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedParamsOfPublicMethod.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedParamsOfPublicMethod.java new file mode 100644 index 000000000000..2af80d1fadc8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedParamsOfPublicMethod.java @@ -0,0 +1,19 @@ +class Sup { + protected void f(int i){} +} +class Foo extends Sup { + public void foo(int i){} + public void g(int i){} + protected void f(int i){} +} +class Sub extends Foo { + public void g(int i){} +} + + +interface fff { + void f(int ggggg);// +} +abstract class ab { + public abstract void f(int ggggg);// +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedParamsOfPublicMethodDisabled.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedParamsOfPublicMethodDisabled.java new file mode 100644 index 000000000000..994ccbab4a9d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/UnusedParamsOfPublicMethodDisabled.java @@ -0,0 +1,19 @@ +class Sup { + protected void f(int i){} +} +class Foo extends Sup { + public void foo(int i){} + public void g(int i){} + protected void f(int i){} +} +class Sub extends Foo { + public void g(int i){} +} + + +interface fff { + void f(int ggggg);// +} +abstract class ab { + public abstract void f(int ggggg);// +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/VariableAlreadyDefined.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/VariableAlreadyDefined.java new file mode 100644 index 000000000000..f549f26717cd --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/VariableAlreadyDefined.java @@ -0,0 +1,34 @@ +class s { + void f() { + int i; + int i; + } + void f1() { + int i; + { + int i; + } + } + void f2() { + int i; + class ss + { + int i; + } + } + + int f; + int f; + void f3() { + int f; + } + + public void tutu(String e) { + try { + Integer.parseInt("3"); + } catch (NumberFormatException e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/VariableAlreadyDefinedTop.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/VariableAlreadyDefinedTop.java new file mode 100644 index 000000000000..e50eb1dc49d2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/VariableAlreadyDefinedTop.java @@ -0,0 +1,25 @@ +class s { + void f() { + int i; + int i; + } + void f1() { + int i; + { + int i; + } + } + void f2() { + int i; + class ss + { + int i; + } + } + + int f; + int f; + void f3() { + int f; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/XXX.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/XXX.java new file mode 100644 index 000000000000..0a9a173f2347 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/XXX.java @@ -0,0 +1,5 @@ +import java.io.*; + +public class x { + static {int i;} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a10.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a10.java new file mode 100644 index 000000000000..a2514171a827 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a10.java @@ -0,0 +1,31 @@ +// string literal +public class a { + char c1 = ''; + char c2 = '\dd'; + char c4 = 'xxx'; + char c5 = '\78'; + char c6 = '\78'; + + char[] cA = new char[] { 'd','\b','\f','\n','\r' + ,'\t','"','\\',' ','\u1234','\uFFFF' + , '\7', '\77', '\345', '\0'}; + + String s1 = "\xd"; + String s11= "\udX"; + String s12= "c:\TEMP\test.jar"; + String s3 = ""; + String s4 = "\u0000"; + + String s5 = "\u000d"; + String s6 = "\u000a"; + char c7 = '\u000d'; + char c8 = '\u000a'; + + + void foo(String a) { + foo("aaa + ); + } + + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a11.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a11.java new file mode 100644 index 000000000000..1edc0de72d6c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a11.java @@ -0,0 +1,106 @@ +//statics in inner +public class a { + + static final Number x = null; + static final int ix = x== null ? 4 : 3; + + class ic { + static + int i; + + static + final int f1 = 3 < 4 ? (a.ix==5 ? 1 : 3) / 4 + 18 : 0; + + static + final int f2 = x instanceof Integer ? 1 : 0; + + static + class a_ic_c {} + + interface a_ic_i {} + static interface a_ic_i2 {} + + static + int a_ic_m(String s) { return 0; } + + // static initializer + static + {} + } + + + interface ii { + static int i = 9; + void f(); + // since nested interface is implicitly static: + static class ii_c {} + } + + // static inside class inside code block + void f() { + class ic2 { + static + int i; + + static + final int f1 = 3 < 4 ? (a.ix==5 ? 1 : 3) / 4 + 18 : 0; + + static + final int f2 = x instanceof Integer ? 1 : 0; + + static + class a_ic_c2 {} + + static + int a_ic_m2(String s) { return 0; } + // static initializer + static + {} + } + } + + void f1() + { + new a() { + static + int i; + + static + final int f1 = 3 < 4 ? (a.ix==5 ? 1 : 3) / 4 + 18 : 0; + + // its not a compile time constant + static + final Object o = null; + + static + final int f2 = x instanceof Integer ? 1 : 0; + + static + class a_ic_c2 {} + + static + int a_ic_m2(String s) { return 0; } + // static initializer + static + {} + }; + } + + // local interface + class cc { + void f() { + interface i {} + } + void ff() { + class inn { + interface i {} + } + } + + Object o = new Runnable() { + interface i {} + public void run() {} + }; + } +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a16.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a16.java new file mode 100644 index 000000000000..8622224336d0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a16.java @@ -0,0 +1,102 @@ +// casts +public class a { + void f(i ii) { + boolean b; + b = 2 instanceof a; + b = null instanceof int; + b = (c3)null instanceof Boolean; + + b = ii instanceof i; + b = ((c2)ii) instanceof c4; + b = null instanceof a; + b = ii instanceof c3; + b = Boolean.valueOf("true") instanceof Boolean; + b = new Long(3) instanceof Number; + b = this instanceof a; + b = ii instanceof a; + b = this instanceof i; + + + // casts + c2 c2i = null; + c3 c3i = null; + c4 c4i = null; + Object o; + c4i = (c4) this; + o = (boolean) c2i; + o = (Integer) c3i; + o = (a) c2i; + o = (int) c3i; + + o = (a) ii; + o = (i) c4i; //cast to interface + o = (c3) c2i; + o = (c3) c3i; + o = (c3) c4i; + o = (Object) ii; + o = (iunrelated) ii; + o = (iunrelated) c2i; + o = (c4) c2i; + o = (c4) ii; + o = (c5) ii; + + int[] ai = null; + o = (byte[])ai; + o = (double[])ai; + c3[] ac3i = null; + o = ac3i; + o = (c4[])ac3i; + o = (i[])ac3i; + Object[] results = null; + int index = ((Integer) results).intValue(); + + + // arrays and Serializable/Cloneable/Object + int[] ai2 = (int[])o; + Cloneable cloneable = null; + ai2 = (int[]) cloneable; + java.io.Serializable serializable = null; + ai2 = (int[]) serializable; + + } + +} + +interface iunrelated {} +interface i {} +class c2 implements i { + public c2() {} + public void f() {} + protected void g() {} +} + +class c3 extends c2 { + protected c3() {} + private int g(int k) { return 0; } +} + +final class c4 extends c3 { + private c4() { + int[] a=new int[3]; + Cloneable s=a; + java.io.Serializable ss = a; + } +} +final class c5 {} + +// clashing interfaces +interface A { + void g(); +} +interface B { + int g(); +} +interface BB extends B { +} +class Foo { + void f(A a) { + B b = (B) a; + BB b2 = (BB) a; + A a2 = (A) b2; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a18.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a18.java new file mode 100644 index 000000000000..5a3b705d1aeb --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a18.java @@ -0,0 +1,1059 @@ +//Missing return statement +import java.io.*; +import java.net.*; +public class a { +interface ii {} + + + + int f1() throws Exception { + } + + Object f2(int i) throws Exception { + if (i == 0) return null; + } + + Object f3(int i) throws Exception { + while (i == 0) return null; + } + + Object f4(int i) throws Exception { + switch (i) { + case 1: return null; + } + } + + Object f5(int i) throws Exception { + if (i==2) return null; + else if (i != 2) return null; + } + + Object f6(int i) throws Exception { + if (true) return null; + } + + int f7(int i) { + try { + if (i==2) return 4; + else throw new IllegalArgumentException(); + } catch (Exception e) { + } + } + + int f8(int i) { + try { + //throw new Error(); + } + finally { + try { + //throw new Exception(); + } + catch (Exception e) { + return 5; + } + } + } + + int cf1(int i) { + return 0; + } + int cf2(int i) { + if (i==2) return 0; + else if (i==4) return -1; + else return 2; + } + int cf3(int i) { + return i==2 ? 3 : 5; + } + int cf4(int i) { + switch (i) { + case 1: return 4; + case 3: return 6; + default: return 5; + } + } + int cf5(int i) { + if (i>1) { + if (i==4) return 0; + else return i==3 ? 2 : 0; + } + else return 2; + } + int cf6(int i) { + return cf4(i+1); + } + + int cf7(int i) throws Exception { + try { + throw new Exception(); + } catch(Error e) { + return 3; + } finally { + return 2; + } + + } + + int cf8(int i) throws Exception { + try { + return 2; + } finally { + return 4; + } + } + int cf9(int i) throws Exception { + try { + i = 5; + } finally { + throw new Exception(); + } + } + + int cf10(int i) { + + while (true) + return 0; + } + int cf11(int i) { + + // commented out reference + // does not work when running under JRE + + while (a.co != 2 && 1+3/2-1 + (int)1.5 + 2%2 == 2 /* && 0x7fffffff == Integer.MAX_VALUE */ && ('c' & 0x00) == 0) + return 0; + } + private static final int co = 1/2 + 1; + int cf12(int i) { + + for (int k=0; (0xf0 | 0x0f) == 0xff && false != true && co == 1;k++) + return 0; + } + + + int cf13() { + try { + try { + throw new IllegalArgumentException(); + //throw new java.io.IOException(); + } catch (IllegalArgumentException e) { + return 3; + } + finally { + throw new java.io.IOException(); + } + + } catch (java.io.IOException ee) { + return 88; + } + } + + int cf14() { + try { + cf13(); + return 13; + } finally { + cf13(); + } + } + + int cf15() { + try { + int i=0; + return i; + } catch (Exception e) { + } finally { + } + return 0; + } + int cf16() { + try { + if ( ! (1==3)) { + return 0; + } + } finally { + // Restore the current position of the other DynAny + } + return 1; + } + + int cf17() { + try { + try { + return 0; + } finally { + } + } finally { + } + } + int cf18(int i) { + int k; + try { + if (i==4) return 0; + k = 4; + } finally { + } + return k; + } + + + void cf19() { + + try { + + try { + } + finally { + } + return ; + } + catch (Exception e) { + } + } + +} + + class a2 { +interface ii {} + + + + int f1() throws Exception { + } + + Object f2(int i) throws Exception { + if (i == 0) return null; + } + + Object f3(int i) throws Exception { + while (i == 0) return null; + } + + Object f4(int i) throws Exception { + switch (i) { + case 1: return null; + } + } + + Object f5(int i) throws Exception { + if (i==2) return null; + else if (i != 2) return null; + } + + Object f6(int i) throws Exception { + if (true) return null; + } + + int f7(int i) { + try { + if (i==2) return 4; + else throw new IllegalArgumentException(); + } catch (Exception e) { + } + } + + int f8(int i) { + try { + //throw new Error(); + } + finally { + try { + //throw new Exception(); + } + catch (Exception e) { + return 5; + } + } + } + + int cf1(int i) { + return 0; + } + int cf2(int i) { + if (i==2) return 0; + else if (i==4) return -1; + else return 2; + } + int cf3(int i) { + return i==2 ? 3 : 5; + } + int cf4(int i) { + switch (i) { + case 1: return 4; + case 3: return 6; + default: return 5; + } + } + int cf5(int i) { + if (i>1) { + if (i==4) return 0; + else return i==3 ? 2 : 0; + } + else return 2; + } + int cf6(int i) { + return cf4(i+1); + } + + int cf7(int i) throws Exception { + try { + throw new Exception(); + } catch(Error e) { + return 3; + } finally { + return 2; + } + + } + + int cf8(int i) throws Exception { + try { + return 2; + } finally { + return 4; + } + } + int cf9(int i) throws Exception { + try { + i = 5; + } finally { + throw new Exception(); + } + } + + int cf10(int i) { + + while (true) + return 0; + } + private static final int co = 1/2 + 1; + int cf12(int i) { + + for (int k=0; (0xf0 | 0x0f) == 0xff && false != true && co == 1;k++) + return 0; + } + + + int cf13() { + try { + try { + throw new IllegalArgumentException(); + //throw new java.io.IOException(); + } catch (IllegalArgumentException e) { + return 3; + } + finally { + throw new java.io.IOException(); + } + + } catch (java.io.IOException ee) { + return 88; + } + } + + int cf14() { + try { + cf13(); + return 13; + } finally { + cf13(); + } + } + + int cf15() { + try { + int i=0; + return i; + } catch (Exception e) { + } finally { + } + return 0; + } + int cf16() { + try { + if ( ! (1==3)) { + return 0; + } + } finally { + // Restore the current position of the other DynAny + } + return 1; + } + + int cf17() { + try { + try { + return 0; + } finally { + } + } finally { + } + } + int cf18(int i) { + int k; + try { + if (i==4) return 0; + k = 4; + } finally { + } + return k; + } + + + void cf19() { + + try { + + try { + } + finally { + } + return ; + } + catch (Exception e) { + } + } + +} + + + class a3 { +interface ii {} + + + + int f1() throws Exception { + } + + Object f2(int i) throws Exception { + if (i == 0) return null; + } + + Object f3(int i) throws Exception { + while (i == 0) return null; + } + + Object f4(int i) throws Exception { + switch (i) { + case 1: return null; + } + } + + Object f5(int i) throws Exception { + if (i==2) return null; + else if (i != 2) return null; + } + + Object f6(int i) throws Exception { + if (true) return null; + } + + int f7(int i) { + try { + if (i==2) return 4; + else throw new IllegalArgumentException(); + } catch (Exception e) { + } + } + + int f8(int i) { + try { + //throw new Error(); + } + finally { + try { + //throw new Exception(); + } + catch (Exception e) { + return 5; + } + } + } + + int cf1(int i) { + return 0; + } + int cf2(int i) { + if (i==2) return 0; + else if (i==4) return -1; + else return 2; + } + int cf3(int i) { + return i==2 ? 3 : 5; + } + int cf4(int i) { + switch (i) { + case 1: return 4; + case 3: return 6; + default: return 5; + } + } + int cf5(int i) { + if (i>1) { + if (i==4) return 0; + else return i==3 ? 2 : 0; + } + else return 2; + } + int cf6(int i) { + return cf4(i+1); + } + + int cf7(int i) throws Exception { + try { + throw new Exception(); + } catch(Error e) { + return 3; + } finally { + return 2; + } + + } + + int cf8(int i) throws Exception { + try { + return 2; + } finally { + return 4; + } + } + int cf9(int i) throws Exception { + try { + i = 5; + } finally { + throw new Exception(); + } + } + + int cf10(int i) { + + while (true) + return 0; + } + private static final int co = 1/2 + 1; + int cf12(int i) { + + for (int k=0; (0xf0 | 0x0f) == 0xff && false != true && co == 1;k++) + return 0; + } + + + int cf13() { + try { + try { + throw new IllegalArgumentException(); + //throw new java.io.IOException(); + } catch (IllegalArgumentException e) { + return 3; + } + finally { + throw new java.io.IOException(); + } + + } catch (java.io.IOException ee) { + return 88; + } + } + + int cf14() { + try { + cf13(); + return 13; + } finally { + cf13(); + } + } + + int cf15() { + try { + int i=0; + return i; + } catch (Exception e) { + } finally { + } + return 0; + } + int cf16() { + try { + if ( ! (1==3)) { + return 0; + } + } finally { + // Restore the current position of the other DynAny + } + return 1; + } + + int cf17() { + try { + try { + return 0; + } finally { + } + } finally { + } + } + int cf18(int i) { + int k; + try { + if (i==4) return 0; + k = 4; + } finally { + } + return k; + } + + + void cf19() { + + try { + + try { + } + finally { + } + return ; + } + catch (Exception e) { + } + } + +} + + + + class a4 { +interface ii {} + + + + int f1() throws Exception { + } + + Object f2(int i) throws Exception { + if (i == 0) return null; + } + + Object f3(int i) throws Exception { + while (i == 0) return null; + } + + Object f4(int i) throws Exception { + switch (i) { + case 1: return null; + } + } + + Object f5(int i) throws Exception { + if (i==2) return null; + else if (i != 2) return null; + } + + Object f6(int i) throws Exception { + if (true) return null; + } + + int f7(int i) { + try { + if (i==2) return 4; + else throw new IllegalArgumentException(); + } catch (Exception e) { + } + } + + int f8(int i) { + try { + //throw new Error(); + } + finally { + try { + //throw new Exception(); + } + catch (Exception e) { + return 5; + } + } + } + + int cf1(int i) { + return 0; + } + int cf2(int i) { + if (i==2) return 0; + else if (i==4) return -1; + else return 2; + } + int cf3(int i) { + return i==2 ? 3 : 5; + } + int cf4(int i) { + switch (i) { + case 1: return 4; + case 3: return 6; + default: return 5; + } + } + int cf5(int i) { + if (i>1) { + if (i==4) return 0; + else return i==3 ? 2 : 0; + } + else return 2; + } + int cf6(int i) { + return cf4(i+1); + } + + int cf7(int i) throws Exception { + try { + throw new Exception(); + } catch(Error e) { + return 3; + } finally { + return 2; + } + + } + + int cf8(int i) throws Exception { + try { + return 2; + } finally { + return 4; + } + } + int cf9(int i) throws Exception { + try { + i = 5; + } finally { + throw new Exception(); + } + } + + int cf10(int i) { + + while (true) + return 0; + } + private static final int co = 1/2 + 1; + int cf12(int i) { + + for (int k=0; (0xf0 | 0x0f) == 0xff && false != true && co == 1;k++) + return 0; + } + + + int cf13() { + try { + try { + throw new IllegalArgumentException(); + //throw new java.io.IOException(); + } catch (IllegalArgumentException e) { + return 3; + } + finally { + throw new java.io.IOException(); + } + + } catch (java.io.IOException ee) { + return 88; + } + } + + int cf14() { + try { + cf13(); + return 13; + } finally { + cf13(); + } + } + + int cf15() { + try { + int i=0; + return i; + } catch (Exception e) { + } finally { + } + return 0; + } + int cf16() { + try { + if ( ! (1==3)) { + return 0; + } + } finally { + // Restore the current position of the other DynAny + } + return 1; + } + + int cf17() { + try { + try { + return 0; + } finally { + } + } finally { + } + } + int cf18(int i) { + int k; + try { + if (i==4) return 0; + k = 4; + } finally { + } + return k; + } + + + void cf19() { + + try { + + try { + } + finally { + } + return ; + } + catch (Exception e) { + } + } + +} + + class a5 { +interface ii {} + + + + int f1() throws Exception { + } + + Object f2(int i) throws Exception { + if (i == 0) return null; + } + + Object f3(int i) throws Exception { + while (i == 0) return null; + } + + Object f4(int i) throws Exception { + switch (i) { + case 1: return null; + } + } + + Object f5(int i) throws Exception { + if (i==2) return null; + else if (i != 2) return null; + } + + Object f6(int i) throws Exception { + if (true) return null; + } + + int f7(int i) { + try { + if (i==2) return 4; + else throw new IllegalArgumentException(); + } catch (Exception e) { + } + } + + int f8(int i) { + try { + //throw new Error(); + } + finally { + try { + //throw new Exception(); + } + catch (Exception e) { + return 5; + } + } + } + + int f9(int i) { + if (i==1) return 0; + else assert false; + } + + + + int cf1(int i) { + return 0; + } + int cf2(int i) { + if (i==2) return 0; + else if (i==4) return -1; + else return 2; + } + int cf3(int i) { + return i==2 ? 3 : 5; + } + int cf4(int i) { + switch (i) { + case 1: return 4; + case 3: return 6; + default: return 5; + } + } + int cf5(int i) { + if (i>1) { + if (i==4) return 0; + else return i==3 ? 2 : 0; + } + else return 2; + } + int cf6(int i) { + return cf4(i+1); + } + + int cf7(int i) throws Exception { + try { + throw new Exception(); + } catch(Error e) { + return 3; + } finally { + return 2; + } + + } + + int cf8(int i) throws Exception { + try { + return 2; + } finally { + return 4; + } + } + int cf9(int i) throws Exception { + try { + i = 5; + } finally { + throw new Exception(); + } + } + + int cf10(int i) { + + while (true) + return 0; + } + private static final int co = 1/2 + 1; + int cf12(int i) { + + for (int k=0; (0xf0 | 0x0f) == 0xff && false != true && co == 1;k++) + return 0; + } + + + int cf13() { + try { + try { + throw new IllegalArgumentException(); + //throw new java.io.IOException(); + } catch (IllegalArgumentException e) { + return 3; + } + finally { + throw new java.io.IOException(); + } + + } catch (java.io.IOException ee) { + return 88; + } + } + + int cf14() { + try { + cf13(); + return 13; + } finally { + cf13(); + } + } + + int cf15() { + try { + int i=0; + return i; + } catch (Exception e) { + } finally { + } + return 0; + } + int cf16() { + try { + if ( ! (1==3)) { + return 0; + } + } finally { + // Restore the current position of the other DynAny + } + return 1; + } + + int cf17() { + try { + try { + return 0; + } finally { + } + } finally { + } + } + int cf18(int i) { + int k; + try { + if (i==4) return 0; + k = 4; + } finally { + } + return k; + } + + + void cf19() { + + try { + + try { + } + finally { + } + return ; + } + catch (Exception e) { + } + } + int cf20(boolean b1, boolean b2) { + do { + } while (b1 || b2); + return 0; + } + + public boolean cf21() throws IOException { + try { + return geta(); + } + catch(IOException e) { + throw new RuntimeException(); + } + finally { + geta(); + } + } + private boolean geta() throws IOException { + return true; + } + + String complexAss(Object o, Object p) { + assert o != null && p != null; + return null; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a22.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a22.java new file mode 100644 index 000000000000..de0f4f0f6d6d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a22.java @@ -0,0 +1,150 @@ +// vars double initialization +import java.io.*; +import java.net.*; +public class a21 { + + void f1(int i) { + final int j; + j = 2; + j = 2; + } + void f2(int i) { + final int j; + if (i==3) j = 2; + else j = 5; + j = 2; + } + void f3(int i) { + final int j; + if (i==4) j = 2; + j = 2; + } + void f5(int i) { + final int j; + j = 2; + if (i==3) return; + j = 2; + } + void f6(int i) { + final int j; + switch (i) { + case 1: j = 2; + } + j = 2; + } + void f7(int i) { + final int j; + while (i < 4) { + j = 2; + final int ii = 4; + i+=ii; + } + + } + void f8(String k) { + if (k != null) { + final String i; + if (k.equals("!")) i = "3"; + if (k.equals("!")) i = "2"; + } + + } + + void f9() { + final Object type; + try { + type = null; + } + catch (Exception e) { + type = null; + } + } + + void f10() { + final int k; + if (false) { + k=0; + //< error descr="Variable 'k' might already have been assigned to">k< /error>=0; + } + } + +class Foo { + final int k; + Foo() { + k=0; + k=0; + } +} + + + + + void cf1(int i) { + final int j; + final int j1 = 3; + j = 5; + final int unused; + final int j2; + if (j == 3) j2 = 4; + final int j3; + if (j==4) j3 = 5; + else j3 = 6; + final int j4 = j3 + 6; + final int j5; + while (i != 9) { + if (j == 8) { + j5 = 9; + break; + } + } + } + + final boolean FB = true; + + void cf2() { + final int k; + if (!FB) { + k = 4; + } + // < error descr="Variable 'k' might already have been assigned to">k< /error>=0; + } + + + // todo: + // in IDEA Variable 'b' might not have been initialized + // in javac: OK + /* + void f2() { + boolean b; + boolean c = true; + if (c && false) { + c = b; + } + } + */ + +} + + +class A { + final int k; + A() { + for (;;) { + k=0; + } + } +} + +class Example { + public int method(boolean b) { + if (b) { + final int indent; + indent = 0; + + return 0; + } + else { + new Runnable(){} + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a22_1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a22_1.java new file mode 100644 index 000000000000..c3de37be1aa4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a22_1.java @@ -0,0 +1,118 @@ +// fields double initialization +import java.io.*; +import java.net.*; +class Foo { + final int k; + final int ff = 5; + Foo(int i) { + k =1; + } + { + k=0; + } +} + +class c2 { + static final int k; + static { + k=0; + } + c2() { + int i = k; + } + static { + k =1; + } +} + +class c3 { + final int k; + { + k=0; + } + c3() { + int i = k; + } + { + k =1; + } +} + +class c4 { + final int k; + { + k=0; + } + c4(int i) { + if (false) + k =1; + } + c4() { + this(0); + k =1; + } +} +// redirected ctrs +class c5 { + final int k; + c5(int i) { + k =1; + } + c5() { + this(0); + k =1; + } + + + c5(char c) { + } + c5(int i, int j) { + this('c'); + k = 5; + } + c5(String s) { + this(0,0); + k =1; + } +} + +class c6 { + final int i; + c6() { + this(0); + } + c6(int i) { + this(0,0); + } + c6(int k, int l) { + i = k; + } +} + + + +// multiple initalizers +class c7 { + private final String x; + { + x = "Hello"; + } + + private final String y; + { + y = x; + } + + private static int i; + { + int j = 0; + } + + static { + i = 9; + } + + { + y = ""+i; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a24.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a24.java new file mode 100644 index 000000000000..721be46f5005 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a24.java @@ -0,0 +1,178 @@ +// unhandled exceptions from superclases/etc +import java.io.*; +import java.net.*; +public class a { + a(int i) {} +} + +// super ctr + +class b extends a { +} + +class c extends a { + c() { + } + + c(String s) { + this(1); + } + c(int i) { + super(i); + } +} + +class A { + private A() {} + class B extends A {} +} + +class A1 { + A1() throws Exception {} +} + +class B1 extends A1 +{} + +class A2 extends A1 { + A2() {} +} + + +// exception thrown from within anonymous +class A3 { + void f() throws Exception { + new A3() { + int g() throws Exception { + return 0; + } + int k=g(); + }; + } +} + + +// in initializer +class Test{ + final String s = makeString(); + String makeString() throws Exception {throw new Exception();} +} + + +class C1 { + public C1() throws IllegalArgumentException {} +} +class C2 extends C1 { + public C2() { + } +} + +// private but accessible base ctr +class D1 { + private D1() {} + static class D2 extends D1 { + D2() { + System.out.println("!"); + } + } + + public static void main(String[] args) { + new D2(); + new D1(); + } +} + + +/////////////// +class MyClass +{ + public MyClass() throws Exception + { + //default ctor throws exc + } + + public MyClass(Object anObject) + { + //other ctor does not + } +} + +class MyClass2 extends MyClass +{ + //HERE good code is marked red + public MyClass2 (Object anObject) + { + super(anObject); + } +} + +class ThrowCC { + public void test3() throws Exception { + Throwable exception = null; + throw exception; + } +} + + +//Inaccessible field +class J { + int t = new I1().i; //access object class is OK + int v = new I2().i; //bad access object class + + class I1 { + class I3 { + int t = i; //visibility OK + } + + private int i; + } + + class I2 extends I1 { + int j = i; //We don't see i from baser class + } + + static I1 i1; + class I4 { + int u = i1.i; //OK, i is visible since the toplevel class is the same + } +} +class Test3 { + + private class Child extends Parent { + } + + private class Parent extends SuperParent { + } + + private class SuperParent { + private int field = 1; + } + + public void foo() { + Child child = new Child(); + int i = child.field; + } +} + +//IDEADEV-4455: this code is OK +class XYZ { + private class Inner extends XYZ { + private final String s; + Inner(String _s) { + this.s = _s; + } + + + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + final Inner y = (Inner) o; + + if (s != null ? !s.equals(y.s) : y.s != null) return false; + + return true; + } + } +} +//end of IDEADEV-4455 \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a25.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a25.java new file mode 100644 index 000000000000..e2f6b4435919 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a25.java @@ -0,0 +1,46 @@ +/// assignment compatible types +import java.io.*; +import java.net.*; +public class a { + final int FI = 2; + final int FIBIG = 200000000; + + + void f() { + // not marked: OK, as literal value is in byte-range + byte b1 = 1; + + // marked: OK, as literal value is out of byte-range and does not compile + byte b2 = 1000; + + // marked: OK, as char-value cannot be determined and does not compile + char c = 0; + byte b3 = c; + + // marked: OK, as literal char-value is out of byte-range and does not compile + byte b4 = '\u20AC'; + + byte b5 = '\n' - 4 + 1800; + // literal char-value is in byte-range and compiles fine + byte b6 = '\u007F'; + byte b7=(short) 0; + byte b8 = (long)0; + + float f1 = 77.3; + float f2 = 77.3F; + + short s1 = 1 + FI; + short s2 = 1000000; + short s3 = 'F' % FIBIG; + + char c1 = 0; + char c2 = -1 + FIBIG; + char c3=(byte) 0; + char c4=(short) 0; + char c5 = 0L; + + int i1='d'; + int i2 = 1L; + + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a28.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a28.java new file mode 100644 index 000000000000..f4630d248617 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a28.java @@ -0,0 +1,42 @@ +/// labels +import java.io.*; +import java.net.*; + +public class a { + + void f(final boolean b) { + while (b) break lab1; + while (b) continue lab1; + + for (;;) { + lab2: ; + break lab2; + continue lab2; + } + + lab3: + new Runnable() { + public void run() { + while (true) { + if (b) break lab3; + if (b) continue lab3; + } + } + }; + } + + void cf() { + boolean b = false; + while (b) { + lab0: break lab0; + } + + lab1: try { + lab2: for (;b;) if (1==3) continue lab2; + break lab1; + } + finally { + break lab1; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a30.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a30.java new file mode 100644 index 000000000000..88dd9534444e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a30.java @@ -0,0 +1,74 @@ +/// forward references +import java.io.*; +import java.net.*; + +public class a { + + { + int i; + if (FI == 4) i = 5; + } + final int FI = 4; + + int k = 1 + ki; + int ki; + + final int fi5 = fi5 + 1; +} + +class a1 { + static int i = j + 2; + static int j = 4; +} +class a2 { + static { i = j + 2; } + static int i, j; + static { j = 4; } +} + +// pasted from JLS 8.3.2.3 +class UseBeforeDeclaration { + static { + x = 100; // ok - assignment + int y = x + 1; // error - read before declaration + int v = x = 3; // ok - x at left hand side of assignment + int z = UseBeforeDeclaration.x * 2; // ok - not accessed via simple name + Object o = new Object(){ + void foo(){x++;} // ok - occurs in a different class + {x++;} // ok - occurs in a different class + }; + } + { + j = 200; // ok - assignment + j = j + 1; // error - right hand side reads before declaration + int k = j = j + 1; + int n = j = 300; // ok - j at left hand side of assignment + int h = j++; // error - read before declaration + int l = this.j * 3; // ok - not accessed via simple name + Object o = new Object(){ + void foo(){j++;} // ok - occurs in a different class + { j = j + 1;} // ok - occurs in a different class + }; + } + + int w = x= 3; // ok - x at left hand side of assignment + int p = x; // ok - instance initializers may access static fields + static int u = (new Object(){int bar(){return x;}}).bar(); // ok - occurs in a different class + static int x; + int m = j = 4; // ok - j at left hand side of assignment + int o = (new Object(){int bar(){return j;}}).bar(); // ok - occurs in a different class + int j; +} + +class a3 { + static { + i+=1; + } + static int j=i+=1; + static int i=0; + { + k+=1; + } + int n=k+=1; + int k=0; +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a32.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a32.java new file mode 100644 index 000000000000..141b59274c19 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a32.java @@ -0,0 +1,40 @@ +// cyclic inhertiance +import java.io.*; +import java.net.*; + +class Foo extends Foo { +} + + +interface Foo1 extends Bar { + interface Bar { + } +} + + +class c1 extends c2 {} +class c2 extends c1 {} + + + +class a1 { + class b extends a1 { + } +} + + +class a { + static class sb extends a { + class c extends a { + void f() { + class d extends a { + } + } + } + } + class b extends sb { + class c extends a { + } + } +} + \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a34.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a34.java new file mode 100644 index 000000000000..b98824c3da0f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a34.java @@ -0,0 +1,69 @@ +// labels +import java.io.*; +import java.net.*; + +class a { + void f() { + a: + } + void f1() { + a: + b: + } + void f2() { + a: return; + } + void f3() { + a: return; + } + void f4() { + a: + b: + return; + } + void f5() { + a: + if (4==5) return; + b: ; + } + void f6() { + a: ; + } +} + + +class AlreadyInUse { + void f0() { + a: { + f0(); + a: f0(); + } + + } + void f1() { + a: + try { + f1(); + a: + f1(); + } + finally { + } + } + void f2() { + { + a:; + } + { + a:; + } + } + void f3() { + a: + new Object() { + void f() { + a:; + } + }; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a35.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a35.java new file mode 100644 index 000000000000..9060718619b7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a35.java @@ -0,0 +1,8 @@ +// unclosed comment +/* + +import java.io.*; +import java.net.*; + +class a { +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a35_1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a35_1.java new file mode 100644 index 000000000000..24870ee08896 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a35_1.java @@ -0,0 +1,9 @@ +// unclosed comment + + +import java.io.*; +import java.net.*; + +/** +class a { + int i; \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a35_2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a35_2.java new file mode 100644 index 000000000000..92d457bb059b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a35_2.java @@ -0,0 +1,3 @@ +// unclosed decl + +class a { \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a37.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a37.java new file mode 100644 index 000000000000..c34b5e9eec3d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a37.java @@ -0,0 +1,31 @@ +// ternary operator + +class a { + void f1() { + byte b = 4; + int i = 2; + boolean bo = false; + long l = 5; + float f = 5; + double d = 45; + + String s; + s = bo ? 1 : 2; + s = bo ? 1L: 2; + s = bo ? b : 2; + s = bo ? b : b+2; + s = bo ? b+1L : 2; + s = bo ? f : f+2; + s = bo ? d : 2; + + } + + void cf1() { + + byte[] byteArr = new byte[10]; + boolean bool = true; + byte i = bool ? byteArr[0] : 0; + } + + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a38.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a38.java new file mode 100644 index 000000000000..64f476698649 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a38.java @@ -0,0 +1,12 @@ +// duplicates in extends + +class a { +} + +class b extends a, a { +} + +interface i {} + +class c implements i, i { +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a39.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a39.java new file mode 100644 index 000000000000..74e0fb4456f1 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a39.java @@ -0,0 +1,32 @@ +// exception java.lang.Exception has already been caught/ illegal catch type + +import java.io.EOFException; +import java.io.IOException; +class Foo { + void f() { + try { + } catch (Throwable t) { + } catch (Exception e) { + } + try { + } catch (RuntimeException e) { + } catch (NullPointerException e) { + } + try { + throw new EOFException(); + } catch (IOException e) { + } catch (EOFException e) { + } + + try { + } + catch (Exception e) { + } + catch (Exception e) { + + } + } + + +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a44.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a44.java new file mode 100644 index 000000000000..5c725d5ba3dc --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a44.java @@ -0,0 +1,54 @@ +// constant expressions in switch + +import java.util.Date; + +class a { + final int f = -3; + + void f1() { + switch (0) { + case new Integer(0).MAX_VALUE: + } + int k=0; + switch (0) { + case false ? k : 0: + case true ? 1 : k: + } + boolean b=true; + switch (0) { + case false && b ? 0 : 1: + case true || b ? 2 : 0: + } + final Object obj=""; + switch (0) { + case obj=="" ? 0 : 0: + case this.f: + } + + int i = 0; + final Integer I = null; + switch (0) { + case i: + case I.MAX_VALUE: + case Integer.MAX_VALUE: + } + + } + + static class b { + static final int c = 8; + } + void cf1() { + final int i = 9; + switch (0) { + case i: + case 2+4: + case f: + case a.b.c: + } + switch (0) { + case true ^ true ? 0 : 0: + } + + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a45.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a45.java new file mode 100644 index 000000000000..2ab5a6639eb9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a45.java @@ -0,0 +1,55 @@ +// access problems in inner classes + +import java.awt.*; +import java.beans.beancontext.BeanContextServicesSupport; +import java.beans.beancontext.BeanContextServicesSupport.BCSSChild; + +class a extends Component { + void f() { + FlipBufferStrategy s = null; + int i = s.numBuffers; + s.createBuffers(1,null); + + // TODO + // now cannot distinquish private from package local in class files + //< error descr="'java.awt.Component.SingleBufferStrategy' has private access in 'java.awt.Component'">SingleBufferStrategy< /error> s2 = null; + //Object o = s2.< error descr="'caps' has private access in 'java.awt.Component.SingleBufferStrategy'">caps< /error>; + } + + + + class ddd extends BeanContextServicesSupport { + BCSSChild.BCSSCServiceClassRef fd = null; + void ff() { + fd.addRequestor(null,null); + } + } + +} + + +interface I { + abstract class Imple implements I { + abstract void f(); + } + abstract class Impl2 extends Imple { + abstract class Inner extends Impl2 { + + } + } +} + + +class Class1 extends Class2 { + public void test() { + new Class2Inner(); + int i = Class2Inner.i; + } +} +class Class2 { + private static class Class2Inner{ + public static int i; + public Class2Inner() { + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a47.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a47.java new file mode 100644 index 000000000000..a768aacd9f37 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a47.java @@ -0,0 +1,35 @@ +// switch statement + +class a { + { + case 0: + } + { + default: + } + + { + switch (0) { + case 0; + } + + switch (0) { + default; + } + + switch (0) { + //////////////// + /** + */ + System.out.println(); + + + default; + } + + switch (0) { + break; + } + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a48.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a48.java new file mode 100644 index 000000000000..df5a2ec2923f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a48.java @@ -0,0 +1,12 @@ +// assert statement + +class a { + void f() { + assert false : System.out.println(); + + assert 0; + assert 'a'; + assert ""; + assert f(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a49.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a49.java new file mode 100644 index 000000000000..6f7edfbead12 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a49.java @@ -0,0 +1,20 @@ +// sync statement + +class a { + void f() { + + synchronized (null) { + } + synchronized (0) { + } + synchronized ('a') { + } + synchronized (true) { + } + synchronized (System.out.println() ) { + } + + + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a50.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a50.java new file mode 100644 index 000000000000..666b2ec14aea --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a50.java @@ -0,0 +1,16 @@ +// multiple extend + +import java.io.*; + +class c1 {} +class c2 implements Serializable, Externalizable { + public void writeExternal(ObjectOutput out) throws IOException { + } + + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + } +} +class a extends c1,c2 { + + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a52.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a52.java new file mode 100644 index 000000000000..9605da3c96b3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a52.java @@ -0,0 +1,37 @@ +// recusrsive ctr call + + +class s { + s() { + this(); + } + + s(int i) { + this(2); + } +} + +class c { + c() { + this(2); + } + + c(int i) { + this(1,1); + } + c(int i, int k) { + this(1); + } +} + +class cv { + cv() { + this(1); + } + + cv(int i) { + this(1,2); + } + + cv(int i,int j) {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a54.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a54.java new file mode 100644 index 000000000000..7a7c9dfcb94e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a54.java @@ -0,0 +1,11 @@ +// single import conflict +import java.sql.Date; +import java.util.Date; +import java.sql.*; +import java.util.*; +// multiple single-type import of the same class is fine +import java.io.IOException; +import java.io.IOException; + + +public class c {} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a54_1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a54_1.java new file mode 100644 index 000000000000..38147e979fa1 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a54_1.java @@ -0,0 +1,9 @@ +// multiple single-type import of the same class + +import java.io.IOException; +import java.io.IOException; + + +public class c { + public IOException m; +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a55.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a55.java new file mode 100644 index 000000000000..f9e9a9abb77d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a55.java @@ -0,0 +1,9 @@ +// Not allowed in interface + + +interface A { + A(); + static {} + {} +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a59.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a59.java new file mode 100644 index 000000000000..ceeea4d323af --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a59.java @@ -0,0 +1,31 @@ +// access static via instance +class AClass +{ + public int get() { + int i = this.fff; + return i; + } + public static AClass getA() { + return null; + } + + Object gg() + { + return this.getA(); + } + static int fff; + + protected static class R { + static int rr = 0; + } + public R getR() { + return null; + } +} + +class anotherclass { + int f(AClass d){ + int i = d.getR().rr; + return i; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a60.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a60.java new file mode 100644 index 000000000000..cba08cdf3f99 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/a60.java @@ -0,0 +1,17 @@ +class Y { + int size = 4; +} + +class Z extends Y { + class I { + void foo() { + System.out.println("size = " + Y.this.size); // illegal construct + } + } +} + +class R { + public void smu() { + System.out.println(Z.super.toString()); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aClassLoader.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aClassLoader.java new file mode 100644 index 000000000000..dbe35eaf91c7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/aClassLoader.java @@ -0,0 +1,1731 @@ +/* + * @(#)ClassLoader.java 1.162 02/03/19 + * + * Copyright 2002 Sun Microsystems, Inc. All rights reserved. + * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. + */ + +import java.io.InputStream; +import java.io.IOException; +import java.io.StringWriter; +import java.io.PrintWriter; +import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Hashtable; +import java.util.Enumeration; +import java.util.Vector; +import java.util.Stack; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.NoSuchElementException; +import java.util.Set; +import java.util.jar.Manifest; +import java.net.URL; +import java.net.MalformedURLException; +import java.security.AccessController; +import java.security.AccessControlContext; +import java.security.PrivilegedAction; +import java.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.security.ProtectionDomain; +import java.security.Permissions; +import java.security.CodeSource; +import java.security.Policy; +import sun.misc.URLClassPath; +import sun.misc.Resource; +import sun.misc.CompoundEnumeration; +import sun.misc.ClassFileTransformer; +//import sun.misc.Launcher; +import sun.reflect.Reflection; +import sun.security.action.GetPropertyAction; + +/** + * A class loader is an object that is responsible for loading + * classes. The class ClassLoader is an abstract class. + * Given the name of a class, a class loader should attempt to locate + * or generate data that constitutes a definition for the class. A + * typical strategy is to transform the name into a file + * name and then read a "class file" of that name from a file system. + *

+ * Every Class object contains a + * {@link Class#getClassLoader() reference} to the + * ClassLoader that defined it. + *

+ * Class objects for array classes are not created by class loaders, but + * are created automatically as required by the Java runtime. The class + * loader for an array class, as returned by {@link Class#getClassLoader()} + * is the same as the class loader for its element type; if the element + * type is a primitive type, then the array class has no class loader. + *

+ * Applications implement subclasses of ClassLoader in + * order to extend the manner in which the Java virtual machine + * dynamically loads classes. + *

+ * Class loaders may typically be used by security managers to + * indicate security domains. + *

+ * The ClassLoader class uses a delegation model to + * search for classes and resources. Each instance of + * ClassLoader has an associated parent class loader. + * When called upon to find a class or resource, a + * ClassLoader instance will delegate the search for + * the class or resource to its parent class loader before + * attempting to find the class or resource itself. The virtual + * machine's built-in class loader, called the bootstrap class loader, + * does not itself have a parent but may serve as the parent of a + * ClassLoader instance. + *

+ * Normally, the Java virtual machine loads classes from the local + * file system in a platform-dependent manner. For example, on UNIX + * systems, the virtual machine loads classes from the directory + * defined by the CLASSPATH environment variable. + *

+ * However, some classes may not originate from a file; they may + * originate from other sources, such as the network, or they could + * be constructed by an application. The method + * defineClass converts an array of bytes into an + * instance of class Class. Instances of this newly + * defined class can be created using the newInstance + * method in class Class. + *

+ * The methods and constructors of objects created by a class loader + * may reference other classes. To determine the class(es) referred + * to, the Java virtual machine calls the loadClass + * method of the class loader that originally created the class. + *

+ * For example, an application could create a network class loader + * to download class files from a server. Sample code might look like: + *

+ *   ClassLoader loader = new NetworkClassLoader(host, port);
+ *   Object main = loader.loadClass("Main", true).newInstance();
+ *	  . . .
+ * 
+ *

+ * The network class loader subclass must define the methods + * findClass and loadClassData + * to load a class from the network. Once it + * has downloaded the bytes that make up the class, it should use the + * method defineClass to create a class instance. A + * sample implementation is: + *


+ *     class NetworkClassLoader extends ClassLoader {
+ *         String host;
+ *         int port;
+ *
+ *         public Class findClass(String name) {
+ *             byte[] b = loadClassData(name);
+ *             return defineClass(name, b, 0, b.length);
+ *         }
+ *
+ *         private byte[] loadClassData(String name) {
+ *             // load the class data from the connection
+ *              . . .
+ *         }
+ *     }
+ * 

+ * + * @version 1.162, 03/19/02 + * @see java.lang.Class + * @see java.lang.Class#newInstance() + * @see java.lang.ClassLoader#defineClass(byte[], int, int) + * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean) + * @see java.lang.ClassLoader#resolveClass(java.lang.Class) + * @since JDK1.0 + */ +public abstract class ClassLoader { + + private static native void registerNatives(); + static { + registerNatives(); + } + + /* + * If initialization succeed this is set to true and security checks will + * succeed. Otherwise the object is not initialized and the object is + * useless. + */ + private boolean initialized = false; + + /* + * The parent class loader for delegation. + */ + private ClassLoader parent; + + /* + * Hashtable that maps packages to certs + */ + private Hashtable package2certs = new Hashtable(11); + + /* + * shared among all packages with unsigned classes + */ + java.security.cert.Certificate[] nocerts; + + /* + * The classes loaded by this class loader. The only purpose of this + * table is to keep the classes from being GC'ed until the loader + * is GC'ed. + */ + private Vector classes = new Vector(); + + /* + * The initiating protection domains for all classes + * loaded by this loader. + */ + private Set domains = new HashSet(); + + /* + * Called by the VM to record every loaded class with this loader. + */ + void addClass(Class c) { + classes.addElement(c); + } + + /* + * The packages defined in this class loader. Each package name is + * mapped to its corresponding Package object. + */ + private HashMap packages = new HashMap(); + + /** + * Creates a new class loader using the specified parent class loader + * for delegation. + *

+ * If there is a security manager, its checkCreateClassLoader + * method is called. This may result in a security exception. + * + * @param parent the parent class loader + * + * @throws SecurityException if a security manager exists and its + * checkCreateClassLoader method doesn't allow creation of a + * new class loader. + * @see java.lang.SecurityException + * @see java.lang.SecurityManager#checkCreateClassLoader() + * @since 1.2 + */ + protected ClassLoader(ClassLoader parent) { + SecurityManager security = System.getSecurityManager(); + if (security != null) { + security.checkCreateClassLoader(); + } + this.parent = parent; + initialized = true; + } + + /** + * Creates a new class loader using the ClassLoader + * returned by the method getSystemClassLoader() as the + * parent class loader. + *

+ * If there is a security manager, its checkCreateClassLoader + * method is called. This may result in a security exception. + * + * @throws SecurityException + * if a security manager exists and its checkCreateClassLoader + * method doesn't allow creation of a new class loader. + * + * @see java.lang.SecurityException + * @see java.lang.SecurityManager#checkCreateClassLoader() + */ + protected ClassLoader() { + SecurityManager security = System.getSecurityManager(); + if (security != null) { + security.checkCreateClassLoader(); + } + this.parent = getSystemClassLoader(); + initialized = true; + } + + /** + * Loads the class with the specified name. This method searches for + * classes in the same manner as the {@link #loadClass(String, boolean)} + * method. It is called by the Java virtual machine to resolve class + * references. Calling this method is equivalent to calling + * loadClass(name, false). + * + * @param name the name of the class + * @return the resulting Class object + * @exception ClassNotFoundException if the class was not found + */ + public Class loadClass(String name) throws ClassNotFoundException + { + return loadClass(name, false); + } + + /** + * Loads the class with the specified name. The default implementation of + * this method searches for classes in the following order:

+ * + *

    + *
  1. Call {@link #findLoadedClass(String)} to check if the class has + * already been loaded.

    + *

  2. Call the loadClass method on the parent class + * loader. If the parent is null the class loader + * built-in to the virtual machine is used, instead.

    + *

  3. Call the {@link #findClass(String)} method to find the class.

    + *

+ * + * If the class was found using the above steps, and the + * resolve flag is true, this method will then call the + * {@link #resolveClass(Class)} method on the resulting class object. + *

+ * From the Java 2 SDK, v1.2, subclasses of ClassLoader are + * encouraged to override + * {@link #findClass(String)}, rather than this method.

+ * + * @param name the name of the class + * @param resolve if true then resolve the class + * @return the resulting Class object + * @exception ClassNotFoundException if the class could not be found + */ + protected synchronized Class loadClass(String name, boolean resolve) + throws ClassNotFoundException + { + // First, check if the class has already been loaded + Class c = findLoadedClass(name); + if (c == null) { + try { + if (parent != null) { + c = parent.loadClass(name, false); + } else { + c = findBootstrapClass0(name); + } + } catch (ClassNotFoundException e) { + // If still not found, then call findClass in order + // to find the class. + c = findClass(name); + } + } + if (resolve) { + resolveClass(c); + } + return c; + } + + /* + * This method is called by the virtual machine to load + * a class. + */ + private synchronized Class loadClassInternal(String name) + throws ClassNotFoundException { + + return loadClass(name); + } + + private void checkPackageAccess(Class cls, ProtectionDomain pd) { + final SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + final String name = cls.getName(); + final int i = name.lastIndexOf('.'); + if (i != -1) { + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + sm.checkPackageAccess(name.substring(0, i)); + return null; + } + }, new AccessControlContext(new ProtectionDomain[] {pd})); + } + } + domains.add(pd); + } + + /** + * Finds the specified class. This method should be overridden + * by class loader implementations that follow the new delegation model + * for loading classes, and will be called by the loadClass + * method after checking the parent class loader for the requested class. + * The default implementation throws ClassNotFoundException. + * + * @param name the name of the class + * @return the resulting Class object + * @exception ClassNotFoundException if the class could not be found + * @since 1.2 + */ + protected Class findClass(String name) throws ClassNotFoundException { + throw new ClassNotFoundException(name); + } + + /** + * Converts an array of bytes into an instance of class + * Class. Before the Class can be used it must be + * resolved. This method is deprecated in favor of the version + * that takes the class name as its first argument, and is more + * secure. + * + * @param b the bytes that make up the class data. The bytes in + * positions off through off+len-1 + * should have the format of a valid class file as defined + * by the + * Java + * Virtual Machine Specification. + * @param off the start offset in b of the class data + * @param len the length of the class data + * @return the Class object that was created from the + * specified class data + * @exception ClassFormatError if the data did not contain a valid class + * @exception IndexOutOfBoundsException if either off or + * len is negative, or if + * off+len is greater than b.length. + * @see ClassLoader#loadClass(java.lang.String, boolean) + * @see ClassLoader#resolveClass(java.lang.Class) + * @deprecated Replaced by defineClass(java.lang.String, byte[], int, int) + */ + protected final Class defineClass(byte[] b, int off, int len) + throws ClassFormatError + { + return defineClass(null, b, off, len, null); + } + + /** + * Converts an array of bytes into an instance of class Class. + * Before the Class can be used it must be resolved. + *

+ * This method assigns a default ProtectionDomain to + * the newly defined class. The ProtectionDomain + * contains the set of permissions granted when + * a call to Policy.getPolicy().getPermissions() is made with + * a code source of null,null. The default domain is + * created on the first invocation of defineClass, and + * re-used on subsequent calls. + *

+ * To assign a specific ProtectionDomain to the class, + * use the defineClass method that takes a + * ProtectionDomain as one of its arguments. + * + * @param name the expected name of the class, or null + * if not known, using '.' and not '/' as the separator + * and without a trailing ".class" suffix. + * @param b the bytes that make up the class data. The bytes in + * positions off through off+len-1 + * should have the format of a valid class file as defined + * by the + * Java + * Virtual Machine Specification. + * @param off the start offset in b of the class data + * @param len the length of the class data + * @return the Class object that was created from the + * specified class data + * @exception ClassFormatError if the data did not contain a valid class + * @exception IndexOutOfBoundsException if either off or + * len is negative, or if + * off+len is greater than b.length. + * @exception SecurityException if an attempt is made to add this class + * to a package that contains classes that were signed by + * a different set of certificates than this class (which + * is unsigned), or if the class name begins with "java.". + * + * @see ClassLoader#loadClass(java.lang.String, boolean) + * @see ClassLoader#resolveClass(java.lang.Class) + * @see java.security.ProtectionDomain + * @see java.security.Policy + * @see java.security.CodeSource + * @see java.security.SecureClassLoader + * @since JDK1.1 + */ + protected final Class defineClass(String name, byte[] b, int off, int len) + throws ClassFormatError + { + return defineClass(name, b, off, len, null); + } + + /** + * Converts an array of bytes into an instance of class Class, + * with an optional ProtectionDomain. If the domain is null, + * then a default domain will be assigned to the class as specified + * in the documentation for {@link #defineClass(String,byte[],int,int)}. + * Before the class can be used it must be resolved. + * + *

The first class defined in a package determines the exact set of + * certificates that all subsequent classes defined in that package must + * contain. The set of certificates for a class is obtained from the + * CodeSource within the ProtectionDomain of + * the class. Any classes added to that package must contain + * the same set of certificates or a SecurityException + * will be thrown. Note that if the name argument is + * null, this check is not performed. You should always pass in the + * name of the class you are defining as well as the bytes. This + * ensures that the class you are defining is indeed the class + * you think it is. + * + *

The specified class name cannot begin with "java.", since all + * classes in the java.* packages can only be defined by the bootstrap + * class loader. If the name parameter is not null, it + * must be equal to the name of the class specified by the byte + * array b, otherwise a ClassFormatError is raised. + * + * @param name the expected name of the class, or null + * if not known, using '.' and not '/' as the separator + * and without a trailing ".class" suffix. + * @param b the bytes that make up the class data. The bytes in + * positions off through off+len-1 + * should have the format of a valid class file as defined + * by the + * Java + * Virtual Machine Specification. + * @param off the start offset in b of the class data + * @param len the length of the class data + * @param protectionDomain the ProtectionDomain of the class + * @return the Class object created from the data, + * and optional ProtectionDomain. + * @exception ClassFormatError if the data did not contain a valid class + * @exception IndexOutOfBoundsException if either off or + * len is negative, or if + * off+len is greater than b.length. + * @exception SecurityException if an attempt is made to add this class + * to a package that contains classes that were signed by + * a different set of certificates than this class, or if + * the class name begins with "java.". + */ + protected final Class defineClass(String name, byte[] b, int off, int len, + ProtectionDomain protectionDomain) + throws ClassFormatError + { + check(); + if ((name != null) && name.startsWith("java.")) { + throw new SecurityException("Prohibited package name: " + + name.substring(0, name.lastIndexOf('.'))); + } + if (protectionDomain == null) { + protectionDomain = getDefaultDomain(); + } + + if (name != null) + checkCerts(name, protectionDomain.getCodeSource()); + + Class c = null; + + try + { + c = defineClass0(name, b, off, len, protectionDomain); + } + catch (ClassFormatError cfe) + { + // Class format error - try to transform the bytecode and + // define the class again + // + Object[] transformers = ClassFileTransformer.getTransformers(); + + for (int i=0; transformers != null && i < transformers.length; i++) + { + try + { + // Transform byte code using transformer + byte[] tb = ((ClassFileTransformer) transformers[i]).transform(b, off, len); + c = defineClass0(name, tb, 0, tb.length, protectionDomain); + break; + } + catch (ClassFormatError cfe2) + { + // If ClassFormatError occurs, try next transformer + } + } + + // Rethrow original ClassFormatError if unable to transform + // bytecode to well-formed + // + if (c == null) + throw cfe; + } + + if (protectionDomain.getCodeSource() != null) { + java.security.cert.Certificate certs[] = + protectionDomain.getCodeSource().getCertificates(); + if (certs != null) + setSigners(c, certs); + } + return c; + } + + private synchronized void checkCerts(String name, CodeSource cs) + { + int i = name.lastIndexOf('.'); + String pname = (i == -1) ? "" : name.substring(0,i); + java.security.cert.Certificate[] pcerts = + (java.security.cert.Certificate[]) package2certs.get(pname); + if (pcerts == null) { + // first class in this package gets to define which + // certificates must be the same for all other classes + // in this package + if (cs != null) { + pcerts = cs.getCertificates(); + } + if (pcerts == null) { + if (nocerts == null) + nocerts = new java.security.cert.Certificate[0]; + pcerts = nocerts; + } + package2certs.put(pname, pcerts); + } else { + java.security.cert.Certificate[] certs = null; + if (cs != null) { + certs = cs.getCertificates(); + } + + if (!compareCerts(pcerts,certs)) { + throw new SecurityException("class \""+ name+ + "\"'s signer information does not match signer information of other classes in the same package"); + } + } + } + + /** + * check to make sure the certs for the new class (certs) are + * the same as the certs for the first class inserted + * in the package (pcerts) + */ + private boolean compareCerts(java.security.cert.Certificate[] pcerts, + java.security.cert.Certificate[] certs) + { + // certs can be null, indicating no certs. + if ((certs == null) || (certs.length == 0)) { + return pcerts.length == 0; + } + + // the length must be the same at this point + if (certs.length != pcerts.length) + return false; + + // go through and make sure all the certs in one array + // are in the other and vice-versa. + boolean match; + for (int i=0; i < certs.length; i++) { + match = false; + for (int j=0; j < pcerts.length; j++) { + if (certs[i].equals(pcerts[j])) { + match = true; + break; + } + } + if (!match) return false; + } + + // now do the same for pcerts + for (int i=0; i < pcerts.length; i++) { + match = false; + for (int j=0; j < certs.length; j++) { + if (pcerts[i].equals(certs[j])) { + match = true; + break; + } + } + if (!match) return false; + } + + return true; + } + + /** + * Links the specified class. + * This (misleadingly named) method may be used by a class loader to + * link a class. If the class c has already been linked, + * then this method simply returns. Otherwise, the class is linked + * as described in the "Execution" chapter of the Java Language + * Specification. + * + * @param c the class to link + * @exception NullPointerException if c is null. + * @see java.lang.ClassLoader#defineClass(java.lang.String,byte[],int,int) + */ + protected final void resolveClass(Class c) { + check(); + resolveClass0(c); + } + + /** + * Finds a class with the specified name, loading it if necessary.

+ * + * Prior to the Java 2 SDK, this method loads a class from the local file + * system in a platform-dependent manner, and returns a class object + * that has no associated class loader.

+ * + * Since the Java 2 SDK v1.2, this method loads the class through the + * system class loader(see {@link #getSystemClassLoader()}). Class objects + * returned might have ClassLoaders associated with them. + * Subclasses of ClassLoader need not usually call this + * method, because most class loaders need to override just {@link + * #findClass(String)}.

+ * + * @param name the name of the class that is to be found + * @return the Class object for the specified + * name + * @exception ClassNotFoundException if the class could not be found + * @see #ClassLoader(ClassLoader) + * @see #getParent() + */ + protected final Class findSystemClass(String name) + throws ClassNotFoundException + { + check(); + ClassLoader system = getSystemClassLoader(); + if (system == null) { + return findBootstrapClass(name); + } + return system.loadClass(name); + } + + /** + * Returns the parent class loader for delegation. Some implementations + * may use null to represent the bootstrap class + * loader. This method will return null in such + * implementations if this class loader's parent is the bootstrap + * class loader. + *

+ * If a security manager is present, and the caller's class loader is + * not null and is not an ancestor of this class loader, then + * this method calls the security manager's checkPermission + * method with a RuntimePermission("getClassLoader") + * permission to ensure it's ok to access the parent class loader. + * If not, a SecurityException will be thrown. + * + * @return the parent ClassLoader + * @throws SecurityException + * if a security manager exists and its + * checkPermission method doesn't allow + * access to this class loader's parent class loader. + * + * @see SecurityManager#checkPermission + * @see java.lang.RuntimePermission + * + * @since 1.2 + */ + public final ClassLoader getParent() { + if (parent == null) + return null; + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + ClassLoader ccl = getCallerClassLoader(); + if (ccl != null && !isAncestor(ccl)) { + sm.checkPermission(getGetClassLoaderPerm()); + } + } + return parent; + } + + /** + * Sets the signers of a class. This should be called after defining a + * class. + * + * @param c the Class object + * @param signers the signers for the class + * @since JDK1.1 + */ + protected final void setSigners(Class c, Object[] signers) { + check(); + c.setSigners(signers); + } + + private Class findBootstrapClass0(String name) + throws ClassNotFoundException { + check(); + return findBootstrapClass(name); + } + + private native Class defineClass0(String name, byte[] b, int off, int len, + ProtectionDomain pd); + private native void resolveClass0(Class c); + private native Class findBootstrapClass(String name) + throws ClassNotFoundException; + + /* + * Check to make sure the class loader has been initialized. + */ + private void check() { + if (!initialized) { + throw new SecurityException("ClassLoader object not initialized"); + } + } + + /** + * Finds the class with the given name if it had been previously loaded + * through this class loader. + * + * @param name the class name + * @return the Class object, or null if + * the class has not been loaded + * @since JDK1.1 + */ + protected native final Class findLoadedClass(String name); + + /** + * Finds the resource with the given name. A resource is some data + * (images, audio, text, etc) that can be accessed by class code in a way + * that is independent of the location of the code.

+ * + * The name of a resource is a "/"-separated path name that identifies + * the resource.

+ * + * This method will first search the parent class loader for the resource; + * if the parent is null the path of the class loader + * built-in to the virtual machine is searched. That failing, this method + * will call findResource to find the resource.

+ * + * @param name resource name + * @return a URL for reading the resource, or null if + * the resource could not be found or the caller doesn't have + * adequate privileges to get the resource. + * @since JDK1.1 + * @see #findResource(String) + */ + public URL getResource(String name) { + URL url; + if (parent != null) { + url = parent.getResource(name); + } else { + url = getBootstrapResource(name); + } + if (url == null) { + url = findResource(name); + } + return url; + } + + /** + * Finds all the resources with the given name. A resource is some data + * (images, audio, text, etc) that can be accessed by class code in a way + * that is independent of the location of the code.

+ * + * The name of a resource is a "/"-separated path name that identifies the + * resource.

+ * + * The search order is described in the documentation for {@link + * #getResource(String)}.

+ * + * @param name resource name + * @return an enumeration of URL to the resource. If no resources could + * be found, the enumeration will be empty. Resources that the + * doesn't have access to will not be in the enumeration. + * @throws IOException if I/O errors occur + * @since 1.2 + * @see #getResource + * @see #findResources + */ + public final Enumeration getResources(String name) throws IOException { + Enumeration[] tmp = new Enumeration[2]; + if (parent != null) { + tmp[0] = parent.getResources(name); + } else { + tmp[0] = getBootstrapResources(name); + } + tmp[1] = findResources(name); + + return new CompoundEnumeration(tmp); + } + + /** + * Returns an Enumeration of URLs representing all the resources with + * the given name. Class loader implementations should override this + * method to specify where to load resources from. + * + * @param name the resource name + * @return an Enumeration of URLs for the resources + * @throws IOException if I/O errors occur + * @since 1.2 + */ + protected Enumeration findResources(String name) throws IOException { + return new CompoundEnumeration(new Enumeration[0]); + } + + /** + * Finds the resource with the given name. Class loader + * implementations should override this method to specify where to + * find resources. + * + * @param name the resource name + * @return a URL for reading the resource, or null + * if the resource could not be found + * @since 1.2 + */ + protected URL findResource(String name) { + return null; + } + + /** + * Find a resource of the specified name from the search path used to load + * classes.

+ * + * In JDK1.1, the search path used is that of the virtual machine's + * built-in class loader.

+ * + * Since the Java 2 SDK v1.2, this method locates the resource through the system class + * loader (see {@link #getSystemClassLoader()}). + * + * @param name the resource name + * @return a URL for reading the resource, or null if + * the resource could not be found + * @since JDK1.1 + */ + public static URL getSystemResource(String name) { + ClassLoader system = getSystemClassLoader(); + if (system == null) { + return getBootstrapResource(name); + } + return system.getResource(name); + } + + /** + * Find resources from the VM's built-in classloader. + */ + private static URL getBootstrapResource(String name) { + URLClassPath ucp = getBootstrapClassPath(); + Resource res = ucp.getResource(name); + return res != null ? res.getURL() : null; + } + + /** + * Finds all resources of the specified name from the search path used to + * load classes. The resources thus found are returned as an + * Enumeration of URL objects.

+ * + * The search order is described in the documentation for {@link + * #getSystemResource(String)}.

+ * + * @param name the resource name + * @return an enumeration of resource URLs + * @throws IOException if I/O errors occur + * @since 1.2 + */ + public static Enumeration getSystemResources(String name) + throws IOException + { + ClassLoader system = getSystemClassLoader(); + if (system == null) { + return getBootstrapResources(name); + } + return system.getResources(name); + } + + /** + * Find resources from the VM's built-in classloader. + */ + private static Enumeration getBootstrapResources(String name) + throws IOException + { + final Enumeration e = getBootstrapClassPath().getResources(name); + return new Enumeration () { + public Object nextElement() { + return ((Resource)e.nextElement()).getURL(); + } + public boolean hasMoreElements() { + return e.hasMoreElements(); + } + }; + } + + /* + * Returns the URLClassPath that is used for finding system resources. + */ + static URLClassPath getBootstrapClassPath() { + if (bootstrapClassPath == null) { + bootstrapClassPath = sun.misc.Launcher.getBootstrapClassPath(); + } + return bootstrapClassPath; + } + + private static URLClassPath bootstrapClassPath; + + /** + * Returns an input stream for reading the specified resource. + * + * The search order is described in the documentation for {@link + * #getResource(String)}.

+ * + * @param name the resource name + * @return an input stream for reading the resource, or null + * if the resource could not be found + * @since JDK1.1 + */ + public InputStream getResourceAsStream(String name) { + URL url = getResource(name); + try { + return url != null ? url.openStream() : null; + } catch (IOException e) { + return null; + } + } + + /** + * Open for reading, a resource of the specified name from the search path + * used to load classes.

+ * + * The search order is described in the documentation for {@link + * #getSystemResource(String)}.

+ * + * @param name the resource name + * @return an input stream for reading the resource, or null + * if the resource could not be found + * @since JDK1.1 + */ + public static InputStream getSystemResourceAsStream(String name) { + URL url = getSystemResource(name); + try { + return url != null ? url.openStream() : null; + } catch (IOException e) { + return null; + } + } + + /** + * Returns the system class loader for delegation. This is the default + * delegation parent for new ClassLoader instances, and + * is typically the class loader used to start the application. + *

+ * This method is first invoked early in the runtime's startup + * sequence, at which point it creates the system class loader + * and sets it as the context class loader of the invoking + * Thread. + *

+ * The default system class loader is an implementation-dependent + * instance of this class. + *

+ * If the system property java.system.class.loader is + * defined when this method is first invoked then the value of that + * property is taken to be the name of a class that will be returned as + * the system class loader. The class is loaded using the default system + * class loader and must define a public constructor that takes a single + * parameter of type ClassLoader which is used + * as the delegation parent. An instance is then created using this + * constructor with the default system class loader as the parameter. + * The resulting class loader is defined to be the system class loader. + *

+ * If a security manager is present, and the caller's class loader is + * not null and the caller's class loader is not the same as or an ancestor of + * the system class loader, then + * this method calls the security manager's checkPermission + * method with a RuntimePermission("getClassLoader") + * permission to ensure it's ok to access the system class loader. + * If not, a SecurityException will be thrown. + * + * @return the system ClassLoader for delegation, or + * null if none + * @throws SecurityException + * if a security manager exists and its + * checkPermission method doesn't allow + * access to the system class loader. + * @throws IllegalStateException + * if invoked recursively during the construction + * of the class loader specified by the + * java.system.class.loader property. + * @throws Error + * if the system property java.system.class.loader + * is defined but the named class could not be loaded, the + * provider class does not define the required constructor, or an + * exception is thrown by that constructor when it is invoked. The + * underlying cause of the error can be retrieved via the + * {@link Throwable#getCause()} method. + * @see SecurityManager#checkPermission + * @see java.lang.RuntimePermission + * @revised 1.4 + */ + public static ClassLoader getSystemClassLoader() { + initSystemClassLoader(); + if (scl == null) { + return null; + } + SecurityManager sm = System.getSecurityManager(); + if (sm != null) { + ClassLoader ccl = getCallerClassLoader(); + if (ccl != null && ccl != scl && !scl.isAncestor(ccl)) { + sm.checkPermission(getGetClassLoaderPerm()); + } + } + return scl; + } + + private static synchronized void initSystemClassLoader() { + if (!sclSet) { + if (scl != null) + throw new IllegalStateException("recursive call"); + sun.misc.Launcher l = sun.misc.Launcher.getLauncher(); + if (l != null) { + Throwable oops = null; + scl = l.getClassLoader(); + try { + PrivilegedExceptionAction a; + a = new SystemClassLoaderAction(scl); + scl = (ClassLoader) AccessController.doPrivileged(a); + } catch (PrivilegedActionException pae) { + oops = pae.getCause(); + if (oops instanceof InvocationTargetException) { + oops = oops.getCause(); + } + } + if (oops != null) { + if (oops instanceof Error) { + throw (Error) oops; + } else { + // wrap the exception + throw new Error(oops); + } + } + } + sclSet = true; + } + } + + // Returns true if the specified class loader can be found + // in this class loader's delegation chain. + boolean isAncestor(ClassLoader cl) { + ClassLoader acl = this; + do { + acl = acl.parent; + if (cl == acl) { + return true; + } + } while (acl != null); + return false; + } + + // Returns the caller's class loader, or null if none. + // NOTE this must always be called when there is exactly one + // intervening frame from the core libraries on the stack between + // this method's invocation and the desired caller. + static ClassLoader getCallerClassLoader() { + // NOTE use of more generic Reflection.getCallerClass() + Class caller = Reflection.getCallerClass(3); + // This can be null if the VM is requesting it + if (caller == null) { + return null; + } + // Circumvent security check since this is package-private + return caller.getClassLoader0(); + } + + // The class loader for the system + private static ClassLoader scl; + + // Set to true once the system class loader has been set + private static boolean sclSet; + + // Permission to access system or parent class loader + private static RuntimePermission getClassLoaderPerm = null; + + static RuntimePermission getGetClassLoaderPerm() + { + if (getClassLoaderPerm == null) + getClassLoaderPerm = new RuntimePermission("getClassLoader"); + return getClassLoaderPerm; + } + + /** + * Defines a package by name in this ClassLoader. This allows class + * loaders to define the packages for their classes. Packages must be + * created before the class is defined, and package names must be + * unique within a class loader and cannot be redefined or changed + * once created. + * + * @param name the package name + * @param specTitle the specification title + * @param specVersion the specification version + * @param specVendor the specification vendor + * @param implTitle the implementation title + * @param implVersion the implementation version + * @param implVendor the implementation vendor + * @param sealBase If not null, then this package is sealed with + * respect to the given code source URL. Otherwise, + * the package is not sealed. + * @return the newly defined Package object + * @exception IllegalArgumentException if package name duplicates an + * existing package either in this class loader or one of + * its ancestors + * @since 1.2 + */ + protected Package definePackage(String name, String specTitle, + String specVersion, String specVendor, + String implTitle, String implVersion, + String implVendor, URL sealBase) + throws IllegalArgumentException + { + synchronized (packages) { + Package pkg = getPackage(name); + if (pkg != null) { + throw new IllegalArgumentException(name); + } + pkg = new Package(name, specTitle, specVersion, specVendor, + implTitle, implVersion, implVendor, + sealBase); + packages.put(name, pkg); + return pkg; + } + } + + /** + * Returns a Package that has been defined by this class loader or any + * of its ancestors. + * + * @param name the package name + * @return the Package corresponding to the given name, or null if not + * found + * @since 1.2 + */ + protected Package getPackage(String name) { + synchronized (packages) { + Package pkg = (Package)packages.get(name); + if (pkg == null) { + if (parent != null) { + pkg = parent.getPackage(name); + } else { + pkg = Package.getSystemPackage(name); + } + if (pkg != null) { + packages.put(name, pkg); + } + } + return pkg; + } + } + + /** + * Returns all of the Packages defined by this class loader and its + * ancestors. + * + * @return the array of Package objects defined by this + * ClassLoader + * @since 1.2 + */ + protected Package[] getPackages() { + Map map; + synchronized (packages) { + map = (Map)packages.clone(); + } + Package[] pkgs; + if (parent != null) { + pkgs = parent.getPackages(); + } else { + pkgs = Package.getSystemPackages(); + } + if (pkgs != null) { + for (int i = 0; i < pkgs.length; i++) { + String pkgName = pkgs[i].getName(); + if (map.get(pkgName) == null) { + map.put(pkgName, pkgs[i]); + } + } + } + return (Package[])map.values().toArray(new Package[map.size()]); + } + + /** + * Returns the absolute path name of a native library. The VM + * invokes this method to locate the native libraries that belong + * to classes loaded with this class loader. If this method returns + * null, the VM searches the library along the path + * specified as the java.library.path property. + * + * @param libname the library name + * @return the absolute path of the native library + * @see java.lang.System#loadLibrary(java.lang.String) + * @see java.lang.System#mapLibraryName(java.lang.String) + * @since 1.2 + */ + protected String findLibrary(String libname) { + return null; + } + + /** + * The inner class NativeLibrary denotes a loaded native library + * instance. Every classloader contains a vector of loaded native + * libraries in the private field nativeLibraries. + * The native libraries loaded into the system are entered into + * the systemNativeLibraries vector. + * + * Every native library reuqires a particular version of JNI. This + * is denoted by the private jniVersion field. This field is set + * by the VM when it loads the library, and used by the VM to pass + * the correct version of JNI to the native methods. + * + * @version 1.162, 03/19/02 + * @see java.lang.ClassLoader + * @since 1.2 + */ + static class NativeLibrary { + /* opaque handle to native library, used in native code. */ + long handle; + /* the version of JNI environment the native library requires. */ + private int jniVersion; + /* the class from which the library is loaded, also indicates + the loader this native library belongs. */ + private Class fromClass; + /* the canonicalized name of the native library. */ + String name; + + native void load(String name); + native long find(String name); + native void unload(); + + public NativeLibrary(Class fromClass, String name) { + this.name = name; + this.fromClass = fromClass; + } + + protected void finalize() { + synchronized (loadedLibraryNames) { + if (fromClass.getClassLoader() != null && handle != 0) { + /* remove the native library name */ + int size = loadedLibraryNames.size(); + for (int i = 0; i < size; i++) { + if (name.equals(loadedLibraryNames.elementAt(i))) { + loadedLibraryNames.removeElementAt(i); + break; + } + } + /* unload the library. */ + ClassLoader.nativeLibraryContext.push(this); + try { + unload(); + } finally { + ClassLoader.nativeLibraryContext.pop(); + } + } + } + } + /* Called in the VM to determine the context class in + JNI_Load/JNI_Unload */ + static Class getFromClass() { + return ((NativeLibrary) + (ClassLoader.nativeLibraryContext.peek())).fromClass; + } + } + + /* the "default" domain. Set as the default ProtectionDomain + * on newly created classses. + */ + private ProtectionDomain defaultDomain = null; + + /* + * returns (and initializes) the default domain. + */ + + private synchronized ProtectionDomain getDefaultDomain() { + if (defaultDomain == null) { + CodeSource cs = new CodeSource(null, null); + defaultDomain = new ProtectionDomain(cs, null, this, null); + } + return defaultDomain; + } + + /* All native library names we've loaded. */ + private static Vector loadedLibraryNames = new Vector(); + /* Native libraries belonging to system classes. */ + private static Vector systemNativeLibraries = new Vector(); + /* Native libraries associated with the class loader. */ + private Vector nativeLibraries = new Vector(); + + /* native libraries being loaded/unloaded. */ + private static Stack nativeLibraryContext = new Stack(); + + /* The paths searched for libraries */ + static private String usr_paths[]; + static private String sys_paths[]; + + private static String[] initializePath(String propname) { + String ldpath = System.getProperty(propname, ""); + String ps = File.pathSeparator; + int ldlen = ldpath.length(); + int i, j, n; + // Count the separators in the path + i = ldpath.indexOf(ps); + n = 0; + while (i >= 0) { + n++; + i = ldpath.indexOf(ps, i+1); + } + + // allocate the array of paths - n :'s = n + 1 path elements + String[] paths = new String[n + 1]; + + // Fill the array with paths from the ldpath + n = i = 0; + j = ldpath.indexOf(ps); + while (j >= 0) { + if (j - i > 0) { + paths[n++] = ldpath.substring(i, j); + } else if (j - i == 0) { + paths[n++] = "."; + } + i = j + 1; + j = ldpath.indexOf(ps, i); + } + paths[n] = ldpath.substring(i, ldlen); + return paths; + } + + + /* Called in the java.lang.Runtime class to implement load + * and loadLibrary. + */ + static void loadLibrary(Class fromClass, String name, + boolean isAbsolute) { + ClassLoader loader = + (fromClass == null) ? null : fromClass.getClassLoader(); + if (sys_paths == null) { + usr_paths = initializePath("java.library.path"); + sys_paths = initializePath("sun.boot.library.path"); + } + if (isAbsolute) { + if (loadLibrary0(fromClass, new File(name))) { + return; + } + throw new UnsatisfiedLinkError("Can't load library: " + name); + } + if (loader != null) { + String libfilename = loader.findLibrary(name); + if (libfilename != null) { + File libfile = new File(libfilename); + if (!libfile.isAbsolute()) { + throw new UnsatisfiedLinkError( + "ClassLoader.findLibrary failed to return an absolute path: " + libfilename); + } + if (loadLibrary0(fromClass, libfile)) { + return; + } + throw new UnsatisfiedLinkError ("Can't load " + libfilename); + } + } + for (int i = 0 ; i < sys_paths.length ; i++) { + File libfile = new File(sys_paths[i], System.mapLibraryName(name)); + if (loadLibrary0(fromClass, libfile)) { + return; + } + } + if (loader != null) { + for (int i = 0 ; i < usr_paths.length ; i++) { + File libfile = new File(usr_paths[i], + System.mapLibraryName(name)); + if (loadLibrary0(fromClass, libfile)) { + return; + } + } + } + // Oops, it failed + throw new UnsatisfiedLinkError("no " + name + " in java.library.path"); + } + + private static boolean loadLibrary0(Class fromClass, final File file) { + Boolean exists = (Boolean) + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return new Boolean(file.exists()); + } + }); + if (!exists.booleanValue()) { + return false; + } + String name; + try { + name = file.getCanonicalPath(); + } catch (IOException e) { + return false; + } + ClassLoader loader = + (fromClass == null) ? null : fromClass.getClassLoader(); + Vector libs = + loader != null ? loader.nativeLibraries : systemNativeLibraries; + synchronized (libs) { + int size = libs.size(); + for (int i = 0; i < size; i++) { + NativeLibrary lib = (NativeLibrary)libs.elementAt(i); + if (name.equals(lib.name)) { + return true; + } + } + + synchronized (loadedLibraryNames) { + if (loadedLibraryNames.contains(name)) { + throw new UnsatisfiedLinkError + ("Native Library " + + name + + " already loaded in another classloader"); + } + /* If the library is being loaded (must be by + * the same thread, because Runtime.load and + * Runtime.loadLibrary are synchronous). The + * reason is can occur is that the JNI_OnLoad + * function can cause another loadLibrary call. + * + * Thus we can use a static stack to hold the list + * of libraries we are loading. + * + * If there is a pending load operation for the + * library, we immediately return success; otherwise, + * we raise UnsatisfiedLinkError. + */ + int n = nativeLibraryContext.size(); + for (int i = 0; i < n; i++) { + NativeLibrary lib = (NativeLibrary) + nativeLibraryContext.elementAt(i); + if (name.equals(lib.name)) { + if (loader == lib.fromClass.getClassLoader()) { + return true; + } else { + throw new UnsatisfiedLinkError + ("Native Library " + + name + + " is being loaded in another classloader"); + } + } + } + NativeLibrary lib = new NativeLibrary(fromClass, name); + nativeLibraryContext.push(lib); + try { + lib.load(name); + } finally { + nativeLibraryContext.pop(); + } + if (lib.handle != 0) { + loadedLibraryNames.addElement(name); + libs.addElement(lib); + return true; + } + return false; + } + } + } + + /* Called in the VM class linking code. */ + static long findNative(ClassLoader loader, String name) { + Vector libs = + loader != null ? loader.nativeLibraries : systemNativeLibraries; + synchronized (libs) { + int size = libs.size(); + for (int i = 0; i < size; i++) { + NativeLibrary lib = (NativeLibrary)libs.elementAt(i); + long entry = lib.find(name); + if (entry != 0) + return entry; + } + } + return 0; + } + + /* + * The default toggle for assertion checking. + */ + private boolean defaultAssertionStatus = false; + + /* + * Maps String packageName to Boolean package default assertion status + * Note that the default package is placed under a null map key. + * If this field is null then we are delegating assertion status queries + * to the VM, i.e., none of this ClassLoader's assertion status + * modification methods have been called. + */ + private Map packageAssertionStatus = null; + + /* + * Maps String fullyQualifiedClassName to Boolean assertionStatus + * If this field is null then we are delegating assertion status queries + * to the VM, i.e., none of this ClassLoader's assertion status + * modification methods have been called. + */ + Map classAssertionStatus = null; + + /** + * Sets the default assertion status for this class loader. This setting + * determines whether classes loaded by this class loader and initialized + * in the future will have assertions enabled or disabled by default. + * This setting may be overridden on a per-package or per-class basis by + * invoking {@link #setPackageAssertionStatus(String,boolean)} or {@link + * #setClassAssertionStatus(String,boolean)}. + * + * @param enabled true if classes loaded by this class loader + * will henceforth have assertions enabled by default, + * false if they will have assertions disabled by default. + * @since 1.4 + */ + public synchronized void setDefaultAssertionStatus(boolean enabled) { + if (classAssertionStatus == null) + initializeJavaAssertionMaps(); + + defaultAssertionStatus = enabled; + } + + /** + * Sets the package default assertion status for the named + * package. The package default assertion status determines the + * assertion status for classes initialized in the future that belong + * to the named package or any of its "subpackages." + *

+ * A subpackage of a package named p is any package whose name + * begins with "p." . For example, javax.swing.text is + * a subpackage of javax.swing, and both java.util + * and java.lang.reflect are subpackages of java. + *

+ * In the event that multiple package defaults apply to a given + * class, the package default pertaining to the most specific package + * takes precedence over the others. For example, if + * javax.lang and javax.lang.reflect both have + * package defaults associated with them, the latter package + * default applies to classes in javax.lang.reflect. + *

+ * Package defaults take precedence over the class loader's default + * assertion status, and may be overridden on a per-class basis by + * invoking {@link #setClassAssertionStatus(String,boolean)}. + * + * @param packageName the name of the package whose package default + * assertion status is to be set. A null value + * indicates the unnamed package that is "current" + * (JLS 7.4.2). + * @param enabled true if classes loaded by this classloader + * and belonging to the named package or any of its subpackages + * will have assertions enabled by default, false if they + * will have assertions disabled by default. + * @since 1.4 + */ + public synchronized void setPackageAssertionStatus(String packageName, + boolean enabled) + { + if (packageAssertionStatus == null) + initializeJavaAssertionMaps(); + + packageAssertionStatus.put(packageName, Boolean.valueOf(enabled)); + } + + /** + * Sets the desired assertion status for the named top-level class in + * this class loader and any nested classes contained therein. + * This setting takes precedence over the class loader's default + * assertion status, and over any applicable per-package default. + * This method has no effect if the named class has already been + * initialized. (Once a class is initialized, its assertion status cannot + * change.) + *

+ * If the named class is not a top-level class, this call will have no + * effect on the actual assertion status of any class, and its return + * value is undefined. + * + * @param className the fully qualified class name of the top-level class + * whose assertion status is to be set. + * @param enabled true if the named class is to have assertions + * enabled when (and if) it is initialized, false if the + * class is to have assertions disabled. + * @since 1.4 + */ + public synchronized void setClassAssertionStatus(String className, + boolean enabled) + { + if (classAssertionStatus == null) + initializeJavaAssertionMaps(); + + classAssertionStatus.put(className, Boolean.valueOf(enabled)); + } + + /** + * Sets the default assertion status for this class loader to + * false and discards any package defaults or class assertion + * status settings associated with the class loader. This call is + * provided so that class loaders can be made to ignore any command line + * or persistent assertion status settings and "start with a clean slate." + * + * @since 1.4 + */ + public synchronized void clearAssertionStatus() { + /* + * Whether or not "Java assertion maps" are initialized, set + * them to empty maps, effectively ignoring any present settings. + */ + classAssertionStatus = new HashMap(); + packageAssertionStatus = new HashMap(); + + defaultAssertionStatus = false; + } + + /** + * Returns the assertion status that would be assigned to the specified + * class if it were to be initialized at the time this method is invoked. + * If the named class has had its assertion status set, the most recent + * setting will be returned; otherwise, if any package default assertion + * status pertains to this class, the most recent setting for the most + * specific pertinent package default assertion status is returned; + * otherwise, this class loader's default assertion status is returned. + * + * @param className the fully qualified class name of the class whose + * desired assertion status is being queried. + * @return the desired assertion status of the specified class. + * @see #setClassAssertionStatus(String,boolean) + * @see #setPackageAssertionStatus(String,boolean) + * @see #setDefaultAssertionStatus(boolean) + * @since 1.4 + */ + synchronized boolean desiredAssertionStatus(String className) { + Boolean result; + + // assert classAssertionStatus != null; + // assert packageAssertionStatus != null; + + // Check for a class entry + result = (Boolean)classAssertionStatus.get(className); + if (result != null) + return result.booleanValue(); + + // Check for most specific package entry + int dotIndex = className.lastIndexOf("."); + if (dotIndex < 0) { // default package + result = (Boolean)packageAssertionStatus.get(null); + if (result != null) + return result.booleanValue(); + } + while(dotIndex > 0) { + className = className.substring(0, dotIndex); + result = (Boolean)packageAssertionStatus.get(className); + if (result != null) + return result.booleanValue(); + dotIndex = className.lastIndexOf(".", dotIndex-1); + } + + // Return the classloader default + return defaultAssertionStatus; + } + + // Set up the assertions with information provided by the VM. + private void initializeJavaAssertionMaps() { + // assert Thread.holdsLock(this); + + classAssertionStatus = new HashMap(); + packageAssertionStatus = new HashMap(); + AssertionStatusDirectives directives = retrieveDirectives(); + + for(int i=0; i + private static final int DRAG_ENTERED = AWTEvent.RESERVED_ID_MAX + 1; + private static final int DRAG_EXITED = AWTEvent.RESERVED_ID_MAX + 2; + + private static long WHEEL_MASK = 0; + private static int MOUSE_WHEEL = 0; + private static Method wheelrotation = null; + static { + try { + WHEEL_MASK = AWTEvent.class.getField("MOUSE_WHEEL_EVENT_MASK").getLong(null); + MOUSE_WHEEL = MouseEvent.class.getField("MOUSE_WHEEL").getInt(null); + } catch (Exception exc) { /* not 1.4 */ } + } + { + if (MOUSE_WHEEL != 0) { // disable global focus-manager for this component in 1.4 + try { + getClass().getMethod("setFocusTraversalKeysEnabled", new Class[] { Boolean.TYPE }). + invoke(this, new Object[] { Boolean.FALSE }); + } catch (Exception exc) { /* never */ } + } + enableEvents(AWTEvent.COMPONENT_EVENT_MASK | + AWTEvent.FOCUS_EVENT_MASK | AWTEvent.KEY_EVENT_MASK | + AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK | WHEEL_MASK); + } + // + int[] pix = new int[block * block]; + int r1 = c_bg.getRed(); int r2 = c_press.getRed(); + int g1 = c_bg.getGreen(); int g2 = c_press.getGreen(); + int b1 = c_bg.getBlue(); int b2 = c_press.getBlue(); + for (int i = 0; i < block; i++) { + int r = r1 - (r1 - r2) * i / block; + int g = g1 - (g1 - g2) * i / block; + int b = b1 - (b1 - b2) * i / block; + int color = (255 << 24) | (r << 16) | (g << 8) | b; + for (int j = 0; j < block; j++) { + pix[i * block + j] = color; + //pix[j * block + i] = color; + } + } + gradient = createImage(new MemoryImageSource(block, block, pix, 0, block)); + // validate (overwrite textfield repaint) + else { + int selected = getInteger(component, "selected", -1); + if (selected != -1) { + Object choice = getItem(component, "choice", selected); + set(component, "text", get(choice, "text")); + set(component, "icon", get(choice, "icon")); + } + } + } + else if (("textfield" == classname) || ("passwordfield" == classname)) { + layoutField(component, 0, ("passwordfield" == classname), 0); + } + else if ("textarea" == classname) { + String text = getString(component, "text", ""); + int start = getInteger(component, "start", 0); + if (start > text.length()) { setInteger(component, "start", start = text.length(), 0); } + int end = getInteger(component, "end", 0); + if (end > text.length()) { setInteger(component, "end", end = text.length(), 0); } + int caretx = 0; int carety = 0; + FontMetrics fm = getFontMetrics(getFont()); //java + int width = 0, height = 0; + for (int i = 0, j = 0; j != -1; i = j + 1) { + j = text.indexOf('\n', i); + if (i != j) { // && i != text.length() + String line = (j != -1) ? text.substring(i, j) : text.substring(i); //java + width = Math.max(width, fm.stringWidth(line)); //java + //midp width = font.substringWidth(text, i, ((j != -1) ? j : text.length()) - i); + } + if ((end >= i) && ((j == -1) || (end <= j))) { + caretx = fm.stringWidth(text.substring(i, end)); //java + //midp caretx = font.substringWidth(text, i, end - i); + carety = height; + } + height += fm.getHeight(); + } + layoutScrollPane(component, width + 2, + height - fm.getLeading() + 2, 0, 0); + scrollToVisible(component, caretx, carety, + 2, fm.getAscent() + fm.getDescent() + 2); + } + else if ("tabbedpane" == classname) { + Rectangle bounds = getRectangle(component, "bounds"); + String placement = getString(component, "placement", "top"); + boolean horizontal = ((placement == "top") || (placement == "bottom")); + int tabd = 0; + int tabsize = 0; + for (Object comp = get(component, "tab"); + comp != null; comp = get(comp, ":next")) { + Dimension d = getSize(comp, 8, 4, "left"); + setRectangle(comp, "bounds", + horizontal ? tabd : 0, horizontal ? 0 : tabd, d.width, d.height); + tabd += horizontal ? d.width : d.height; + tabsize = Math.max(tabsize, horizontal ? d.height : d.width); + } + for (Object comp = get(component, "tab"); + comp != null; comp = get(comp, ":next")) { + Rectangle r = getRectangle(comp, "bounds"); + if (horizontal) { + if (placement == "bottom") { r.y = bounds.height - tabsize; } + r.height = tabsize; + } else { + if (placement == "right") { r.x = bounds.width - tabsize; } + r.width = tabsize; + } + } + int cx = (placement == "left") ? (tabsize + 1) : 2; + int cy = (placement == "top") ? (tabsize + 1) : 2; + int cwidth = bounds.width - (horizontal ? 4 : (tabsize + 3)); + int cheight = bounds.height - (horizontal ? (tabsize + 3) : 4); + for (Object comp = get(component, "component"); + comp != null; comp = get(comp, ":next")) { + if (!getBoolean(comp, "visible", true)) { continue; } + setRectangle(comp, "bounds", cx, cy, cwidth, cheight); + doLayout(comp); + } + } + else if (("panel" == classname) || (classname == "dialog")) { + int gap = getInteger(component, "gap", 0); + int[][] grid = getGrid(component, gap); + if (grid != null) { + int top = getInteger(component, "top", 0); + int left = getInteger(component, "left", 0); + int bottom = getInteger(component, "bottom", 0); + int right = getInteger(component, "right", 0); + if (classname == "dialog") { + int titleheight = getInteger(component, "titleheight", 0); + top += 4 + titleheight; left += 4; bottom += 4; right += 4; + } + + Rectangle bounds = getRectangle(component, "bounds"); + for (int i = 0; i < 2; i++) { + int d = ((i == 0) ? (bounds.width - left - right) : + (bounds.height - top - bottom)) - + getSum(grid[i], 0, grid[i].length, gap, false); + if (d != 0) { + int w = getSum(grid[2 + i], 0, grid[2 + i].length, 0, false); + if (w > 0) { + for (int j = 0; j < grid[i].length; j++) { + if (grid[2 + i][j] != 0) { + grid[i][j] += d * grid[2 + i][j] / w; + } + } + } + } + } + + int i = 0; + for (Object comp = get(component, "component"); + comp != null; comp = get(comp, ":next")) { + if (!getBoolean(comp, "visible", true)) { continue; } + int ix = left + getSum(grid[0], 0, grid[4][i], gap, true); + int iy = top + getSum(grid[1], 0, grid[5][i], gap, true); + int iwidth = getSum(grid[0], grid[4][i], grid[6][i], gap, false); + int iheight = getSum(grid[1], grid[5][i], grid[7][i], gap, false); + String halign = getString(comp, "halign", "fill"); + String valign = getString(comp, "valign", "fill"); + if ((halign != "fill") || (valign != "fill")) { + Dimension d = getPreferredSize(comp); + if (halign != "fill") { + int dw = Math.max(0, iwidth - d.width); + if (halign == "center") { ix += dw / 2; } + else if (halign == "right") { ix += dw; } + iwidth -= dw; + } + if (valign != "fill") { + int dh = Math.max(0, iheight - d.height); + if (valign == "center") { iy += dh / 2; } + else if (valign == "bottom") { iy += dh; } + iheight -= dh; + } + } + setRectangle(comp, "bounds", ix, iy, iwidth, iheight); + doLayout(comp); + i++; + } + } + } + else if ("desktop" == classname) { + Rectangle bounds = getRectangle(component, "bounds"); + for (Object comp = get(component, "component"); + comp != null; comp = get(comp, ":next")) { + String iclass = getClass(comp); + if (iclass == "dialog") { + Dimension d = getPreferredSize(comp); + if (get(comp, "bounds") == null) + setRectangle(comp, "bounds", + Math.max(0, (bounds.width - d.width) / 2), + Math.max(0, (bounds.height - d.height) / 2), + Math.min(d.width, bounds.width), Math.min(d.height, bounds.height)); + } else if ((iclass == "combolist") || (iclass == "popupmenu")) { + iclass = iclass; //compiler bug + } else { + setRectangle(comp, "bounds", 0, 0, bounds.width, bounds.height); + } + doLayout(comp); + } + } + else if ("spinbox" == classname) { + layoutField(component, block, false, 0); + } + else if ("splitpane" == classname) { + Rectangle bounds = getRectangle(component, "bounds"); + boolean horizontal = ("vertical" != get(component, "orientation")); + int divider = getInteger(component, "divider", -1); + int maxdiv = (horizontal ? bounds.width : bounds.height) - 5; + + Object comp1 = get(component, "component"); + boolean visible1 = (comp1 != null) && getBoolean(comp1, "visible", true); + if (divider == -1) { + int d1 = 0; + if (visible1) { + Dimension d = getPreferredSize(comp1); + d1 = horizontal ? d.width : d.height; + } + divider = Math.min(d1, maxdiv); + setInteger(component, "divider", divider, -1); + } + else if (divider > maxdiv) { + setInteger(component, "divider", divider = maxdiv, -1); + } + + if (visible1) { + setRectangle(comp1, "bounds", 0, 0, horizontal ? divider : bounds.width, + horizontal ? bounds.height : divider); + doLayout(comp1); + } + Object comp2 = (comp1 != null) ? get(comp1, ":next") : null; + if ((comp2 != null) && getBoolean(comp2, "visible", true)) { + setRectangle(comp2, "bounds", horizontal ? (divider + 5) : 0, + horizontal ? 0 : (divider + 5), + horizontal ? (bounds.width - 5 - divider) : bounds.width, + horizontal ? bounds.height : (bounds.height - 5 - divider)); + doLayout(comp2); + } + } + else if (("list" == classname) || + ("table" == classname) || ("tree" == classname)) { + int width = 0; + int columnheight = 0; + if ("table" == classname) { + for (Object column = get(component, "column"); + column != null; column = get(column, ":next")) { + width += getInteger(column, "width", 80); + Dimension d = getSize(column, 2, 2, "left"); + columnheight = Math.max(columnheight, d.height); + } + } + String itemname = ("list" == classname) ? "item" : + (("table" == classname) ? "row" : "node"); + int y = 0; + int level = 0; + for (Object item = get(component, itemname); item != null;) { + int x = 0; + int iwidth = 0; int iheight = 0; + if ("table" == classname) { + iwidth = width; + for (Object cell = get(item, "cell"); + cell != null; cell = get(cell, ":next")) { + Dimension d = getSize(cell, 2, 3, "left"); + iheight = Math.max(iheight, d.height); + } + } + else { + if ("tree" == classname) { + x = (level + 1) * block; + } + Dimension d = getSize(item, 2, 3, "left"); + iwidth = d.width; iheight = d.height; + width = Math.max(width, x + d.width); + } + setRectangle(item, "bounds", x, y, iwidth, iheight); + y += iheight; + if ("tree" == classname) { + Object next = get(item, "node"); + if ((next != null) && getBoolean(item, "expanded", true)) { + level++; + } else { + while (((next = get(item, ":next")) == null) && (level > 0)) { + item = getParent(item); + level--; + } + } + item = next; + } else { + item = get(item, ":next"); + } + } + layoutScrollPane(component, width, y - 1, 0, columnheight); + } + else if ("menubar" == classname) { + Rectangle bounds = getRectangle(component, "bounds"); + int x = 0; + for (Object menu = get(component, "menu"); + menu != null; menu = get(menu, ":next")) { + Dimension d = getSize(menu, 8, 4, "left"); + setRectangle(menu, "bounds", x, 0, d.width, bounds.height); + x += d.width; + } + } + else if (("combolist" == classname) || ("popupmenu" == classname)) { + boolean combo = ("combolist" == classname); + int pw = 0; int ph = 0; int pxy = combo ? 0 : 1; + for (Object item = get(get(component, combo ? "combobox" : "menu"), + combo ? "choice" : "menu"); item != null; item = get(item, ":next")) { + String itemclass = combo ? null : getClass(item); + Dimension d = (itemclass == "separator") ? new Dimension(1, 1) : + getSize(item, 8 , 4, "left"); + if (itemclass == "checkboxmenuitem") { + d.width = d.width + block + 3; + d.height = Math.max(block, d.height); + } + else if (itemclass == "menu") { + d.width += block; + } + setRectangle(item, "bounds", pxy, pxy + ph, d.width, d.height); + pw = Math.max(pw, d.width); + ph += d.height; + } + Rectangle r = getRectangle(component, "bounds"); + r.width = pw + 2; r.height = ph + 2; + if (combo) { + Rectangle db = getRectangle(content, "bounds"); + if (r.y + ph + 2 > db.height) { + r.width = pw + 2 + block; + r.height = db.height - r.y; + } + else { + r.height = Math.min(r.height, db.height - r.y); + } + r.width = Math.min(r.width, db.width - r.x); + layoutScrollPane(component, pw, ph, 0, 0);//~ + } + } + //java> + else if ("bean" == classname) { + Rectangle r = getRectangle(component, "bounds"); + ((Component) get(component, "bean")).setBounds(r); + } + // text.length()) { setInteger(component, "start", start = text.length(), 0); } + int end = getInteger(component, "end", 0); + if (end > text.length()) { setInteger(component, "end", end = text.length(), 0); } + int offset = getInteger(component, "offset", 0); + int off = offset; + FontMetrics fm = getFontMetrics(getFont()); + int caret = hidden ? (fm.charWidth('*') * end) : + fm.stringWidth(text.substring(0, end)); //java + //midp font.substringWidth(text, 0, end); + if (off > caret) { + off = caret; + } + else if (off < caret - width + 4) { + off = caret - width + 4; + } + off = Math.max(0, Math.min(off, (hidden ? (fm.charWidth('*') * + text.length()) : fm.stringWidth(text)) - width + 4)); + if (off != offset) { + setInteger(component, "offset", off, 0); + } + } + + /** + * + */ + private void layoutScrollPane(Object component, + int contentwidth, int contentheight, int rowwidth, int columnheight) { + Rectangle bounds = getRectangle(component, "bounds"); + boolean hneed = false; boolean vneed = false; + if (contentwidth > bounds.width - rowwidth - 2) { + hneed = true; + vneed = (contentheight > bounds.height - columnheight - 2 - block); + } + if (vneed || (contentheight > bounds.height - columnheight - 2)) { + vneed = true; + hneed = hneed || (contentwidth > bounds.width - rowwidth - 2 - block); + } + int viewportwidth = bounds.width - rowwidth - (vneed ? block : 0); + int viewportheight = bounds.height - columnheight - (hneed ? block : 0); + setRectangle(component, ":port", + rowwidth, columnheight, viewportwidth, viewportheight); //?rowwidth + + Rectangle view = getRectangle(component, ":view"); + setRectangle(component, ":view", + (view != null) ? Math.max(0, + Math.min(view.x, contentwidth - viewportwidth + 2)) : 0, + (view != null) ? Math.max(0, + Math.min(view.y, contentheight - viewportheight + 2)) : 0, + Math.max(viewportwidth - 2, contentwidth), + Math.max(viewportheight - 2, contentheight)); + } + + /** + * + */ + private void scrollToVisible(Object component, + int x, int y, int width, int height) { + Rectangle view = getRectangle(component, ":view"); + Rectangle port = getRectangle(component, ":port"); + int vx = Math.max(x + width - port.width + 2, Math.min(view.x, x)); + int vy = Math.max(y + height - port.height + 2, Math.min(view.y, y)); + if ((view.x != vx) || (view.y != vy)) { + repaint(component); // horizontal | vertical + view.x = vx; view.y = vy; + } + } + + /** + * + */ + public Dimension getPreferredSize() { + return getPreferredSize(content); + } + + /** + * + */ + private Dimension getPreferredSize(Object component) { + int width = getInteger(component, "width", 0); + int height = getInteger(component, "height", 0); + if ((width > 0) && (height > 0)) { + return new Dimension(width, height); + } + String classname = getClass(component); + //System.out.println("classname: " + classname); + if ("label" == classname) { + return getSize(component, 0, 0, "left"); + } + if ("button" == classname) { + return getSize(component, 12, 6, "center"); + } + if ("checkbox" == classname) { + Dimension d = getSize(component, 0, 0, "left"); + d.width = d.width + block + 3; + d.height = Math.max(block, d.height); + return d; + } + if ("combobox" == classname) { + if (getBoolean(component, "editable", true)) { + Dimension size = getFieldSize(component); + Image icon = getIcon(component, "icon", null); + if (icon != null) { + size.width += icon.getWidth(this); + size.height = Math.max(size.height, icon.getHeight(this) + 2); + } + size.width += block; + return size; + } else { + int selected = getInteger(component, "selected", -1); + return getSize((selected != -1) ? + getItemImpl(component, "choice", selected) : + get(component, "choice"), 4 + block, 4, "left"); + } + } + if (("textfield" == classname) || ("passwordfield" == classname)) { + return getFieldSize(component); + } + if ("textarea" == classname) { + int columns = getInteger(component, "columns", 0); + int rows = getInteger(component, "rows", 0); // 'e' -> 'm' ? + FontMetrics fm = getFontMetrics(getFont()); //java + return new Dimension( + ((columns > 0) ? (columns * fm.charWidth('e') + 2) : 76) + 2 + block, + ((rows > 0) ? (rows * fm.getHeight() - fm.getLeading() + 2) : 76) + 2 + block); + } + if ("tabbedpane" == classname) { + String placement = getString(component, "placement", "top"); + boolean horizontal = ((placement == "top") || (placement == "bottom")); + int tabsize = 0; + int contentwidth = 0; int contentheight = 0; + for (Object comp = get(component, "tab"); + comp != null; comp = get(comp, ":next")) { + Dimension d = getSize(comp, 8, 4, "left"); + tabsize = Math.max(tabsize, horizontal ? d.height : d.width); + } + for (Object comp = get(component, "component"); + comp != null; comp = get(comp, ":next")) { + if (!getBoolean(comp, "visible", true)) { continue; } + Dimension d = getPreferredSize(comp); + contentwidth = Math.max(contentwidth, d.width); + contentheight = Math.max(contentheight, d.height); + } + return new Dimension(contentwidth + (horizontal ? 4 : (tabsize + 3)), + contentheight + (horizontal ? (tabsize + 3) : 4)); + } + if (("panel" == classname) || (classname == "dialog")) { + Dimension size = new Dimension( + getInteger(component, "left", 0) + getInteger(component, "right", 0), + getInteger(component, "top", 0) + getInteger(component, "bottom", 0)); + if (classname == "dialog") { + int titleheight = getSize(component, 0, 0, "left").height; + setInteger(component, "titleheight", titleheight, 0); + size.width += 8; size.height += 8 + titleheight; + } + int gap = getInteger(component, "gap", 0); + int[][] grid = getGrid(component, gap); + if (grid != null) { + size.width += getSum(grid[0], 0, grid[0].length, gap, false); + size.height += getSum(grid[1], 0, grid[1].length, gap, false); + } + return size; + } + else if ("desktop" == classname) { + Dimension size = new Dimension(); + for (Object comp = get(component, "component"); + comp != null; comp = get(comp, ":next")) { + String iclass = getClass(comp); + if ((iclass != "dialog") && (iclass != "popupmenu") && + (iclass != "combolist")) { + Dimension d = getPreferredSize(comp); + size.width = Math.max(d.width, size.width); + size.height = Math.max(d.height, size.height); + } + } + return size; + } + if ("spinbox" == classname) { + Dimension size = getFieldSize(component); + size.width += block; + return size; + } + if ("progressbar" == classname) { + boolean horizontal = ("vertical" != get(component, "orientation")); + return new Dimension(horizontal ? 76 : 6, horizontal ? 6 : 76); + } + if ("slider" == classname) { + boolean horizontal = ("vertical" != get(component, "orientation")); + return new Dimension(horizontal ? 76 : 10, horizontal ? 10 : 76); + } + if ("splitpane" == classname) { + boolean horizontal = ("vertical" != get(component, "orientation")); + Object comp1 = get(component, "component"); + Dimension size = ((comp1 == null) || !getBoolean(comp1, "visible", true)) ? + new Dimension() : getPreferredSize(comp1); + Object comp2 = get(comp1, ":next"); + if ((comp2 != null) && getBoolean(comp2, "visible", true)) { + Dimension d = getPreferredSize(comp2); + size.width = horizontal ? (size.width + d.width) : + Math.max(size.width, d.width); + size.height = horizontal ? Math.max(size.height, d.height) : + (size.height + d.height); + } + if (horizontal) { size.width += 5; } else { size.height += 5; } + return size; + } + if (("list" == classname) || + ("table" == classname) || ("tree" == classname)) { + return new Dimension(76 + 2 + block, 76 + 2 + block); + } + if ("separator" == classname) { + return new Dimension(1, 1); + } + if ("menubar" == classname) { + Dimension size = new Dimension(0, 0); + for (Object menu = get(component, "menu"); + menu != null; menu = get(menu, ":next")) { + Dimension d = getSize(menu, 8, 4, "left"); + size.width += d.width; + size.height = Math.max(size.height, d.height); + } + return size; + } + //java> + if ("bean" == classname) { + return ((Component) get(component, "bean")).getPreferredSize(); + } + // columns)) { + x = 0; y++; j = -1; + } + else if (columnheight[x + j] > y) { + x += (j + 1); j = -1; + } + } + if (y + rowspan > grid[1].length) { + int[] rowheights = new int[y + rowspan]; + System.arraycopy(grid[1], 0, rowheights, 0, grid[1].length); + grid[1] = rowheights; + int[] rowweights = new int[y + rowspan]; + System.arraycopy(grid[3], 0, rowweights, 0, grid[3].length); + grid[3] = rowweights; + } + for (int j = 0; j < colspan; j++) { + columnheight[x + j] = y + rowspan; + } + + int weightx = getInteger(comp, "weightx", 0); + int weighty = getInteger(comp, "weighty", 0); + Dimension d = getPreferredSize(comp); + + if (colspan == 1) { + grid[0][x] = Math.max(grid[0][x], d.width); // columnwidths + grid[2][x] = Math.max(grid[2][x], weightx); // columnweights + } + else { + if (cache == null) { cache = new int[4][count]; } + cache[0][i] = d.width; + cache[2][i] = weightx; + if ((nextsize == 0) || (colspan < nextsize)) { nextsize = colspan; } + } + if (rowspan == 1) { + grid[1][y] = Math.max(grid[1][y], d.height); // rowheights + grid[3][y] = Math.max(grid[3][y], weighty); // rowweights + } + else { + if (cache == null) { cache = new int[4][count]; } + cache[1][i] = d.height; + cache[3][i] = weighty; + if ((nextsize == 0) || (rowspan < nextsize)) { nextsize = rowspan; } + } + grid[4][i] = x; //gridx + grid[5][i] = y; //gridy + grid[6][i] = colspan; //gridwidth + grid[7][i] = rowspan; //gridheight + + x += colspan; + i++; + } + + while (nextsize != 0) { + int size = nextsize; nextsize = 0; + for (int j = 0; j < 2; j++) { // horizontal, vertical + for (int k = 0; k < count; k++) { + if (grid[6 + j][k] == size) { // gridwidth, gridheight + int gridpoint = grid[4 + j][k]; // gridx, gridy + + int weightdiff = cache[2 + j][k]; + for (int m = 0; (weightdiff > 0) && (m < size); m++) { + weightdiff -= grid[2 + j][gridpoint + m]; + } + if (weightdiff > 0) { + int weightsum = cache[2 + j][k] - weightdiff; + for (int m = 0; (weightsum > 0) && (m < size); m++) { + int weight = grid[2 + j][gridpoint + m]; + if (weight > 0) { + int weightinc = weight * weightdiff / weightsum; + grid[2 + j][gridpoint + m] += weightinc; + weightdiff -= weightinc; + weightsum -= weightinc; + } + } + grid[2 + j][gridpoint + size - 1] += weightdiff; + } + + int sizediff = cache[j][k]; + int weightsum = 0; + for (int m = 0; (sizediff > 0) && (m < size); m++) { + sizediff -= grid[j][gridpoint + m]; + weightsum += grid[2 + j][gridpoint + m]; + } + if (sizediff > 0) { + for (int m = 0; (weightsum > 0) && (m < size); m++) { + int weight = grid[2 + j][gridpoint + m]; + if (weight > 0) { + int sizeinc = weight * sizediff / weightsum; + grid[j][gridpoint + m] += sizeinc; + sizediff -= sizeinc; + weightsum -= weight; + } + } + grid[j][gridpoint + size - 1] += sizediff; + } + } + else if ((grid[6 + j][k] > size) && + ((nextsize == 0) || (grid[6 + j][k] < nextsize))) { + nextsize = grid[6 + j][k]; + } + } + } + } + return grid; + } + + /** + * + */ + private int getSum(int[] values, + int from, int length, int gap, boolean last) { + if (length <= 0) { return 0; } + int value = 0; + for (int i = 0; i < length; i++) { + value += values[from + i]; + } + return value + (length - (last ? 0 : 1)) * gap; + } + + /** + * + */ + private Dimension getFieldSize(Object component) { + String text = getString(component, "text", ""); + int columns = getInteger(component, "columns", 0); + FontMetrics fm = getFontMetrics(getFont()); + return new Dimension(((columns > 0) ? + (columns * fm.charWidth('e')) : 76) + 4, + fm.getAscent() + fm.getDescent() + 4); // fm.stringWidth(text) + } + + /** + * + */ + private Dimension getSize(Object component, + int dx, int dy, String defaultalignment) { + String text = getString(component, "text", null); + int tw = 0; int th = 0; + if (text != null) { + FontMetrics fm = getFontMetrics(getFont()); + tw = fm.stringWidth(text); + th = fm.getAscent() + fm.getDescent(); + } + Image icon = getIcon(component, "icon", null); + int iw = 0; int ih = 0; + if (icon != null) { + iw = icon.getWidth(this); + ih = icon.getHeight(this); + } + return new Dimension(tw + iw + dx, Math.max(th, ih) + dy); + } + //java> + + /** + * + */ + public void update(Graphics g) { + paint(g); + } + + /** + *~ + */ + public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) { + if (infoflags == ImageObserver.ALLBITS) { + validate(content); + return super.imageUpdate(img, infoflags, x, y, width, height); + } + return true; + } + + /** + * + */ + public void paint(Graphics g) { + //g.setColor(Color.orange); + //g.fillRect(0, 0, getSize().width, getSize().height); + //long time = System.currentTimeMillis(); + Rectangle clip = g.getClipBounds(); + ///dg.setClip(r.x, r.y, r.width, r.height); + paint(g, clip.x, clip.y, clip.width, clip.height, content, isEnabled()); + //System.out.println(System.currentTimeMillis() - time); + ///g.setClip(0, 0, getSize().width, getSize().height); + //g.setColor(Color.red); g.drawRect(clip.x, clip.y, clip.width - 1, clip.height - 1); + } + + // bounds.x + bounds.width) || + (clipy + clipheight < bounds.y) || + (clipy > bounds.y + bounds.height)) { + return; + } + clipx -= bounds.x; clipy -= bounds.y; + String classname = getClass(component); + boolean pressed = (mousepressed == component); + boolean inside = (mouseinside == component) && + ((mousepressed == null) || pressed); + boolean focus = focusinside && (focusowner == component); + enabled = getBoolean(component, "enabled", true); //enabled && + g.translate(bounds.x, bounds.y); + //g.setClip(0, 0, bounds.width, bounds.height); + + if ("label" == classname) { + paintContent(component, g, clipx, clipy, clipwidth, clipheight, + 0, 0, bounds.width, bounds.height, + enabled ? c_text : c_disable, "left", true); + } + else if ("button" == classname) { + paintRect(g, 0, 0, bounds.width, bounds.height, + enabled ? c_border : c_disable, + enabled ? ((inside != pressed) ? c_hover : + (pressed ? c_press : c_ctrl)) : c_bg, true, true, true, true); + if (focus) { + g.setColor(c_focus); + g.drawRect(2, 2, bounds.width - 5, bounds.height - 5); + } + paintContent(component, g, clipx, clipy, clipwidth, clipheight, + 6, 3, bounds.width - 12, bounds.height - 6, + enabled ? c_text : c_disable, "center", true); + } + else if ("checkbox" == classname) { + boolean selected = getBoolean(component, "selected", false); + String group = getString(component, "group", null); + Color border = enabled ? c_border : c_disable; + Color foreground = enabled ? ((inside != pressed) ? c_hover : + (pressed ? c_press : c_ctrl)) : c_bg; + int dy = (bounds.height - block + 2) / 2; + if (group == null) { + paintRect(g, 1, dy + 1, block - 2, block - 2, + border, foreground, true, true, true, true); + } else { + g.setColor((foreground != c_ctrl) ? foreground : c_bg); + g.fillOval(1, dy + 1, block - 3, block - 3); //java + g.setColor(border); + g.drawOval(1, dy + 1, block - 3, block - 3); //java + } + if (focus) { + g.setColor(c_focus); + if (group == null) { + g.drawRect(3, dy + 3, block - 7, block - 7); + } else { + g.drawOval(3, dy + 3, block - 7, block - 7); //java + } + } + if((!selected && inside && pressed) || + (selected && (!inside || !pressed))) { + g.setColor(enabled ? c_text : c_disable); + if (group == null) { + g.fillRect(3, dy + block - 9, 2, 6); + g.drawLine(3, dy + block - 4, block - 4, dy + 3); + g.drawLine(4, dy + block - 4, block - 4, dy + 4); + } else { + g.fillOval(5, dy + 5, block - 10, block - 10); //java + g.drawOval(4, dy + 4, block - 9, block - 9); //java + } + } + paintContent(component, g, clipx, clipy, clipwidth, clipheight, + block + 3, 0, bounds.width - block - 3, bounds.height, + enabled ? c_text : c_disable, "left", true); + } + else if ("combobox" == classname) { + if (getBoolean(component, "editable", true)) { + Image icon = getIcon(component, "icon", null); + int left = (icon != null) ? icon.getWidth(this) : 0; + paintField(g, clipx, clipy, clipwidth, clipheight, component, + bounds.width - block, bounds.height, + inside, pressed, focus, enabled, false, left); + if (icon != null) { + g.drawImage(icon, 2, (bounds.height - icon.getHeight(this)) / 2, this); //java + //midp g.drawImage(icon, 2, bounds.height / 2, Graphics.LEFT | Graphics.VCENTER); + } + paintArrow(g, bounds.width - block, 0, block, bounds.height, + 'S', enabled, inside, pressed, "down", true, false, true, true); + } else { + paintRect(g, 0, 0, bounds.width, bounds.height, + enabled ? c_border : c_disable, + enabled ? ((inside != pressed) ? c_hover : + (pressed ? c_press : c_ctrl)) : c_bg, true, true, true, true); + paintContent(component, g, clipx, clipy, clipwidth, clipheight, + 2, 2, bounds.width - block - 4, bounds.height - 4, + enabled ? c_text : c_disable, "left", false); + paintArrow(g, bounds.width - block, 0, block, bounds.height, 'S'); + if (focus) { + g.setColor(c_focus); + g.drawRect(2, 2, bounds.width - block - 5, bounds.height - 5); + } + } + } + else if ("combolist" == classname) { + Rectangle view = getRectangle(component, ":view"); + Rectangle viewport = getRectangle(component, ":port"); + g.setColor(c_border); + g.drawRect(viewport.x, viewport.y, viewport.width - 1, viewport.height - 1); + if (paintScrollPane(g, clipx, clipy, clipwidth, clipheight, + bounds, view, viewport, enabled, inside, pressed)) { + Object selected = get(component, "inside"); + int ly = clipy - viewport.y - 1; + int yfrom = view.y + Math.max(0, ly); + int yto = view.y + Math.min(viewport.height - 2, ly + clipheight); + for (Object choice = get(get(component, "combobox"), "choice"); + choice != null; choice = get(choice, ":next")) { + Rectangle r = getRectangle(choice, "bounds"); + if (yto <= r.y) { break; } + if (yfrom >= r.y + r.height) { continue; } + boolean armed = (selected == choice); + paintRect(g, r.x, r.y, bounds.width - 2, r.height, c_border, + armed ? c_select : c_bg, false, false, false, false); + paintContent(choice, g, clipx, yfrom, clipwidth, yto - yfrom, + r.x + 4, r.y + 2, bounds.width - 10, r.height - 4, + getBoolean(choice, "enabled", true) ? c_text : c_disable, "left", false); + } + resetScrollPane(g, clipx, clipy, clipwidth, clipheight, view, viewport); + } + //paintRect(g, 0, 0, bounds.width, bounds.height, + // secondary1, c_ctrl, true, true, true, true); + } + else if (("textfield" == classname) || ("passwordfield" == classname)) { + paintField(g, clipx, clipy, clipwidth, clipheight, component, + bounds.width, bounds.height, + inside, pressed, focus, enabled, ("passwordfield" == classname), 0); + } + else if ("textarea" == classname) { + Rectangle view = getRectangle(component, ":view"); + Rectangle viewport = getRectangle(component, ":port"); + boolean editable = getBoolean(component, "editable", true); + paintRect(g, viewport.x, viewport.y, viewport.width, viewport.height, + enabled ? c_border : c_disable, editable ? c_textbg : c_bg, + true, true, true, true); + if (paintScrollPane(g, clipx, clipy, clipwidth, clipheight, + bounds, view, viewport, enabled, inside, pressed)) { + String text = getString(component, "text", ""); + int start = focus ? getInteger(component, "start", 0) : 0; + int end = focus ? getInteger(component, "end", 0) : 0; + int is = Math.min(start, end); int ie = Math.max(start, end); + boolean wrap = getBoolean(component, "wrap", false); + FontMetrics fm = g.getFontMetrics(); //java + int fontascent = fm.getAscent(); int fontheight = fm.getHeight(); //java + //midp int fontheight = fm.getHeight(); + int ascent = 1; + int ly = clipy - viewport.y - 1; + int yfrom = view.y + Math.max(0, ly); + int yto = view.y + Math.min(viewport.height - 2, ly + clipheight); + //g.setColor(Color.pink); g.fillRect(0, yfrom - 1, 75, 2); g.fillRect(0, yto - 1, 75, 2); + + boolean prevletter = false; int n = text.length(); char c = 0; + for (int i = 0, j = -1, k = 0; k <= n; k++) { // j is the last space index (before k) + if (yto <= ascent) { break; } + if (wrap) { + if (((k == n) || ((c = text.charAt(k)) == '\n') || (c == ' ')) && + (j > i) && (fm.stringWidth(text.substring(i, k)) > viewport.width - 4)) { + k--; // draw line to the begin of the current word (+ spaces) if it is out of width + } + else if ((k == n) || (c == '\n')) { // draw line to the text/line end + j = k; prevletter = false; + } + else { + if ((c == ' ') && (prevletter || (j > i))) { j = k; } // keep spaces starting the line + prevletter = (c != ' '); + continue; + } + } + else { + if ((k == n) || ((c = text.charAt(k)) == '\n')) { j = k; } else { continue; } + } + if (yfrom < ascent + fontheight) { + String line = (j != -1) ? text.substring(i, j) : text.substring(i); //java + if (focus && (is != ie) && (ie >= i) && ((j == -1) || (is <= j))) { + int xs = (is < i) ? -1 : (((j != -1) && (is > j)) ? (view.width - 1) : + fm.stringWidth(text.substring(i, is))); //java + //midp font.substringWidth(text, i, is - i)); + int xe = ((j != -1) && (ie > j)) ? (view.width - 1) : + fm.stringWidth(text.substring(i, ie)); //java + //midp font.substringWidth(text, i, ie - i); + g.setColor(c_select); + g.fillRect(1 + xs, ascent, xe - xs, fontheight); + } + g.setColor(enabled ? c_text : c_disable); + g.drawString(line, 1, ascent + fontascent); //java + //midp g.drawSubstring(text, i, ((j != -1) ? j : text.length()) - i, 1, ascent, Graphics.LEFT | Graphics.TOP); + if (focus && (end >= i) && ((j == -1) || (end <= j))) { + int caret = fm.stringWidth(text.substring(i, end)); //java + //midp int caret = font.substringWidth(text, i, end - i); + g.setColor(c_focus); + g.fillRect(caret, ascent, 1, fontheight); + } + } + ascent += fontheight; + i = j + 1; + } + resetScrollPane(g, clipx, clipy, clipwidth, clipheight, view, viewport); + } + } + else if ("tabbedpane" == classname) { + int i = 0; Rectangle last = null; + int selected = getInteger(component, "selected", 0); + String placement = getString(component, "placement", "top"); + for (Object comp = get(component, "tab"); + comp != null; comp = get(comp, ":next")) { + Rectangle r = getRectangle(comp, "bounds"); + boolean hover = !(selected == i) && inside && + (mousepressed == null) && (insidepart == comp); + boolean sel = (selected == i); + boolean tabenabled = enabled && getBoolean(comp, "enabled", true); + paintRect(g, r.x, r.y, r.width, r.height, + enabled ? c_border : c_disable, + tabenabled ? (sel ? c_bg : (hover ? c_hover : c_ctrl)) : c_ctrl, + (placement != "bottom") || !sel, (placement != "right") || !sel, + (placement == "bottom") || ((placement == "top") && !sel), + (placement == "right") || ((placement == "left") && !sel)); + if (focus && sel) { + g.setColor(c_focus); + g.drawRect(r.x + 2, r.y + 2, r.width - 4, r.height - 4); + } + paintContent(comp, g, clipx, clipy, clipwidth, clipheight, + r.x + 4, r.y + 2, r.width - 8, r.height - 4, + tabenabled ? c_text : c_disable, "left", true); + i++; last = r; + } + if (last != null) { + boolean horizontal = ((placement == "top") || (placement == "bottom")); + paintRect(g, horizontal ? (last.x + last.width) : last.x, + horizontal ? last.y : (last.y + last.height), + horizontal ? (bounds.width - last.x - last.width) : last.width, + horizontal ? last.height : (bounds.height - last.y - last.height), + enabled ? c_border : c_disable, c_bg, + (placement != "top"), (placement != "left"), + (placement == "top"), (placement == "left")); + paintRect(g, (placement == "left") ? last.width : 0, + (placement == "top") ? last.height : 0, + horizontal ? bounds.width : (bounds.width - last.width), + horizontal ? (bounds.height - last.height) : bounds.height, + enabled ? c_border : c_disable, c_bg, + (placement != "top"), (placement != "left"), + (placement != "bottom"), (placement != "right")); + } + Object tabcontent = getItemImpl(component, "component", selected); + if (tabcontent != null) { + paint(g, clipx, clipy, clipwidth, clipheight, tabcontent, enabled); + } + } + else if (("panel" == classname) || ("dialog" == classname)) { + if ("dialog" == classname) { + int titleheight = getInteger(component, "titleheight", 0); + paintRect(g, 0, 0, bounds.width, 3 + titleheight, + c_border, c_ctrl, true, true, false, true); + paintRect(g, 0, 3 + titleheight, bounds.width, bounds.height - 3 - titleheight, + c_border, c_press, false, true, true, true); + paintContent(component, g, clipx, clipy, clipwidth, clipheight, + 3, 2, bounds.width - 6, titleheight, c_text, "left", false); + paintRect(g, 3, 3 + titleheight, bounds.width - 6, bounds.height - 6 - titleheight, + c_border, c_bg, true, true, true, true); + } else { + paintRect(g, 0, 0, bounds.width, bounds.height, + c_border, c_bg, false, false, false, false); + } + for (Object comp = get(component, "component"); + comp != null; comp = get(comp, ":next")) { + paint(g, clipx, clipy, clipwidth, clipheight, comp, enabled); + } + } + else if ("desktop" == classname) { + paintReverse(g, clipx, clipy, clipwidth, clipheight, + get(component, "component"), enabled); + //g.setColor(Color.red); if (clip != null) g.drawRect(clipx, clipy, clipwidth, clipheight); + if (tooltipowner != null) { + Rectangle r = getRectangle(tooltipowner, "tooltipbounds"); + paintRect(g, r.x, r.y, r.width, r.height, + c_border, c_bg, true, true, true, true); + String text = getString(tooltipowner, "tooltip", null); + g.setColor(c_text); + g.drawString(text, r.x + 2, r.y + g.getFontMetrics().getAscent() + 2); //java + //midp g.drawString(text, r.x + 2, r.y + (r.height - font.getHeight()) / 2, Graphics.LEFT | Graphics.TOP); + } + } + else if ("spinbox" == classname) { + paintField(g, clipx, clipy, clipwidth, clipheight, component, + bounds.width - block, bounds.height, + inside, pressed, focus, enabled, false, 0); + paintArrow(g, bounds.width - block, 0, block, bounds.height / 2, + 'N', enabled, inside, pressed, "up", true, false, false, true); + paintArrow(g, bounds.width - block, bounds.height / 2, + block, bounds.height - (bounds.height / 2), + 'S', enabled, inside, pressed, "down", true, false, true, true); + } + else if ("progressbar" == classname) { + int minimum = getInteger(component, "minimum", 0); + int maximum = getInteger(component, "maximum", 100); + int value = getInteger(component, "value", 0); + boolean horizontal = ("vertical" != get(component, "orientation")); + int length = (value - minimum) * + ((horizontal ? bounds.width : bounds.height) - 1) / (maximum - minimum); + paintRect(g, 0, 0, horizontal ? length : bounds.width, + horizontal ? bounds.height : length, enabled ? c_border : c_disable, + c_select, true, true, horizontal, !horizontal); + paintRect(g, horizontal ? length : 0, horizontal ? 0 : length, + horizontal ? (bounds.width - length) : bounds.width , + horizontal ? bounds.height : (bounds.height - length), + enabled ? c_border : c_disable, c_bg, true, true, true, true); + } + else if ("slider" == classname) { + int minimum = getInteger(component, "minimum", 0); + int maximum = getInteger(component, "maximum", 100); + int value = getInteger(component, "value", 0); + boolean horizontal = ("vertical" != get(component, "orientation")); + int length = (value - minimum) * + ((horizontal ? bounds.width : bounds.height) - block) / + (maximum - minimum); + paintRect(g, horizontal ? 0 : 3, horizontal ? 3 : 0, + horizontal ? length : (bounds.width - 6), + horizontal ? (bounds.height - 6) : length, + enabled ? c_border : c_disable, + c_bg, true, true, horizontal, !horizontal); + paintRect(g, horizontal ? length : 0, horizontal ? 0 : length, + horizontal ? block : bounds.width, horizontal ? bounds.height : block, + enabled ? c_border : c_disable, + enabled ? c_ctrl : c_bg, true, true, true, true); + if (focus) { + g.setColor(c_focus); + g.drawRect(horizontal ? (length + 2) : 2, horizontal ? 2 : (length + 2), + (horizontal ? block : bounds.width) - 5, + (horizontal ? bounds.height : block) - 5); + //g.drawRect(length + 1, 1, block - 3, bounds.height - 3); + } + paintRect(g, horizontal ? (block + length) : 3, + horizontal ? 3 : (block + length), + bounds.width - (horizontal ? (block + length) : 6), + bounds.height - (horizontal ? 6 : (block + length)), + enabled ? c_border : c_disable, + c_bg, horizontal, !horizontal, true, true); + } + else if ("splitpane" == classname) { + boolean horizontal = ("vertical" != get(component, "orientation")); + int divider = getInteger(component, "divider", -1); + paintRect(g, horizontal ? divider : 0, horizontal ? 0 : divider, + horizontal ? 5 : bounds.width, horizontal ? bounds.height : 5, + c_border, c_bg, false, false, false, false); + g.setColor(enabled ? (focus ? c_focus : c_border) : c_disable); + int xy = horizontal ? bounds.height : bounds.width; + int xy1 = Math.max(0, xy / 2 - 12); + int xy2 = Math.min(xy / 2 + 12, xy - 1); + for (int i = divider + 1; i < divider + 4; i += 2) { + if (horizontal) { g.drawLine(i, xy1, i, xy2); } + else { g.drawLine(xy1, i, xy2, i); } + } + Object comp1 = get(component, "component"); + if (comp1 != null) { + paint(g, clipx, clipy, clipwidth, clipheight, comp1, enabled); + Object comp2 = get(comp1, ":next"); + if (comp2 != null) { + paint(g, clipx, clipy, clipwidth, clipheight, comp2, enabled); + } + } + } + else if (("list" == classname) || + ("table" == classname) || ("tree" == classname)) { + Rectangle view = getRectangle(component, ":view"); + Rectangle viewport = getRectangle(component, ":port"); + int[] columnwidths = null; + int lx = clipx - viewport.x - 1; + int xfrom = view.x + Math.max(0, lx); + int xto = view.x + Math.min(viewport.width - 2, lx + clipwidth); + if ("table" == classname) { + columnwidths = new int[getItemCountImpl(component, "column")]; + int i = 0; int x = 0; boolean drawheader = (clipy < viewport.y); + if (drawheader) { g.setClip(viewport.x, 0, viewport.width, viewport.y); } + for (Object column = get(component, "column"); + column != null; column = get(column, ":next")) { + boolean lastcolumn = (i == columnwidths.length - 1); + int width = getInteger(column, "width", 80); + if (lastcolumn) { width = Math.max(width, viewport.width - x); } + columnwidths[i] = width; + if (drawheader && (xfrom < x + width) && (xto > x)) { + paintRect(g, x - view.x, 0, width, viewport.y, + enabled ? c_border : c_disable, enabled ? c_ctrl : c_bg, + true, true, false, lastcolumn); + paintContent(column, g, clipx, clipy, clipwidth, clipheight, + x + 2 - view.x, 1, width - 2, + viewport.y - 2, enabled ? c_text : c_disable, "left", false); + } + i++; x += width; + } + if (drawheader) { g.setClip(clipx, clipy, clipwidth, clipheight); } + } + paintRect(g, viewport.x, viewport.y, viewport.width, viewport.height, + enabled ? c_border : c_disable, c_textbg, true, true, true, true); + if (paintScrollPane(g, clipx, clipy, clipwidth, clipheight, bounds, + view, viewport, enabled, inside, pressed)) { + Object lead = get(component, "lead"); + int ly = clipy - viewport.y - 1; + int yfrom = view.y + Math.max(0, ly); + int yto = view.y + Math.min(viewport.height - 2, ly + clipheight); + for (Object item = get(component, ("list" == classname) ? "item" : + (("table" == classname) ? "row" : "node")); item != null;) { + Rectangle r = getRectangle(item, "bounds"); + if (lead == null) { + set(component, "lead", lead = item); // draw first item focused when lead is null + } + if (yto <= r.y) { break; } // the clip bounds are above + + Object next = ("tree" == classname) ? get(item, "node") : null; + boolean expanded = (next != null) && + getBoolean(item, "expanded", true); + if (yfrom < r.y + r.height) { // the clip rectangle is not bellow the current item + boolean selected = getBoolean(item, "selected", false); + paintRect(g, 0, r.y, view.width, r.height, + c_bg, selected ? c_select : c_textbg, false, false, true, false); + if (focus && (lead == item)) { + g.setColor(c_focus); + g.drawRect(0, r.y, view.width - 1, r.height - 2); + } + if ("table" == classname) { + int x = 0; int i = 0; + for (Object cell = get(item, "cell"); + cell != null; cell = get(cell, ":next")) { + if (xto <= x) { break; } + int iwidth = (i < columnwidths.length) ? columnwidths[i] : 80; + if (xfrom < x + iwidth) { + boolean cellenabled = enabled && getBoolean(cell, "enabled", true); + paintContent(cell, g, xfrom, yfrom, xto - xfrom, yto - yfrom, + r.x + x + 1, r.y + 1, iwidth - 2, r.height - 3, + cellenabled ? c_text : c_disable, "left", false); + } + x += iwidth; i++; + } + } else { + boolean itemenabled = enabled && getBoolean(item, "enabled", true); + paintContent(item, g, xfrom, yfrom, xto - xfrom, yto - yfrom, + r.x + 1, r.y + 1, view.width - r.x - 2, + r.height - 3, itemenabled ? c_text : c_disable, "left", false); + + if (next != null) { + int x = r.x - block / 2; + int y = r.y + (r.height - 1) / 2; + //g.drawRect(x - 4, y - 4, 8, 8); + paintRect(g, x - 4, y - 4, 9, 9, itemenabled ? c_border : c_disable, + itemenabled ? c_ctrl : c_bg, true, true, true, true); + g.setColor(itemenabled ? c_text : c_disable); + g.drawLine(x - 2, y, x + 2, y); + if (!expanded) { + g.drawLine(x, y - 2, x, y + 2); + } + } + } + } + if ("tree" == classname) { + if ((next == null) || !expanded) { + while ((item != component) && ((next = get(item, ":next")) == null)) { + item = getParent(item); + } + } + item = next; + } else { + item = get(item, ":next"); + } + } + /*if (columnwidths != null) { + g.setColor(c_bg); + for (int i = 0, cx = -1; i < columnwidths.length - 1; i++) { + cx += columnwidths[i]; + g.drawLine(cx, 0, cx, view.height); + } + }*/ + resetScrollPane(g, clipx, clipy, clipwidth, clipheight, view, viewport); + } + } + else if ("separator" == classname) { + g.setColor(enabled ? c_border : c_disable); + g.fillRect(0, 0, bounds.width, bounds.height); + } + else if ("menubar" == classname) { + Object selected = get(component, "selected"); + int lastx = 0; + for (Object menu = get(component, "menu"); + menu != null; menu = get(menu, ":next")) { + Rectangle mb = getRectangle(menu, "bounds"); + if (clipx + clipwidth <= mb.x) { break; } + if (clipx >= mb.x + mb.width) { continue; } + boolean armed = (selected == menu); + boolean hoover = (selected == null) && (insidepart == menu); + paintRect(g, mb.x, 0, mb.width, bounds.height, enabled ? c_border : c_disable, + enabled ? (armed ? c_select : (hoover ? c_hover : c_ctrl)) : c_bg, + armed, armed, true, armed); + paintContent(menu, g, clipx, clipy, clipwidth, clipheight, + mb.x + 4, 1, mb.width, bounds.height, + (enabled && getBoolean(menu, "enabled", true)) ? c_text : c_disable, + "left", true); + lastx = mb.x + mb.width; + } + paintRect(g, lastx, 0, bounds.width - lastx, bounds.height, + enabled ? c_border : c_disable, enabled ? c_ctrl : c_bg, + false, false, true, false); + } + else if ("popupmenu" == classname) { + paintRect(g, 0, 0, bounds.width, bounds.height, + c_border, c_bg, true, true, true, true); + Object selected = get(component, "selected"); + for (Object menu = get(get(component, "menu"), "menu"); + menu != null; menu = get(menu, ":next")) { + Rectangle r = getRectangle(menu, "bounds"); + if (clipy + clipheight <= r.y) { break; } + if (clipy >= r.y + r.height) { continue; } + String itemclass = getClass(menu); + if (itemclass == "separator") { + g.setColor(c_border); + g.fillRect(r.x, r.y, bounds.width - 2, r.height); + } else { + boolean armed = (selected == menu); + boolean menuenabled = getBoolean(menu, "enabled", true); + paintRect(g, r.x, r.y, bounds.width - 2, r.height, c_border, + armed ? c_select : c_bg, false, false, false, false); + int tx = r.x; + if (itemclass == "checkboxmenuitem") { + tx += block + 3; + boolean checked = getBoolean(menu, "selected", false); + String group = getString(menu, "group", null); + g.translate(r.x + 4, r.y + 2); + g.setColor(menuenabled ? c_border : c_disable); + if (group == null) { + g.drawRect(1, 1, block - 3, block - 3); + } else { + g.drawOval(1, 1, block - 3, block - 3); //java + } + if (checked) { + g.setColor(menuenabled ? c_text : c_disable); + if (group == null) { + g.fillRect(3, block - 9, 2, 6); + g.drawLine(3, block - 4, block - 4, 3); + g.drawLine(4, block - 4, block - 4, 4); + } else { + g.fillOval(5, 5, block - 10, block - 10); //java + g.drawOval(4, 4, block - 9, block - 9); //java + } + } + g.translate(-r.x - 4, -r.y - 2); + } + paintContent(menu, g, clipx, clipy, clipwidth, clipheight, + tx + 4, r.y + 2, bounds.width - 10, + r.height - 4, menuenabled ? c_text : c_disable, "left", true); + if (itemclass == "menu") { + paintArrow(g, r.x + bounds.width - block, r.y, block, r.height, 'E'); + } + } + } + } + //java> + else if ("bean" == classname) { + g.clipRect(0, 0, bounds.width, bounds.height); + ((Component) get(component, "bean")).paint(g); + g.setClip(clipx, clipy, clipwidth, clipheight); + } + // bounds.x + bounds.width) || + (clipy < bounds.y) || + (clipy + clipheight > bounds.y + bounds.height)) { + paintReverse(g, clipx, clipy, clipwidth, clipheight, + get(component, ":next"), enabled); + } + paint(g, clipx, clipy, clipwidth, clipheight, component, enabled); + } + } + + /** + * + */ + private void paintField(Graphics g, + int clipx, int clipy, int clipwidth, int clipheight, Object component, + int width, int height, boolean inside, boolean pressed, + boolean focus, boolean enabled, boolean hidden, int left) { + boolean editable = getBoolean(component, "editable", true); + paintRect(g, 0, 0, width, height, enabled ? c_border : c_disable, + editable ? c_textbg : c_bg, true, true, true, true); + g.clipRect(1 + left, 1, width - left - 2, height - 2); + + String text = getString(component, "text", ""); + int offset = getInteger(component, "offset", 0); + FontMetrics fm = g.getFontMetrics(); //java + + int caret = 0; + if (focus) { + int start = getInteger(component, "start", 0); + int end = getInteger(component, "end", 0); + caret = hidden ? (fm.charWidth('*') * end) : + fm.stringWidth(text.substring(0, end)); //java + //midp font.substringWidth(text, 0, end); + if (start != end) { + int is = hidden ? (fm.charWidth('*') * start) : + fm.stringWidth(text.substring(0, start)); //java + //midp font.substringWidth(text, 0, start); + g.setColor(c_select); + g.fillRect(2 + left - offset + Math.min(is, caret), 1, + Math.abs(caret - is), height - 2); + } + } + + if (focus) { + g.setColor(c_focus); + g.fillRect(1 + left - offset + caret, 1, 1, height - 2); + } + + g.setColor(enabled ? c_text : c_disable); + int fx = 2 + left - offset; + int fy = (height + fm.getAscent() - fm.getDescent()) / 2; //java + //midp int fy = (height - font.getHeight()) / 2; + if (hidden) { + int fh = fm.charWidth('*'); + for (int i = text.length(); i > 0; i--) { + g.drawString("*", fx, fy); //java + //midp g.drawChar('*', fx, fy, Graphics.LEFT | Graphics.TOP); + fx += fh; + } + } else { + g.drawString(text, fx, fy); //java + //midp g.drawString(text, fx, fy, Graphics.LEFT | Graphics.TOP); + } + g.setClip(clipx, clipy, clipwidth, clipheight); + } + + /** + * + */ + private boolean paintScrollPane(Graphics g, + int clipx, int clipy, int clipwidth, int clipheight, Rectangle bounds, + Rectangle view, Rectangle viewport, + boolean enabled, boolean inside, boolean pressed) { + if ((viewport.y + viewport.height < bounds.height) && + (clipy + clipheight > viewport.y + viewport.height)) { // need horizontal + int x = viewport.x; + int y = viewport.y + viewport.height; + int height = bounds.height - y; + int button = Math.min(block, viewport.width / 2); + int track = viewport.width - (2 * button); //max 10 + int knob = Math.min(track, Math.max(track * (viewport.width - 2) / view.width, 6)); + int decrease = view.x * (track - knob) / + (view.width - viewport.width + 2); + int increase = track - decrease - knob; + paintArrow(g, x, y, button, height, + 'W', enabled, inside, pressed, "left", false, true, true, false); + paintRect(g, x + button, y, decrease, height, + enabled ? c_border : c_disable, c_bg, false, true, true, false); + paintRect(g, x + button + decrease, y, knob, height, + enabled ? c_border : c_disable, enabled ? c_ctrl : c_bg, false, true, true, true); + int n = Math.min(5, (knob - 4) / 3); + g.setColor(enabled ? c_border : c_disable); + int cx = (x + button + decrease) + (knob + 2 - n * 3) / 2; + for (int i = 0; i < n; i++ ) { + g.drawLine(cx + i * 3, y + 2, cx + i * 3, y + height - 4); + } + paintRect(g, x + button + decrease + knob, y, increase, height, + enabled ? c_border : c_disable, c_bg, false, false, true, true); + paintArrow(g, x + button + track, y, button, height, + 'E', enabled, inside, pressed, "right", false, false, true, true); + } + if ((viewport.x + viewport.width < bounds.width) && + (clipx + clipwidth > viewport.x + viewport.width)) { // need vertical + int x = viewport.x + viewport.width; + int y = viewport.y; + int width = bounds.width - x; + //if (y > 0) { + // paintRect(g, x - 1, 0, width + 1, y, + // enabled ? c_border : c_disable, c_bg, false, true, false, false); + //} + int track = viewport.height - (2 * block); + int knob = track * (viewport.height - 2) / view.height; + int decrease = view.y * (track - knob) / + (view.height - viewport.height + 2); + int increase = track - decrease - knob; + paintArrow(g, x, y, width, block, + 'N', enabled, inside, pressed, "up", true, false, false, true); + paintRect(g, x, y + block, width, decrease, + enabled ? c_border : c_disable, c_bg, true, false, false, true); + paintRect(g, x, y + block + decrease, width, knob, + enabled ? c_border : c_disable, enabled ? c_ctrl : c_bg, true, false, true, true); + int n = Math.min(5, (knob - 4) / 3); + g.setColor(enabled ? c_border : c_disable); + int cy = (y + block + decrease) + (knob + 2 - n * 3) / 2; + for (int i = 0; i < n; i++ ) { + g.drawLine(x + 2, cy + i * 3, x + width - 4, cy + i * 3); + } + paintRect(g, x, y + block + decrease + knob, width, increase, + enabled ? c_border : c_disable, c_bg, false, false, true, true); + paintArrow(g, x, y + block + track, width, block, + 'S', enabled, inside, pressed, "down", false, false, true, true); + } + if ((clipx + clipwidth > viewport.x) && (clipy + clipheight > viewport.y) && + (clipx < viewport.x + viewport.width) && (clipy < viewport.y + viewport.height)) { + g.clipRect(viewport.x + 1, viewport.y + 1, viewport.width - 2, viewport.height - 2); + g.translate(viewport.x + 1 - view.x, viewport.y + 1 - view.y); + return true; + } + return false; + } + + /** + * + */ + private void resetScrollPane(Graphics g, + int clipx, int clipy, int clipwidth, int clipheight, + Rectangle view, Rectangle viewport) { + g.translate(view.x - viewport.x - 1, view.y - viewport.y - 1); + g.setClip(clipx, clipy, clipwidth, clipheight); + } + + /** + * + */ + private void paintRect(Graphics g, int x, int y, int width, int height, + Color border, Color bg, + boolean top, boolean left, boolean bottom, boolean right) { + if ((width <= 0) || (height <= 0)) return; + g.setColor(border); + if (top) { + g.drawLine(x + width - 1, y, x, y); + y++; height--; if (height <= 0) return; + } + if (left) { + g.drawLine(x, y, x, y + height - 1); + x++; width--; if (width <= 0) return; + } + if (bottom) { + g.drawLine(x, y + height - 1, x + width - 1, y + height - 1); + height--; if (height <= 0) return; + } + if (right) { + g.drawLine(x + width - 1, y + height - 1, x + width - 1, y); + width--; if (width <= 0) return; + } + + //java> + if (bg == c_ctrl) { + if (height > block) { + g.setColor(c_bg); + g.fillRect(x, y, width, height - block); + } + for (int i = 0; i < width; i += block) { + g.drawImage(gradient, x + i, (height > block) ? (y + height - block) : y, + x + Math.min(i + block, width), y + height, + 0, 0, Math.min(block, width - i), Math.min(block, height), null); + } + /*if (width > block) { + g.setColor(c_bg); + g.fillRect(x, y, width - block, height); + } + for (int i = 0; i < height; i += block) { + g.drawImage(gradient, (width > block) ? (x + width - block) : x, y + i, + x + width, y + Math.min(i + block, height), + 0, 0, Math.min(block, width), Math.min(block, height - i), null); + }*/ + } + else { + g.setColor(bg); + g.fillRect(x, y, width, height); + } + // width) || (th > height) || (ih > height); + int cx = x; + if ("center" == alignment) { cx += (width - tw - iw) / 2; } + else if ("right" == alignment) { cx += width - tw - iw; } + + if (clipped) { g.clipRect(x, y, width, height); } + if (icon != null) { + g.drawImage(icon, cx, y + (height - ih) / 2, this); //java + //midp g.drawImage(icon, cx, y + height / 2, Graphics.LEFT | Graphics.VCENTER); + cx += iw; + } + if (text != null) { + int ty = y + (height - th) / 2 + ta; //java + g.drawString(text, cx, ty); //java + //midp g.drawString(text, cx, y + (height - th) / 2, Graphics.LEFT | Graphics.TOP); + if (checkmnemonic) { + int mnemonic = getInteger(component, "mnemonic", -1); + if ((mnemonic != -1) && (mnemonic < text.length())) { + int mx = cx + fm.stringWidth(text.substring(0, mnemonic)); //java + //midp int mx = cx + font.substringWidth(text, 0, mnemonic); + //midp int ty = (height + th) / 2; + g.drawLine(mx, ty + 1, mx + fm.charWidth(text.charAt(mnemonic)), ty + 1); + } + } + } + if (clipped) { g.setClip(clipx, clipy, clipwidth, clipheight); } + } + //midp private void setTimer(long delay) {} + //java> + + /** + * + */ + public synchronized void run() { + while (timer == Thread.currentThread()) { + try { + if (watch == 0) { + wait(0); + } else { + long current = System.currentTimeMillis(); + if (watch > current) { + wait(watch - current); + } else { + watch = 0; + if ((watchdelay == 300L) || (watchdelay == 60L)) { + if (processScroll(mousepressed, pressedpart)) { setTimer(60L); } + } else if ((watchdelay == 375L) || (watchdelay == 75L)) { + if (processSpin(mousepressed, pressedpart)) { setTimer(75L); } + } else if (watchdelay == 750L) { + //System.out.println("> tip: " + getClass(mouseinside) + " : " + ((insidepart instanceof Object[]) ? getClass(insidepart) : insidepart)); + showTip(); + } + } + } + } catch (InterruptedException ie) {} //ie.printStackTrace(); + } + } + + /** + * + */ + private void setTimer(long delay) { + watchdelay = delay; + if (delay == 0) { + watch = 0; + } else { + long prev = watch; + watch = System.currentTimeMillis() + delay; + if (timer == null) { + timer = new Thread(this); + timer.setPriority(Thread.MIN_PRIORITY); + timer.setDaemon(true); + timer.start(); + } + if ((prev == 0) || (watch < prev)) { + synchronized (this) { notify(); } //try {}catch (IllegalMonitorStateException imse) {} + } + } + } + + /** + * + */ + public boolean isFocusTraversable() { + return true; + } + + // 0) { + processKeyPress((popupowner != null) ? popupowner : focusowner, + false, false, 1, keyCode, 0); + } + else { + int keychar = 0, key = 0; + switch (getGameAction(keyCode)) { + case UP: key = KeyEvent.VK_UP; break; + case LEFT: key = KeyEvent.VK_LEFT; break; + case DOWN: key = KeyEvent.VK_DOWN; break; + case RIGHT: key = KeyEvent.VK_RIGHT; break; + case FIRE: key = KeyEvent.VK_ENTER; keychar = KeyEvent.VK_SPACE; break; + case GAME_A: key = KeyEvent.VK_ESCAPE; break; + } + if (key != 0) { + processKeyPress((popupowner != null) ? popupowner : focusowner, + false, false, 1, keychar, key); + } + //if (keyCode == getKeyCode(LEFT)) { + } + } + } + + protected void keyRepeated(int keyCode) { + keyPressed(keyCode); + } + + private static final Command nextcommand = new Command("Next", Command.SCREEN, 0); + //private static final Command prevcommand = new Command("Previous", Command.SCREEN, 0); + { + addCommand(nextcommand); + //addCommand(prevcommand); + setCommandListener(this); + } + + public void commandAction(Command command, Displayable displayable) { + if (command == nextcommand) { + setNextFocusable(focusowner, false); + repaint(focusowner); + closeup(); + } + //else if (command == prevcommand) { + //setPreviousFocusable(focusowner, null, true, true, false); + //repaint(focusowner); + //closeup(); + //} + } + midp*/ + //java> + + /** + * + */ + protected void processEvent(AWTEvent e) { + int id = e.getID(); + if ((id >= MouseEvent.MOUSE_FIRST) && (id <= MouseEvent.MOUSE_LAST)) { + MouseEvent me = (MouseEvent) e; + int x = me.getX(); + int y = me.getY(); + int clickcount = me.getClickCount(); + boolean shiftdown = me.isShiftDown(); + boolean controldown = me.isControlDown(); + boolean popuptrigger = me.isPopupTrigger(); + if (id == MouseEvent.MOUSE_ENTERED) { + if (mousepressed == null) { + findComponent(content, x, y); + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + MouseEvent.MOUSE_ENTERED, mouseinside, insidepart); + } + } + else if (id == MouseEvent.MOUSE_MOVED) { + Object previnside = mouseinside; + Object prevpart = insidepart; + findComponent(content, x, y); + if ((previnside == mouseinside) && (prevpart == insidepart)) { + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + MouseEvent.MOUSE_MOVED, mouseinside, insidepart); + } + else { + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + MouseEvent.MOUSE_EXITED, previnside, prevpart); + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + MouseEvent.MOUSE_ENTERED, mouseinside, insidepart); + } + } + else if (id == MouseEvent.MOUSE_EXITED) { + if (mousepressed == null) { + Object mouseexit = mouseinside; + Object exitpart = insidepart; + mouseinside = insidepart = null; + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + MouseEvent.MOUSE_EXITED, mouseexit, exitpart); + } + } + else if (id == MouseEvent.MOUSE_PRESSED) { + if (popupowner != null) { + String classname = getClass(mouseinside); + if ((popupowner != mouseinside) && + (classname != "popupmenu") && (classname != "combolist")) { + closeup(); + } + } + mousepressed = mouseinside; + pressedpart = insidepart; + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + MouseEvent.MOUSE_PRESSED, mousepressed, pressedpart); + } + else if (id == MouseEvent.MOUSE_DRAGGED) { + Object previnside = mouseinside; + Object prevpart = insidepart; + findComponent(content, x, y); + boolean same = (previnside == mouseinside) && (prevpart == insidepart); + boolean isin = (mousepressed == mouseinside) && (pressedpart == insidepart); + boolean wasin = (mousepressed == previnside) && (pressedpart == prevpart); + + if (wasin && !isin) { + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + MouseEvent.MOUSE_EXITED, mousepressed, pressedpart); + } + else if (!same && (popupowner != null) && !wasin) { + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + DRAG_EXITED, previnside, prevpart); + } + if (isin && !wasin) { + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + MouseEvent.MOUSE_ENTERED, mousepressed, pressedpart); + } + else if (!same && (popupowner != null) && !isin) { + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + DRAG_ENTERED, mouseinside, insidepart); + } + if (isin == wasin) { + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + MouseEvent.MOUSE_DRAGGED, mousepressed, pressedpart); + } + } + else if (id == MouseEvent.MOUSE_RELEASED) { + Object mouserelease = mousepressed; + Object releasepart = pressedpart; + mousepressed = pressedpart = null; + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + MouseEvent.MOUSE_RELEASED, mouserelease, releasepart); + if ((mouseinside != null) && + ((mouserelease != mouseinside) || (releasepart != insidepart))) { + handleMouseEvent(x, y, clickcount, shiftdown, controldown, popuptrigger, + MouseEvent.MOUSE_ENTERED, mouseinside, insidepart); + } + } + } + else if (id == MOUSE_WHEEL) { + Rectangle port = getRectangle(mouseinside, ":port"); + if (port != null) { // is scrollable + Rectangle bounds = getRectangle(mouseinside, "bounds"); + try { // mouse wheel is supported since 1.4 thus it use reflection + if (wheelrotation == null) { + wheelrotation = e.getClass().getMethod("getWheelRotation", null); + } + int rotation = ((Integer) wheelrotation.invoke(e, null)).intValue(); + + if (port.x + port.width < bounds.width) { // has vertical scrollbar + processScroll(mouseinside, (rotation > 0) ? "down" : "up"); + } + else if (port.y + port.height < bounds.height) { // has horizontal scrollbar + processScroll(mouseinside, (rotation > 0) ? "right" : "left"); + } + } catch (Exception exc) { /* never */ } + } + } + else if ((id == KeyEvent.KEY_PRESSED) || (id == KeyEvent.KEY_TYPED)) { + if (focusinside && ((popupowner != null) || (focusowner != null))) { + hideTip(); + KeyEvent ke = (KeyEvent) e; + int keychar = ke.getKeyChar(); + boolean control = (keychar <= 0x1f) || + ((keychar >= 0x7f) && (keychar <= 0x9f)) || + (keychar >= 0xffff) || ke.isControlDown(); + if (control == (id == KeyEvent.KEY_PRESSED)) { + int keycode = control ? ke.getKeyCode() : 0; + if (!processKeyPress((popupowner != null) ? popupowner : focusowner, + ke.isShiftDown(), ke.isControlDown(), ke.getModifiers(), + control ? 0 : keychar, keycode)) { + if ((keycode == KeyEvent.VK_TAB) || + ((keycode == KeyEvent.VK_F6) && (ke.isAltDown() || ke.isControlDown()))) { + boolean outgo = (keycode == KeyEvent.VK_F6); + if (!ke.isShiftDown() ? setNextFocusable(focusowner, outgo) : + setPreviousFocusable(focusowner, outgo)) { + ke.consume(); + } else if (MOUSE_WHEEL != 0) { // 1.4 + if (!ke.isShiftDown()) { + transferFocus(); + } + else { try { + getClass().getMethod("transferFocusBackward", null). invoke(this, null); + } catch (Exception exc) { /* never */ } } + } + repaint(focusowner); + closeup(); + } + else if (keycode == KeyEvent.VK_F8) { + for (Object splitpane = focusowner; + splitpane != null; splitpane = getParent(splitpane)) { + if (getClass(splitpane) == "splitpane") { + setFocus(splitpane); repaint(splitpane); break; //middle + } + } + } + } + else ke.consume(); + /*else if (keycode == KeyEvent.VK_F10) { + Object menubar = null; // find("class", "menubar") + if ((menubar != null) && (get(menubar, "selected") == null)) { + set(menubar, "selected", getMenu(menubar, null, true, false)); + Object popup = popup(menubar, "menubar"); + set(popup, "selected", getMenu(popup, null, true, true)); + repaint(menubar); // , selected + } + }*/ + } + } + } + /*else if (id == KeyEvent.KEY_RELEASED) { + if (focusinside && (focusowner != null)) { + KeyEvent ke = (KeyEvent) e; + //pressedkey = 0; + processKeyRelease(focusowner, ke, ke.getKeyCode()); + } + }*/ + else if (id == FocusEvent.FOCUS_LOST) { + focusinside = false; + if (focusowner != null) { repaint(focusowner); } + closeup(); + } + else if (id == FocusEvent.FOCUS_GAINED) { + focusinside = true; + if (focusowner == null) { setFocus(content); } + else { repaint(focusowner); } + } + else if ((id == ComponentEvent.COMPONENT_RESIZED) || + (id == ComponentEvent.COMPONENT_SHOWN)) { + Dimension d = getSize(); + //System.out.println(id + ": " + d.width + ", " + d.height); + setRectangle(content, "bounds", 0, 0, d.width, d.height); + validate(content); + closeup(); + if (!focusinside) { requestFocus(); } + } + } + + /** + * + */ + /*private boolean processKeyPress(Object component, + KeyEvent e, int keycode, Object invoker) { + if (processKeyPress(component, e, keycode)) { return true; } + for (Object comp = get(component, "component"); + comp != null; comp = get(comp, ":next")) { + if ((comp != invoker) && processKeyPress(comp, e, keycode, null)) { + return true; + } + } + if ((invoker != null) && (component != content)) { + Object parent = getParent(component); + if (parent != null) { + return processKeyPress(parent, e, keycode, component); + } + } + return false; + }*/ + // 0) && (text.charAt(iend - 1) != '\n')) { iend--; } + if (!shiftdown) { istart = iend; } + } + else if ((keycode == KeyEvent.VK_END) && !controldown) { + iend = text.indexOf('\n', end); + if (iend == -1) { iend = text.length(); } + if (!shiftdown) { istart = iend; } + } + else if ((keycode == KeyEvent.VK_UP) || + (keycode == KeyEvent.VK_PAGE_UP)) { + int prev = end; + while ((prev > 0) && (text.charAt(prev - 1) != '\n')) { prev--; } + if (prev != 0) { + int dx = end - prev; + int lines = (keycode == KeyEvent.VK_PAGE_UP) ? + (getRectangle(component, ":port").height / + getFontMetrics(getFont()).getHeight()) : 1; + int first = prev; + do { + prev = first; first--; lines--; + while ((first > 0) && (text.charAt(first - 1) != '\n')) { first--; } + } while ((first > 0) && (lines > 0)); + iend = Math.min(first + dx, prev - 1); + if (!shiftdown) { istart = iend; } + } + } + else if ((keycode == KeyEvent.VK_DOWN) || + (keycode == KeyEvent.VK_PAGE_DOWN)) { + int next = text.indexOf('\n', end); + if (next != -1) { + int prev = end; + while ((prev > 0) && (text.charAt(prev - 1) != '\n')) { prev--; } + if (keycode == KeyEvent.VK_PAGE_DOWN) { + int lines = getRectangle(component, ":port").height / + getFontMetrics(getFont()).getHeight(); + for (int more = 0; (lines > 1) && + ((more = text.indexOf('\n', next + 1)) != -1); next = more) { + lines--; + } + } + int last = text.indexOf('\n', next + 1); + iend = Math.min(next + 1 + end - prev, + (last == -1) ? (text.length() + 1) : last); + if (!shiftdown) { istart = iend; } + } + } + return changeField(component, text, insert, istart, iend, start, end) ? + true : processField(component, shiftdown, controldown, modifiers, + keychar, keycode, true, false); + } + else if ("tabbedpane" == classname) { + if ((keycode == KeyEvent.VK_RIGHT) || (keycode == KeyEvent.VK_DOWN) || + (keycode == KeyEvent.VK_LEFT) || (keycode == KeyEvent.VK_UP)) { + int selected = getInteger(component, "selected", 0); + boolean increase = (keycode == KeyEvent.VK_RIGHT) || (keycode == KeyEvent.VK_DOWN); + int newvalue = selected; + int n = increase ? getItemCountImpl(component, "tab") : 0; + int d = (increase ? 1 : -1); + for (int i = selected + d; increase ? (i < n) : (i >= 0); i += d) { + if (getBoolean(getItemImpl(component, "tab", i), "enabled", true)) { + newvalue = i; break; + } + } + if (newvalue != selected) { + setInteger(component, "selected", newvalue, 0); + repaint(component); + invoke(component, "action"); + } + } + } + else if ("spinbox" == classname) { + if ((keycode == KeyEvent.VK_UP) || (keycode == KeyEvent.VK_DOWN)) { + processSpin(component, (keycode == KeyEvent.VK_UP)? "up" : "down"); + return true; + } + return processField(component, shiftdown, controldown, modifiers, + keychar, keycode, false, false); + } + else if ("slider" == classname) { + int value = getInteger(component, "value", 0); + int d = 0; + if ((keycode == KeyEvent.VK_HOME) || (keycode == KeyEvent.VK_LEFT) || + (keycode == KeyEvent.VK_UP) || (keycode == KeyEvent.VK_PAGE_UP)) { + d = getInteger(component, "minimum", 0) - value; + if ((keycode == KeyEvent.VK_LEFT) || (keycode == KeyEvent.VK_UP)) { + d = Math.max(d, -getInteger(component, "unit", 5)); + } + else if (keycode == KeyEvent.VK_PAGE_UP) { + d = Math.max(d, -getInteger(component, "block", 25)); + } + } + else if ((keycode == KeyEvent.VK_END) || (keycode == KeyEvent.VK_RIGHT) || + (keycode == KeyEvent.VK_DOWN) || (keycode == KeyEvent.VK_PAGE_DOWN)) { + d = getInteger(component, "maximum", 100) - value; + if ((keycode == KeyEvent.VK_RIGHT) || (keycode == KeyEvent.VK_DOWN)) { + d = Math.min(d, getInteger(component, "unit", 5)); + } + else if (keycode == KeyEvent.VK_PAGE_DOWN) { + d = Math.min(d, getInteger(component, "block", 25)); + } + } + if (d != 0) { + setInteger(component, "value", value + d, 0); + repaint(component); + invoke(component, "action"); + } + } + else if ("splitpane" == classname) { + int divider = getInteger(component, "divider", -1); + int d = 0; + if (keycode == KeyEvent.VK_HOME) { + d = -divider; + } + else if ((keycode == KeyEvent.VK_LEFT) || (keycode == KeyEvent.VK_UP)) { + d = Math.max(-10, -divider); + } + else if ((keycode == KeyEvent.VK_END) || + (keycode == KeyEvent.VK_RIGHT) || (keycode == KeyEvent.VK_DOWN)) { + boolean horizontal = ("vertical" != get(component, "orientation")); + Rectangle bounds = getRectangle(component, "bounds"); + int max = (horizontal ? bounds.width : bounds.height) - 5; + d = max - divider; + if (keycode != KeyEvent.VK_END) { + d = Math.min(d, 10); + } + } + if (d != 0) { + setInteger(component, "divider", divider + d, -1); + validate(component); + } + } + else if ("list" == classname) { + return processList(component, shiftdown, controldown, keychar, keycode, "item", null); + } + else if ("table" == classname) { + return processList(component, shiftdown, controldown, keychar, keycode, "row", null); + } + else if ("tree" == classname) { + //? clear childs' selection, select this is its subnode was selected + if (keycode == KeyEvent.VK_LEFT) { + Object lead = get(component, "lead"); + if ((get(lead, "node") != null) && getBoolean(lead, "expanded", true)) { + setBoolean(lead, "expanded", false, true); + selectItem(component, lead, "node", "node"); + validate(component); + invoke(component, "collapse"); //lead + return true; + } + else { + Object parent = getParent(lead); + if (parent != component) { + selectItem(component, parent, "node", "node"); + setLead(component, lead, parent); + return true; + } + } + } + //? for interval mode select its all subnode or deselect all after + else if (keycode == KeyEvent.VK_RIGHT) { + Object lead = get(component, "lead"); + Object node = get(lead, "node"); + if (node != null) { + if (getBoolean(lead, "expanded", true)) { + selectItem(component, node, "node", "node"); + setLead(component, lead, node); + } + else { + setBoolean(lead, "expanded", true, true); + selectItem(component, lead, "node", "node"); + validate(component); + invoke(component, "expand"); //lead + } + return true; + } + } + return processList(component, shiftdown, controldown, keychar, keycode, "node", "node"); + } + else if ("menubar" == classname) { + Object previous = null; Object last = null; + for (Object i = get(component, "popupmenu"); + i != null; i = get(i, "popupmenu")) { + previous = last; last = i; + } + Object selected = get(last, "selected"); + Object hotpopup = ((selected != null) || (previous == null)) ? + last : previous; + if ((selected == null) && (previous != null)) { + selected = get(previous, "selected"); + } + + if ((keycode == KeyEvent.VK_UP) || (keycode == KeyEvent.VK_DOWN)) { + set(hotpopup, "selected", null); + popup(hotpopup, "popupmenu"); + selected = getMenu(hotpopup, + selected, keycode == KeyEvent.VK_DOWN, true); + set(hotpopup, "selected", selected); + repaint(hotpopup); + } + else if (keycode == KeyEvent.VK_LEFT) { + if (previous != null) { + selected = get(previous, "selected"); + set(previous, "selected", null); + popup(previous, "popupmenu"); + set(previous, "selected", selected); + repaint(previous); // , selected + } + else { + selected = getMenu(component, get(component, "selected"), false, false); + set(component, "selected", selected); + Object popup = popup(component, "menubar"); + set(popup, "selected", getMenu(popup, null, true, true)); + repaint(component); // , selected + } + } + else if (keycode == KeyEvent.VK_RIGHT) { + if ((previous != null) && (selected == null)) { + set(last, "selected", get(get(last, "menu"), "menu")); + repaint(last); // , selected + } + else if ((selected != null) && (getClass(selected) == "menu")) { + Object popup = popup(last, "popupmenu"); + set(popup, "selected", get(get(popup, "menu"), "menu")); + } + else { + selected = getMenu(component, get(component, "selected"), true, false); + set(component, "selected", selected); + Object popup = popup(component, "menubar"); + set(popup, "selected", getMenu(popup, null, true, true)); + repaint(component); // , selected + } + } + else if ((keycode == KeyEvent.VK_ENTER) || + (keychar == KeyEvent.VK_SPACE) || (keycode == KeyEvent.VK_ESCAPE)) { + if ((keycode != KeyEvent.VK_ESCAPE) && + getBoolean(selected, "enabled", true)) { + if ((selected != null) && (getClass(selected) == "checkboxmenuitem")) { + changeCheck(selected, false); + } + else invoke(selected, "action"); + } + closeup(component); + } + else return false; + return true; + } + return false; + } + + /** + * + */ + private boolean changeCheck(Object component, boolean box) { + String group = getString(component, "group", null); + if (group != null) { + if (getBoolean(component, "selected", false)) { return false; } + for (Object comp = get(getParent(component), + box ? "component" : "menu"); comp != null; comp = get(comp, ":next")) { + if (comp == component) { + setBoolean(component, "selected", true); + } + else if (group.equals(get(comp, "group")) && + getBoolean(comp, "selected", false)) { + setBoolean(comp, "selected", false); + if (box) { repaint(comp); } //checkbox only + } + } + } + else { + setBoolean(component, "selected", + !getBoolean(component, "selected", false), false); + } + invoke(component, "action"); + return true; + } + + /** + * + */ + private Object getMenu(Object component, Object part, + boolean forward, boolean popup) { + if (forward) { + if (part != null) { part = get(part, ":next"); } + if (part == null) { + part = get(popup ? get(component, "menu") : component, "menu"); + } + } + else { + Object prev = get(popup ? get(component, "menu") : component, "menu"); + for (Object next = get(prev, ":next"); + (next != null) && (next != part); next = get(next, ":next")) { + prev = next; + } + part = prev; + } + return (getClass(part) == "separator") ? + getMenu(component, part, forward, popup) : part; + } + + /** + * + */ + /*private boolean processKeyRelease(Object component, KeyEvent e, int keycode) { + return true; + }*/ + + /** + * + */ + private boolean processField(Object component, + boolean shiftdown, boolean controldown, int modifiers, + int keychar, int keycode, boolean multiline, boolean hidden) { + String text = getString(component, "text", ""); + int start = getInteger(component, "start", 0); + int end = getInteger(component, "end", 0); + boolean editable = getBoolean(component, "editable", true); + + int istart = start; + int iend = end; + String insert = null; + //midp if (editable && (keychar != 0)) { + if (editable && (keychar != 0) && //java + ((modifiers == 0) || (modifiers == InputEvent.SHIFT_MASK))) { //java + insert = String.valueOf((char) keychar); + } + else if (multiline && editable && (keycode == KeyEvent.VK_ENTER)) { + insert = "\n"; + } + else if (editable && (keycode == KeyEvent.VK_BACK_SPACE)) { + insert = ""; + if (start == end) { istart -= 1; } + } + else if (keycode == KeyEvent.VK_END) { + iend = text.length(); + if (!shiftdown) { istart = iend; } + } + else if (keycode == KeyEvent.VK_HOME) { + iend = 0; + if (!shiftdown) { istart = iend; } + } + else if (keycode == KeyEvent.VK_LEFT) { + //java> + if (controldown) { + for (int i = 0; i < 2; i++) { + while ((iend > 0) && ((i != 0) == + Character.isLetterOrDigit(text.charAt(iend - 1)))) { iend--; } + } + } else { + iend -= 1; + } + // + if (controldown) { + for (int i = 0; i < 2; i++) { + while ((iend < text.length()) && ((i == 0) == + Character.isLetterOrDigit(text.charAt(iend)))) { iend++; } + } + } else { + iend += 1; + } + // + try { + /* Personal Basis Profile doesn't contain datatransfer package + Toolkit toolkit = getToolkit(); + Object systemclipboard = toolkit.getClass().getMethod("getSystemClipboard", null).invoke(toolkit, null); + Class selectionclass = Class.forName("java.awt.datatransfer." + "StringSelection"); + Object selection = selectionclass.getConstructor(new Class[] { String.class }). + newInstance(new Object[] { clipboard }); + systemclipboard.getClass().getMethod("setContents", new Class[] { + Class.forName("java.awt.datatransfer." + "Transferable"), + Class.forName("java.awt.datatransfer." + "ClipboardOwner") }). + invoke(systemclipboard, new Object[] { selection, null });*/ + getToolkit().getSystemClipboard().setContents( + new StringSelection(clipboard), null); + } catch (Exception exc) {} + // + try { + /* no datatransfer package in PBP + Toolkit toolkit = getToolkit(); + Object systemclipboard = toolkit.getClass().getMethod("getSystemClipboard", null).invoke(toolkit, null); + Object contents = systemclipboard.getClass().getMethod("getContents", new Class[] { Object.class }). + invoke(systemclipboard, new Object[] { this }); + Class dataflavor = Class.forName("java.awt.datatransfer." + "DataFlavor"); + insert = (String) (contents.getClass().getMethod("getTransferData", new Class[] { dataflavor }). + invoke(contents, new Object[] { dataflavor.getField("stringFlavor").get(null) }));*/ + insert = (String) getToolkit().getSystemClipboard(). + getContents(this).getTransferData(DataFlavor.stringFlavor); + } catch (Exception exc) { + insert = clipboard; + } + // 0x1f) && (ckey < 0x7f)) || + ((ckey > 0x9f) && (ckey < 0xffff)) || + (multiline && (ckey == '\n'))) { + filtered.append(ckey); + } + } + if (filtered.length() != insert.length()) { + insert = filtered.toString(); + } + } + return changeField(component, text, insert, istart, iend, start, end); + } + + /** + * + */ + private boolean changeField(Object component, String text, String insert, + int movestart, int moveend, int start, int end) { + if ((insert == null) && (start == movestart) && (end == moveend)) { + return false; + } + movestart = Math.max(0, Math.min(movestart, text.length())); + moveend = Math.max(0, Math.min(moveend, text.length())); + if (insert != null) { + int min = Math.min(movestart, moveend); + set(component, "text", text.substring(0, min) + insert + + text.substring(Math.max(movestart, moveend))); + movestart = moveend = min + insert.length(); + invoke(component, "action"); + } + if (start != movestart) { setInteger(component, "start", movestart, 0); } + if (end != moveend) { setInteger(component, "end", moveend, 0); } + if ((insert != null) || (start != movestart) || (end != moveend)) { + validate(component); + } + return true; + } + + /** + * + */ + private boolean processList(Object component, boolean shiftdown, boolean controldown, + int keychar, int keycode, String itemname, String leafname) { + if ((keycode == KeyEvent.VK_UP) || + (keycode == KeyEvent.VK_DOWN) || (keycode == KeyEvent.VK_PAGE_UP) || + (keycode == KeyEvent.VK_PAGE_DOWN) || + (keycode == KeyEvent.VK_HOME) || (keycode == KeyEvent.VK_END)) { + Object lead = get(component, "lead"); + Object row = getListItem(component, component, + keycode, lead, itemname, leafname); + if (row != null) { + String selection = getString(component, "selection", "single"); + if (shiftdown && (selection != "single") && (lead != null)) { + extend(component, lead, row, itemname, leafname); + } + else if (!controldown) { + selectItem(component, row, itemname, leafname); + } + setLead(component, lead, row); + Rectangle r = getRectangle(row, "bounds"); + scrollToVisible(component, r.x, r.y, 0, r.height - 1); + return true; + } + } + else if (keychar == KeyEvent.VK_SPACE) { + select(component, get(component, "lead"), + itemname, leafname, shiftdown, controldown); //... + return true; + } + else if (controldown) { + if (((keycode == KeyEvent.VK_A) || (keycode == 0xBF)) && //KeyEvent.VK_SLASH + (getString(component, "selection", "single") != "single")) { + selectAll(component, true, itemname, leafname); + return true; + } + else if (keycode == 0xDC) { //KeyEvent.VK_BACK_SLASH + selectAll(component, false, itemname, leafname); + return true; + } + } + return false; + } + + /** + * + */ + private Object getListItem(Object component, Object scrollpane, + int keycode, Object lead, String itemname, String leafname) { + Object row = null; + if (keycode == KeyEvent.VK_UP) { + for (Object prev = get(component, itemname); prev != lead; + prev = getNextItem(component, prev, leafname)) { + row = prev; // component -> getParent(lead) + } + } + else if (keycode == KeyEvent.VK_DOWN) { + row = (lead == null) ? get(component, itemname) : + getNextItem(component, lead, leafname); + } + else if ((keycode == KeyEvent.VK_PAGE_UP) || + (keycode == KeyEvent.VK_PAGE_DOWN)) { + Rectangle view = getRectangle(scrollpane, ":view"); + Rectangle port = getRectangle(scrollpane, ":port"); + Rectangle rl = (lead != null) ? getRectangle(lead, "bounds") : null; + int vy = (keycode == KeyEvent.VK_PAGE_UP) ? + view.y : (view.y + port.height - 2); + if ((keycode == KeyEvent.VK_PAGE_UP) && + (rl != null) && (rl.y <= view.y)) { + vy -= port.height - 2; + } + if ((keycode == KeyEvent.VK_PAGE_DOWN) && + (rl != null) && (rl.y + rl.height >= view.y + port.height - 2)) { + vy += port.height - 2; + } + for (Object item = get(component, itemname); item != null; + item = getNextItem(component, item, leafname)) { + Rectangle r = getRectangle(item, "bounds"); + if (keycode == KeyEvent.VK_PAGE_UP) { + row = item; + if (r.y + r.height > vy) { break; } + } else { + if (r.y > vy) { break; } + row = item; + } + } + } + else if (keycode == KeyEvent.VK_HOME) { + row = get(component, itemname); + } + else if (keycode == KeyEvent.VK_END) { + for (Object last = lead; last != null; + last = getNextItem(component, last, leafname)) { + row = last; + } + } + return row; + } + + /** + * + */ + private void selectAll(Object component, + boolean selected, String itemname, String leafname) { + boolean changed = false; + for (Object item = get(component, itemname); + item != null; item = getNextItem(component, item, leafname)) { + if (setBoolean(item, "selected", selected, false)) { + repaint(component, null, item); changed = true; + } + } + set(component, "anchor", null); + if (changed) {invoke(component, "action"); } + } + + /** + * + */ + private void selectItem(Object component, + Object row, String itemname, String leafname) { + boolean changed = false; + for (Object item = get(component, itemname); + item != null; item = getNextItem(component, item, leafname)) { + if (setBoolean(item, "selected", (item == row), false)) { + repaint(component, null, item); changed = true; + } + } + set(component, "anchor", null); + if (changed) { invoke(component, "action"); } + } + + /** + * + */ + private void extend(Object component, Object lead, + Object row, String itemname, String leafname) { + Object anchor = get(component, "anchor"); + if (anchor == null) { set(component, "anchor", anchor = lead); } + char select = 'n'; boolean changed = false; + for (Object item = get(component, itemname); // anchor - row + item != null; item = getNextItem(component, item, leafname)) { + if (item == anchor) select = (select == 'n') ? 'y' : 'r'; + if (item == row) select = (select == 'n') ? 'y' : 'r'; + if (setBoolean(item, "selected", (select != 'n'), false)) { + repaint(component, null, item); changed = true; + } + if (select == 'r') select = 'n'; + } + if (changed) { invoke(component, "action"); } + } + + /** + * + */ + private void setLead(Object component, Object oldlead, Object lead) { + if (oldlead != lead) { //? + if (oldlead != null) { repaint(component, null, oldlead); } + set(component, "lead", lead); + repaint(component, null, lead); + } + } + + /*public void repaint(int x, int y, int width, int height) { + System.out.println("repaint(" + x + ", " + y + ", " + width + ", " + height + ")"); + super.repaint(x, y, width, height); + }*/ + + /** + * + */ + private void handleMouseEvent(int x, int y, int clickcount, + boolean shiftdown, boolean controldown, boolean popuptrigger, + int id, Object component, Object part) { + if (id == MouseEvent.MOUSE_ENTERED) { + setTimer(750L); + } + else if (id == MouseEvent.MOUSE_EXITED) { + hideTip(); + } + if (!getBoolean(component, "enabled", true)) { return; } + String classname = getClass(component); + if (("button" == classname) || ("checkbox" == classname)) { + if ((id == MouseEvent.MOUSE_ENTERED) || + (id == MouseEvent.MOUSE_EXITED) || + (id == MouseEvent.MOUSE_PRESSED) || + (id == MouseEvent.MOUSE_RELEASED)) { + if (id == MouseEvent.MOUSE_PRESSED) { + setFocus(component); + } + else if ((id == MouseEvent.MOUSE_RELEASED) && + (mouseinside == component)) { + if ("checkbox" == classname) { + changeCheck(component, true); + } + else invoke(component, "action"); + } + repaint(component); + } + } + else if ("combobox" == classname) { + boolean editable = getBoolean(component, "editable", true); + if (editable && (part == null)) { + Image icon = null; + int left = ((id == MouseEvent.MOUSE_PRESSED) && + ((icon = getIcon(component, "icon", null)) != null)) ? + icon.getWidth(this) : 0; + processField(x, y, clickcount, id, component, part, false, false, left); + } + else if (part != "icon") { // part = "down" + if (((id == MouseEvent.MOUSE_ENTERED) || + (id == MouseEvent.MOUSE_EXITED)) && (mousepressed == null)) { + if (editable) { repaint(component, "combobox", part); } + else { repaint(component); } + } + else if (id == MouseEvent.MOUSE_PRESSED) { + Object combolist = get(component, "combolist"); + if (combolist == null) { + setFocus(component); + repaint(component); + popup(component, classname); + } else { + closeup(component, combolist, null); + } + } + else if (id == MouseEvent.MOUSE_RELEASED) { + if (mouseinside != component) { + Object combolist = get(component, "combolist"); + closeup(component, combolist, + (mouseinside == combolist) ? insidepart : null); + } else { + repaint(component); + } + } + } + } + else if ("combolist" == classname) { + if (!processScroll(x, y, id, component, part)) { + if ((id == MouseEvent.MOUSE_ENTERED) || (id == DRAG_ENTERED)) { + if (part != null) { + // repaint previous inside + set(component, "inside", part); + repaint(component, classname, part); + } + } + else if ((id == MouseEvent.MOUSE_EXITED) || (id == DRAG_EXITED)) { + if (part != null) { + set(component, "inside", null); + repaint(component, classname, part); + } + } + else if (id == MouseEvent.MOUSE_RELEASED) { + closeup(get(component, "combobox"), component, part); + } + } + } + else if (("textfield" == classname) || ("passwordfield" == classname)) { + processField(x, y, clickcount, id, component, part, + false, ("passwordfield" == classname), 0); + } + else if ("textarea" == classname) { + if (!processScroll(x, y, id, component, part)) { + processField(x, y, clickcount, id, component, part, true, false, 0); + } + } + //java> + else if ("desktop" == classname) { + if (id == MouseEvent.MOUSE_ENTERED) { + setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); + } + else if (id == MouseEvent.MOUSE_EXITED) { + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + } + // + else if ((id == MouseEvent.MOUSE_ENTERED) && (mousepressed == null)) { + boolean horizontal = ("vertical" != get(component, "orientation")); + setCursor(Cursor.getPredefinedCursor(horizontal ? + Cursor.E_RESIZE_CURSOR : Cursor.S_RESIZE_CURSOR)); + } + else if (((id == MouseEvent.MOUSE_EXITED) && (mousepressed == null)) || + ((id == MouseEvent.MOUSE_RELEASED) && (mouseinside != component))) { + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + //= r.x - block) && (get(item, "node") != null)) { + boolean expanded = getBoolean(item, "expanded", true); + setBoolean(item, "expanded", !expanded, true); + selectItem(component, item, "node", "node"); + setLead(component, get(component, "lead"), item); + setFocus(component); + validate(component); + invoke(component, expanded ? "collapse" : "expand"); //item + } + break; + } + } + if ((id != MouseEvent.MOUSE_DRAGGED) || + !getBoolean(item, "selected", false)) { + select(component, item, itemname, subitem, shiftdown, controldown); + if (id != MouseEvent.MOUSE_DRAGGED) { + if (setFocus(component)) { repaint(component, classname, item); } //? + } + } + break; + } + item = getNextItem(component, item, subitem); + } + } + } + } + else if ("menubar" == classname) { + Object selected = get(component, "selected"); + if (((id == MouseEvent.MOUSE_ENTERED) || (id == MouseEvent.MOUSE_EXITED)) && + (part != null) && (selected == null)) { + repaint(component, classname, part); + } + else if ((part != null) && ((selected == null) ? + (id == MouseEvent.MOUSE_PRESSED) : + ((id == MouseEvent.MOUSE_ENTERED) || (id == DRAG_ENTERED)))) { + set(component, "selected", part); + popup(component, classname); + repaint(component, classname, part); + } + else if ((id == MouseEvent.MOUSE_PRESSED) && (selected != null)) { + closeup(component); + } + else if (id == MouseEvent.MOUSE_RELEASED) { + if ((part != insidepart) && + ((insidepart == null) || (getClass(insidepart) != "menu"))) { + if ((insidepart != null) && getBoolean(insidepart, "enabled", true)) { + if (getClass(insidepart) == "checkboxmenuitem") { + changeCheck(insidepart, false); + } + else invoke(insidepart, "action"); + } + closeup(component); + } + } + } + else if ("popupmenu" == classname) { + if (part != null) { + if ((id == MouseEvent.MOUSE_ENTERED) || (id == DRAG_ENTERED)) { + set(component, "selected", part); + popup(component, classname); + repaint(component, classname, part); + } + else if (id == MouseEvent.MOUSE_RELEASED) { + if ((insidepart == null) || (getClass(insidepart) != "menu")) { + Object menubar = part; + do { + menubar = getParent(menubar); + } while (getClass(menubar) != "menubar"); + if ((insidepart != null) && getBoolean(insidepart, "enabled", true)) { + if (getClass(insidepart) == "checkboxmenuitem") { + changeCheck(insidepart, false); + } + else invoke(insidepart, "action"); + } + closeup(menubar); + } + } + else if ((id == MouseEvent.MOUSE_EXITED) || (id == DRAG_EXITED)) { + if (getClass(part) != "menu") { + set(component, "selected", null); + } + repaint(component, classname, part); + } + } + } + else if ("dialog" == classname) { + if (part == "header") { + if (id == MouseEvent.MOUSE_PRESSED) { + referencex = mousex; referencey = mousey; + if (!getBoolean(component, "modal", false) && + (get(content, "component") != component)) { + removeItemImpl(content, "component", component); + insertItem(content, "component", component, 0); + set(component, ":parent", content); + repaint(component); + } + } + else if (id == MouseEvent.MOUSE_DRAGGED) { + Rectangle bounds = getRectangle(component, "bounds"); + int dx = mousex - referencex; int dy = mousey - referencey; + repaint(component, + bounds.x + Math.min(0, dx), bounds.y + Math.min(0, dy), + bounds.width + Math.abs(dx), bounds.height + Math.abs(dy)); + bounds.x += dx; bounds.y += dy; + referencex = mousex; referencey = mousey; + } + } + } + } + + /** + * + */ + private void setReference(Object component, int x, int y) { + referencex = x; referencey = y; + for (; component != null; component = getParent(component)) { + Rectangle bounds = getRectangle(component, "bounds"); + referencex += bounds.x; referencey += bounds.y; + } + } + + /** + * + */ + private void select(Object component, Object row, String first, + String child, boolean shiftdown, boolean controldown) { + String selection = getString(component, "selection", "single"); + Object lead = null; + if (shiftdown && (selection != "single") && + ((lead = get(component, "lead")) != null)) { + extend(component, lead, row, first, child); + } + else { + if (controldown && (selection == "multiple")) { + setBoolean(row, "selected", + !getBoolean(row, "selected", false), false); + repaint(component, null, row); + invoke(component, "action"); + set(component, "anchor", null); + } + else if (controldown && getBoolean(row, "selected", false)) { + for (Object item = row; + item != null; item = getNextItem(component, item, child)) { + if (setBoolean(item, "selected", false, false)) { + repaint(component, null, item); + } + } + invoke(component, "action"); + set(component, "anchor", null); + } + else { + selectItem(component, row, first, child); + } + } + setLead(component, (lead != null) ? lead : get(component, "lead"), row); + } + + /** + * + */ + private Object getNextItem(Object component, + Object item, String subitem) { + if (subitem == null) { return get(item, ":next"); } + Object next = get(item, subitem); + if ((next == null) || !getBoolean(item, "expanded", true)) { + while ((item != component) && ((next = get(item, ":next")) == null)) { + item = getParent(item); + } + } + return next; + } + + /** + * + */ + private void processField(int x, int y, int clickcount, + int id, Object component, + Object part, boolean multiline, boolean hidden, int left) { + if (id == MouseEvent.MOUSE_PRESSED) { + setReference(component, 2 + left, 2); + int mx = x - referencex; + int my = 0; + if (!multiline) { + mx += getInteger(component, "offset", 0); + } else { + Rectangle view = getRectangle(component, ":view"); + mx += view.x - 1; + my = y - referencey + view.y - 1; + } + int caretstart = getCaretLocation(component, mx, my, hidden); + int caretend = caretstart; + //java> + if (clickcount > 1) { + String text = getString(component, "text", ""); + while ((caretstart > 0) && ((clickcount == 2) ? + Character.isLetterOrDigit(text.charAt(caretstart - 1)) : + (text.charAt(caretstart - 1) != '\n'))) { caretstart--; } + while ((caretend < text.length()) && ((clickcount == 2) ? + Character.isLetterOrDigit(text.charAt(caretend)) : + (text.charAt(caretend) != '\n'))) { caretend++; } + } + // + else if ((id == MouseEvent.MOUSE_ENTERED) && (mousepressed == null)) { + setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR)); + } + else if (((id == MouseEvent.MOUSE_EXITED) && (mousepressed == null)) || + ((id == MouseEvent.MOUSE_RELEASED) && + ((mouseinside != component) || (insidepart != null)))) { + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + } + // 0)) || + (((part == "right") || (part == "righttrack")) && + (view.x < view.width - port.width + 2)) || + (((part == "up") || (part == "uptrack")) && (view.y > 0)) || + (((part == "down") || (part == "downtrack")) && + (view.y < view.height - port.height + 2)); + } + + /** + * + */ + private boolean processSpin(Object component, Object part) { + String text = getString(component, "text", null); + if (text != null) { + try { + String value = String.valueOf( + Integer.parseInt(text) + ((part == "up") ? 1 : -1)); + setString(component, "text", value, null); + setInteger(component, "start", value.length(), 0); + setInteger(component, "end", 0, 0); + repaint(component, "spinbox", null); + invoke(component, "action"); + return true; + } catch (NumberFormatException nfe) {} + } + return false; + } + + //java> + /*public void setEventHandler(Object component, Object eventhandler) { + set(component, ":handler", eventhandler); + }*/ + + /** + * + */ + private void invoke(Object component, String event) { + Method method = (Method) get(component, event); + if (method != null) { + try { + method.invoke(this, null); + } catch (InvocationTargetException ite) { + ite.getTargetException().printStackTrace(); + } catch (Exception exc) { + exc.printStackTrace(); + } + } + } + //= bounds.width) || + //midp (y < bounds.y) || (y - bounds.y >= bounds.height)) { return false; } + mouseinside = component; + x -= bounds.x; y -= bounds.y; + String classname = getClass(component); + + if ("combobox" == classname) { + if (getBoolean(component, "editable", true) && (x <= bounds.width - block)) { + Image icon = getIcon(component, "icon", null); + insidepart = ((icon != null) && (x <= 2 + icon.getWidth(this))) ? + "icon" : null; + } else { + insidepart = "down"; + } + } + else if ("combolist" == classname) { + if (!findScrollPane(component, x, y, bounds)) { + y += getRectangle(component, ":view").y; + for (Object choice = get(get(component, "combobox"), "choice"); + choice != null; choice = get(choice, ":next")) { + Rectangle r = getRectangle(choice, "bounds"); + if ((y >= r.y) && (y < r.y + r.height)) { + insidepart = choice; break; + } + } + } + } + else if ("textarea" == classname) { + findScrollPane(component, x, y, bounds); + } + else if ("tabbedpane" == classname) { + Object tabcontent = getItemImpl(component, + "component", getInteger(component, "selected", 0)); + if ((tabcontent == null) || !findComponent(tabcontent, x, y)) { + for (Object comp = get(component, "tab"); + comp != null; comp = get(comp, ":next")) { + Rectangle r = getRectangle(comp, "bounds"); + if (r.contains(x, y)) { //java + //midp if ((x >= r.x) && (x - r.x < r.width) && (y >= r.y) && (y - r.y < r.height)) { + insidepart = comp; break; + } + } + } + } + else if (("panel" == classname) || ("desktop" == classname) || + ("dialog" == classname)) { + if (("dialog" == classname) && + (y < 4 + getInteger(component, "titleheight", 0))) { + insidepart = "header"; + } else { + for (Object comp = get(component, "component"); + comp != null; comp = get(comp, ":next")) { + if (findComponent(comp, x, y)) { break; } + if (("desktop" == classname) && + getBoolean(comp, "modal", false)) { break; } // && dialog + } + } + } + else if ("spinbox" == classname) { + insidepart = (x <= bounds.width - block) ? null : + ((y <= bounds.height / 2) ? "up" : "down"); + } + else if ("splitpane" == classname) { + Object comp1 = get(component, "component"); + if (comp1 != null) { + if (!findComponent(comp1, x, y)) { + Object comp2 = get(comp1, ":next"); + if (comp2 != null) { + findComponent(comp2, x, y); + } + } + } + } + else if ("list" == classname) { + findScrollPane(component, x, y, bounds); + } + else if ("table" == classname) { + findScrollPane(component, x, y, bounds); + } + else if ("tree" == classname) { + findScrollPane(component, x, y, bounds); + } + else if ("menubar" == classname) { + for (Object menu = get(component, "menu"); + menu != null; menu = get(menu, ":next")) { + Rectangle r = getRectangle(menu, "bounds"); + if ((x >= r.x) && (x < r.x + r.width)) { + insidepart = menu; break; + } + } + } + else if ("popupmenu" == classname) { + for (Object menu = get(get(component, "menu"), "menu"); + menu != null; menu = get(menu, ":next")) { + Rectangle r = getRectangle(menu, "bounds"); + if ((y >= r.y) && (y < r.y + r.height)) { + insidepart = menu; break; + } + } + } + return true; + } + + /** + * + */ + private boolean findScrollPane(Object component, + int x, int y, Rectangle bounds) { + Rectangle port = getRectangle(component, ":port"); + if ((x < port.x) || (y < port.y) || + ((x >= port.x + port.width) && (y >= port.y + port.height))) { + insidepart = "corner"; + } + else if ((x >= port.x + port.width) || (y >= port.y + port.height)) { + boolean horizontal = (y >= port.y + port.height); + int p = horizontal ? (x - port.x) : (y - port.y); + int portsize = horizontal ? port.width : port.height; + int button = Math.min(block, portsize / 2); + if (p < button) { + insidepart = horizontal ? "left" : "up"; + } + else if (p >= portsize - button) { + insidepart = horizontal ? "right" : "down"; + } + else { + Rectangle view = getRectangle(component, ":view"); + int viewp = horizontal ? view.x : view.y; + int viewsize = horizontal ? view.width : view.height; + int track = portsize - (2 * button); + int knob = Math.min(track, + Math.max(track * (portsize - 2) / viewsize, 6)); + int decrease = viewp * (track - knob) / (viewsize - portsize + 2); + if (p < button + decrease) { + insidepart = horizontal ? "lefttrack" : "uptrack"; + } + else if (p < button + decrease + knob) { + insidepart = horizontal ? "hknob" : "vknob"; + } + else { + insidepart = horizontal ? "righttrack" : "downtrack"; + } + } + } + else { return false; } + return true; + } + + /** + * + */ + private void repaint(Object component, Object classname, Object part) { + Rectangle b = getRectangle(component, "bounds"); + if ((classname == "combobox") || (classname == "spinbox")) { + boolean down = (part == "up") || (part == "down"); // else text + repaint(component, down ? (b.x + b.width - block) : b.x, b.y, + down ? block : (b.width - block), b.height); + } + //else if (classname == "dialog") {} + //int titleheight = getInteger(component, "titleheight", 0); + //else if (classname == "splitpane") {} + else if ((classname == "tabbedpane") || + (classname == "menubar") || (classname == "popupmenu")) { + Rectangle r = getRectangle(part, "bounds"); + repaint(component, b.x + r.x, b.y + r.y, + (classname == "popupmenu") ? b.width : r.width, r.height); + } + else //if ((classname == "combolist") || (classname == "textarea") || + {//(classname == "list") || (classname == "table") || (classname == "tree")) { + Rectangle port = getRectangle(component, ":port"); + if (part == "left") { + repaint(component, b.x + port.x, b.y + b.height - block, block, block); + } + else if (part == "right") { + repaint(component, b.x + port.x + port.width - block, b.y + b.height - block, block, block); + } + else if (part == "up") { + repaint(component, b.x + b.width - block, b.y + port.y, block, block); + } + else if (part == "down") { + repaint(component, b.x + b.width - block, b.y + port.y + port.height - block, block, block); + } + else if (part == "horizontal") { // horizontaly center part + repaint(component, b.x + port.x, b.y, port.width, b.height); + } + else if (part == "vertical") { + repaint(component, b.x, b.y + port.y, b.width, port.height); + } + else if (part == "text") { //textarea + repaint(component, b.x + port.x, b.y + port.y, port.width, port.height); + } + else { + Rectangle view = getRectangle(component, ":view"); + Rectangle r = getRectangle(part, "bounds"); + if ((r.y + r.height >= view.y) && (r.y <= view.y + port.height)) { + repaint(component, b.x + port.x, b.y + port.y - view.y + 1 + r.y, + port.width, r.height); + //? need cut item rectangle above/bellow viewport + } + } + } + } + + /** + * + */ + private void validate(Object component) { + repaint(component); + Rectangle bounds = getRectangle(component, "bounds"); + bounds.width = -1 * Math.abs(bounds.width); + } + + /** + * + */ + private void repaint(Object component) { + Rectangle bounds = getRectangle(component, "bounds"); + if (bounds != null) { + repaint(component, bounds.x, bounds.y, bounds.width, bounds.height); + } + } + + /** + * + */ + private void repaint(Object component, int x, int y, int width, int height) { + while ((component = getParent(component)) != null) { + Rectangle bounds = getRectangle(component, "bounds"); + x += bounds.x; + y += bounds.y; + } + repaint(x, y, width, height); + } + + /*private void clip(Graphics g, + Rectangle clip, int x, int y, int width, int height) { + int x1 = Math.max(clip.x, x); + int y1 = Math.max(clip.y, y); + int x2 = Math.min(clip.x + clip.width, x + width); + int y2 = Math.min(clip.y + clip.height, y + height); + g.setClip(x1, y1, x2 - x1, y2 - y1); + }*/ + + /** + * + */ + public boolean requestFocus(Object component) { + if (checkFocusable(component, true)) { + setFocus(component); return true; + } + return false; + } + + /** + * + */ + private boolean setFocus(Object component) { + if (!focusinside) { //java + requestFocus(); //java + } //java + if (focusowner != component) { + Object focused = focusowner; + focusowner = component; + if (focused != null) { + //mouseEvent(null, FocusEvent.FOCUS_LOST, focused, null, null); + repaint(focused); + //focusGained(component); + } + return true; + } + return false; + } + + /** + * @return next focusable component is found (not the first of the desktop/dialog) + */ + private boolean setNextFocusable(Object current, boolean outgo) { + boolean consumed = true; + for (Object next = null, component = current; true; component = next) { + next = get(component, "component"); // check first subcomponent + if (next == null) { next = get(component, ":next"); } // check next component + while (next == null) { // find the next of the parents, or the topmost + component = getParent(component); // current is not on the desktop + if (component == null) { return false; } + if ((component == content) || ((getClass(component) == "dialog") && + (!outgo || getBoolean(component, "modal", false)))) { + consumed = false; // find next focusable but does not consume event + next = component; // the topmost (desktop or modal dialog) + } + else { + next = get(component, ":next"); + } + } + if (next == current) { return false; } // one fucusable, no loop + if (checkFocusable(next, false)) { + setFocus(next); + return consumed; + } + } + } + + //java> + /** + * @return previous focusable component is found (not the last of the desktop/dialog) + */ + private boolean setPreviousFocusable(Object component, boolean outgo) { + for (int i = 0; i < 2; i++) { // 0 is backward direction + Object previous = getPreviousFocusable(component, null, true, false, (i == 0), outgo); + if (previous != null) { + setFocus(previous); + return (i == 0); + } + } + return false; + } + + /** + * For the starting component search its parent direction for a focusable component, and then + * its next component (if not search backward from the component).
+ * For its parent components check its first component, the current one, and its parent direction + * (backward search), or its parent, then next component (forward direction).
+ * For the rest components check the next, then the first subcomponent direction, and finally + * check whether the component is focusable. + */ + private Object getPreviousFocusable(Object component, + Object block, boolean start, boolean upward, boolean backward, boolean outgo) { + Object previous = null; + if ((component != null) && (component != block)) { + boolean go = ((getClass(component) != "dialog") || + (outgo && !getBoolean(component, "modal", false))); + if (!start && !upward && go) { + previous = getPreviousFocusable(get(component, ":next"), block, false, false, backward, outgo); + } + if ((previous == null) && ((upward && backward) || (!start && !upward))) { + previous = getPreviousFocusable(get(component, "component"), block, false, false, backward, outgo); + if ((previous == null) && checkFocusable(component, false)) { + previous = component; + } + } + if ((previous == null) && (start || upward) && go) { + previous = getPreviousFocusable(getParent(component), component, false, true, backward, outgo); + } + if ((previous == null) && (start || upward) && !backward && go) { + previous = getPreviousFocusable(get(component, ":next"), block, false, false, backward, outgo); + } + } + return previous; + } + // " + path + " " + inputstream); + } catch (Throwable e) {} //java + //if (inputstream == null) { // applet code + // inputstream = new URL(getCodeBase(), path).openStream(); + //} + return parse(inputstream); //, Object handler + } + + /** + * + */ + public Object parse(InputStream inputstream) throws Exception { + return parse(inputstream, true); + } + + /** + * + */ + protected void parseXML(InputStream inputstream) throws Exception { + parse(inputstream, false); + } + + /** + * + */ + protected void startElement(String name, Hashtable attributelist) {} + + /** + * + */ + protected void characters(String text) {} + + /** + * + */ + protected void endElement() {} + + /** + * + */ + private Object parse(InputStream inputstream, boolean validate) throws Exception { + BufferedReader reader = new BufferedReader(new InputStreamReader(inputstream)); //java + //midp InputStreamReader reader = new InputStreamReader(inputstream); + Object[] parentlist = null; + Object current = null; + Hashtable attributelist = null; + StringBuffer text = new StringBuffer(); + for (int c = reader.read(); c != -1;) { + if (c == '<') { + if ((c = reader.read()) == '/') { //endtag + if (text.length() > 0) { + if (text.charAt(text.length() - 1) == ' ') { + text.setLength(text.length() - 1); + } + if (!validate) { + characters(text.toString()); + }// else { + //addContent(current, text.toString()); + //} + text.setLength(0); + } + String tagname = (String) parentlist[2]; //getClass(current); + for (int i = 0; i < tagname.length(); i++) { // current-tag + if ((c = reader.read()) != tagname.charAt(i)) { + throw new IllegalArgumentException(tagname); + } + } + while (" \t\n\r".indexOf(c = reader.read()) != -1); // whitespace + if (c != '>') throw new IllegalArgumentException(); // '>' + c = reader.read(); + if (!validate) { endElement(); } + if (parentlist[0] == null) { + reader.close(); + return current; + } + current = parentlist[0]; + parentlist = (Object[]) parentlist[1]; + } + else { //start or standalone tag + boolean instruction = (c == '?'); // Processing Instructions + if (c == '!') { while ((c = reader.read()) != '>'); continue; } // DOCTYPE + if (instruction) { c = reader.read(); } + text.setLength(0); + boolean iscomment = false; + while (">/ \t\n\r".indexOf(c) == -1) { + text.append((char) c); + if ((text.length() == 3) && (text.charAt(0) == '!') && + (text.charAt(1) == '-') && (text.charAt(2) == '-')) { + int m = 0; + while (true) { + c = reader.read(); + if (c == '-') { m++; } + else if ((c == '>') && (m >= 2)) { break; } + else { m = 0; } + } + iscomment = true; + } + c = reader.read(); + } + if (iscomment) { continue; } + if (!instruction) { + String tagname = text.toString(); + parentlist = new Object[] { current, parentlist, tagname }; + if (validate) { + current = (current != null) ? + addElement(current, tagname) : create(tagname); + } else { + current = tagname; + } + } + text.setLength(0); + while (true) { + boolean whitespace = false; + while (" \t\n\r".indexOf(c) != -1) { + c = reader.read(); + whitespace = true; + } + if (c == '>') { + if (instruction) throw new IllegalArgumentException(); // '?>' + if (!validate) { + startElement((String) current, attributelist); attributelist = null; + } + c = reader.read(); + break; + } + else if (c == '/') { + if (instruction) throw new IllegalArgumentException(); // '?>' + if ((c = reader.read()) != '>') { + throw new IllegalArgumentException(); // '>' + } + if (!validate) { + startElement((String) current, attributelist); attributelist = null; + endElement(); + } + if (parentlist[0] == null) { + reader.close(); + return current; + } + current = parentlist[0]; + parentlist = (Object[]) parentlist[1]; + c = reader.read(); + break; + } + else if (instruction && (c == '?')) { + if ((c = reader.read()) != '>') { + throw new IllegalArgumentException(); // '>' + } + c = reader.read(); + break; + } + else if (whitespace) { + while ("= \t\n\r".indexOf(c) == -1) { + text.append((char) c); + c = reader.read(); + } + String key = text.toString(); + text.setLength(0); + while (" \t\n\r".indexOf(c) != -1) c = reader.read(); + if (c != '=') throw new IllegalArgumentException(); + while (" \t\n\r".indexOf(c = reader.read()) != -1); + char quote = (char) c; + if ((c != '\"') && (c != '\'')) throw new IllegalArgumentException(); + while (quote != (c = reader.read())) { + if (c == '&') { + StringBuffer eb = new StringBuffer(); + while (';' != (c = reader.read())) { eb.append((char) c); } + String entity = eb.toString(); + if ("lt".equals(entity)) { text.append('<'); } + else if ("gt".equals(entity)) { text.append('>'); } + else if ("amp".equals(entity)) { text.append('&'); } + else if ("quot".equals(entity)) { text.append('"'); } + else if ("apos".equals(entity)) { text.append('\''); } + else if (entity.startsWith("#")) { + text.append((char) Integer.parseInt(entity.substring(1))); + } + else throw new IllegalArgumentException("unknown " + "entity " + entity); + } + else text.append((char) c); + } + if (!instruction) { + if (validate) { + addAttribute(current, key, text.toString()); + } else { + if (attributelist == null) { attributelist = new Hashtable(); } + attributelist.put(key, text.toString()); + } + } + text.setLength(0); + c = reader.read(); + } + else throw new IllegalArgumentException(); + } + } + } + else { + if (" \t\n\r".indexOf(c) != -1) { + if ((text.length() > 0) && (text.charAt(text.length() - 1) != ' ')) { + text.append(' '); + } + } + else { + text.append((char) c); + } + c = reader.read(); + } + } + throw new IllegalArgumentException(); + } + + /** + * Convert entities. + */ + private static String convert(StringBuffer text) { + return null; + } + + /*private InputStream inputreader; + private byte[] data; + private int inputfrom = 0, inputto = 0; + private int read() throws Exception { + if (data == null) { data = new byte[1024]; } + if (inputfrom >= inputto) { + inputfrom = 0; + inputto = inputreader.read(data); + } + inputfrom++; + return data[inputfrom - 1]; + }*/ + + /** + * + */ + private void addImpl(Object parent, Object component, int index) { + String parentclass = getClass(parent); + String classname = getClass(component); + //System.out.println("add " + classname + " -> " + parentclass); + if ((("combobox" == parentclass) && ("choice" == classname)) || + (("tabbedpane" == parentclass) && ("tab" == classname)) || + (("list" == parentclass) && ("item" == classname)) || + (("table" == parentclass) && (("column" == classname) || ("row" == classname))) || + (("row" == parentclass) && ("cell" == classname)) || + ((("tree" == parentclass) || ("node" == parentclass)) && ("node" == classname)) || + (("menubar" == parentclass) && ("menu" == classname))) { + classname = classname; // compiler bug + } + else if (("menu" == parentclass) && (("menu" == classname) || ("menuitem" == classname) || + ("checkboxmenuitem" == classname) || ("separator" == classname))) { + classname = "menu"; + } + else if (("panel" == parentclass) || ("desktop" == parentclass) || + ("splitpane" == parentclass) || ("dialog" == parentclass) || + ("tabbedpane" == parentclass)) { + while ("component" != classname) { + String extendclass = null; + for (int i = 0; i < dtd.length; i += 3) { + if (classname == dtd[i]) { + extendclass = (String) dtd[i + 1]; break; + } + } + if (extendclass == null) throw new IllegalArgumentException(classname + " not component"); + classname = extendclass; + } + } + else throw new IllegalArgumentException(classname + " add " + parentclass); + insertItem(parent, (String) classname, component, index); + set(component, ":parent", parent); + //if (parent == content) System.out.println(getClass(parent) + ".add(" + getClass(component) + ") : " + classname); + } + + /** + * + */ + private Object addElement(Object parent, String name) { + //System.out.println("create '" + name + "'"); + Object component = create(name); + addImpl(parent, component, -1); + return component; + } + + /** + * + */ + private void addAttribute(Object component, String key, String value) { + //System.out.println("attribute '" + key + "'='" + value + "'"); + Object[] definition = getDefinition(component, key, null); + key = (String) definition[1]; + if ("string" == definition[0]) { + setString(component, key, value, (String) definition[3]); + } + else if ("choice" == definition[0]) { + String[] values = (String[]) definition[3]; + setChoice(component, key, value, values, values[0]); + } + else if ("boolean" == definition[0]) { + if ("true".equals(value)) { + if (definition[3] == Boolean.FALSE) { + set(component, key, Boolean.TRUE); + } + } + else if ("false".equals(value)) { + if (definition[3] == Boolean.TRUE) { + set(component, key, Boolean.FALSE); + } + } + else throw new IllegalArgumentException(value); + } + else if ("integer" == definition[0]) { + set(component, key, Integer.valueOf(value)); + } + else if ("icon" == definition[0]) { + set(component, key, getIcon(value)); + } + else if ("method" == definition[0]) { + try { //java + set(component, key, getClass().getMethod(value, null)); //java + } catch (Exception exc) { System.err.println(value); exc.printStackTrace(); } //java + //midp setMethod(component, key, value); + } + //java> + else if ("bean" == definition[0]) { + try { + set(component, key, (Component) Class.forName(value).newInstance()); + } catch (Exception exc) { System.err.println(value); exc.printStackTrace(); } + } + // + try { + image = Toolkit.getDefaultToolkit().getImage(getClass().getResource(path)); + //image = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource(path)); + } catch (Throwable e) {} + if (image == null) { + try { + InputStream is = getClass().getResourceAsStream(path); + //InputStream is = ClassLoader.getSystemResourceAsStream(path); + if (is != null) { + byte[] data = new byte[is.available()]; + is.read(data, 0, data.length); + image = getToolkit().createImage(data); + is.close(); + } + } catch (Throwable e) {} + } + //if (image == null) { // applet code + // try { + // image = getImage(getCodeBase(), path); + // } catch (Throwable e) {} + //} + if (preload && (image != null)) { + MediaTracker mediatracker = new MediaTracker(this); + mediatracker.addImage(image, 1); + try { + mediatracker.waitForID(1, 50); + } catch (InterruptedException ie) { } + //imagepool.put(path, image); + } + //class p4 extends effectiveAccess.pp { + public void f() {} +} + +class pderived extends p2 { + protected void f() { + super.f(); + } + protected void v() { + super.v(); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessLevel/effectiveAccess/pp.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessLevel/effectiveAccess/pp.java new file mode 100644 index 000000000000..76072f2a8a9c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessLevel/effectiveAccess/pp.java @@ -0,0 +1,12 @@ +package effectiveAccess; + +/** + * Created by IntelliJ IDEA. + * User: cdr + * Date: Jan 24, 2003 + * Time: 3:12:09 PM + * To change this template use Options | File Templates. + */ +public abstract class pp { + abstract void f(); +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessLevel/effectiveAccess/ppp.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessLevel/effectiveAccess/ppp.java new file mode 100644 index 000000000000..6c93e76ec78a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessLevel/effectiveAccess/ppp.java @@ -0,0 +1,13 @@ +package effectiveAccess; + +/** + * Created by IntelliJ IDEA. + * User: cdr + * Date: Jan 24, 2003 + * Time: 3:13:09 PM + * To change this template use Options | File Templates. + */ +public abstract class ppp extends pp { + abstract protected void f(); + protected void v() {} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/blue/Base.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/blue/Base.java new file mode 100644 index 000000000000..3b9b467dacaa --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/blue/Base.java @@ -0,0 +1,5 @@ +package com.blue; + +public class Base { + public void foo() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/blue/BaseComponent.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/blue/BaseComponent.java new file mode 100644 index 000000000000..1f5da16b9446 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/blue/BaseComponent.java @@ -0,0 +1,8 @@ +package com.blue; + +public class BaseComponent { + + protected class Header extends Base { + } + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/red/B.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/red/B.java new file mode 100644 index 000000000000..d8d64310a936 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/red/B.java @@ -0,0 +1,11 @@ +package com.red; + +import com.blue.BaseComponent; + +public class B extends BaseComponent { + + public Header getHeader() { + return null; + } + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/red/C.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/red/C.java new file mode 100644 index 000000000000..8962df8791b1 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/accessibleMember/com/red/C.java @@ -0,0 +1,7 @@ +package com.red; + +public class C extends B { + protected void add(B nodeGrid) { + nodeGrid.getHeader().foo(); // no error here since we are checking getHeader() method accessibility rather than Header class + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/alreadyImportedClass/pack/AlreadyImportedClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/alreadyImportedClass/pack/AlreadyImportedClass.java new file mode 100644 index 000000000000..8e3b2fd5bf06 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/alreadyImportedClass/pack/AlreadyImportedClass.java @@ -0,0 +1,12 @@ +package pack; + +import java.util.Date; +import pack.my; + +class Date { +} + +class my { + class Date extends java.util.Date { + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/arrayLength/p/Test.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/arrayLength/p/Test.java new file mode 100644 index 000000000000..a64cc394e94f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/arrayLength/p/Test.java @@ -0,0 +1,6 @@ +package p; +public class Test { + protected class Inner {} + + protected Inner[] strings = new Inner[10]; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/arrayLength/p2/SubTest.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/arrayLength/p2/SubTest.java new file mode 100644 index 000000000000..0b7f01071bb1 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/arrayLength/p2/SubTest.java @@ -0,0 +1,10 @@ +package p2; + +import p.Test; + +public class SubTest extends Test { +void foo() { +System.out.println(strings.length); +// "Cannot access 'length' in '_Dummy_.__Array__'" warning here +} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/duplicateClass/A.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/duplicateClass/A.java new file mode 100644 index 000000000000..cc6a9da90092 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/duplicateClass/A.java @@ -0,0 +1,6 @@ +package duplicateClass; + +// actual error text depends on temporary dir location + +class Foo { +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/duplicateClass/B.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/duplicateClass/B.java new file mode 100644 index 000000000000..dd596007ab13 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/duplicateClass/B.java @@ -0,0 +1,4 @@ +package duplicateClass; + +class Foo { +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/duplicateClass/java/lang/Runnable.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/duplicateClass/java/lang/Runnable.java new file mode 100644 index 000000000000..2348b17d0f70 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/duplicateClass/java/lang/Runnable.java @@ -0,0 +1,7 @@ + +// should not contend with Runnable from rt.jar + +package java.lang; + +public class Runnable { +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/foreignPackageInBetween/a/A1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/foreignPackageInBetween/a/A1.java new file mode 100644 index 000000000000..2c5819e26fbf --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/foreignPackageInBetween/a/A1.java @@ -0,0 +1,11 @@ +package a; + +import b.B; + +class A1 { + + { + new B().f(); + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/foreignPackageInBetween/a/A2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/foreignPackageInBetween/a/A2.java new file mode 100644 index 000000000000..1f41e7855592 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/foreignPackageInBetween/a/A2.java @@ -0,0 +1,8 @@ +package a; + +public class A2 { + + void f() { + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/foreignPackageInBetween/b/B.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/foreignPackageInBetween/b/B.java new file mode 100644 index 000000000000..2899e954b9fd --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/foreignPackageInBetween/b/B.java @@ -0,0 +1,7 @@ +package b; + +import a.A2; + +public class B extends A2 { + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/Test.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/Test.java new file mode 100644 index 000000000000..64f17b3299c0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/Test.java @@ -0,0 +1,4 @@ +public class Test { + public Test(int i) { + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/x/ImportOnDemandUsage.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/x/ImportOnDemandUsage.java new file mode 100644 index 000000000000..0e2695134701 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/x/ImportOnDemandUsage.java @@ -0,0 +1,7 @@ +package x; + +import x.n.*; + +class Foos2 { + Test t = new Test(); +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/x/Usage.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/x/Usage.java new file mode 100644 index 000000000000..cff269b30118 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/x/Usage.java @@ -0,0 +1,7 @@ +package x; + +import x.n.Test; + +class Foos { + Test t = new Test(); +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/x/n/Test.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/x/n/Test.java new file mode 100644 index 000000000000..900fe597f84e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importDefaultPackage/x/n/Test.java @@ -0,0 +1,2 @@ +package x.n; +public class Test {} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemand/x1/X1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemand/x1/X1.java new file mode 100644 index 000000000000..d36f1fc3f563 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemand/x1/X1.java @@ -0,0 +1,2 @@ +package x1; +public class X1 {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemand/x2/X1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemand/x2/X1.java new file mode 100644 index 000000000000..cfafcb90a87a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemand/x2/X1.java @@ -0,0 +1,2 @@ +package x2; +public class X1 {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemand/y/Y.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemand/y/Y.java new file mode 100644 index 000000000000..a58ad6e6662f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemand/y/Y.java @@ -0,0 +1,6 @@ +import x1.*; +import x2.*; + +class Y { + X1 x1; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemandVsSingle/x1/Class.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemandVsSingle/x1/Class.java new file mode 100644 index 000000000000..ccd1d9bf4ef5 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemandVsSingle/x1/Class.java @@ -0,0 +1,2 @@ +package x1; +public class Class{} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemandVsSingle/y/Y.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemandVsSingle/y/Y.java new file mode 100644 index 000000000000..6674d8a83d8a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importOnDemandVsSingle/y/Y.java @@ -0,0 +1,6 @@ +import x1.*; +import java.lang.Class; + +class Y { + Class aClass; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importSingleVsSamePackage/x1/C.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importSingleVsSamePackage/x1/C.java new file mode 100644 index 000000000000..0dad652ff7ac --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importSingleVsSamePackage/x1/C.java @@ -0,0 +1,4 @@ +package x1; +public class C { + public C(String s){} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importSingleVsSamePackage/y/C.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importSingleVsSamePackage/y/C.java new file mode 100644 index 000000000000..dea2311e1604 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importSingleVsSamePackage/y/C.java @@ -0,0 +1,4 @@ +package y; +public class C { + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importSingleVsSamePackage/y/Y.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importSingleVsSamePackage/y/Y.java new file mode 100644 index 000000000000..987670324a0f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/importSingleVsSamePackage/y/Y.java @@ -0,0 +1,6 @@ +package y; +import x1.C; + +class Y { + C aClass = new C(""); +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava4/com/Java4.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava4/com/Java4.java new file mode 100644 index 000000000000..6e4c2d4691be --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava4/com/Java4.java @@ -0,0 +1,9 @@ +package com; + +import java.util.*; + +public class Java4 { + public List getList() { + return null; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava4/java4.iml b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava4/java4.iml new file mode 100644 index 000000000000..e2a1e755cb1e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava4/java4.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava5/com/Java5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava5/com/Java5.java new file mode 100644 index 000000000000..2b79a23c3f42 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava5/com/Java5.java @@ -0,0 +1,12 @@ +package com; +import java.util.List; + +public class Java5 { + void test(Java4 foo) { + List list = foo.getList(); + for (Object o : list) { + } + for (Object o : foo.getList()) { + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava5/java5.iml b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava5/java5.iml new file mode 100644 index 000000000000..0479ef60077f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/multiJDKConflict/moduleJava5/java5.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/onDemandImportConflict/Outer.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/onDemandImportConflict/Outer.java new file mode 100644 index 000000000000..41565e3a494c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/onDemandImportConflict/Outer.java @@ -0,0 +1,5 @@ +import x.*; +import y.*; +public class Outer { + TTT ttt = new TTT(); +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/onDemandImportConflict/x/TTT.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/onDemandImportConflict/x/TTT.java new file mode 100644 index 000000000000..0a62989a36cf --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/onDemandImportConflict/x/TTT.java @@ -0,0 +1,3 @@ +package x; + +public class TTT {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/onDemandImportConflict/y/TTT.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/onDemandImportConflict/y/TTT.java new file mode 100644 index 000000000000..1c371b02eae4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/onDemandImportConflict/y/TTT.java @@ -0,0 +1,3 @@ +package y; + +class TTT {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/overridePackageLocal/x/Base.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/overridePackageLocal/x/Base.java new file mode 100644 index 000000000000..3cdc73d76179 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/overridePackageLocal/x/Base.java @@ -0,0 +1,4 @@ +package x; +public class Base { + void f() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/overridePackageLocal/x/y/Derived.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/overridePackageLocal/x/y/Derived.java new file mode 100644 index 000000000000..d26a617dbfa3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/overridePackageLocal/x/y/Derived.java @@ -0,0 +1,5 @@ +package x.y; + +public class Derived extends x.Base { + private void f() {} +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocalOverride/x/A.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocalOverride/x/A.java new file mode 100644 index 000000000000..e53429486df5 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocalOverride/x/A.java @@ -0,0 +1,6 @@ +package x; + +public class A { + int method() { return 0; } + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocalOverride/y/B.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocalOverride/y/B.java new file mode 100644 index 000000000000..02530e67909e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocalOverride/y/B.java @@ -0,0 +1,8 @@ +package y; + +import x.A; + +public class B extends A { + public double method() { return 0.0; } +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocalOverride/y/C.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocalOverride/y/C.java new file mode 100644 index 000000000000..0d4010497455 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocalOverride/y/C.java @@ -0,0 +1,5 @@ +package y; + +public class C extends B { + public double method() { return 0; } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/A.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/A.java new file mode 100644 index 000000000000..3bbbd1a5ee87 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/A.java @@ -0,0 +1,15 @@ +package x; +public class A extends D{ + int k; + static void staticF() {} +} +class C extends x.sub.B { + int n=k; + + // can call despite inherited through package local from other package + void f() { A.staticF(); } +} + +class D{ + public void foo(){} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/ContainerClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/ContainerClass.java new file mode 100644 index 000000000000..85fe8cef2abb --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/ContainerClass.java @@ -0,0 +1,9 @@ +// package local class in the middle + +package x; +class ComponentClass { + public int size; +} +public class ContainerClass { + public ComponentClass cc = new ComponentClass(); +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/sub/B.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/sub/B.java new file mode 100644 index 000000000000..095c8725661f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/sub/B.java @@ -0,0 +1,6 @@ +package x.sub; + +public class B extends x.A { +} + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/sub/UsingMain.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/sub/UsingMain.java new file mode 100644 index 000000000000..76214eac5d19 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/packageLocals/x/sub/UsingMain.java @@ -0,0 +1,12 @@ +package x.sub; + +import x.ContainerClass; +import x.A; + +public class UsingMain { + public static void main(String[] args) { + final ContainerClass cont = new ContainerClass(); + System.out.println(cont.cc.size);//// + new A().foo(); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/a/A.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/a/A.java new file mode 100644 index 000000000000..e6e1e6fd30c9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/a/A.java @@ -0,0 +1,6 @@ +package a; +import b.B; + +public class A extends B { + int f = super.bbb; +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/a/Father.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/a/Father.java new file mode 100644 index 000000000000..fd5c0391ce46 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/a/Father.java @@ -0,0 +1,7 @@ +package a; + +public class Father { + protected void func() { + System.out.println("Father.func"); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/a/Main.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/a/Main.java new file mode 100644 index 000000000000..c9ef5ed94b99 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/a/Main.java @@ -0,0 +1,12 @@ +package a; + +import b.Son; + +public class Main { + public static void main(String[] args) { + + Son bad = new Son(); + bad.func(); + + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/b/B.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/b/B.java new file mode 100644 index 000000000000..1c778bd0c697 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/b/B.java @@ -0,0 +1,5 @@ +package b; + +public class B { + protected int bbb; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/b/Son.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/b/Son.java new file mode 100644 index 000000000000..8ad712814e9b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedAccessFromOtherPackage/b/Son.java @@ -0,0 +1,9 @@ +package b; + +import a.Father; + +public class Son extends Father { + protected void func() { + System.out.println("Son.func"); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/p1/C1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/p1/C1.java new file mode 100644 index 000000000000..4ae157d72804 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/p1/C1.java @@ -0,0 +1,5 @@ +package p1; + +public class C1 { + protected C1(int i) { } //protected constructor +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/p2/C2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/p2/C2.java new file mode 100644 index 000000000000..156980382b53 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/p2/C2.java @@ -0,0 +1,18 @@ +package p2; + +import p1.C1; + +public class C2 extends C1 { + public C2() { + super(9); + } + + public void amethod() { + new C1(9); + } + + Object gg() { + // anonymous is ok?! + return new C1(1){}; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/samePackage/C1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/samePackage/C1.java new file mode 100644 index 000000000000..7bdcdb89c686 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/samePackage/C1.java @@ -0,0 +1,14 @@ +package samePackage; + +public class C1 { + protected C1(int i) { } //protected constructor +} +class Cc extends C1 { + public Cc() { + super(9); + } + + public void amethod() { + new C1(9); // <<<<---------- This is an error + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/samePackage/C2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/samePackage/C2.java new file mode 100644 index 000000000000..7c21a7be89c8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructor/samePackage/C2.java @@ -0,0 +1,13 @@ +package samePackage; + +import samePackage.C1; + +public class C2 extends C1 { + public C2() { + super(9); + } + + public void amethod() { + new C1(9); // <<<<---------- This is an error + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructorInInner/p1/C1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructorInInner/p1/C1.java new file mode 100644 index 000000000000..067481b8367d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructorInInner/p1/C1.java @@ -0,0 +1,7 @@ +package p1; + +public class C1 { + protected static class InnerClassInBase + { + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructorInInner/p2/C2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructorInInner/p2/C2.java new file mode 100644 index 000000000000..39d5d1914f18 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/protectedConstructorInInner/p2/C2.java @@ -0,0 +1,10 @@ +package p2; + +import p1.C1; + +public class C2 extends C1 { + public void amethod() { + InnerClassInBase inner; + inner = new InnerClassInBase(); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/Usage.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/Usage.java new file mode 100644 index 000000000000..3a79af4db913 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/Usage.java @@ -0,0 +1,13 @@ +package x; + +import x.n.X1; +import x.n.X2; +import x.n.X3; + +public class Y { + X1 x1; + x.n.Class s; + X2 x2; + Class aclass; + X3 cc3; +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/Usage_afterOptimize.txt b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/Usage_afterOptimize.txt new file mode 100644 index 000000000000..8ac2b4e0d83e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/Usage_afterOptimize.txt @@ -0,0 +1,13 @@ +package x; + +import x.n.*; + +import java.lang.Class; + +public class Y { + X1 x1; + x.n.Class s; + X2 x2; + Class aclass; + X3 cc3; +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/Class.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/Class.java new file mode 100644 index 000000000000..890855be1778 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/Class.java @@ -0,0 +1,2 @@ +package x.n; +public class Class{} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/X1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/X1.java new file mode 100644 index 000000000000..6601d86fab2c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/X1.java @@ -0,0 +1,4 @@ +package x.n; + +public class X1 { +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/X2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/X2.java new file mode 100644 index 000000000000..c22bb4c57c6e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/X2.java @@ -0,0 +1,4 @@ +package x.n; + +public class X2 { +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/X3.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/X3.java new file mode 100644 index 000000000000..e8afd6c59a3d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/reimportConflictingClasses/x/n/X3.java @@ -0,0 +1,4 @@ +package x.n; + +public class X3 { +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/lib/lib.jar b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/lib/lib.jar new file mode 100644 index 000000000000..80e445de7e3c Binary files /dev/null and b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/lib/lib.jar differ diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/lib/libsrc.zip b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/lib/libsrc.zip new file mode 100644 index 000000000000..7eaf87403c79 Binary files /dev/null and b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/lib/libsrc.zip differ diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/severalInstances.iml b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/severalInstances.iml new file mode 100644 index 000000000000..7cd339e406a7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/severalInstances.iml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/severalInstances.ipr b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/severalInstances.ipr new file mode 100644 index 000000000000..c25cbf1b6e94 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/severalInstances.ipr @@ -0,0 +1,265 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/severalInstances.iws b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/severalInstances.iws new file mode 100644 index 000000000000..2518b89676af --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/severalInstances.iws @@ -0,0 +1,529 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + localhost + 5050 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/src/ppp/BadClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/src/ppp/BadClass.java new file mode 100644 index 000000000000..f3ac9f52295f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/src/ppp/BadClass.java @@ -0,0 +1,17 @@ +package ppp; + +/** + * Created by IntelliJ IDEA. + * User: JEKA + * Date: Sep 11, 2008 + * Time: 4:01:38 PM + * To change this template use File | Settings | File Templates. + */ +public class BadClass { + public static void method() { + System.out.println("Hello"); + System.out.println("Hello"); + System.out.println("Hello"); + System.out.println("Hello"); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/src/ppp/SomeClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/src/ppp/SomeClass.java new file mode 100644 index 000000000000..a78254d056ba --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameClassesInSourceAndLib/src/ppp/SomeClass.java @@ -0,0 +1,5 @@ +package ppp; + +public class SomeClass { + BadClass f; +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/base/Base.iml b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/base/Base.iml new file mode 100644 index 000000000000..aec43ef6fe99 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/base/Base.iml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/base/src/bug/test/BaseClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/base/src/bug/test/BaseClass.java new file mode 100644 index 000000000000..c4612c624c74 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/base/src/bug/test/BaseClass.java @@ -0,0 +1,15 @@ +package bug.test; + +/** + * Created by IntelliJ IDEA. + * Date: Dec 13, 2007 + * Time: 4:12:50 PM + * To change this template use File | Settings | File Templates. + */ +public class BaseClass { + + public void doSomething(String arg1){ + System.out.println("In BaseClass::doSomething(int arg1)"); + } + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/client/Client.iml b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/client/Client.iml new file mode 100644 index 000000000000..c33e171a1111 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/client/Client.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/client/src/BugTest.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/client/src/BugTest.java new file mode 100644 index 000000000000..2698a666ea34 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/client/src/BugTest.java @@ -0,0 +1,17 @@ +import bug.test.BaseClass; + +/** + * Created by IntelliJ IDEA. + * Date: Dec 13, 2007 + * Time: 4:15:48 PM + * To change this template use File | Settings | File Templates. + */ +public class BugTest { + public static void main(){ + BaseClass testClass = new BaseClass(); + + testClass.doSomething(5); + + testClass.doSomethingElse(5); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/override/Override.iml b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/override/Override.iml new file mode 100644 index 000000000000..61a4c9018a2c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/override/Override.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/override/src/bug/test/BaseClass.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/override/src/bug/test/BaseClass.java new file mode 100644 index 000000000000..ce13ccd96734 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/sameFQNClasses/override/src/bug/test/BaseClass.java @@ -0,0 +1,18 @@ +package bug.test; + +/** + * Created by IntelliJ IDEA. + * Date: Dec 13, 2007 + * Time: 4:14:49 PM + */ +public class BaseClass { + + public void doSomething(int arg1) { + System.out.println("In OVERRIDDEN BaseClass::doSomething(int arg1)"); + } + + + public void doSomethingElse(int arg1) { + System.out.println("In OVERRIDDEN BaseClass::doSomethingElse(int arg1)"); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/scopeBased/x/Shared.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/scopeBased/x/Shared.java new file mode 100644 index 000000000000..913a45aff6df --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/scopeBased/x/Shared.java @@ -0,0 +1,10 @@ +package x; +class Shared { + Shared x = new Shared(); + java.util.List + list( + java.util.Map map + ) { + return null; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/scopeBased/x/X.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/scopeBased/x/X.java new file mode 100644 index 000000000000..36bfc3e1718e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/scopeBased/x/X.java @@ -0,0 +1,10 @@ +package x; +class X { + X x = new X(); + java.util.List + list( + java.util.Map map + ) { + return null; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/singleImport/c.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/singleImport/c.java new file mode 100644 index 000000000000..e4505d8874a3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/singleImport/c.java @@ -0,0 +1,3 @@ +public class c { + public static class inn {} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/singleImport/d.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/singleImport/d.java new file mode 100644 index 000000000000..4499a98d629e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/singleImport/d.java @@ -0,0 +1,7 @@ +import c; +import c.*; + +class d { + c c = null; + inn inn = null; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/staticImportConflict/Usage.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/staticImportConflict/Usage.java new file mode 100644 index 000000000000..2fc102ab046e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/staticImportConflict/Usage.java @@ -0,0 +1,3 @@ +import static x.Base2.f; +class Usage { +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/staticImportConflict/x/Base1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/staticImportConflict/x/Base1.java new file mode 100644 index 000000000000..806e7245b587 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/staticImportConflict/x/Base1.java @@ -0,0 +1,5 @@ +package x; + +public class Base1 { + public static void f() {} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/staticImportConflict/x/Base2.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/staticImportConflict/x/Base2.java new file mode 100644 index 000000000000..3cc84ff93016 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/staticImportConflict/x/Base2.java @@ -0,0 +1,5 @@ +package x; + +public class Base2 extends Base1 { + public static void f() {} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/SwitchByString.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/SwitchByString.java new file mode 100644 index 000000000000..1f7253fadf06 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting7/SwitchByString.java @@ -0,0 +1,41 @@ +public class Test { + private static final String BAZ = "baz"; + + private void stringSwitch() { + final String bar = "bar"; + String key = "key"; + switch (key) { + case "": { + System.out.println("Nothing"); + break; + } + case "foo": // fallthrough works as before + case bar: // local final variables are ok + case BAZ: { // constants are ok + System.out.println("Matched key"); + break; + } + default: + break; + } + } + + private void illegalStringSwitch() { + String foo = "foo"; + String key = "key"; + switch (key) { + case foo: + case getStringValue(): { + System.out.println("illegal"); + break; + } + default: + break; + } + } + + private String getStringValue() { + return ""; + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/AnnotationsAsPartOfModifierList.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/AnnotationsAsPartOfModifierList.java new file mode 100644 index 000000000000..3fca0c0f200b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/AnnotationsAsPartOfModifierList.java @@ -0,0 +1,9 @@ +@Deprecated @SuppressWarnings("") +public class Foo implements Runnable { + +} + +class F { + @Deprecated @SuppressWarnings("") void f() {} + @Deprecated @SuppressWarnings("") void f() {} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Autoboxing.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Autoboxing.java new file mode 100644 index 000000000000..5e02b2774de3 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Autoboxing.java @@ -0,0 +1,69 @@ +public class Autoboxing { + public boolean compare(short s, Integer i) { + return i == s; //OK, i is unboxed + } + + public boolean compare(Short s, Integer i) { + return i == s; //comparing as references + } + + void f(Integer i) { + switch(i) { + default: + } + } + + { + Object data = 1; + boolean is1 = data == 1; + } + + //IDEADEV-5549: Short and double are convertible + public static double f () { + Short s = 0; + return (double)s; + } + + //IDEADEV-5613 + class DumbTest { + private long eventId; + + public int hashCode() { + return ((Long) eventId).hashCode(); + } + } + + public static void main(String[] args) { + Long l = 0L; + Short s = 0; + + int d = (int)l; + d = (int)s; + + short t = 0; + Integer d1 = (Integer) t; + Byte b = (Byte) t; + + } + + { + { + boolean cond = true; + // test for JLS3 bug, see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6888770 + Byte B = 0; + byte b = 0; + byte value = cond ? B : b; ///////// + + short s = 0; + Short S = 0; + short rs = cond ? S : s; + + char c = 0; + Character C = 0; + char rc = cond ? C : c; + + boolean bb = cond ? Boolean.FALSE : true; + } + + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/AutoboxingConstructors.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/AutoboxingConstructors.java new file mode 100644 index 000000000000..12c5332362d6 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/AutoboxingConstructors.java @@ -0,0 +1,13 @@ +public class Test { + + public Test(Object a) { + } + + public Test(int i) { + this(new Integer(i)); + } + + public Test(long l) { + this(new Long(l)); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/AutoboxingMethods.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/AutoboxingMethods.java new file mode 100644 index 000000000000..d02099757c94 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/AutoboxingMethods.java @@ -0,0 +1,44 @@ +public class Autoboxing { + void method(int i) { + System.out.println("i = " + i); + } + + void method(Integer integer) { + System.out.println("integer = " + integer); + } + + void m1(Integer integer) { } + void m2(int i) { } + + { + method(10); + method(new Integer(10)); + m1(10); + m1(new Integer(10)); + m2(10); + m2(new Integer(10)); + } +} +public class Autoboxing1 { + void method(String s, int i) { + System.out.println("i = " + i); + } + + void method(String s, Object o) { + System.out.println("integer = " + o); + } + + { + method("abc", new Integer(10)); + method("abc", 10); + } +} + +class BoxingConflict { + public static void main(String[] args) { + add(0L, 0L); + } + + public static void add(long k, Long v) { } + public static void add(Long k, Long v) { } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ClassInheritance.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ClassInheritance.java new file mode 100644 index 000000000000..1a4e80f95827 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ClassInheritance.java @@ -0,0 +1,122 @@ +class D implements I{ +} +class DT implements I{ +} + +interface I { +} + +class CCC extends D implements I { +} +abstract class CCC2 extends DT implements I { +} + +class a extends b implements c>, d,d>> {} +public class b implements c> { } +interface c extends d> {} +interface d {} + +// extending final classes in bounds +class C { + void f() {} +} + +class GenericExtendItself +{ + GenericExtendItself foo; +} + + +//////////////////// +public abstract class ZZZZ { + public abstract E getElement(); +} +abstract class Z extends ZZZZ {} +class Z2 extends Z { + public Integer getElement() { + return null; + } +} +///////////////// +class BaseC { + E remove(){ + return null; + } +} + +class DerivedC extends BaseC { + public String remove() { + String s = super.remove(); + return null; + } +} + +/// raw in the multiple supers +interface Int { + AClass f(); +} +abstract class AClass implements Int { + public abstract AClass f(); +} + +class MyClass extends AClass implements Int{ + public AClass f() { + return null; + } +} + +class A{ + A(){} + A(T t){} + + { + new A(new A()){}; + } +} + +//IDEADEV-4733: this overriding is OK +class Outer +{ + public class Inner + { + private final T t; + + public Inner(T t) { this.t = t; } + + public T getT() { return t; } + + public String toString() { return t.toString(); } + } +} + +class Other extends Outer +{ + public class Ither extends Outer.Inner + { + public Ither() + { + super("hello"); //valid super constructor call + } + } +} + +//end of //IDEADEV-4733 +interface AI { +} +interface BI { +} +abstract class AbstractClass { + AbstractClass(Class clazz) { + } +} +class ConcreteClass extends AbstractClass { + ConcreteClass() { + super(AI.class); + } + class InnerClass extends AbstractClass { + InnerClass() { + super(BI.class); // + } + } +} +/////////////////////// diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ConditionalExpression.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ConditionalExpression.java new file mode 100644 index 000000000000..64d6ac1c71f2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ConditionalExpression.java @@ -0,0 +1,21 @@ +import java.util.TreeMap; +import java.util.HashMap; +import java.util.Map; + +class Test { + boolean f () { + return false; + } + + Boolean g (int i) { + //This is OK thanks to boxing f() + return i > 0 ? f () : null; + } + + { + Object values = new Object(); + //IDEADEV-1756: this should be OK + final Map newValues = true ? new TreeMap() : new HashMap(); + newValues.get(values); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ConvertibleTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ConvertibleTypes.java new file mode 100644 index 000000000000..58ce4599fac2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ConvertibleTypes.java @@ -0,0 +1,84 @@ +import java.util.Collection; +import java.util.ArrayList; + +interface YO<T> {} +interface YO1 extends YO {} +interface YO2 extends YO {} + +public class ConvertibleTest { + + YO2 bar (YO1 s) { + return (YO2) s; + } +} + + +//IDEA-1097 +interface Interface1 {} +interface Interface2 {} + +class Implementation implements Interface1 {} + +public class InconvertibleTypesTest +{ + E thing; + + public E getThing() { + return thing; + } + + Implementation foo(InconvertibleTypesTest i2) { + //This is a valid cast from intersection type + return (Implementation) i2.getThing(); + } +} + +class MyCollection extends ArrayList {} +class Tester { + Collection x(MyCollection l) { + return (Collection) l; + } +} + + +class IDEADEV3978 { + class Constructor { + Class getDeclaringClass() { + return null; + } + } + public static void foo(Constructor constructor) { + if(constructor.getDeclaringClass() == String.class) { //captured wildcard is convertible + System.out.println("yep"); + } + } +} + +class C2 { + void f(T t) { + if (t instanceof Object[]) return; + } +} + +class Casting { + void f(Object o) + { + if (o instanceof int[]) return; + + Object obj1 = (Object)true; f(obj1); + Object ob = (Number)1; f(ob); + Object ob2 = (Object)1; f(ob2); + + } + + public static T convert(Class clazz, Object obj) { + if (obj == null) return null; + if (String[].class == clazz) + return (T) parseArray(obj); + return null; + } + + private static String[] parseArray(Object obj) { + return obj.toString().split(","); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/DeepConflictingReturnTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/DeepConflictingReturnTypes.java new file mode 100644 index 000000000000..0477aeefdd3e --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/DeepConflictingReturnTypes.java @@ -0,0 +1,21 @@ +class W { + Object f() { + return 0; + } +} + +class WW extends W { + String f() { + return null; + } +} + +interface IQ { + void f(); +} + + +class WWW extends WW implements IQ { + +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Enum.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Enum.java new file mode 100644 index 000000000000..d724dc5e0efa --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Enum.java @@ -0,0 +1,189 @@ +enum Operation { + X; + static int s = 0; + public static final String constS = ""; + Operation() { + int i = Operation.s; + i = s; + s = 0; + final int x = Integer.MAX_VALUE; + String co = constS; + // TODO: unclear + //Operation o = X; + } + static { + int i = Operation.s; + i = s; + s = 0; + final int x = Integer.MAX_VALUE; + String co = constS; + // TODO: unclear + //Operation o = X; + } + { + int i = Operation.s; + i = s; + s = 0; + final int x = Integer.MAX_VALUE; + String co = constS; + // TODO: unclear + //Operation o = X; + + Operation ooo = new Operation(); + } + + void values() {} + void values(int i) {} + void valueOf() {} + void valueOf(String s) {} +} + +class exte extends Operation { +} + +class use { + void f(Operation op) { + switch(op) { + case Operation.X: break; + } + switch(op) { + case X: break; + } + switch(op) { + case X: break; + case X: break; + } + } +} + +enum pubCtr { + X(1); + public pubCtr(int i) {} +} +enum protCtr { + X(1); + protected protCtr(int i) {} +} +final enum Fin { Y } +abstract enum Abstr { } + +enum params { +} + +enum OurEnum { + A, B, C; + + OurEnum() { + } + + { + Enum a = A; + OurEnum enumValue = B; + switch (enumValue) { + } + + switch (enumValue) { + case A: + break; + } + } +} + +enum TestEnum +{ + A(B), B(A); + TestEnum(TestEnum other) { + super(null, 0); + } +} + +enum abstr implements Runnable { +} + +//this one is OK, enum constants are checked instead of enum itself +enum abstr1 implements Runnable { + A { + public void run() {} + }; +} + +class X extends Enum { + public X(String name, int ordinal) { + super(name, ordinal); + } +} + +enum StaticInEnumConstantInitializer { + AN { + static class s { + } + private static final String t = String.valueOf(1); + }; +} + +interface Barz { + void baz(); +} + +enum Fooz implements Barz { + FOO; +} + +/////////////////////// +class sss { + void f() { + enum EEEE { EE, YY }; + } +} + +////////////////////// +//This code is OK +enum PowerOfTen { + ONE(1),TEN(10), + HUNDRED(100) { + public String toString() { + return Integer.toString(super.val); + } + }; + + private final int val; + + PowerOfTen(int val) { + this.val = val; + } + + public String toString() { + return name().toLowerCase(); + } + + public static void main(String[] args) { + System.out.println(ONE + " " + TEN + " " + HUNDRED); + } +} + +//IDEADEV-8192 +enum MyEnum { + X1, X2; + + private static MyEnum[] values = values(); + + public static void test() { + + for (MyEnum e : values) { // values is colored red + e.toString(); + } + } +} +//end of IDEADEV-8192 + + +class EnumBugIDEADEV15333 { + public enum Type { one, to } + Type type = Type.one; + public void main() { + switch(type){ + case one: + Object one = new Object(); + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/EnumWithAbstractMethods.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/EnumWithAbstractMethods.java new file mode 100644 index 000000000000..61b111b4236a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/EnumWithAbstractMethods.java @@ -0,0 +1,24 @@ +abstract enum OurEnum { + A { + }, + B, + C { + void foo() {} + } + ; + + abstract void foo(); +} + +enum xxx { + X, + Y { + }; + + abstract void f(); +} + +enum ok { + X { void f() {} }; + abstract void f(); +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Exceptions.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Exceptions.java new file mode 100644 index 000000000000..039cfe64b491 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Exceptions.java @@ -0,0 +1,23 @@ +class C { + void foo () throws T {} + void bar () { + foo (); + } + + void goo() { + try { + int i = 12; + } catch (T ex) { + } + } +} + +//IDEADEV-4169: no problem here +interface Blub { + public void Switch() throws E; +} + +class Blib implements Blub { + public void Switch() throws E { + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ExplicitMethodParameters.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ExplicitMethodParameters.java new file mode 100644 index 000000000000..98fb88be4176 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ExplicitMethodParameters.java @@ -0,0 +1,20 @@ +import java.util.*; + +class Foo { + void foo() {} + void foo1() {} + void bar() {} + void xyz(T l) {} + + { + foo(); + this.foo(); + this.foo(); + this.bar(); + this.bar(); + this.<String, Integer>foo1(); + this.xyz(Integer.valueOf("27")); + ArrayList list = new ArrayList(); + } +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ExplicitMethodParameters1.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ExplicitMethodParameters1.java new file mode 100644 index 000000000000..cc3d83ed409f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ExplicitMethodParameters1.java @@ -0,0 +1,15 @@ +import java.util.*; + +class Foo { + interface Comparable { } + static > void sort(T t) {} + + class C implements Comparable {} + class D implements Comparable {} + + { + Foo.sort(new C()); + Foo.<D>sort(new D()); + } +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ForeachTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ForeachTypes.java new file mode 100644 index 000000000000..c9fc821243f8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ForeachTypes.java @@ -0,0 +1,29 @@ +class a { + void f(int[] c) { + for (int i:c) {} + for (char i:c) {} + for (double i:c) {} + double[] db = null; + for (int i:db) {} + for (double i:db) {} + + java.util.List list = null; + for (String i:list) {} + for (Object o:list) {} + + java.util.List ct = null; + for (Number n:ct) {} + for (Object n:ct) {} + for (Integer n:ct) {} + for (String i:ct) {} + for (java.util.List i:ct) {} + + Object o = null; + for (Object oi: (Iterable)o) {} + + + for (int i:db) { + for (int p: list) {} + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/GenericExtendException.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/GenericExtendException.java new file mode 100644 index 000000000000..1befccb938f7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/GenericExtendException.java @@ -0,0 +1,4 @@ +class T extends Exception {} +class E extends Error {} +class M extends T {} +class Ex extends Throwable {} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV10459.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV10459.java new file mode 100644 index 000000000000..fe5265973893 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV10459.java @@ -0,0 +1,31 @@ +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +/** @noinspection UnusedDeclaration*/ +public class GenericsTest98 { + public static void main(String[] args) throws Exception{ + List> list = new ArrayList> (); + Factory factory = Factory.newInstance(); + // Doesn't compile, but Idea doesn't complain + Mover mover = factory.getNew(list); + } +} + +abstract class Factory { + public static Factory newInstance(){ + return null; + } + + // This should actually be + // public abstract Mover getNew (List> source); + public abstract Mover getNew (List> source); +} + +/** @noinspection UnusedDeclaration*/ +interface Movable extends Serializable { +} + +/** @noinspection UnusedDeclaration*/ +interface Mover { +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV12951.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV12951.java new file mode 100644 index 000000000000..03cd4b6e61d2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV12951.java @@ -0,0 +1,29 @@ +class ClassExt { + + /** @noinspection UnusedDeclaration*/ + public static T newInstance(Class clazz, + Class t1, P1 p1, + Class t2, P2 p2) { + return null; + } + + +} + +abstract class TKey { + + protected abstract Class getType(); +} + + +class GoodIsRed6 { + + + public static > TK createClone(TK tkey, String key) { + + + Class clazz = null; + + return ClassExt.newInstance(clazz, String.class, key, Class.class, tkey.getType()); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV13011.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV13011.java new file mode 100644 index 000000000000..f4e5c5364963 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV13011.java @@ -0,0 +1,29 @@ +/** @noinspection UnusedDeclaration*/ +class LimitedPool { + private int capacity; + private final ObjectFactory factory; + private Object[] storage; + private int index = 0; + + public LimitedPool(final int capacity, ObjectFactory factory) { + this.capacity = capacity; + this.factory = factory; + storage = new Object[capacity]; + } + + interface ObjectFactory { + T create(); + void cleanup(T t); + } + + public T alloc() { + if (index >= capacity) return factory.create(); + + if (storage[index] == null) { + storage[index] = factory.create(); + } + + return storage; + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV14006.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV14006.java new file mode 100644 index 000000000000..f73206bd35cb --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV14006.java @@ -0,0 +1,18 @@ +/** @noinspection UnusedDeclaration*/ +interface TestIF2 extends TestIF3 {} + +/** @noinspection UnusedDeclaration*/ +interface TestIF> { + void run(T o1); +} + +/** @noinspection UnusedDeclaration*/ +interface TestIF3 {} + +class Test2 {} + +class Test { + public void test(TestIF testIF) { + testIF.run(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV14103.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV14103.java new file mode 100644 index 000000000000..77e6bb02bdc4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV14103.java @@ -0,0 +1,52 @@ +class TestGenerics { + + static interface EnumInterface { + public String getSomething(); + } + + static enum Enum1 implements EnumInterface { + A("alpha"), + B("beta"), + G("gamme"), + ; + private String text; + + Enum1(String text) { + this.text = text; + } + + public String getSomething() { + return text; + } + } + + static class TestBase & EnumInterface> { + + protected final void add(Eval eval) { + eval.hashCode(); + } + + abstract class Eval { + private I enumI; + + public Eval(I enumI) { + this.enumI = enumI; + } + + public final void doSomething() { + System.out.println(enumI.getSomething()); + } + } + + } + + + + + class Test1 extends TestBase { + + public Test1() { + add(new Eval(Enum1.A) {}); + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV15534.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV15534.java new file mode 100644 index 000000000000..d4042a575841 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV15534.java @@ -0,0 +1,29 @@ +import java.util.ArrayList; +import java.util.Collections; + +class SortTest> implements Comparable> { + R r; + + public SortTest(R r) { + this.r = r; + } + + public int compareTo(SortTest o) { + return r.compareTo(o.r); + } + + public static void main(String[] args) { + ArrayList> list = new ArrayList>(); + SortTest t1 = new SortTest(""); + list.add(t1); + SortTest t2 = new SortTest(0); + list.add(t2); + Collections.sort(list); + t1.compareTo(t2); + + //this should be OK + SortTest[] arr = new SortTest[0]; + arr[0] = new SortTest(""); + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV23157.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV23157.java new file mode 100644 index 000000000000..c0c2b70bf36c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV23157.java @@ -0,0 +1,10 @@ +import java.util.List; +import java.util.Arrays; + +public class ZZZ { + + List> f(Class[] exceptionTypes) { + List> nd = Arrays.asList(exceptionTypes); + return nd; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV24166.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV24166.java new file mode 100644 index 000000000000..c1952d1119a9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV24166.java @@ -0,0 +1,49 @@ +import java.util.*; + +interface TypesafeMap { + + @SuppressWarnings({"UnusedDeclaration"}) + public interface Key { } + + public > + boolean has(Class key); + + public > + VALUE get(Class key); + + public > + VALUE set(Class key, VALUE value); + + public > + VALUE remove(Class key); + + public Set> keySet(); + + public > + boolean containsKey(Class key); +} + + +interface CoreMap extends TypesafeMap { } + +interface CoreAnnotation + extends TypesafeMap.Key { + + public Class getType(); +} + + +class CoreMaps { + + public static Map toMap(Collection coremaps, + Class> keyKey, Class> valueKey) { + + Map map = new HashMap(); + for (CoreMap cm : coremaps) { + map.put(cm.get(keyKey), cm.get(valueKey)); + } + + return map; + } +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV25778.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV25778.java new file mode 100644 index 000000000000..a46a4a808ad4 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV25778.java @@ -0,0 +1,17 @@ +class Price { + public PT clone() { + return null; + } +} + +class BondPrice extends Price { + public PT clone() { + return null; + } +} + +class User { + public static void main(String[] args) { + new BondPrice().clone(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV7337.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV7337.java new file mode 100644 index 000000000000..9abc7f553609 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IDEADEV7337.java @@ -0,0 +1,74 @@ +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Comparator; + + +class TestIDEA +{ + + public static class Test1 + { + public void process(Serializable s) + { + } + public void process(Type t) + { + } + } + + public static class Test2 extends Test1 + { + public void process(Serializable s) + { + super.process(s); + } + + public void process(ArrayList t) + { + super.process(t); // this call is OK resolving to parameterized method in super + } + } + + public static void main(String[] args) + { + Test2 test=new Test2(); + ArrayList list=new ArrayList(); + test.process(list); + test.process((Serializable)list); + } +} + +class Key { + Object add(T v) { + return v; + } +} + +class WKey extends Key { + + W add(T v) { + return null; + } +} + +class IBug { + + public static void addItem(WKey key, T v) { + key.add(v); // --> demetra draw this in red, see attachment + } +} + +//IDEADEV-7698 +abstract class Collator implements Comparator { + public abstract int compare(String source, String target); + + public int compare(Object o1, Object o2) { + return compare((String)o1, (String)o2); + } + + public void foo(Collator c) { + c.compare("foo", "bar"); + } +} +//end of //IDEADEV-7698 \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ImplementAnnotation.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ImplementAnnotation.java new file mode 100644 index 000000000000..bbe1e30338ac --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ImplementAnnotation.java @@ -0,0 +1,15 @@ +import java.lang.annotation.Annotation; + +public @interface Foo { + String id(); +} + +class Bar implements Foo { + public String id() { + return null; + } + + public Class annotationType() { + return null; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/InferenceWithBounds.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/InferenceWithBounds.java new file mode 100644 index 000000000000..bfdb8c5124f8 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/InferenceWithBounds.java @@ -0,0 +1,61 @@ +import java.util.*; + +class CLS { + static void bar (V v) {} + + static void foo () { + bar(new Object()); + } +} +////////////////////////////// +public abstract class ZZZ { + public abstract ZZZ get(); +} +class Z2 extends ZZZ { + public Z2 get() { + return null; + } + void f() { + Z2 z2 = get(); + } +} +///////////////// +abstract class LeastRecentlyUsedCache { +interface Callable { + V call() throws Exception; +} + + Callable e(E e) { + return null; + } + Callable f(boolean b, final T t) { + return b ? e(t) : new Callable() { + public T call() throws Exception { + return t; + } + }; + } + + void ff() { + + } + + class A {} + class B extends A {} +} +////////////////////////// +public class BadCodeGreen> { + public BadCodeGreen(C c, T t) { + c.add(t); + } +} +//////////////////////////// +abstract class A { + public abstract > T create(); +} +class B extends A { + public > T create() { + return null; + } +} +/////////////////////////// \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/InheritFromTypeParameter.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/InheritFromTypeParameter.java new file mode 100644 index 000000000000..3f9c26cc3f7d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/InheritFromTypeParameter.java @@ -0,0 +1,2 @@ +class C extends T +{} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IntersectionTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IntersectionTypes.java new file mode 100644 index 000000000000..090c21cf4dcd --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/IntersectionTypes.java @@ -0,0 +1,165 @@ +import java.io.*; +import java.util.*; + +class Test { + List asList (T... ts) { + ts.hashCode(); + return null; + } + + void foo() { + List> l = this.asList(String.class, Integer.class); + l.size(); + List objects = this.asList(new String(), new Integer(0)); + objects.size(); + } +} + +//SUN BUG ID 5034571 +interface I1 { + void i1(); +} + +class G1 { + T get() { return null; } +} + +interface I2 { + void i2(); +} + +class Main { + void f2(G1 g1) { + g1.get().i1(); // this should be OK + g1.get().i2(); // this should also be OK + } +} + +//IDEADEV4200: this code is OK +interface I11 { + String i1(); +} + +interface I21 { + String i2(); +} + +interface A { + T some(); +} + +interface B extends A { + +} + +class User { + + public static void main(B test) { + System.out.println(test.some().i1()); + System.out.println(test.some().i2()); + } +} +//end of IDEADEV4200 + +//IDEADEV-4214 +interface Keyable { + /** + * @return the key for the instance. + */ + public K getKey(); +} + +abstract class Date implements java.io.Serializable, Cloneable, Comparable { + +} + +class Maps { + public static class MapEntry implements Map.Entry { + K k; + V v; + + public K getKey() { + return k; + } + + public V getValue() { + return v; + } + + public V setValue(V value) { + return v = value; + } + + public MapEntry(K k, V v) { + this.k = k; + this.v = v; + } + } + + public static Map.Entry entry(K key, V value) { + return new MapEntry(key, value); + } + + public static Map asMap(Map.Entry ... entries) { + return null; + } + + public static > Map asMap(V ... entries) { + return null; + } +} + +class Client { + void f(Date d) { + //this call should be OK + Maps.asMap(Maps.entry(fieldName(), "Test"), + Maps.entry(fieldName(), 1), + Maps.entry(fieldName(), d)); + } + + String fieldName() { + return null; + } +} +//end of IDEADEV-4214 + +class IDEADEV25515 { + static List asList (T... ts) { + ts.hashCode(); + return null; + } + + public static final + List> SIMPLE_TYPES = +asList(String.class, Integer.class ,Long.class, Double.class, /*Date.class,*/ +Boolean.class, Boolean.TYPE /*,String[].class */ /*,BigDecimal.class*/); + + + public static final List> SIMPLE_TYPES_INFERRED = + asList(String.class, Integer.class ,Long.class, Double.class, /*Date.class,*/ + Boolean.class, Boolean.TYPE ,String[].class /*,BigDecimal.class*/); + + +} +/////////////////////// +class Axx { + T a() { + String s = a(); + s.hashCode(); + return null; + } +} +/////////////// +interface L {} +public class MaximalType { + public static T getParentOfType(Class... classes) { + classes.hashCode(); + return null; + } + { + getParentOfType(M2.class, M.class); + } +} +class M extends MaximalType implements L{} +class M2 extends MaximalType implements L{} +///////////// \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Methods.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Methods.java new file mode 100644 index 000000000000..d0f994e48b76 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Methods.java @@ -0,0 +1,38 @@ +import java.util.*; + +interface Base { +} + +class Derived implements Base { +} + +class X { + void method(int i, Base b) { } + void method(int i, Derived b) { } + + { + Derived d = new Derived(); + method(10, d); + } +} + +class Temp {} + +class A { + public > A(T list) {} + public > A(T list) {} +} +class B { + public B(T list) {} + public > B(T list) {} +} + + + +////////////////////////////////////////// +class IdeaBug { + + static T cloneMe(T arg) throws CloneNotSupportedException { + return (T) arg.clone(); + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideAtLanguageLevel5.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideAtLanguageLevel5.java new file mode 100644 index 000000000000..8634677340cf --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideAtLanguageLevel5.java @@ -0,0 +1,16 @@ +interface I { + void f(); +} +interface II extends I { + @Override + void f(); +} +class C implements I { + @Override + public void f() { + } + + @Override + public void notoverride() { + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideAtLanguageLevel6.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideAtLanguageLevel6.java new file mode 100644 index 000000000000..d83cf659d8a9 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverrideAtLanguageLevel6.java @@ -0,0 +1,13 @@ +interface I { + void f(); +} +interface II extends I { + @Override + void f(); +} +class C implements I { + @Override + public void f() { + + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverridingMethods.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverridingMethods.java new file mode 100644 index 000000000000..45318c41832c --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/OverridingMethods.java @@ -0,0 +1,513 @@ +import java.util.*; + +abstract class C { + abstract T f(int t); + void ff(T t) {} + + C covariant1() { return null; } + C covariant2() { return null; } + A get() { return null; } +} +abstract class D extends C> { + abstract U f(int t); + + // overloaded, not overrridden + int ff(int u) { return 0; } + + int ff(C u) { + return 0; + } + + Object covariant1() { return null; } + D covariant2() { return null; } + + A get() { return null; } +} + + +abstract class C1 { + abstract T f(int t); +} +abstract class D1 extends C1> { + abstract C1 f(int i); +} + + +class CC { + CC f() { return null; } + CC f2() { return null; } + CC f3() { return null; } + + + K f(V v) { return null; } + int fPrimitive() { return 0; } +} +class DD extends CC { + DD f() { return null; } + + DD f2() { return null; } + CC f3() { return null; } + + O f(O o) { return null; } + + // incompatible although assignable + double fPrimitive() { return 0; } +} + +interface Gen { + void f(Gen cc); +} +class Raw implements Gen { + public void f(Gen o) { + abstract class MyComparator { + abstract int compare(T t, T t1); + } + // raw type implemetation + new MyComparator() { + public int compare(Object t, Object t1) { + return 0; + } + }; + } +} + +class Gen2 implements Gen { + public void f(Gen o) {} +} + +////////////// ERASURE CONFLICT +class A1 { + T id(T t) { + return t; + } +} +interface I1 { + T id(T t); +} +class A2 extends A1 { + T id(T t) { + return t; + } +} +class A3 extends A1 { + Object id(Object o) { + return o; + } +} +class A4 extends A1 implements I1 { + String id(String t) + { return null;} + public Integer id(Integer i) + { return null; } +} + +interface II1 { + T id(int t); +} +interface II2 { + T id(int t); +} +abstract class A5 implements II1, II2 {} +abstract class A6 implements II1, II2 {} +abstract class A7 implements II1, II2{} +abstract class A8 implements II1, II2{} + + +abstract class HasGenericMethods { + abstract

void toArray(P[] p); +} +public class RawOverridesGenericMethods extends HasGenericMethods{ + public void toArray(Object[] ps) { + } +} + +class CloneTest { + interface A { + A dup(); + } + interface B extends A { + B dup(); + } + interface C extends A { + C dup(); + } + interface D extends B, C { + D dup(); + } + interface X extends C, B { + X dup(); + } + interface E extends C,A { + E dup(); + } +} +/////////////// +class ArrBase { + C getC() { return null; } + Object[] getO() { return null; } +} +class ArrTest extends ArrBase { + C getC() { return null; } + String[] getO() { return null; } +} + +/////////// +class BarIU { + public B[] toArray(B[] ts) { + return null; + } +} +interface IU { + public I[] toArray(I[] ts); +} +public class BarIUBarIU extends BarIU implements IU{ + public T[] toArray(T[] ts) { + return null; + } +} +////////////////////// +class MyIterator { +} +class AAA { + public MyIterator iterator() { + return null; + } +} + +interface III { + MyIterator iterator(); +} + +class CCC extends AAA implements III { + public MyIterator iterator() { + return null; + } +} +////////////////////////////////// +interface CloneCovariant { + CloneCovariant clone(); +} + +interface ICloneCovariant extends CloneCovariant { +} + +interface Cmp { + int compareTo (T t); +} +class Singleton implements Cmp> { + public int compareTo(Singleton t1) { + return 0; + } +} + +class e { + void u (T t) {} +} + +class f extends e { + //If we inherit by erasure, then no type parameters must be present + void u (Object o) {} +} + +//SCR 41593, the following overriding is valid +interface q { + q foo(); +} + +interface p { + p foo(); +} + +class r implements q, p { + public r foo() { + return null; + } +} + +//IDEADEV-2255: this overriding is OK +class Example { + interface Property { + T t(); + } + + public static void main(String[] args) { + new ValueChangeListener() { + public void valueChanged(Property parent, E oldValue, E newValue) { + } + }; + } + + interface ValueChangeListener { + void valueChanged(Property property, E oldValue, E newValue); + } +} + +//IDEADEV-3310: there is no hiding("static overriding") in this code thus no return-type-substitutability should be checked +class BaseClass {} + +class SubClass extends BaseClass {} + +class BaseBugReport { + + public static + java.util.Set doSomething() { + return null; + } +} + +class SubBugReport extends BaseBugReport { + + public static + java.util.Set doSomething() { + return null; + } +} + +class First { + void m(T t) { + System.out.println("A: " + t); + } +} + +class Second extends First { + //@Override + void m(S t) { + System.out.println("B: " + t); + } +} + +class Third extends Second { + void m(Number t) { + System.out.println("D#m(Number): " + t); + } + + //@Override + void m(Integer t) { + System.out.println("D#m(Integer): " + t); + } +} + +//IDEADEV-4587: this code is OK +interface SuperA { + T method() throws E; +} + +interface SuperB { + T method() throws E; +} + +interface MyInterface extends SuperA, SuperB { +} + +//IDEADEV-2832 +class IDEADEV2832Test { + public static void main(String[] args) { + Listener dl = new Listener() { + public void listen(String obj) { + } + + public void listen(Object obj) { + } + }; + } +} + +interface Listener { + void listen(T obj); +} + +//end of IDEADEV-2832 + +//IDEADEV-8393 +class Super { + public String sameErasure(final List arg) + { + System.out.println("Int list"); + return null; + } + +} + + +final class Manista extends Super { + + public Collection sameErasure(final List arg) { + System.out.println("String list"); + return null; + } +} +//end of IDEADEV-8393 + +/////////////////// +public class Prim { + Object g() { + return null; + } +} +class SPrim extends Prim { + byte[] g() { + return null; + } +} + +//IDEADEV-21921 +interface TypeDispatcher { + public void dispatch(Class clazz, S obj); +} +class DefaultDispatcher implements TypeDispatcher { + public void dispatch(Class clazz, S obj) { + } +} +interface Node { +} + +class BubbleTypeDispatcher extends DefaultDispatcher { +} +//end of IDEADEV-21921 + +//////////////////////////////////////// +public class Bug2 extends SmartList implements Places { +} +interface Places extends java.util.List {} + +class SmartList extends java.util.AbstractList{ + public E get(int index) { + return null; + } + + public int size() { + return 0; + } +} +////////////////IDEADEV-23176 +class ActionImplementation extends MyAbstractAction +{ + public void actionPerformed() + { + throw new RuntimeException(); + } +} +abstract class MyAbstractAction extends AbstractAction implements MyAction { } +interface MyAction extends Action, BoundBean { } +interface BoundBean { + void addPropertyChangeListener(); + void removePropertyChangeListener(); +} +interface Action extends ActionListener { + public void addPropertyChangeListener(); + public void removePropertyChangeListener(); +} +interface ActionListener { + public void actionPerformed(); +} +abstract class AbstractAction implements Action{ + public synchronized void addPropertyChangeListener() { + } + public synchronized void removePropertyChangeListener() { + } +} +////////////////////////////// +class A extends BaseBuild implements SRunningBuild{ +} + +interface Build { + boolean isPersonal(); +} +class BaseBuild implements Build { + public boolean isPersonal() { + return false; + } +} +interface HistoryBuild { + boolean isPersonal(); +} +interface SRunningBuild extends Build,HistoryBuild{ } +//////////////////////////////////// + +interface PsiReferenceExpression extends PsiElement, PsiJavaCodeReferenceElement{} + +interface PsiJavaCodeReferenceElement extends Cloneable, PsiQualifiedReference{} +interface PsiQualifiedReference extends PsiElement {} + +interface PsiElement { + String toString(); +} +///////////////////////IDEADEV-24300 //////////////////////// +public class ActionContext { +} +public abstract class ContextAction { + protected abstract void performAction(AC context); +} +public class OurAction extends TableContextAction { + protected void performAction(TableContext context) { + } +} +public class TableContext extends ActionContext> { +} +public abstract class TableContextAction extends ContextAction> { +} +///////////////////////////////IDEADEV-23176 ///////////////////// +public interface MyListModel { } +public interface MyList { + Object get(int i); + int hashCode(); +} +public interface MutableListModel extends MyListModel, MyList { +} +public class ListModelImpl { + public Object get(int i) { + return null; + } +} +public class MutableListModelImpl extends ListModelImpl implements MutableListModel { +} +/////////////////////////////////////////////////////////////// + +public class InheritanceBug { + interface A { + Object clone(); + } + + interface B { + + } + + interface C extends A, B { + + } + + class X implements C { + public Object clone() { + return null; + } + } + + class Y extends X { + } +} +/////////////////////////////////////// +class ideadev { +interface A { + A f(); +} + +interface B extends A { + B f(); +} + +interface C extends A,B { + +} + +class s implements C { + public A f() { + return null; + } +} +class sOk implements C { + public B f() { + return null; + } +} + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Raw.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Raw.java new file mode 100644 index 000000000000..eb1101989c0b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Raw.java @@ -0,0 +1,177 @@ +import java.util.ArrayList; + +class Reference<T> { +} +class WeakReference extends Reference { +} +class Item<Key, T> extends WeakReference { + { + Reference ref = null; + Item item = (Item) ref; + equals(item); + } +} + +// assign raw to generic are allowed +class a { + void f(a t){ + t.hashCode(); + } +} +class b { + a f(a raw) { + a unbound = raw; + raw = unbound; + + a generic = raw; + raw.f(raw); + raw.f(generic); + generic.f(raw); + generic.f(generic); + generic.f(new a()); + generic = raw; + + + return raw; + } +} + +class List { + V[] toArray (V[] vs) { return vs; } + void add(T t) { + t.hashCode(); + } +} + +class c { + /*String[] f () { + List l = new List(); + error descr="Incompatible types. Found: 'java.lang.Object[]', required: 'java.lang.String[]'">return l.toArray (new String[0]); l = new List(); + return l.toArray (new String[0]); + } +} + +class d { + class Y <T> { + } + + class Z <T> extends Y { + } + + class Pair { + void foo(Y y) { + y.hashCode(); + } + } + + Pair pair; + + void bar(Y y) { + pair.foo(y); + } +} + +class e { + String foo () { + MyList myList = new MyList(); + return myList.get(0); + } + + static class MyList<T> extends ArrayList{ + } +} + +class ccc { + static Comparable f() { + return new Comparable () { + public int compareTo(final Object o) { + return 0; + } + }; + } +} + +class ddd { + COMP comp; + ddd foo() { + return comp; //no unchecked warning is signalled here + } +} + +class G1 { + T t; +} +class G2 { + T t; + + static ArrayList f() { + return null; + } +} + +class Inst { + static void f () { + G2> g2 = new G2>(); + for (G1 g1 : g2.f()) { + g1.toString(); + } + } +} + +class A111 { + T t; + V f(V v) { + return v; + } + + String g(A111 a) { + //noinspection unchecked + return a.f(""); + } +} + +class A1 { + V f(V v) { + return v; + } +} + +class A11 extends A1 { + T t; + + //this is OK, type parameters of base class are not raw + String s = new A11().f(""); +} + +//IDEADEV-26163 +class Test1 { + X x; + java.util.ArrayList foo = new java.util.ArrayList(); + public static Number foo() { + return new Test1().foo.get(0); + } +} +//end of IDEADEV-26163 + + +/////////////// signatures in non-parameterized class are not erased +public class C3 { + public int get(Class c) { + return 0; + } +} + +class Cp extends C3 { + public T i; +} +class C extends Cp/**/ { + @Override + public int get(Class c) { + return 0; + } +} +////////////// \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/RawOverridingMethods.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/RawOverridingMethods.java new file mode 100644 index 000000000000..19340121a4c7 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/RawOverridingMethods.java @@ -0,0 +1,271 @@ +import java.util.*; + +class Base { + public void method(Base base) { } + public void method1(Base> base) { } + public Base foo() { return null; } + public Base bar() { return null; } + public Base> far() { return null; } +} + +class Derived extends Base { + public void method(Base base) { } + public Base foo() { return null; } + public Base bar() { return null; } +} + +class Derived1 extends Base { + public void method1(Base base) { } + public Base far() { return null; } // Acceptable construct as of JDK 1.5 beta 2 may 2004 +} + +class X { + public void foo () {} +} + +class YY extends X { + public void foo() {} +} + +interface List { + public T[] toArray(T[] ts); +} +class AbstractList { + public T[] toArray(T[] ts) {return null;} +} +//Signatures from List and AbstractList are equal +class ArrayList extends AbstractList implements List {} + +//SCR 39485: the following overriding is OK +abstract class Doer { + abstract void go(X x); +} + +class MyList + extends Doer { + X x; + void go(Y y) {} +} + +class MyListRaw + extends MyList { +} + +//See IDEADEV-1125 +//The following two classes are OK +class A1 { + void foo(T t) {} +} + +class A2 extends A1 { + void foo(Object o) {} +} + +//While these are not +class A3 { + void foo(Object o) {} +} + +class A4 extends A3 { + void foo(T t) {} +} + +//This sibling override is OK +class A5 { + public void foo(Object o) {} +} + +interface I1 { + void foo(T t); +} + +class A6 extends A5 implements I1 {} + +//While this is not +class A7 { + public void foo(T t) {} +} + +interface I2 { + public void foo(Object o); +} + +class A8 extends A7 implements I2 {} + +//IDEA-9321 +abstract class MyMap implements java.util.Map { + public Object put(K key, V value) { + return null; + } +} +//end of IDEA-9321 + +abstract class AA { + abstract void foo(T t); +} + +abstract class BB extends AA { + void foo(BB b) {} +} + +class CC extends BB { + //foo is correctly seen from BB +} + +class QQQ {} + +abstract class GrandParent { + public abstract void paint(T object); +} + +class Parent extends GrandParent { + public void paint(T component) { + } +} + +// this overriding should be OK +class Child2 extends Parent { + +} + +class IDEA16494 { + class Base { + public List elements() { + return null; + } + } + + class Derived extends Base { + } + + class MostDerived extends Derived { + + public List elements() { + return null; + } + } +} +class IDEA16494Original { + class Base { + public List elements() { + return null; + } + } + + class Derived extends Base { + } + + class MostDerived extends Derived { + + public List elements() { + return null; + } + } +} +class IDEADEV23176Example { + public abstract class AbstractBase extends AbstractParent implements Interface { + } + public abstract class AbstractParent { + public void Implemented(Collection c) { + } + public abstract void mustImplement(); + } + public class Baseclass extends AbstractBase implements Interface { + public void mustImplement() { + } + } + public interface Interface { + void Implemented(Collection c); + } +} + +/** @noinspection UnusedDeclaration*/ +class IDEADEV26185 +{ + public static abstract class SuperAbstract + { + public abstract Object foo(Type other); + } + + public static abstract class HalfGenericSuper extends SuperAbstract + { + public abstract Object foo(String other); + } + + public static abstract class AbstractImpl extends HalfGenericSuper + { + public Object foo(String other) + { + return null; + } + } + + public static class Concrete extends AbstractImpl + { + } +} + +class ideadev30090 { + abstract class MyBeanContext + implements MyListInterface/**/ { + public Object get(int index) { + return null; + } + } + + interface MyListInterface + extends List { + } + interface MyListMember { + void f(); + } +} +////////////////////////////////////////// +class IDEADEV32421 { + interface InterfaceWithFoo { + Class foo(); + } + + class ParentWithFoo implements InterfaceWithFoo { + public Class foo() { + return null; + } + } + + class TestII extends ParentWithFoo implements InterfaceWithFoo { + } +} + +class IDEADEV32421_TheOtherWay { + interface InterfaceWithFoo { + Class foo(); + } + + class ParentWithFoo implements InterfaceWithFoo { + public Class foo() { + return null; + } + } + + class TestII extends ParentWithFoo implements InterfaceWithFoo { + } +} +////////////////////////////////////// +class SBBug { + abstract class A implements Comparable> {} + + class B extends A { + public int compareTo(Object o) { + return 0; + } + } +} +class SBBug2 { + abstract class A implements Comparable> {} + + class B extends A { + public int compareTo(A o) { + return 0; + } + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ReferenceTypeParams.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ReferenceTypeParams.java new file mode 100644 index 000000000000..2831950aba69 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/ReferenceTypeParams.java @@ -0,0 +1,128 @@ +import java.util.*; + +class C { + + C c1 = new C(); + C c2 = new C(); + Object o = new Object(); + + C c3 = new C(); + C c4 = new C(); + C c5 = new C(); +} + +class D { + { + new D<Integer>(); + new D(); + class CC extends C {}; + new D(); + new D(); + } + + T field = new T(); + T field2 = new T() { }; + T[] array = new T[10]; +} + +class Primitives { + Object a = new Primitives<? extends int>(); + Object o = new Primitives<int>(); + void f(Primitives<boolean> param) { + if (this instanceof Primitives<double>) { + return; + } + } +} + + +/////// calling super on generic bound class +public class Generic { + Generic(T t){} +} +public class Bound extends Generic{ + public Bound(String s) { + super(s); + } +} + +//// +class Generic2 { + class A {} + class B {} + private Generic2 map = new Generic2(); + { + map = new Generic2(); + map = new Generic2(); + } +} + +class DummyList {} +abstract class GenericTest3 implements DummyList<? extends String> { + DummyList> l; + void foo () {} + void bar () { + this.>foo(); + DummyList>[] l = new DummyList>[0]; + DummyList[] l1 = {}; + } + + public T[] getComponents (Class baseInterfaceClass) { + T[] ts = {}; + + return ts; + } +} + +class mylist {} +class myAList extends mylist { + { + mylist l = (mylist) new myAList(); + boolean b = new myAList() == new myAList(); + + if (l instanceof myAList); + Object o = new Object(); + if (o instanceof T); + } + + Class foo (Class clazz) { + Class clazz1 = (Class)clazz; //Should be unchecked warning + return T.class; + } +} + +class testDupT> { // CAN IT BE HIGHLIGHTED? b + public T> void foo() { // CAN IT BE HIGHLIGHTED? + } +} + +class aaaa { + { + Class c = String.class; + } +} + +//IDEADEV-6103: this code is OK +class Foo { + mylist foo; + + public Foo(mylist foo) { + this.foo = foo; + } + + public Foo() { + this(new mylist()); + } + + private class Test { + } +} +//end of IDEADEV-6103 + +class IDontCompile { + Map.Entry map; +} + +abstract class GenericTest99> { + GenericTest99<Enum> local; +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SameErasure.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SameErasure.java new file mode 100644 index 000000000000..9bb49b29ce2b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SameErasure.java @@ -0,0 +1,34 @@ +import java.util.*; + +class SameSignatureTest { + public static void sameErasure(List strings) { + } + + public static void sameErasure(List integers) { + } +} + + class CCC { + void f(Object o) {} + + void f(Object o) {} +} + +public class Test1 { + public void bug(String s) { + } + + public static T bug(String s) { + return null; + } +} +//////////////////////////////// +class Test { + public static HashMap test() { + return new HashMap(); + } + + public static String test() { + return ""; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SameErasureDifferentReturnTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SameErasureDifferentReturnTypes.java new file mode 100644 index 000000000000..f203f95c25de --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SameErasureDifferentReturnTypes.java @@ -0,0 +1,53 @@ +/** @noinspection UnusedDeclaration*/ +interface Matcher { + + boolean matches(java.lang.Object object); + + void _dont_implement_Matcher___instead_extend_BaseMatcher_(); +} + +interface ArgumentConstraintPhrases { + T with(Matcher matcher); + boolean with(Matcher matcher); + byte with(Matcher matcher); + short with(Matcher matcher); + int with(Matcher matcher); + long with(Matcher matcher); + float with(Matcher matcher); + double with(Matcher matcher); +} + +class ExpectationGroupBuilder implements ArgumentConstraintPhrases { + + public T with(final Matcher matcher) { + return null; + } + + public boolean with(final Matcher matcher) { + return false; + } + + public byte with(final Matcher matcher) { + return 0; + } + + public short with(final Matcher matcher) { + return 0; + } + + public int with(final Matcher matcher) { + return 0; + } + + public long with(final Matcher matcher) { + return 0; + } + + public float with(final Matcher matcher) { + return 0; + } + + public double with(final Matcher matcher) { + return 0; + } +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/StaticImports.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/StaticImports.java new file mode 100644 index 000000000000..047391deb774 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/StaticImports.java @@ -0,0 +1,16 @@ + +import static java.util.Arrays.asList; +import static java.util.Arrays.sort; +import static java.util.Arrays.binarySearch; + +public class StaticImports { + { + asList(new Object[]{}); + } + + void method() { + sort(new long[0]); +// sort< error descr="Cannot resolve method 'sort()'">()< /error>; + } + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SuperMethodCallWithErasure.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SuperMethodCallWithErasure.java new file mode 100644 index 000000000000..4bd51c05016d --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/SuperMethodCallWithErasure.java @@ -0,0 +1,18 @@ +import java.util.Set; + +interface Interface { + void method(Set s); +} + +class SuperClass implements Interface { + public void method(Set s) { + // do nothing + } +} + +class SubClass extends SuperClass { + public void method(Set s) { + super.method(s); //ERROR: Abstract method 'method(Set)' cannot be accessed directly + } +} + diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgsOnRaw.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgsOnRaw.java new file mode 100644 index 000000000000..f8e48b201857 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeArgsOnRaw.java @@ -0,0 +1,21 @@ +class GenericsTest { + + static class SomeClass { + public T getX() { + return null; + } + public String f() { + return this.getX(); + } + } + + + + public static void main(String[] args) { + + String v1 = new SomeClass().getX(); + String v2 = new SomeClass().f(); // + + } + +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeInference.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeInference.java new file mode 100644 index 000000000000..f0d2741302b2 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeInference.java @@ -0,0 +1,95 @@ +import java.io.FileNotFoundException; +import java.util.*; + +interface PrivilegedExceptionAction { + void run() throws E; +} + +class AccessController { + public static Object doPrivileged(PrivilegedExceptionAction action) throws E { + return null; + } +} +class Test { + public static void main(String[] args) { + try { + AccessController.doPrivileged( + new PrivilegedExceptionAction() { + public void run() throws FileNotFoundException { + } + }); + } catch (FileNotFoundException f) { + } + } + +// @#@! mock JDK Class does not take params +// static T create(Class t) throws InstantiationException, IllegalAccessException { +// return t.newInstance(); +// } +} + +//IDEADEV-6390 +class Printer { + private final List _elements; + + private Printer(final Collection col) { + _elements = new ArrayList(col); + } + + public static Printer build(final Collection col) { + return new Printer(col); + } + + public static Printer build(final S... elements) { + return new Printer(Arrays.asList(elements)); + } + + public void print() { + for (final T element : _elements) { + System.out.println(element); + } + + } + + public static void main(final String[] args) { + final Printer objects = build(Integer.valueOf(5), Boolean.TRUE, "A String!"); //this is OK + objects.print(); + } + +} +//end of IDEADEV-6390 + +//IDEADEV-6738 +interface I1, P2 extends I2>{} +interface I2, P2 extends I2>{} + +class C1 implements I1{} +class C2 implements I2{} + +class U { + public static , P2 extends I2> P1 test(P1 p1) { + return null; + } + { + C1 c = new C1(); + U.test(c); //this should be OK + } +} +//end of IDEADEV-6738 + +/////////////////////////////////// +public class Err { + void f() { + Decl[] extensions = getExtensions(Decl.EXTENSION_POINT_NAME); + } + + static T[] getExtensions(List tExtensionPointName) { + return null; + } + + public static class Decl { + public static List EXTENSION_POINT_NAME = null; + } + +} +///////////////////////////////////// \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeParameterBoundsList.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeParameterBoundsList.java new file mode 100644 index 000000000000..506add049639 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/TypeParameterBoundsList.java @@ -0,0 +1,33 @@ +class CException,U> { + +} + +class Stuff { + Runnable> T method(V v) { + return null; + } + + Runnable & Comparable> void f(T t) { + + } + + void f2(T t) { + + } + void f3(T t) { + + } +} + +//////////////// +public class TypeParameters { + class X {} + static void f(Class t){} + + static { + f(X.class); + } +} +class Typr { + void f() {} +} diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/UncheckedCasts.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/UncheckedCasts.java new file mode 100644 index 000000000000..3833c5afa515 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/UncheckedCasts.java @@ -0,0 +1,58 @@ +import java.util.*; + +class X<T> { + +} + +class XX extends X { + Object f(X x) { + if (x != null) { + XX xx = (XX)new XX(); + return xx; + } + if (1 == 1) { + XX xx = (XX)x; + return xx; + } + return null; + } +} + +class eee { + COMP comp; + COMP foo() { + return (COMP) new eee(); + } +} + +class AllPredicate + { + private List> lists; + + public void e(AllPredicate that) + { + lists = (List>)that.lists; + } + + public static List fff() { + Collection c = new ArrayList(); + return (List) c; //not unchecked + } + + public static Comparable ggg() { + Object time = new Object(); + return (Comparable) time; + } + + public static void foo(SortedMap sourceSortedMap) { + new TreeMap((Comparator) sourceSortedMap.comparator()); + } +} + +class K { } +class L extends K { } +class M { + public static L f(T t) { + return (L) t; //this should NOT generate unchecked cast + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/UncheckedOverriding.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/UncheckedOverriding.java new file mode 100644 index 000000000000..44ef9ce1811b --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/UncheckedOverriding.java @@ -0,0 +1,45 @@ +class List { T t;} + +class Base { + List getList(List l) { + return null; + } + + +} + +class Derived extends Base { + List getList(List l) { + return null; + } +} + +class A1 { + T foo(T t) { + return null; + } +} + +class A2 extends A1 { + Object foo(Object o) { + return null; + } +} + +//IDEADEV-15918 +abstract class Outer { + public abstract Inner m(U u); + + public class Inner { + } +} + +class Other extends Outer { + public Ither m(Other other) { + return new Ither(); + } + + public class Ither extends Inner { + } +} +//end of IDEADEV-15918 \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Unused.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Unused.java new file mode 100644 index 000000000000..f6d429e227c0 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Unused.java @@ -0,0 +1,11 @@ +enum e { + A("xxx"); + + private String s; + e(String str) { + s = str; + } + public String getS() { + return s; + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Varargs.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Varargs.java new file mode 100644 index 000000000000..c9956f62c035 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Varargs.java @@ -0,0 +1,33 @@ +class clazz1 { + clazz1(int... args) { args = null; } + public static class Myclazz1 extends clazz1 {} +} + +class AmbiguousReference { + void test() { + doSomething(null, 1); + } + + void doSomething(String s, Number... n) { + s+=n; + } + + void doSomething(Number... n) { + n.hashCode(); + } +} + +class OK { + protected void fff() { + find(""); + } + public void find(String queryString) { + queryString.hashCode(); + } + + public void find(final String queryString, final Object... values) { + queryString.hashCode(); + values.hashCode(); + } + +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Variance.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Variance.java new file mode 100644 index 000000000000..12d15ab6844a --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/Variance.java @@ -0,0 +1,246 @@ +import java.util.List; +import java.util.Map; +import java.util.Iterator; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; + + +/** + * Created by IntelliJ IDEA. + * User: dsl + * Date: Mar 25, 2004 + * Time: 8:08:44 PM + * To change this template use File | Settings | File Templates. + */ +public class VarianceTesting { + void method(List l) { +// l.add(new VarianceTesting()); + l.add(null); + } + + static void shuffle(Collection c) {} + + static class X { + T field; + T[] arrayField; + T[] method() {return arrayField;}; + void putAll(Collection c) {} + } + + void method1(List l) { + List l1 = new ArrayList(); + l1.add(new VarianceTesting()); + List> lll = null; + lll.add(l1); + X x = new X(); + VarianceTesting z = x.field; + VarianceTesting[] v = x.arrayField; + VarianceTesting v1 = x.arrayField[0]; + x.arrayField[0] = new VarianceTesting(); + x.field = new VarianceTesting(); + VarianceTesting[] k = x.method(); + k[0] = new VarianceTesting(); + x.method()[0] = new VarianceTesting(); + x.arrayField = new VarianceTesting[10]; + l1.addAll(new ArrayList()); + List l2 = new ArrayList(); + List l3 = l2; + VarianceTesting t = l1.get(0); + l.add(new VarianceTesting()); + l.add(null); + VarianceTesting t1 = l.get(0); + X x1 = null; + x1.putAll(new ArrayList()); + List unknownlist = l; + List unknownlist1 = new ArrayList(); + List unknownlist2 = new ArrayList<?>(); + shuffle(l); + shuffle(new ArrayList()); + List lllll = new ArrayList(); + lllll.removeAll(new ArrayList()); + } + +} + +class SuperTester { + void go(Acceptor acceptor, U u) { + acceptor.accept(this, u); + } + + static class Acceptor { + void accept(SuperTester tester, V v) { } + } +} + +class SCR40202 { + void foo(Map map) { + for (Iterator> it = map.entrySet().iterator(); it.hasNext();) { + + } + } +} + +class CaptureTest { + static class Emum { + T t; + public static > T valueOf(Class enumType, + String name) { + return null; + } + } + + void foo (Class> clazz) { + Emum.valueOf(clazz, "CCC"); + } +} + +class SuperTest { + public List> waitingList; + + public Comparator> SIZE_COMPARATOR; + + { + //This call has its type arguments inferred alright: T -> List> + Collections.sort(waitingList, SIZE_COMPARATOR); + } +} + +class Bug { + static class B { + } + + static class D { + B f() { + return null; + } + } + + void h(B b) { + } + + void foo(D d) { + h(d.f()); //This call is OK as a result of reopening captured wildcard for calling "h" + } +} + +//IDEA-4215 +class Case2 { + class A {} + + class B extends A {} + + Comparator aComparator; + Case2() { + + ArrayList blist = new ArrayList(); + + // this call is OK: T -> B + Collections.sort(blist, aComparator); + } +} + +class S1 { + void f(List l1, T l2) { + + } + + void bar(List k) { + f(k, k.get(0)); + } +} + +class S2 { + void f(List l1, List l2) { + + } + + void bar(List k) { + f(k, k); + } +} + +class S3 { + void f(Map l2) { + + } + + void bar(Map k) { + f(k); + } +} + +class TypeBug { + private static class ValueHolder { + public T value; + } + + public static void main(final String[] args) { + List> multiList = new ArrayList>(); + + ValueHolder intHolder = new ValueHolder(); + intHolder.value = 1; + + ValueHolder doubleHolder = new ValueHolder(); + doubleHolder.value = 1.5; + + multiList.add(intHolder); + multiList.add(doubleHolder); + swapFirstTwoValues(multiList); //need to be highlighted + + // this line causes a ClassCastException when checked. + Integer value = intHolder.value; + System.out.println(value); + } + + private static void swapFirstTwoValues(List> multiList) { + ValueHolder intHolder = multiList.get(0); + ValueHolder doubleHolder = multiList.get(1); + + intHolder.value = doubleHolder.value; + } +} + +class OtherBug { +public static void foo(List foos) { + final Comparator comparator = createComparator(); + Collections.sort(foos, comparator); //this call is OK + } + + private static Comparator createComparator() { + return null; + } + + public interface Foo { + } +} + +class OtherBug1 { + public static void foo(List foos) { + final Comparator comparator = createComparator(); + Collections.sort(foos, comparator); + } + + private static Comparator createComparator() { + return null; + } + + public interface Foo { + } +} + +//IDEADEV-7187 +class AA , C extends AA>{} +//end of IDEADEV-7187 + +//IDEADEV-8697 +class GenericTest99,F> { +} +class GenericTest99D> extends GenericTest99 { +} +class Use99,F> { +} +class Use99n extends Use99,Double> { +} +//end of IDEADEV-8697 diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardTypes.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardTypes.java new file mode 100644 index 000000000000..9cbac324b412 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/genericsHighlighting/WildcardTypes.java @@ -0,0 +1,164 @@ +import java.util.*; + +class a { + public void printList(List list) { + for (Iterator i = list.iterator(); i.hasNext();) { + System.out.println(i.next().toString()); + } + } +} + +class b<T> { + public interface Lst > { + Self subList(int fromIndex, int toIndex); + } + + public static Lst foo(Lst lst) { + Lst myl = lst.subList(0, 2); + return myl; + } +} + +class ThingUser { + V v; + { + new ThingUser<?>() { + }; + } +} + +class SuperWildcardTest { + static void method(List list) { + List l = list; + l.size(); + } +} + +class IdeaDev4166 { + Map f( Map fieldsTemplate) { + return new HashMap( fieldsTemplate); + } +} + +//IDEADEV-5816 +class TwoD { + int x, y; + TwoD(int a, int b) { + x = a; + y = b; + } +} +// Three-dimensional coordinates. +class ThreeD extends TwoD { + int z; + ThreeD(int a, int b, int c) { + super(a, b); + z = c; + } +} +// Four-dimensional coordinates. +class FourD extends ThreeD { + int t; + FourD(int a, int b, int c, int d) { + super(a, b, c); + t = d; + } +} +// This class holds an array of coordinate objects. +class Coords { + T[] coords; + Coords(T[] o) { coords = o; } +} + +// Demonstrate a bounded wildcard. +class BoundedWildcard { + + static void showXY(Coords c) { + System.out.println("X Y Coordinates:"); + for(int i=0; i < c.coords.length; i++) { + System.out.println(c.coords[i].x + " " + c.coords[i].y); + } + System.out.println(); + } + + static void showXYZ(Coords c) { + System.out.println("X Y Z Coordinates:"); + for(int i=0; i < c.coords.length; i++) + System.out.println(c.coords[i].x + " " + + c.coords[i].y + " " + + c.coords[i].z); + System.out.println(); + } + + static void showAll(Coords c) { + System.out.println("X Y Z T Coordinates:"); + for(int i=0; i < c.coords.length; i++) + System.out.println(c.coords[i].x + " " + + c.coords[i].y + " " + + c.coords[i].z + " " + + c.coords[i].t); + System.out.println(); + } + + public static void main(String args[]) { + TwoD td[] = { + new TwoD(0, 0), + new TwoD(7, 9), + new TwoD(18, 4), + new TwoD(-1, -23) + }; + Coords tdlocs = new Coords(td); + System.out.println("Contents of tdlocs."); + showXY(tdlocs); // OK, is a TwoD + showXYZ(tdlocs); + showAll(tdlocs); + // Now, create some FourD objects. + FourD fd[] = { + new FourD(1, 2, 3, 4), + new FourD(6, 8, 14, 8), + new FourD(22, 9, 4, 9), + new FourD(3, -2, -23, 17) + }; + Coords fdlocs = new Coords(fd); + System.out.println("Contents of fdlocs."); + // These are all OK. + showXY(fdlocs); + showXYZ(fdlocs); + showAll(fdlocs); + } +} +//end of IDEADEV-5816 + +interface I33 {} +public class Q { + T t; + List foo(Q v) { + v.hashCode(); + return null; + } + + List g (Q q) { + return foo(q); + } +} + +//IDEADEV-16628 +class CollectionHelper { + public static Collection convertDown(Collection collection) { + return collection == null ? null : null; + } + public static Collection convertUp(Collection collection) { + return collection == null ? null : null; + } + + public static void main(String[] args) { + // Downcast examples + final Collection numbers1 = new ArrayList(1); + Collection integers1 = CollectionHelper.convertDown(numbers1); + integers1.hashCode(); + // Upcast example + final Collection integers4 = new ArrayList(1); + final Collection numbers4 = CollectionHelper.convertUp(integers4); + numbers4.hashCode(); + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingTest.java new file mode 100644 index 000000000000..ba39b86c07fb --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/AdvHighlightingTest.java @@ -0,0 +1,187 @@ +package com.intellij.codeInsight.daemon; + +import com.intellij.analysis.PackagesScopesProvider; +import com.intellij.application.options.colors.ColorAndFontOptions; +import com.intellij.codeInsight.daemon.impl.HighlightInfo; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.application.ex.PathManagerEx; +import com.intellij.openapi.editor.colors.EditorColorsManager; +import com.intellij.openapi.editor.colors.EditorColorsScheme; +import com.intellij.openapi.editor.colors.TextAttributesKey; +import com.intellij.openapi.editor.markup.EffectType; +import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.fileTypes.StdFileTypes; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleManager; +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.projectRoots.SdkModificator; +import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; +import com.intellij.openapi.roots.*; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.packageDependencies.DependencyValidationManager; +import com.intellij.pom.java.LanguageLevel; +import com.intellij.psi.*; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.scope.packageSet.NamedScope; +import com.intellij.psi.search.scope.packageSet.NamedScopeManager; +import com.intellij.psi.search.scope.packageSet.NamedScopesHolder; +import com.intellij.psi.search.scope.packageSet.PatternPackageSet; +import org.jetbrains.annotations.NonNls; + +import java.awt.*; +import java.io.File; +import java.util.Collection; + +/** + * This class intended for "heavily-loaded" tests only, e.g. those need to setup separate project directory structure to run + * For "lightweight" tests use LightAdvHighlightingTest + */ +public class AdvHighlightingTest extends DaemonAnalyzerTestCase { + @NonNls private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/advHighlighting"; + + public void testPackageLocals() throws Exception { doTest(BASE_PATH+"/packageLocals/x/sub/UsingMain.java", BASE_PATH+"/packageLocals", false, false); } + public void testPackageLocalClassInTheMiddle() throws Exception { doTest(BASE_PATH+"/packageLocals/x/A.java", BASE_PATH+"/packageLocals", false, false); } + + public void testEffectiveAccessLevel() throws Exception { doTest(BASE_PATH+"/accessLevel/effectiveAccess/p2/p3.java", BASE_PATH+"/accessLevel", false, false); } + public void testSingleImportConflict() throws Exception { doTest(BASE_PATH+"/singleImport/d.java", BASE_PATH+"/singleImport", false, false); } + + public void testDuplicateTopLevelClass() throws Exception { doTest(BASE_PATH+"/duplicateClass/A.java", BASE_PATH+"/duplicateClass", false, false); } + public void testDuplicateTopLevelClass2() throws Exception { doTest(BASE_PATH+"/duplicateClass/java/lang/Runnable.java", BASE_PATH+"/duplicateClass", false, false); } + + public void testProtectedConstructorCall() throws Exception { doTest(BASE_PATH+"/protectedConstructor/p2/C2.java", BASE_PATH+"/protectedConstructor", false, false); } + public void testProtectedConstructorCallInSamePackage() throws Exception { doTest(BASE_PATH+"/protectedConstructor/samePackage/C2.java", BASE_PATH+"/protectedConstructor", false, false); } + public void testProtectedConstructorCallInInner() throws Exception { doTest(BASE_PATH+"/protectedConstructorInInner/p2/C2.java", BASE_PATH+"/protectedConstructorInInner", false, false); } + public void testArrayLengthAccessFromSubClass() throws Exception { doTest(BASE_PATH+"/arrayLength/p2/SubTest.java", BASE_PATH+"/arrayLength", false, false); } + public void testAccessibleMember() throws Exception { doTest(BASE_PATH+"/accessibleMember/com/red/C.java", BASE_PATH+"/accessibleMember", false, false); } + public void testOnDemandImportConflict() throws Exception { doTest(BASE_PATH+"/onDemandImportConflict/Outer.java", BASE_PATH+"/onDemandImportConflict", false, false); } + public void testPackageLocalOverride() throws Exception { doTest(BASE_PATH+"/packageLocalOverride/y/C.java", BASE_PATH+"/packageLocalOverride", false, false); } + public void testPackageLocalOverrideJustCheckThatPackageLocalMethodDoesNotGetOverridden() throws Exception { doTest(BASE_PATH+"/packageLocalOverride/y/B.java", BASE_PATH+"/packageLocalOverride", false, false); } + public void testProtectedAccessFromOtherPackage() throws Exception { doTest(BASE_PATH+"/protectedAccessFromOtherPackage/a/Main.java", BASE_PATH+"/protectedAccessFromOtherPackage", false, false); } + public void testProtectedFieldAccessFromOtherPackage() throws Exception { doTest(BASE_PATH+"/protectedAccessFromOtherPackage/a/A.java", BASE_PATH+"/protectedAccessFromOtherPackage", false, false); } + public void testPackageLocalClassInTheMiddle1() throws Exception { doTest(BASE_PATH+"/foreignPackageInBetween/a/A1.java", BASE_PATH+"/foreignPackageInBetween", false, false); } + + protected Sdk getTestProjectJdk() { + @NonNls boolean is50 = "StaticImportConflict".equals(getTestName(false)); + LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(is50 ? LanguageLevel.JDK_1_5 : LanguageLevel.JDK_1_4); + return is50 ? JavaSdkImpl.getMockJdk15("java 1.5") : JavaSdkImpl.getMockJdk("java 1.4"); + } + + public void testStaticImportConflict() throws Exception { doTest(BASE_PATH+"/staticImportConflict/Usage.java", BASE_PATH+"/staticImportConflict", false, false); } + public void testImportOnDemand() throws Exception { doTest(BASE_PATH+"/importOnDemand/y/Y.java", BASE_PATH+"/importOnDemand", false, false); } + public void testImportOnDemandVsSingle() throws Exception { doTest(BASE_PATH+"/importOnDemandVsSingle/y/Y.java", BASE_PATH+"/importOnDemandVsSingle", false, false); } + public void testImportSingleVsSamePackage() throws Exception { doTest(BASE_PATH+"/importSingleVsSamePackage/y/Y.java", BASE_PATH+"/importSingleVsSamePackage", false, false); } + + public void testOverridePackageLocal() throws Exception { doTest(BASE_PATH+"/overridePackageLocal/x/y/Derived.java", BASE_PATH+"/overridePackageLocal", false, false); } + public void testAlreadyImportedClass() throws Exception { doTest(BASE_PATH+"/alreadyImportedClass/pack/AlreadyImportedClass.java", BASE_PATH+"/alreadyImportedClass", false, false); } + public void testImportDefaultPackage() throws Exception { doTest(BASE_PATH+"/importDefaultPackage/x/Usage.java", BASE_PATH+"/importDefaultPackage", false, false); } + public void testImportDefaultPackage2() throws Exception { doTest(BASE_PATH+"/importDefaultPackage/x/ImportOnDemandUsage.java", BASE_PATH+"/importDefaultPackage", false, false); } + + public void testScopeBased() throws Exception { + NamedScope xscope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_SOURCE, null)); + NamedScope utilscope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null)); + NamedScopeManager scopeManager = NamedScopeManager.getInstance(getProject()); + scopeManager.addScope(xscope); + scopeManager.addScope(utilscope); + + EditorColorsManager manager = EditorColorsManager.getInstance(); + EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone(); + manager.addColorsScheme(scheme); + EditorColorsManager.getInstance().setGlobalScheme(scheme); + TextAttributesKey xKey = ColorAndFontOptions.getScopeTextAttributeKey(xscope.getName()); + TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, EffectType.BOXED, Font.ITALIC); + scheme.setAttributes(xKey, xAttributes); + + TextAttributesKey utilKey = ColorAndFontOptions.getScopeTextAttributeKey(utilscope.getName()); + TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD); + scheme.setAttributes(utilKey, utilAttributes); + + try { + doTest(BASE_PATH+"/scopeBased/x/X.java", BASE_PATH+"/scopeBased", false, true); + } + finally { + scopeManager.removeAllSets(); + } + } + public void testSharedScopeBased() throws Exception { + NamedScope xscope = new NamedScope("xxx", new PatternPackageSet("x..*", PatternPackageSet.SCOPE_ANY, null)); + NamedScope utilscope = new NamedScope("util", new PatternPackageSet("java.util.*", PatternPackageSet.SCOPE_LIBRARY, null)); + NamedScopesHolder scopeManager = DependencyValidationManager.getInstance(getProject()); + scopeManager.addScope(xscope); + scopeManager.addScope(utilscope); + + EditorColorsManager manager = EditorColorsManager.getInstance(); + EditorColorsScheme scheme = (EditorColorsScheme)manager.getGlobalScheme().clone(); + manager.addColorsScheme(scheme); + EditorColorsManager.getInstance().setGlobalScheme(scheme); + TextAttributesKey xKey = ColorAndFontOptions.getScopeTextAttributeKey(xscope.getName()); + TextAttributes xAttributes = new TextAttributes(Color.cyan, Color.darkGray, Color.blue, null, Font.ITALIC); + scheme.setAttributes(xKey, xAttributes); + + TextAttributesKey utilKey = ColorAndFontOptions.getScopeTextAttributeKey(utilscope.getName()); + TextAttributes utilAttributes = new TextAttributes(Color.gray, Color.magenta, Color.orange, EffectType.STRIKEOUT, Font.BOLD); + scheme.setAttributes(utilKey, utilAttributes); + + NamedScope projectScope = PackagesScopesProvider.getInstance(myProject).getProjectProductionScope(); + TextAttributesKey projectKey = ColorAndFontOptions.getScopeTextAttributeKey(projectScope.getName()); + TextAttributes projectAttributes = new TextAttributes(null, null, Color.blue, EffectType.BOXED, Font.ITALIC); + scheme.setAttributes(projectKey, projectAttributes); + + try { + doTest(BASE_PATH+"/scopeBased/x/Shared.java", BASE_PATH+"/scopeBased", false, true); + } + finally { + scopeManager.removeAllSets(); + } + } + + public void testMultiJDKConflict() throws Exception { + String path = PathManagerEx.getTestDataPath() + BASE_PATH + "/" + getTestName(true); + VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(new File(path)); + loadAllModulesUnder(root); + ModuleManager moduleManager = ModuleManager.getInstance(getProject()); + final Module java4 = moduleManager.findModuleByName("java4"); + Module java5 = moduleManager.findModuleByName("java5"); + final ModuleRootManager rootManager4 = ModuleRootManager.getInstance(java4); + final ModuleRootManager rootManager5 = ModuleRootManager.getInstance(java5); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + public void run() { + final ModifiableRootModel rootModel4 = rootManager4.getModifiableModel(); + rootModel4.setSdk(JavaSdkImpl.getMockJdk("java 1.4")); + rootModel4.commit(); + final ModifiableRootModel rootModel5 = rootManager5.getModifiableModel(); + rootModel5.setSdk(JavaSdkImpl.getMockJdk15("java 1.5")); + rootModel5.addModuleOrderEntry(java4); + rootModel5.commit(); + } + }); + + configureByExistingFile(root.findFileByRelativePath("moduleJava5/com/Java5.java")); + Collection infos = highlightErrors(); + assertEmpty(infos); + } + + public void testSameFQNClasses() throws Exception { + String path = PathManagerEx.getTestDataPath() + BASE_PATH + "/" + getTestName(true); + VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(new File(path)); + loadAllModulesUnder(root); + + configureByExistingFile(root.findFileByRelativePath("client/src/BugTest.java")); + Collection infos = highlightErrors(); + assertEmpty(infos); + } + + public void testSameClassesInSourceAndLib() throws Exception { + String path = PathManagerEx.getTestDataPath() + BASE_PATH + "/" + getTestName(true); + VirtualFile root = LocalFileSystem.getInstance().findFileByIoFile(new File(path)); + loadAllModulesUnder(root); + + configureByExistingFile(root.findFileByRelativePath("src/ppp/SomeClass.java")); + PsiField field = ((PsiJavaFile)myFile).getClasses()[0].findFieldByName("f", false); + PsiClass aClass = ((PsiClassType)field.getType()).resolve(); + assertEquals("ppp.BadClass", aClass.getQualifiedName()); + //lies in source + assertEquals(myFile.getVirtualFile().getParent(), aClass.getContainingFile().getVirtualFile().getParent()); + } + +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java new file mode 100644 index 000000000000..947fbdf48892 --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/GenericsHighlightingTest.java @@ -0,0 +1,112 @@ +package com.intellij.codeInsight.daemon; + +import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; +import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection; +import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.projectRoots.impl.JavaSdkImpl; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; +import com.intellij.psi.PsiClass; +import com.intellij.psi.search.GlobalSearchScope; +import org.jetbrains.annotations.NonNls; + + +public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase { + @NonNls private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/genericsHighlighting"; + private LanguageLevel myOldLanguageLevel; + + + protected LocalInspectionTool[] configureLocalInspectionTools() { + return new LocalInspectionTool[]{new UncheckedWarningLocalInspection(), new UnusedSymbolLocalInspection(), new UnusedImportLocalInspection()}; + } + + private void doTest(boolean checkWarnings) throws Exception { + doTest(getTestName(false) + ".java", checkWarnings); + } + + private void doTest(@NonNls String filePath, boolean checkWarnings) throws Exception { + doTest(BASE_PATH + "/" + filePath, checkWarnings, false); + } + + protected void setUp() throws Exception { + super.setUp(); + myOldLanguageLevel = LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).getLanguageLevel(); + LanguageLevel level = getTestName(false).contains("Level6") ? LanguageLevel.JDK_1_6 : LanguageLevel.JDK_1_5; + LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(level); + } + + @Override protected Sdk getProjectJDK() { + return JavaSdkImpl.getMockJdk15("java 1.5"); + } + + protected void tearDown() throws Exception { + LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(myOldLanguageLevel); + super.tearDown(); + } + + public void testReferenceTypeParams() throws Exception { doTest(false); } + public void testOverridingMethods() throws Exception { doTest(false); } + public void testTypeParameterBoundsList() throws Exception { doTest(false); } + public void testClassInheritance() throws Exception { doTest(false); } + public void testTypeInference() throws Exception { doTest(false); } + public void testRaw() throws Exception { doTest(true); } + public void testExceptions() throws Exception { doTest(false); } + public void testExplicitMethodParameters() throws Exception { doTest(false); } + public void testExplicitMethodParameters1() throws Exception { doTest(false); } + public void testInferenceWithBounds() throws Exception {doTest(false);} + public void testVariance() throws Exception {doTest(false);} + public void testForeachTypes() throws Exception {doTest(false);} + public void testRawOverridingMethods() throws Exception {doTest(false);} + public void testAutoboxing() throws Exception {doTest(false);} + public void testAutoboxingMethods() throws Exception {doTest(false);} + public void testAutoboxingConstructors() throws Exception {doTest(false);} + public void testEnumWithAbstractMethods() throws Exception { doTest(false); } + public void testEnum() throws Exception { doTest(false); } + public void testSameErasure() throws Exception { doTest(false); } + + public void testMethods() throws Exception { doTest(false); } + public void testStaticImports() throws Exception { doTest(true); } + public void testUncheckedCasts() throws Exception { doTest(true); } + public void testUncheckedOverriding() throws Exception { doTest(true); } + public void testWildcardTypes() throws Exception { doTest(true); } + public void testConvertibleTypes() throws Exception { doTest(true); } + + public void testIntersectionTypes() throws Exception { doTest(true); } + public void testVarargs() throws Exception { doTest(true); } + public void testTypeArgsOnRaw() throws Exception { doTest(false); } + public void testConditionalExpression() throws Exception { doTest(false); } + + public void testUnused() throws Exception { doTest(true); } + + public void testIDEADEV7337() throws Exception { doTest(true); } + public void testIDEADEV10459() throws Exception { doTest(true); } + public void testIDEADEV12951() throws Exception { doTest(true); } + public void testIDEADEV13011() throws Exception { doTest(true); } + public void testIDEADEV14006() throws Exception { doTest(true); } + public void testIDEADEV14103() throws Exception { doTest(true); } + public void testIDEADEV15534() throws Exception { doTest(true); } + public void testIDEADEV23157() throws Exception { doTest(true); } + public void testIDEADEV24166() throws Exception { doTest(true); } + public void testIDEADEV25778() throws Exception { doTest(true); } + public void testGenericExtendException() throws Exception { doTest(false); } + public void testSameErasureDifferentReturnTypes() throws Exception { doTest(false); } + public void testDeepConflictingReturnTypes() throws Exception { doTest(false); } + public void testInheritFromTypeParameter() throws Exception { doTest(false); } + public void testAnnotationsAsPartOfModifierList() throws Exception { doTest(false); } + public void testImplementAnnotation() throws Exception { doTest(false); } + public void testOverrideAtLanguageLevel6() throws Exception { doTest(false); } + public void testOverrideAtLanguageLevel5() throws Exception { doTest(false); } + public void testSuperMethodCallWithErasure() throws Exception { doTest(false); } + + public void testJavaUtilCollections() throws Exception { + PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule())); + + assertNotNull(collectionsClass); + collectionsClass = (PsiClass)collectionsClass.getNavigationElement(); + final String text = collectionsClass.getContainingFile().getText(); + configureFromFileText("Collections.java", text.replaceAll("\r","\n")); + doTestConfiguredFile(false, false); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java new file mode 100644 index 000000000000..4f8e50531b9a --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingJdk7Test.java @@ -0,0 +1,33 @@ +package com.intellij.codeInsight.daemon; + +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; +import org.jetbrains.annotations.NonNls; + +/** + * This class is for "lightweight" tests only, i.e. those which can run inside default light project set up + * For "heavyweight" tests use AdvHighlightingTest + */ +public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase { + @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/advHighlighting7"; + private LanguageLevel myOldLanguageLevel; + + private void doTest(boolean checkWarnings, boolean checkInfos) throws Exception { + doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, checkInfos); + } + + protected void setUp() throws Exception { + super.setUp(); + myOldLanguageLevel = LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).getLanguageLevel(); + LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_7); + } + + protected void tearDown() throws Exception { + LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(myOldLanguageLevel); + super.tearDown(); + } + + public void testSwitchByString() throws Exception { + doTest(true, false); + } +} diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java new file mode 100644 index 000000000000..18223fd7cb1e --- /dev/null +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingTest.java @@ -0,0 +1,308 @@ +package com.intellij.codeInsight.daemon; + +import com.intellij.ExtensionPoints; +import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.accessStaticViaInstance.AccessStaticViaInstance; +import com.intellij.codeInspection.deadCode.UnusedCodeExtension; +import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection; +import com.intellij.codeInspection.deprecation.DeprecationInspection; +import com.intellij.codeInspection.javaDoc.JavaDocLocalInspection; +import com.intellij.codeInspection.reference.RefElement; +import com.intellij.codeInspection.sillyAssignment.SillyAssignmentInspection; +import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection; +import com.intellij.codeInspection.unneededThrows.RedundantThrowsDeclaration; +import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection; +import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection; +import com.intellij.idea.Bombed; +import com.intellij.lang.Language; +import com.intellij.lang.LanguageAnnotators; +import com.intellij.lang.annotation.AnnotationHolder; +import com.intellij.lang.annotation.Annotator; +import com.intellij.lang.annotation.HighlightSeverity; +import com.intellij.openapi.extensions.ExtensionPoint; +import com.intellij.openapi.extensions.Extensions; +import com.intellij.openapi.fileTypes.StdFileTypes; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; +import com.intellij.psi.*; +import com.intellij.psi.impl.source.PostprocessReformattingAspect; +import com.intellij.psi.xml.XmlAttribute; +import com.intellij.psi.xml.XmlTag; +import com.intellij.psi.xml.XmlToken; +import com.intellij.psi.xml.XmlTokenType; +import org.jdom.Element; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.util.Calendar; +import java.util.List; + +import static com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase.filter; + +/** + * This class is for "lightweight" tests only, i.e. those which can run inside default light project set up + * For "heavyweight" tests use AdvHighlightingTest + */ +public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase { + @NonNls static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/advHighlighting"; + private LanguageLevel myOldLanguageLevel; + private UnusedSymbolLocalInspection myUnusedSymbolLocalInspection; + + private void doTest(boolean checkWarnings, boolean checkInfos) throws Exception { + doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, checkInfos); + } + + protected void setUp() throws Exception { + super.setUp(); + myOldLanguageLevel = LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).getLanguageLevel(); + LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_4); + } + + protected void tearDown() throws Exception { + LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(myOldLanguageLevel); + super.tearDown(); + } + + protected LocalInspectionTool[] configureLocalInspectionTools() { + myUnusedSymbolLocalInspection = new UnusedSymbolLocalInspection(); + return new LocalInspectionTool[]{ + new SillyAssignmentInspection(), + new AccessStaticViaInstance(), + new DeprecationInspection(), + new RedundantThrowsDeclaration(), + myUnusedSymbolLocalInspection, + new UnusedImportLocalInspection(), + new UncheckedWarningLocalInspection()}; + } + + public void testCanHaveBody() throws Exception { doTest(false, false); } + public void testInheritFinal() throws Exception { doTest(false, false); } + public void testBreakOutside() throws Exception { doTest(false, false); } + public void testLoop() throws Exception { doTest(false, false); } + public void testIllegalModifiersCombination() throws Exception { doTest(false, false); } + public void testModifierAllowed() throws Exception { doTest(false, false); } + public void testAbstractMethods() throws Exception { doTest(false, false); } + public void testInstantiateAbstract() throws Exception { doTest(false, false); } + public void testDuplicateClassMethod() throws Exception { doTest(false, false); } + public void testa10() throws Exception { doTest(false, false); } + public void testa11() throws Exception { doTest(false, false); } + public void testInvalidExpressions() throws Exception { doTest(false, false); } + public void testIllegalVoidType() throws Exception { doTest(false, false); } + public void testIllegalType() throws Exception { doTest(false, false); } + public void testOperatorApplicability() throws Exception { doTest(false, false); } + public void testIncompatibleTypes() throws Exception { doTest(false, false); } + public void testCtrCallIsFirst() throws Exception { doTest(false, false); } + public void testAccessLevelClash() throws Exception { doTest(false, false); } + public void testa16() throws Exception { doTest(false, false); } + public void testOverrideConflicts() throws Exception { doTest(false, false); } + public void testOverriddenMethodIsFinal() throws Exception { doTest(false, false); } + public void testa18() throws Exception { doTest(false, false); } + public void testUnreachable() throws Exception { doTest(false, false); } + public void testFinalFieldInit() throws Exception { doTest(false, false); } + public void testLocalVariableInitialization() throws Exception { doTest(false, false); } + public void testa22() throws Exception { doTest(false, false); } + public void testa22_1() throws Exception { doTest(false, false); } + public void testAssignToFinal() throws Exception { doTest(false, false); } + public void testa24() throws Exception { doTest(false, false); } + public void testa25() throws Exception { doTest(false, false); } + public void testMustBeBoolean() throws Exception { doTest(false, false); } + + public void testNumericLiterals() throws Exception { doTest(false, false); } + public void testInitializerCompletion() throws Exception { doTest(false, false); } + + public void testa28() throws Exception { doTest(false, false); } + public void testDuplicateSwitchLabels() throws Exception { doTest(false, false); } + public void testStringSwitchLabels() throws Exception { doTest(false, false); } + public void testa30() throws Exception { doTest(false, false); } + public void testStaticOverride() throws Exception { doTest(false, false); } + public void testa32() throws Exception { doTest(false, false); } + public void testReferenceMemberBeforeCtrCalled() throws Exception { doTest(false, false); } + public void testa34() throws Exception { doTest(false, false); } + public void testa35() throws Exception { doTest(false, false); } + public void testa35_1() throws Exception { doTest(false, false); } + public void testa35_2() throws Exception { doTest(false, false); } + public void testSillyAssignment() throws Exception { doTest(true, false); } + public void testa37() throws Exception { doTest(false, false); } + public void testa38() throws Exception { doTest(false, false); } + public void testa39() throws Exception { doTest(false, false); } + public void testMustBeThrowable() throws Exception { doTest(false, false); } + public void testUnhandledMessingWithFinally() throws Exception { doTest(false, false); } + public void testSerializableStuff() throws Exception { doTest(true, false); } + public void testDeprecated() throws Exception { doTest(true, false); } + public void testJavadoc() throws Exception { enableInspectionTool(new JavaDocLocalInspection()); doTest(true, false); } + public void testa44() throws Exception { doTest(false, false); } + public void testa45() throws Exception { doTest(false, false); } + + public void testExceptionNeverThrown() throws Exception { doTest(true, false); } + public void testExceptionNeverThrownInTry() throws Exception { doTest(false, false); } + + public void testa47() throws Exception { doTest(false, false); } + public void testa48() throws Exception { doTest(false, false); } + + public void testa49() throws Exception { doTest(false, false); } + public void testa50() throws Exception { doTest(false, false); } + public void testa52() throws Exception { doTest(false, false); } + public void testMethodCalls() throws Exception { doTest(false, false); } + public void testa54() throws Exception { doTest(false, false); } + public void testa54_1() throws Exception { doTest(true, false); } //duplicate imports + public void testa55() throws Exception { doTest(false, false); } + public void testQualifiedNew() throws Exception { doTest(false, false); } + public void testEnclosingInstance() throws Exception { doTest(false, false); } + + public void testa59() throws Exception { doTest(true, false); } // static via instabnce + public void testa60() throws Exception { doTest(true, false); } //illegal qualified this or super + + public void testAmbiguousMethodCall() throws Exception { doTest(false, false); } + + public void testImplicitConstructor() throws Exception { doTest(false, false); } + public void testDotBeforeDecl() throws Exception { doTest(false, false); } + public void testComputeConstant() throws Exception { doTest(false, false); } + + public void testAnonInAnon() throws Exception { doTest(false, false); } + public void testAnonBaseRef() throws Exception { doTest(false, false); } + public void testReturn() throws Exception { doTest(false, false); } + public void testInterface() throws Exception { doTest(false, false); } + public void testExtendsClause() throws Exception { doTest(false, false); } + public void testMustBeFinal() throws Exception { doTest(false, false); } + + public void testXXX() throws Exception { doTest(false, false); } + public void testUnused() throws Exception { doTest(true, false); } + public void testQualifierBeforeClassName() throws Exception { doTest(false, false); } + public void testQualifiedSuper() throws Exception { doTest(false, false); } + public void testCastFromVoid() throws Exception { doTest(false, false); } + public void testCatchUnknownMethod() throws Exception { doTest(false, false); } + public void testIDEADEV8822() throws Exception { doTest(false, false); } + public void testIDEADEV9201() throws Exception { doTest(false, false); } + public void testIDEADEV11877() throws Exception { doTest(false, false); } + public void testIDEADEV25784() throws Exception { doTest(false, false); } + public void testIDEADEV13249() throws Exception { doTest(false, false); } + public void testIDEADEV11919() throws Exception { doTest(false, false); } + public void testMethodCannotBeApplied() throws Exception { doTest(false, false); } + + public void testUnusedParamsOfPublicMethod() throws Exception { doTest(true, false); } + public void testUnusedParamsOfPublicMethodDisabled() throws Exception { + myUnusedSymbolLocalInspection.REPORT_PARAMETER_FOR_PUBLIC_METHODS = false; + doTest(true, false); + } + public void testUnusedNonPrivateMembers() throws Exception { + UnusedDeclarationInspection deadCodeInspection = new UnusedDeclarationInspection(); + enableInspectionTool(deadCodeInspection); + doTest(true, false); + } + public void testUnusedNonPrivateMembers2() throws Exception { + ExtensionPoint point = Extensions.getRootArea().getExtensionPoint(ExtensionPoints.DEAD_CODE_TOOL); + UnusedCodeExtension extension = new UnusedCodeExtension() { + @NotNull + @Override + public String getDisplayName() { + return "duh"; + } + + @Override + public boolean isEntryPoint(RefElement refElement) { + return false; + } + + @Override + public boolean isEntryPoint(PsiElement psiElement) { + return psiElement instanceof PsiMethod && ((PsiMethod)psiElement).getName().equals("myTestMethod"); + } + + @Override + public boolean isSelected() { + return false; + } + + @Override + public void setSelected(boolean selected) { + + } + + public void readExternal(Element element) { + + } + + public void writeExternal(Element element) { + + } + }; + + point.registerExtension(extension); + + try { + + UnusedDeclarationInspection deadCodeInspection = new UnusedDeclarationInspection(); + enableInspectionTool(deadCodeInspection); + + doTest(true, false); + } + finally { + point.unregisterExtension(extension); + } + + } + + public void testNamesHighlighting() throws Exception { + LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_5); + doTest(false, true); + } + + public static class MyAnnotator implements Annotator { + public void annotate(@NotNull PsiElement psiElement, @NotNull final AnnotationHolder holder) { + psiElement.accept(new XmlElementVisitor() { + @Override public void visitXmlTag(XmlTag tag) { + XmlAttribute attribute = tag.getAttribute("aaa", ""); + if (attribute != null) { + holder.createWarningAnnotation(attribute, "AAATTR"); + } + } + + @Override public void visitXmlToken(XmlToken token) { + if (token.getTokenType() == XmlTokenType.XML_ENTITY_REF_TOKEN) { + holder.createWarningAnnotation(token, "ENTITY"); + } + } + }); + } + } + public void testInjectedAnnotator() throws Exception { + Annotator annotator = new MyAnnotator(); + Language xml = StdFileTypes.XML.getLanguage(); + LanguageAnnotators.INSTANCE.addExplicitExtension(xml, annotator); + try { + List list = LanguageAnnotators.INSTANCE.allForLanguage(xml); + assertTrue(list.toString(), list.contains(annotator)); + doTest(BASE_PATH + "/" + getTestName(false) + ".xml",true,false); + } + finally { + LanguageAnnotators.INSTANCE.removeExplicitExtension(xml, annotator); + } + + List list = LanguageAnnotators.INSTANCE.allForLanguage(xml); + assertFalse(list.toString(), list.contains(annotator)); + } + + @Bombed(month = Calendar.DECEMBER, day=31, user="cdr") + public void testSOEForTypeOfHugeBinaryExpression() throws IOException { + configureFromFileText("a.java", "class A { String s = \"\"; }"); + assertEmpty(filter(doHighlighting(), HighlightSeverity.ERROR)); + + PsiField field = ((PsiJavaFile)getFile()).getClasses()[0].getFields()[0]; + + // have to manipulate PSI, will get SOE in BlockSupportImpl otherwise + PsiExpression literal = JavaPsiFacade.getElementFactory(getProject()).createExpressionFromText("\"xxx\"", field); + + PsiBinaryExpression binary = (PsiBinaryExpression)JavaPsiFacade.getElementFactory(getProject()).createExpressionFromText("a+b", field); + for (int i=0; i<2000;i++) { + PsiExpression expression = field.getInitializer(); + binary.getLOperand().replace(expression); + binary.getROperand().replace(literal); + + expression.replace(binary); + PostprocessReformattingAspect.getInstance(getProject()).clear(); // OOM otherwise + } + + field.getInitializer().getType(); // SOE + } +}