Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: marcphilipp/Unused-methods-eclipse-plugin
base: master
...
head fork: marcphilipp/Unused-methods-eclipse-plugin
compare: better-markers
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Commits on Mar 14, 2012
@marcphilipp Markers on method names b32e63e
View
1  unused.methods/pdetestsrc/test/Actor.java_
@@ -10,6 +10,7 @@ public class Actor {
public void lonelyMethod() {
}
+ @Deprecated
public static void lonelyStaticMethod() {
}
View
26 unused.methods/src/unused/methods/core/UnusedMethodsMarker.java
@@ -1,6 +1,7 @@
package unused.methods.core;
-import static org.eclipse.core.resources.IMarker.LINE_NUMBER;
+import static org.eclipse.core.resources.IMarker.CHAR_END;
+import static org.eclipse.core.resources.IMarker.CHAR_START;
import static org.eclipse.core.resources.IMarker.MESSAGE;
import static org.eclipse.core.resources.IMarker.SEVERITY;
import static org.eclipse.core.resources.IMarker.SEVERITY_WARNING;
@@ -10,8 +11,8 @@
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
public class UnusedMethodsMarker {
@@ -39,24 +40,11 @@ private static void addMarker(IMethod method) throws CoreException {
JavaCore.getJavaCore().configureJavaElementMarker(marker, method);
marker.setAttribute(MESSAGE, "Method " + method.getElementName() + " is not used.");
marker.setAttribute(SEVERITY, SEVERITY_WARNING);
- marker.setAttribute(LINE_NUMBER, findLine(method));
- }
- }
-
- private static int findLine(IMethod method) throws JavaModelException {
- String sourceOfCompilationUnit = method.getCompilationUnit().getSource();
- int offsetInCharacters = method.getSourceRange().getOffset();
- String linesBeforeMethod = sourceOfCompilationUnit.substring(0, offsetInCharacters);
- return countLines(linesBeforeMethod);
- }
-
- private static int countLines(String text) {
- int countLines = 1;
- for (int i = 0; i < text.length(); i++) {
- if (text.charAt(i) == '\n') {
- countLines++;
+ ISourceRange nameRange = method.getNameRange();
+ if (nameRange != null) {
+ marker.setAttribute(CHAR_START, nameRange.getOffset());
+ marker.setAttribute(CHAR_END, nameRange.getOffset() + nameRange.getLength());
}
}
- return countLines;
}
}
View
3  unused.methods/test/unused/methods/core/AllPdeTests.java
@@ -5,7 +5,8 @@
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
-@SuiteClasses({ FindUnusedMethodsInJavaProjectPdeTest.class, FindUnusedContructorsPdeTest.class })
+@SuiteClasses({ FindUnusedMethodsInJavaProjectPdeTest.class, FindUnusedContructorsPdeTest.class,
+ LineNumbersPdeTest.class })
// TODO test Markers
public class AllPdeTests {
View
41 unused.methods/test/unused/methods/core/LineNumbersPdeTest.java
@@ -0,0 +1,41 @@
+package unused.methods.core;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.SourceRange;
+import org.junit.Test;
+
+public class LineNumbersPdeTest extends PdeTestCaseWithTestProject {
+
+ @Test
+ public void findUnusedMethodsInProject() throws CoreException, IOException {
+ List<IMethod> unusedMethods = calculateUnusedMethods();
+
+ IMethod lonelyMethod = findMethodByName(unusedMethods, "lonelyMethod");
+ assertThat(lonelyMethod.getNameRange(), is((ISourceRange) new SourceRange(128, 12)));
+
+ IMethod lonelyStaticMethod = findMethodByName(unusedMethods, "lonelyStaticMethod");
+ assertThat(lonelyStaticMethod.getNameRange(), is((ISourceRange) new SourceRange(182, 18)));
+ }
+
+ private IMethod findMethodByName(List<IMethod> unusedMethods, String name) {
+ for (IMethod method : unusedMethods) {
+ if (name.equals(method.getElementName())) {
+ return method;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ protected String[] getTestFiles() {
+ return new String[] { "/test/Movie.java", "/test/Actor.java" };
+ }
+}
View
2  unused.methods/test/unused/methods/core/PdeTestCaseWithTestProject.java
@@ -13,8 +13,6 @@
import org.junit.Before;
import org.junit.Rule;
-import unused.methods.core.FindUnusedMethodsInJavaProjects;
-
/**
* Do not use classes from jdt in example code as no jre or classpath is set up
* in test project!!!

No commit comments for this range

Something went wrong with that request. Please try again.