mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-15 00:17:45 +00:00
work in progress on ProjectSearcher.
This commit is contained in:
1 parent
7d51842ca3
commit
324022b719
6 files changed
+177
No files matched your search
@@ -0,0 +1,14 @@
|
||||
<ivy-module version="2.0">
|
||||
<info organisation="org.eclipse.custom" module="core.jobs" revision="3.5.200" publication="20120521234600">
|
||||
<license name="Eclipse Public Licence v1.0" url="http://www.eclipse.org/org/documents/epl-v10.php" />
|
||||
<description homepage="http://www.eclipse.org/eclipse/" />
|
||||
</info>
|
||||
<configurations>
|
||||
<conf name="default" />
|
||||
<conf name="sources" />
|
||||
</configurations>
|
||||
<publications>
|
||||
<artifact conf="default" url="http://projectlombok.org/ivyrepo/eclipse/org.eclipse.core.jobs_3.5.200.v20120521-2346.jar" />
|
||||
<artifact type="zip" conf="sources" url="http://projectlombok.org/ivyrepo/eclipse/org.eclipse.core.jobs_3.5.200.v20120521-2346-sources.jar" />
|
||||
</publications>
|
||||
</ivy-module>
|
||||
@@ -0,0 +1,14 @@
|
||||
<ivy-module version="2.0">
|
||||
<info organisation="org.eclipse.custom" module="core.resources" revision="3.7.0" publication="20110510071200">
|
||||
<license name="Eclipse Public Licence v1.0" url="http://www.eclipse.org/org/documents/epl-v10.php" />
|
||||
<description homepage="http://www.eclipse.org/eclipse/" />
|
||||
</info>
|
||||
<configurations>
|
||||
<conf name="default" />
|
||||
<conf name="sources" />
|
||||
</configurations>
|
||||
<publications>
|
||||
<artifact conf="default" url="http://projectlombok.org/ivyrepo/eclipse/org.eclipse.core.resources_3.7.100.v20110510-0712.jar" />
|
||||
<artifact type="zip" conf="sources" url="http://projectlombok.org/ivyrepo/eclipse/org.eclipse.core.resources_3.7.100.v20110510-0712-sources.jar" />
|
||||
</publications>
|
||||
</ivy-module>
|
||||
@@ -41,9 +41,11 @@
|
||||
<dependency org="netbeans.org" name="modules.java.source" rev="6.8beta" conf="netbeansBuild->build" />
|
||||
|
||||
<dependency org="org.eclipse.custom" name="core.runtime" rev="3.6.0" conf="eclipseBuild->default; contrib->sources" />
|
||||
<dependency org="org.eclipse.custom" name="core.resources" rev="3.7.0" conf="eclipseBuild->default; contrib->sources" />
|
||||
<dependency org="org.eclipse.custom" name="jdt.core" rev="3.6.0" conf="eclipseBuild->default; contrib->sources" />
|
||||
<dependency org="org.eclipse.custom" name="jdt.ui" rev="3.6.0" conf="eclipseBuild->default; contrib->sources" />
|
||||
<dependency org="org.eclipse.custom" name="equinox.common" rev="3.6.0" conf="eclipseBuild->default; contrib->sources" />
|
||||
<dependency org="org.eclipse.custom" name="osgi" rev="3.6.0" conf="eclipseBuild->default; contrib->sources" />
|
||||
<dependency org="org.eclipse.custom" name="core.jobs" rev="3.5.200" conf="eclipseBuild->default; contrib->sources" />
|
||||
</dependencies>
|
||||
</ivy-module>
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package lombok.eclipse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.eclipse.core.internal.resources.Project;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jdt.core.IClasspathEntry;
|
||||
import org.eclipse.jdt.core.JavaCore;
|
||||
import org.eclipse.jdt.internal.core.ClasspathEntry;
|
||||
import org.eclipse.jdt.internal.core.JavaProject;
|
||||
|
||||
public class EclipseProjectSearcher {
|
||||
private final JavaProject project;
|
||||
|
||||
public EclipseProjectSearcher(JavaProject project) {
|
||||
this.project = project;
|
||||
}
|
||||
|
||||
private static final String[] ENTRY_KINDS = {"", "CPE_LIBRARY", "CPE_PROJECT", "CPE_SOURCE", "CPE_VARIABLE", "CPE_CONTAINER"};
|
||||
|
||||
|
||||
public static JavaProject getProject(String projectName) {
|
||||
Project depProjWrapper = (Project) ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
|
||||
if (depProjWrapper == null) return null;
|
||||
if (!JavaProject.hasJavaNature(depProjWrapper)) return null;
|
||||
return (JavaProject) JavaCore.create(depProjWrapper);
|
||||
}
|
||||
|
||||
public List<String> findAllWithName(String pathSpec) throws Exception {
|
||||
List<IPath> list = new ArrayList<IPath>();
|
||||
findAllWithName0(list, new HashSet<String>(), pathSpec, project, false);
|
||||
System.out.println("-------RESULTS [" + pathSpec + "]:");
|
||||
System.out.println(list);
|
||||
System.out.println("---------------");
|
||||
|
||||
for (IPath path : list) {
|
||||
try {
|
||||
System.out.println(path + ": " + ResourcesPlugin.getWorkspace().getRoot().getFile(path.append(pathSpec)).getLocationURI());
|
||||
} catch (Exception ignore) {
|
||||
try {
|
||||
System.out.println(path + ": " + ResourcesPlugin.getWorkspace().getRoot().getFolder(path.append(pathSpec)).getLocationURI());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
// Check if we got through (didn't double-exept out), and then check if the resulting file URI
|
||||
// actually exists.
|
||||
//
|
||||
// Then, check if 'path' itself is a jar, and if so, go root around in there.
|
||||
}
|
||||
|
||||
System.out.println("---------------");
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void findAllWithName0(List<IPath> list, Set<String> coveredProjectNames, String pathSpec, JavaProject proj, boolean exportedOnly) throws Exception {
|
||||
if (proj == null) return;
|
||||
// if (System.currentTimeMillis() > 0) return;
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
Research conclusions:
|
||||
|
||||
* Eclipse is CRAZY.
|
||||
* Take a path, for which you don't know if it's project relative or not (nor does eclipse!!! yes, crazy), append the resource you are looking for (whether you know if its a jar or a path),
|
||||
and ask eclipse if it exists as a file. If yes, you have your answer.
|
||||
* Then, check if the path is 1 or 0 long, in that case, there is no answer.
|
||||
* Then, check if the path itself is a file and if yes, try and open it as a zip. Possibly try appending exclamationmark-resource and ask eclipse, maybe it has jar-style handling built in.
|
||||
* Cache the heck out of this because this code is called after just about every keystroke.
|
||||
* We should probably do something about duplicate detection and collapse, maybe just grab the textual content of those IPaths (they sure as hell don't contain anything useful beyond that), and
|
||||
toss em in a set.
|
||||
|
||||
*/
|
||||
if (!coveredProjectNames.add(proj.getElementName())) return;
|
||||
|
||||
for (IClasspathEntry rawEntry : proj.getResolvedClasspath(true)) {
|
||||
ClasspathEntry entry = (ClasspathEntry) rawEntry;
|
||||
if (exportedOnly && !entry.isExported() && entry.entryKind != IClasspathEntry.CPE_SOURCE) continue;
|
||||
|
||||
switch (entry.entryKind) {
|
||||
case IClasspathEntry.CPE_PROJECT:
|
||||
String projName = entry.path.lastSegment();
|
||||
JavaProject depProj = getProject(projName);
|
||||
findAllWithName0(list, coveredProjectNames, pathSpec, depProj, true);
|
||||
break;
|
||||
case IClasspathEntry.CPE_SOURCE:
|
||||
list.add(entry.path);
|
||||
break;
|
||||
case IClasspathEntry.CPE_LIBRARY:
|
||||
list.add(entry.path);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Wot's this then? " + entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,11 +31,13 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Lombok;
|
||||
import lombok.core.AST.Kind;
|
||||
import lombok.core.AnnotationValues;
|
||||
import lombok.core.TransformationsUtil;
|
||||
import lombok.eclipse.EclipseAnnotationHandler;
|
||||
import lombok.eclipse.EclipseNode;
|
||||
import lombok.eclipse.EclipseProjectSearcher;
|
||||
import lombok.eclipse.handlers.EclipseHandlerUtil.FieldAccess;
|
||||
import lombok.experimental.Wither;
|
||||
|
||||
@@ -56,6 +58,7 @@ import org.eclipse.jdt.internal.compiler.ast.ThisReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
|
||||
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
|
||||
import org.eclipse.jdt.internal.core.JavaProject;
|
||||
import org.mangosdk.spi.ProviderFor;
|
||||
|
||||
@ProviderFor(EclipseAnnotationHandler.class)
|
||||
@@ -124,6 +127,18 @@ public class HandleWither extends EclipseAnnotationHandler<Wither> {
|
||||
AccessLevel level = annotation.getInstance().value();
|
||||
if (level == AccessLevel.NONE || node == null) return;
|
||||
|
||||
/** hackery */ {
|
||||
JavaProject project = annotationNode.getAst().getProject();
|
||||
if (project != null) try {
|
||||
new EclipseProjectSearcher(project).findAllWithName("/java/lang/String.class");
|
||||
} catch (Exception e) {
|
||||
throw Lombok.sneakyThrow(e);
|
||||
} else {
|
||||
Thread.dumpStack();
|
||||
System.err.println("****!!!!*!*!*!*!*!*!!*!********!!!! PROJECT IS NULL!!!!");
|
||||
}
|
||||
}
|
||||
|
||||
List<Annotation> onMethod = unboxAndRemoveAnnotationParameter(ast, "onMethod", "@Setter(onMethod=", annotationNode);
|
||||
List<Annotation> onParam = unboxAndRemoveAnnotationParameter(ast, "onParam", "@Setter(onParam=", annotationNode);
|
||||
|
||||
|
||||
Reference in new issue
Block a user