Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsboyko2016-02-05 10:37:14 +0000
committersboyko2016-02-05 10:37:14 +0000
commit9110ad3aaaa03893626d14b07dad9428435dea79 (patch)
treea134253a093ca652ca12014b37ea52f6aee83cf5
parenta13f1f88a7bd2bb427facdff6c408a8c0ef48ad3 (diff)
downloadorg.eclipse.qvto-9110ad3aaaa03893626d14b07dad9428435dea79.tar.gz
org.eclipse.qvto-9110ad3aaaa03893626d14b07dad9428435dea79.tar.xz
org.eclipse.qvto-9110ad3aaaa03893626d14b07dad9428435dea79.zip
[474603] Resolve Java blackboxes in workspace
-rw-r--r--plugins/org.eclipse.m2m.qvt.oml.editor.ui/src/org/eclipse/m2m/internal/qvt/oml/editor/ui/completion/collectors/ImportModuleCollector.java2
-rw-r--r--plugins/org.eclipse.m2m.qvt.oml.editor.ui/src/org/eclipse/m2m/internal/qvt/oml/editor/ui/hyperlinks/QvtFileHyperlink.java2
-rw-r--r--plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/plugin.xml2
-rw-r--r--plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtBlackboxHelper.java76
-rw-r--r--plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtBlackboxProvider.java179
-rw-r--r--plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtModuleHandle.java37
7 files changed, 296 insertions, 4 deletions
diff --git a/plugins/org.eclipse.m2m.qvt.oml.editor.ui/src/org/eclipse/m2m/internal/qvt/oml/editor/ui/completion/collectors/ImportModuleCollector.java b/plugins/org.eclipse.m2m.qvt.oml.editor.ui/src/org/eclipse/m2m/internal/qvt/oml/editor/ui/completion/collectors/ImportModuleCollector.java
index 35b2171e1..5a7b21075 100644
--- a/plugins/org.eclipse.m2m.qvt.oml.editor.ui/src/org/eclipse/m2m/internal/qvt/oml/editor/ui/completion/collectors/ImportModuleCollector.java
+++ b/plugins/org.eclipse.m2m.qvt.oml.editor.ui/src/org/eclipse/m2m/internal/qvt/oml/editor/ui/completion/collectors/ImportModuleCollector.java
@@ -22,7 +22,6 @@ import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.m2m.internal.qvt.oml.blackbox.AbstractCompilationUnitDescriptor;
import org.eclipse.m2m.internal.qvt.oml.blackbox.BlackboxRegistry;
import org.eclipse.m2m.internal.qvt.oml.blackbox.ResolutionContextImpl;
-import org.eclipse.m2m.internal.qvt.oml.blackbox.java.jdt.JdtBlackboxHelper;
import org.eclipse.m2m.internal.qvt.oml.common.project.DeployedTransformation;
import org.eclipse.m2m.internal.qvt.oml.compiler.UnitProvider;
import org.eclipse.m2m.internal.qvt.oml.compiler.UnitProxy;
@@ -33,6 +32,7 @@ import org.eclipse.m2m.internal.qvt.oml.editor.ui.completion.CompletionProposalU
import org.eclipse.m2m.internal.qvt.oml.editor.ui.completion.QvtCompletionData;
import org.eclipse.m2m.internal.qvt.oml.editor.ui.completion.QvtCompletionProposal;
import org.eclipse.m2m.internal.qvt.oml.emf.util.URIUtils;
+import org.eclipse.m2m.internal.qvt.oml.runtime.jdt.blackbox.JdtBlackboxHelper;
import org.eclipse.m2m.internal.qvt.oml.runtime.project.QvtTransformationRegistry;
import lpg.runtime.IToken;
diff --git a/plugins/org.eclipse.m2m.qvt.oml.editor.ui/src/org/eclipse/m2m/internal/qvt/oml/editor/ui/hyperlinks/QvtFileHyperlink.java b/plugins/org.eclipse.m2m.qvt.oml.editor.ui/src/org/eclipse/m2m/internal/qvt/oml/editor/ui/hyperlinks/QvtFileHyperlink.java
index 60a8c7bea..f7110b512 100644
--- a/plugins/org.eclipse.m2m.qvt.oml.editor.ui/src/org/eclipse/m2m/internal/qvt/oml/editor/ui/hyperlinks/QvtFileHyperlink.java
+++ b/plugins/org.eclipse.m2m.qvt.oml.editor.ui/src/org/eclipse/m2m/internal/qvt/oml/editor/ui/hyperlinks/QvtFileHyperlink.java
@@ -15,10 +15,10 @@ import org.eclipse.core.resources.IFile;
import org.eclipse.emf.common.util.URI;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.m2m.internal.qvt.oml.blackbox.java.jdt.JdtBlackboxHelper;
import org.eclipse.m2m.internal.qvt.oml.compiler.BlackboxUnitResolver;
import org.eclipse.m2m.internal.qvt.oml.editor.ui.QvtEditor;
import org.eclipse.m2m.internal.qvt.oml.emf.util.URIUtils;
+import org.eclipse.m2m.internal.qvt.oml.runtime.jdt.blackbox.JdtBlackboxHelper;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/META-INF/MANIFEST.MF b/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/META-INF/MANIFEST.MF
index 4cfcd22c9..576030bab 100644
--- a/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/META-INF/MANIFEST.MF
@@ -11,4 +11,4 @@ Require-Bundle: org.eclipse.m2m.qvt.oml;bundle-version="3.5.0",
org.eclipse.core.filesystem;bundle-version="1.5.0",
org.eclipse.jdt.ui;bundle-version="3.11.0",
org.eclipse.ui;bundle-version="3.107.0"
-Export-Package: org.eclipse.m2m.internal.qvt.oml.blackbox.java.jdt
+Export-Package: org.eclipse.m2m.internal.qvt.oml.runtime.jdt.blackbox
diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/plugin.xml b/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/plugin.xml
index 55bbe27ab..616a42946 100644
--- a/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/plugin.xml
+++ b/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/plugin.xml
@@ -5,7 +5,7 @@
name="JDT blackbox implementation provider"
point="org.eclipse.m2m.qvt.oml.blackboxProvider">
<provider
- class="org.eclipse.m2m.internal.qvt.oml.blackbox.java.jdt.JdtBlackboxProvider">
+ class="org.eclipse.m2m.internal.qvt.oml.runtime.jdt.blackbox.JdtBlackboxProvider">
</provider>
</extension>
diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtBlackboxHelper.java b/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtBlackboxHelper.java
new file mode 100644
index 000000000..dafd6a500
--- /dev/null
+++ b/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtBlackboxHelper.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Sergey Boyko 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:
+ * Sergey Boyko - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2m.internal.qvt.oml.runtime.jdt.blackbox;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.m2m.internal.qvt.oml.emf.util.URIUtils;
+import org.eclipse.ui.IEditorPart;
+
+public class JdtBlackboxHelper {
+
+ private JdtBlackboxHelper() {}
+
+ public static void navigateToJavaElement(java.net.URI scriptContext, String qualifiedName, String elementName) {
+ IResource resource = URIUtils.getResource(URI.createFileURI(scriptContext.getPath()));
+
+ if (resource == null || !resource.exists()) {
+ return;
+ }
+
+ List<IProject> projects = new ArrayList<IProject>();
+ projects.add(resource.getProject());
+ try {
+ projects.addAll(Arrays.asList(resource.getProject().getReferencedProjects()));
+ } catch (CoreException e) {
+ // ignore
+ }
+
+ for (IProject project : projects) {
+ IJavaProject javaProject = JavaCore.create(project);
+
+ try {
+ IType findType = javaProject.findType(qualifiedName);
+ if (findType != null) {
+ IEditorPart editorPart = JavaUI.openInEditor(findType);
+
+ if (elementName != null) {
+ for (IMethod m : findType.getMethods()) {
+ if (m.getElementName().equals(elementName)) {
+ JavaUI.revealInEditor(editorPart, m.getPrimaryElement());
+ }
+ }
+ }
+
+ return;
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ }
+
+ public static boolean isJdtUnitUri(URI uri) {
+ return JdtBlackboxProvider.URI_BLACKBOX_JDT_QUERY.equals(uri.query());
+ }
+
+}
diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtBlackboxProvider.java b/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtBlackboxProvider.java
new file mode 100644
index 000000000..dc5a2b002
--- /dev/null
+++ b/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtBlackboxProvider.java
@@ -0,0 +1,179 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Christopher Gerking 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:
+ * Christopher Gerking - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2m.internal.qvt.oml.runtime.jdt.blackbox;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceProxy;
+import org.eclipse.core.resources.IResourceProxyVisitor;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.m2m.internal.qvt.oml.QvtPlugin;
+import org.eclipse.m2m.internal.qvt.oml.blackbox.AbstractCompilationUnitDescriptor;
+import org.eclipse.m2m.internal.qvt.oml.blackbox.ResolutionContext;
+import org.eclipse.m2m.internal.qvt.oml.blackbox.java.JavaBlackboxProvider;
+import org.eclipse.m2m.internal.qvt.oml.emf.util.URIUtils;
+
+public class JdtBlackboxProvider extends JavaBlackboxProvider {
+
+ public static final String URI_BLACKBOX_JDT_QUERY = "jdt"; //$NON-NLS-1$
+
+ @Override
+ public Collection<? extends AbstractCompilationUnitDescriptor> getModuleDescriptors(ResolutionContext resolutionContext) {
+ IProject project = getProject(resolutionContext);
+ if (project == null) {
+ return Collections.emptyList();
+ }
+
+ List<IProject> projects = new ArrayList<IProject>();
+ projects.add(project);
+ try {
+ projects.addAll(Arrays.asList(project.getReferencedProjects()));
+ } catch (CoreException e) {
+ // ignore
+ }
+
+ List<AbstractCompilationUnitDescriptor> descriptors = new ArrayList<AbstractCompilationUnitDescriptor>();
+ for (IProject p : projects) {
+ final List<String> classes = getAllClasses(p);
+
+ for (String qualifiedName : classes) {
+ AbstractCompilationUnitDescriptor jdtUnitDescriptor = getJdtUnitDescriptor(p, qualifiedName);
+ if (jdtUnitDescriptor != null) {
+ descriptors.add(jdtUnitDescriptor);
+ }
+ }
+ }
+
+ return descriptors;
+ }
+
+ @Override
+ public AbstractCompilationUnitDescriptor getModuleDescriptor(String qualifiedName, ResolutionContext resolutionContext) {
+ IProject project = getProject(resolutionContext);
+ if (project == null) {
+ return null;
+ }
+
+ return getJdtUnitDescriptor(project, qualifiedName);
+ }
+
+ private AbstractCompilationUnitDescriptor getJdtUnitDescriptor(IProject project, String qualifiedName) {
+ URLClassLoader loader = null;
+ try {
+ final IJavaProject javaProject = JavaCore.create(project);
+ IPath projectRelativeOutputPath = javaProject.getOutputLocation().removeFirstSegments(1);
+
+ IPath outputPath = project.getLocation().append(projectRelativeOutputPath);
+ URL outputUrl = outputPath.addTrailingSeparator().toFile().toURI().toURL();
+
+ loader = new URLClassLoader(new URL[] { outputUrl }, this.getClass().getClassLoader());
+
+ Class<?> moduleJavaClass = loader.loadClass(qualifiedName);
+ return new JdtDescriptor(qualifiedName, moduleJavaClass) {
+ @Override
+ protected String getFragment() {
+ return javaProject.getElementName();
+ }
+ };
+
+ } catch (JavaModelException e) {
+ // ignore
+ } catch (MalformedURLException e) {
+ QvtPlugin.error(e);
+ } catch (ClassNotFoundException e) {
+ // ignore
+ } finally {
+ try {
+ if (loader != null) {
+ loader.close();
+ }
+ } catch (IOException e) {
+ QvtPlugin.error(e);
+ }
+ }
+
+ return null;
+ }
+
+ private IProject getProject(ResolutionContext resolutionContext) {
+ IResource resource = URIUtils.getResource(resolutionContext.getURI());
+
+ if (resource == null || !resource.exists()) {
+ return null;
+ }
+
+ return resource.getProject();
+ }
+
+ private List<String> getAllClasses(IProject project) {
+ final List<String> classes = new ArrayList<String>();
+
+ try {
+ IJavaProject javaProject = JavaCore.create(project);
+ IResource folder = ResourcesPlugin.getWorkspace().getRoot().findMember(javaProject.getOutputLocation());
+ final String folderPath = folder.getFullPath().toString();
+
+ folder.accept(new IResourceProxyVisitor() {
+
+ public boolean visit(IResourceProxy proxy) throws CoreException {
+ if (proxy.getType() == IResource.FOLDER) {
+ return true;
+ }
+ if (proxy.getType() == IResource.FILE) {
+ if (proxy.getName().endsWith(".class")) {
+ String filePath = proxy.requestFullPath().toString();
+ filePath = filePath.substring(0, filePath.length() - 6);
+ if (filePath.startsWith(folderPath)) {
+ filePath = filePath.substring(folderPath.length() + 1);
+ }
+ classes.add(filePath.replace('/', '.'));
+ }
+ }
+ return false;
+ }
+
+ }, IResource.NONE);
+ } catch (CoreException e) {
+ // ignore
+ }
+
+ return classes;
+ }
+
+ private class JdtDescriptor extends JavaBlackboxProvider.JavaUnitDescriptor {
+
+ public JdtDescriptor(String unitQualifiedName, Class<?> moduleJavaClass) {
+ super(unitQualifiedName);
+ addModuleHandle(new JdtModuleHandle(unitQualifiedName, moduleJavaClass));
+ }
+
+ @Override
+ protected String getUnitQuery() {
+ return URI_BLACKBOX_JDT_QUERY;
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtModuleHandle.java b/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtModuleHandle.java
new file mode 100644
index 000000000..ac5e9156c
--- /dev/null
+++ b/plugins/org.eclipse.m2m.qvt.oml.runtime.jdt/src/org/eclipse/m2m/internal/qvt/oml/runtime/jdt/blackbox/JdtModuleHandle.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Christopher Gerking 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:
+ * Christopher Gerking - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.m2m.internal.qvt.oml.runtime.jdt.blackbox;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.eclipse.m2m.internal.qvt.oml.blackbox.java.ModuleHandle;
+
+public class JdtModuleHandle extends ModuleHandle {
+
+ private final Class<?> moduleJavaClass;
+
+ JdtModuleHandle(String moduleName, Class<?> moduleJavaClass) {
+ super(moduleJavaClass.getName(), moduleName);
+ this.moduleJavaClass = moduleJavaClass;
+ }
+
+ @Override
+ public List<String> getUsedPackages() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public Class<?> getModuleJavaClass() throws ClassNotFoundException {
+ return moduleJavaClass;
+ }
+
+}

Back to the top