aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/EclipseAST.java
diff options
context:
space:
mode:
authorReinier Zwitserloot <reinier@zwitserloot.com>2013-03-11 21:01:28 +0100
committerReinier Zwitserloot <reinier@zwitserloot.com>2013-12-15 18:48:11 +0100
commit324022b71903ae5a9a61e9e9a3d7eb92d3d9d96c (patch)
tree4cd7a9aacac31dcf4dd788f0665b6bd04948e04a /src/core/lombok/eclipse/EclipseAST.java
parent7d51842ca381c491d5dfb44bc76b0cea345e7170 (diff)
downloadlombok-324022b71903ae5a9a61e9e9a3d7eb92d3d9d96c.tar.gz
lombok-324022b71903ae5a9a61e9e9a3d7eb92d3d9d96c.tar.bz2
lombok-324022b71903ae5a9a61e9e9a3d7eb92d3d9d96c.zip
work in progress on ProjectSearcher.
Diffstat (limited to 'src/core/lombok/eclipse/EclipseAST.java')
-rw-r--r--src/core/lombok/eclipse/EclipseAST.java29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/core/lombok/eclipse/EclipseAST.java b/src/core/lombok/eclipse/EclipseAST.java
index 370b40fc..0f04f749 100644
--- a/src/core/lombok/eclipse/EclipseAST.java
+++ b/src/core/lombok/eclipse/EclipseAST.java
@@ -28,6 +28,8 @@ import org.eclipse.jdt.internal.compiler.CompilationResult;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import lombok.Lombok;
import lombok.core.AST;
@@ -45,6 +47,9 @@ import org.eclipse.jdt.internal.compiler.ast.Initializer;
import org.eclipse.jdt.internal.compiler.ast.LocalDeclaration;
import org.eclipse.jdt.internal.compiler.ast.Statement;
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
+import org.eclipse.jdt.internal.core.BasicCompilationUnit;
+import org.eclipse.jdt.internal.core.JavaElement;
+import org.eclipse.jdt.internal.core.JavaProject;
/**
* Wraps around Eclipse's internal AST view to add useful features as well as the ability to visit parents from children,
@@ -177,6 +182,30 @@ public class EclipseAST extends AST<EclipseAST, EclipseNode, ASTNode> {
return ast.compilationResult.fileName == null ? null : new String(ast.compilationResult.fileName);
}
+ private static final Pattern PROJECT_NAME_FROM_FILEPATH = Pattern.compile("^/([^/]+)/(.*)$");
+ /**
+ * Returns the JavaProject object (eclipse's abstraction of the project) associated with the source file that is represented by this AST.
+ */
+ public JavaProject getProject() {
+ CompilationUnitDeclaration cud = (CompilationUnitDeclaration) top().get();
+
+ if (cud.compilationResult().getCompilationUnit() instanceof JavaElement) {
+ JavaElement icu = (JavaElement) cud.compilationResult.compilationUnit;
+ return (JavaProject) icu.getJavaProject();
+ }
+
+ char[] fn = cud.compilationResult().getFileName();
+
+ Matcher m = PROJECT_NAME_FROM_FILEPATH.matcher(new String(fn));
+ if (m.matches()) {
+ String projName = m.group(1);
+ String path = m.group(2);
+ return EclipseProjectSearcher.getProject(projName);
+ }
+
+ return null;
+ }
+
/**
* Call this method to move an EclipseAST generated for a diet parse to rebuild itself for the full parse -
* with filled in method bodies and such. Also propagates problems and errors, which in diet parse