Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVikas Chandra2014-04-07 08:33:38 +0000
committerCurtis Windatt2014-04-08 17:11:12 +0000
commita642552ccc53ba8536424fdde41b181be8502a9a (patch)
tree529670b64a0353f01ab7a99722174abff732a2ff /apitools
parent6224d229a34fa423d7ffa3f603e7a360a5759c2a (diff)
downloadeclipse.pde.ui-a642552ccc53ba8536424fdde41b181be8502a9a.tar.gz
eclipse.pde.ui-a642552ccc53ba8536424fdde41b181be8502a9a.tar.xz
eclipse.pde.ui-a642552ccc53ba8536424fdde41b181be8502a9a.zip
Bug 427502 - [1.8] Support method referencesI20140408-1645
Conflicts: apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/AbstractProblemDetector.java Change-Id: I8773fd240e24b424e4168d81054154bbdaf13193 Signed-off-by: Vikas Chandra <Vikas.Chandra@in.ibm.com>
Diffstat (limited to 'apitools')
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8MethodConstRefUsageTests.java139
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8UsageTest.java1
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/testMethodReference.java44
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/testMethodReference2.java33
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/META-INF/MANIFEST.MF2
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReference.java50
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterface.java16
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterfaceArg.java17
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterfaceParamArg.java17
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MR.java45
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MethodReference.java32
-rw-r--r--apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MethodReferenceInterface.java4
-rw-r--r--apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/AbstractProblemDetector.java41
13 files changed, 434 insertions, 7 deletions
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8MethodConstRefUsageTests.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8MethodConstRefUsageTests.java
new file mode 100644
index 0000000000..c4d929b677
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8MethodConstRefUsageTests.java
@@ -0,0 +1,139 @@
+/*******************************************************************************
+ * Copyright (c) 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.pde.api.tools.builder.tests.usage;
+
+import junit.framework.Test;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.pde.api.tools.internal.provisional.problems.IApiProblem;
+
+public class Java8MethodConstRefUsageTests extends MethodUsageTests {
+ /**
+ * Constructor
+ *
+ * @param name
+ */
+ public Java8MethodConstRefUsageTests(String name) {
+ super(name);
+ }
+
+ /**
+ * @return the test class for this suite
+ */
+ public static Test suite() {
+ return buildTestSuite(Java8MethodConstRefUsageTests.class);
+ }
+
+ /**
+ * @see org.eclipse.pde.api.tools.builder.tests.ApiBuilderTest#getTestCompliance()
+ */
+ @Override
+ protected String getTestCompliance() {
+ return JavaCore.VERSION_1_8;
+ }
+
+ @Override
+ protected IPath getTestSourcePath() {
+ return super.getTestSourcePath().removeLastSegments(1).append("java8"); //$NON-NLS-1$
+ }
+
+ /**
+ * Tests illegal references to method reference and constructor reference
+ * (full)
+ */
+ public void testMethodConstructorRefF() {
+ x1(false);
+ }
+
+ /**
+ * Tests illegal references to method reference and constructor reference
+ * (incremental)
+ */
+ public void testMethodConstructorRefI() {
+ x1(true);
+ }
+
+ private void x1(boolean inc) {
+ int[] pids = new int[] {
+
+ getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.METHOD),
+ getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.METHOD),
+ getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.CONSTRUCTOR_METHOD),
+ getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.CONSTRUCTOR_METHOD),
+ getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.CONSTRUCTOR_METHOD) };
+ setExpectedProblemIds(pids);
+ String typename = "testMethodReference"; //$NON-NLS-1$
+
+ String[][] args = new String[][] {
+ { "MethodReference", typename, "method1()" }, //$NON-NLS-1$ //$NON-NLS-2$
+ { "MethodReference", typename, "method2()" }, //$NON-NLS-1$ //$NON-NLS-2$
+ { "ConstructorReference()", typename, null }, //$NON-NLS-1$
+ { "ConstructorReference(String)", typename, null }, //$NON-NLS-1$
+ { "ConstructorReference(List<String>)", typename, null }, //$NON-NLS-1$
+
+ };
+ setExpectedMessageArgs(args);
+ setExpectedLineMappings(new LineMapping[] {
+ new LineMapping(31, pids[0], args[0]),
+ new LineMapping(34, pids[1], args[1]),
+ new LineMapping(36, pids[2], args[2]),
+ new LineMapping(38, pids[3], args[3]),
+ new LineMapping(40, pids[4], args[4]),
+
+ });
+
+ deployUsageTest(typename, inc);
+ }
+
+ /**
+ * Tests illegal references to method reference (full)
+ */
+ public void testMethodConstructorRef2F() {
+ x2(false);
+ }
+
+ /**
+ * Tests illegal references to method reference (incremental)
+ */
+ public void testMethodConstructorRef2I() {
+ x2(true);
+ }
+
+ private void x2(boolean inc) {
+ int[] pids = new int[] {
+
+ getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.METHOD),
+ getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.METHOD),
+ getProblemId(IApiProblem.ILLEGAL_REFERENCE, IApiProblem.METHOD) };
+ setExpectedProblemIds(pids);
+ String typename = "testMethodReference2"; //$NON-NLS-1$
+
+ String[][] args = new String[][] {
+ { "MR", typename, "mrCompare(String, String)" }, //$NON-NLS-1$ //$NON-NLS-2$
+ { "MR", typename, "mrCompare2(String, String)" }, //$NON-NLS-1$ //$NON-NLS-2$
+ { "MR", typename, "con(Supplier<T>)" } }; //$NON-NLS-1$ //$NON-NLS-2$
+
+
+ setExpectedMessageArgs(args);
+ setExpectedLineMappings(new LineMapping[] {
+ new LineMapping(27, pids[0], args[0]),
+ new LineMapping(29, pids[1], args[1]),
+ new LineMapping(31, pids[2], args[2]),
+
+
+ });
+
+ deployUsageTest(typename, inc);
+ }
+
+}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8UsageTest.java b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8UsageTest.java
index 21e133a94a..aef96977bf 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8UsageTest.java
+++ b/apitools/org.eclipse.pde.api.tools.tests/src/org/eclipse/pde/api/tools/builder/tests/usage/Java8UsageTest.java
@@ -174,6 +174,7 @@ public class Java8UsageTest extends ApiBuilderTest {
private static Class<?>[] getAllTestClasses() {
ArrayList<Class<?>> classes = new ArrayList<Class<?>>();
classes.add(Java8LambdaUsageTests.class);
+ classes.add(Java8MethodConstRefUsageTests.class);
return classes.toArray(new Class[classes.size()]);
}
}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/testMethodReference.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/testMethodReference.java
new file mode 100644
index 0000000000..f0d5a45805
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/testMethodReference.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) April 5, 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+
+package x.y.z;
+
+import m.MethodReference;
+import m.MethodReferenceInterface;
+import m.ConstructorReference;
+import m.ConstructorReferenceInterface;
+import m.ConstructorReferenceInterfaceArg;
+import m.ConstructorReferenceInterfaceParamArg;
+import java.util.ArrayList;
+
+
+
+/**
+ * Tests illegal use of method accessed by method reference
+ */
+public class testMethodReference {
+
+ public void m1(){
+ MethodReferenceInterface met = MethodReference::method1;
+ met.process();
+ MethodReference m = new MethodReference();
+ met = m::method2;
+ met.process();
+ ConstructorReferenceInterface<ConstructorReference> con = ConstructorReference::new;
+ con.create1().getString();
+ ConstructorReferenceInterfaceArg<ConstructorReference,String> conWithArg = ConstructorReference::new;
+ conWithArg.create2("test").getString();
+ ConstructorReferenceInterfaceParamArg<ConstructorReference,String> conParamArg = ConstructorReference::<String>new;
+ conParamArg.create3(new ArrayList<String>()).getStrings().size();
+ }
+
+}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/testMethodReference2.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/testMethodReference2.java
new file mode 100644
index 0000000000..9fd4af162d
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usage/java8/testMethodReference2.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * Copyright (c) April 5, 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+
+
+package x.y.z;
+
+import m.MR;
+import java.util.Arrays;
+import java.util.HashSet;
+
+/**
+ * Tests illegal use of method accessed by method reference
+ */
+
+public class testMethodReference2 {
+public void m1() {
+ String[] array = {"one"};
+ Arrays.sort(array, MR::mrCompare);
+ MR mr = new MR();
+ Arrays.sort(array, mr::mrCompare2);
+ MR mr2 = new MR();
+ mr2.con(HashSet<String>::new);
+ }
+ } \ No newline at end of file
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/META-INF/MANIFEST.MF b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/META-INF/MANIFEST.MF
index 2a8f6e8a13..6072c16bd6 100644
--- a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/META-INF/MANIFEST.MF
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/META-INF/MANIFEST.MF
@@ -3,7 +3,7 @@ Bundle-ManifestVersion: 2
Bundle-Name: refproject
Bundle-SymbolicName: refprojectjava8
Bundle-Version: 1.0.0
-Export-Package: i
+Export-Package: i,m
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.pde.api.tools;bundle-version="1.0.600",
org.eclipse.pde.api.tools.annotations;bundle-version="1.0.0"
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReference.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReference.java
new file mode 100644
index 0000000000..2715c7a05c
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReference.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) April 5, 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package m;
+import java.util.List;
+
+public class ConstructorReference {
+ private String str;
+
+ private List<String> strs;
+
+ /**
+ * @noreference This constructor is not intended to be referenced by clients.
+ */
+ public ConstructorReference() {
+ this.str = "test1";
+ }
+ /**
+ * @noreference This constructor is not intended to be referenced by clients.
+ */
+ public ConstructorReference(String str) {
+ this.str = str;
+ }
+ /**
+ * @noreference This constructor is not intended to be referenced by clients.
+ */
+ public ConstructorReference(List<String> strs) {
+ this.strs = strs;
+ }
+
+ public String getString()
+ {
+ return str;
+ }
+
+ public List<String> getStrings()
+ {
+ return strs;
+ }
+
+
+}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterface.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterface.java
new file mode 100644
index 0000000000..32deff8960
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterface.java
@@ -0,0 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) April 5, 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package m;
+
+public interface ConstructorReferenceInterface<T> {
+ T create1();
+}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterfaceArg.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterfaceArg.java
new file mode 100644
index 0000000000..54bec60189
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterfaceArg.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) April 5, 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package m;
+
+public interface ConstructorReferenceInterfaceArg<T,U> {
+ T create2(U arg);
+
+}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterfaceParamArg.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterfaceParamArg.java
new file mode 100644
index 0000000000..b3a0d02c00
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/ConstructorReferenceInterfaceParamArg.java
@@ -0,0 +1,17 @@
+/*******************************************************************************
+ * Copyright (c) April 5, 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package m;
+import java.util.List;
+public interface ConstructorReferenceInterfaceParamArg<T,U> {
+ T create3(List<U> arg);
+
+}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MR.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MR.java
new file mode 100644
index 0000000000..c30ceaac34
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MR.java
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) April 5, 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package m;
+
+import java.util.function.Supplier;
+
+public class MR {
+
+ /**
+ * @noreference This method is not intended to be referenced by clients.
+ * @param supplier
+ */
+ public <T> void con (Supplier<T> supplier) {}
+
+ /**@noreference This method is not intended to be referenced by clients.
+ *
+ * @param str1
+ * @param str2
+ * @return
+ */
+ public int mrCompare2(String str1, String str2) {
+ return 0;
+ }
+ /**
+ * @noreference
+ * @param str1
+ * @param str2
+ * @return
+ */
+
+ public static int mrCompare(String str1, String str2) {
+ return 0;
+ }
+
+
+}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MethodReference.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MethodReference.java
new file mode 100644
index 0000000000..57862329e9
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MethodReference.java
@@ -0,0 +1,32 @@
+
+/*******************************************************************************
+ * Copyright (c) 2014 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package m;
+
+public class MethodReference {
+ /**
+ * @noreference This method is not intended to be referenced by clients.
+
+ * @return
+ */
+ public static void method1() {
+ return ;
+ }
+ /**
+ * @noreference This method is not intended to be referenced by clients.
+ * @return
+ */
+ public void method2() {
+ return ;
+ }
+
+
+}
diff --git a/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MethodReferenceInterface.java b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MethodReferenceInterface.java
new file mode 100644
index 0000000000..a8dc995a53
--- /dev/null
+++ b/apitools/org.eclipse.pde.api.tools.tests/test-builder/usageprojectsjava8/refprojectjava8/src/m/MethodReferenceInterface.java
@@ -0,0 +1,4 @@
+package m;
+public interface MethodReferenceInterface {
+ void process();
+}
diff --git a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/AbstractProblemDetector.java b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/AbstractProblemDetector.java
index ac12939200..cd9be60f5f 100644
--- a/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/AbstractProblemDetector.java
+++ b/apitools/org.eclipse.pde.api.tools/src/org/eclipse/pde/api/tools/internal/builder/AbstractProblemDetector.java
@@ -64,6 +64,9 @@ import org.eclipse.pde.api.tools.internal.util.Util;
*/
public abstract class AbstractProblemDetector implements IApiProblemDetector {
+ public static final String METHOD_REFERENCE = "::"; //$NON-NLS-1$
+ public static final String CONSTRUCTOR_NEW = "new"; //$NON-NLS-1$
+
/**
* Class used to look up the name of the enclosing method for an
* {@link IApiType} when we do not have any enclosing method infos (pre Java
@@ -445,7 +448,7 @@ public abstract class AbstractProblemDetector implements IApiProblemDetector {
* @return the index of the method name on the given line or -1 if not found
*/
protected int findMethodNameStart(String namepart, String line, int index) {
- if (namepart.startsWith("::")) { //$NON-NLS-1$
+ if (namepart.startsWith(METHOD_REFERENCE)) {
// a method ref, walk back to find the token
int offset = index;
char c = line.charAt(offset);
@@ -468,12 +471,27 @@ public abstract class AbstractProblemDetector implements IApiProblemDetector {
return -1;
}
int offset = start + namepart.length();
- while (line.charAt(offset) == ' ') {
+ char c = line.charAt(offset);
+ while (c == ' ') {
offset++;
+ c = line.charAt(offset);
}
- if (line.charAt(offset) == '(' || line.charAt(offset) == '<') {
+
+ if (c == '(' || c == '<') {
return start;
}
+
+ // assumes that "::" & method name/"new" in same line
+ if (line.contains(METHOD_REFERENCE)) {
+ if ((c == ';') || (c == '\r') || (c == ')')) {
+ return start;
+ }
+ // method reference constructor
+ if ((c == ':') && line.charAt(offset + 1) == ':' && line.contains(CONSTRUCTOR_NEW)) {
+ return start;
+ }
+
+ }
return findMethodNameStart(namepart, line, offset);
}
}
@@ -914,14 +932,15 @@ public abstract class AbstractProblemDetector implements IApiProblemDetector {
if (isContructor) {
// new keyword should only be checked if the method is a
// constructor
- start = line.indexOf("::new"); //$NON-NLS-1$
+ // what if space between the two?
+ start = line.indexOf(METHOD_REFERENCE + CONSTRUCTOR_NEW);
if (start < 0) {
- line.indexOf("new"); //$NON-NLS-1$
+ line.indexOf(CONSTRUCTOR_NEW);
if (start < 0) {
start = 0;
}
} else {
- int first = findMethodNameStart("::new", line, start); //$NON-NLS-1$
+ int first = findMethodNameStart(METHOD_REFERENCE + CONSTRUCTOR_NEW, line, start);
return new Position(offset + first, (start - first) + 5);
}
} else {
@@ -935,11 +954,21 @@ public abstract class AbstractProblemDetector implements IApiProblemDetector {
}
}
int first = findMethodNameStart(methodname, line, start);
+
+ if (line.contains(METHOD_REFERENCE) && line.contains(CONSTRUCTOR_NEW) && isContructor) {
+ String afterReference = line.substring(line.indexOf(METHOD_REFERENCE));
+ methodname = afterReference.substring(afterReference.indexOf(METHOD_REFERENCE) + 2, afterReference.indexOf(CONSTRUCTOR_NEW) + 3);
+ }
if (first < 0) {
methodname = "super"; //$NON-NLS-1$
first = findMethodNameStart(methodname, line, start);
}
if (first > -1) {
+ idx = line.indexOf(METHOD_REFERENCE, first);
+ if (idx > -1 && isContructor) {
+ //a method ref, add the start + :: + method name length
+ return new Position(offset + first, (idx - first) + 2 + methodname.length());
+ }
return new Position(offset + first, methodname.length());
}
return null;

Back to the top