[jbosstools-commits] JBoss Tools SVN: r42125 - trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Wed Jun 20 19:09:21 EDT 2012
Author: scabanovich
Date: 2012-06-20 19:09:21 -0400 (Wed, 20 Jun 2012)
New Revision: 42125
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProjectAsYouType.java
Log:
JBIDE-10611
https://issues.jboss.org/browse/JBIDE-10611
CDI Model for as-you-type with modified file is improved to find injected beans correctly - copy is created with modified set of all beans.
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2012-06-20 23:06:12 UTC (rev 42124)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProject.java 2012-06-20 23:09:21 UTC (rev 42125)
@@ -82,8 +82,9 @@
* @author Viacheslav Kabanovich
*
*/
-public class CDIProject extends CDIElement implements ICDIProject {
+public class CDIProject extends CDIElement implements ICDIProject, Cloneable {
CDICoreNature n;
+ private ICDIProject declaringProject = this;
private Map<String, StereotypeElement> stereotypes = new HashMap<String, StereotypeElement>();
private Map<IPath, StereotypeElement> stereotypesByPath = new HashMap<IPath, StereotypeElement>();
@@ -114,6 +115,25 @@
public CDIProject() {}
+ public CDIProject getModifiedCopy(IFile file, Set<IBean> beans) {
+ CDIProject p = null;
+ try {
+ p = (CDIProject)clone();
+ } catch (CloneNotSupportedException e) {
+ e.printStackTrace();
+ return null;
+ }
+ p.declaringProject = this;
+ p.allBeans = new HashSet<IBean>();
+ synchronized(this) {
+ p.allBeans.addAll(allBeans);
+ }
+ p.allBeans.removeAll(getBeans(file.getFullPath()));
+ p.allBeans.addAll(beans);
+
+ return p;
+ }
+
@Override
public CDICoreNature getNature() {
return n;
@@ -316,7 +336,7 @@
* @see org.jboss.tools.cdi.core.IBeanManager#getBeans(boolean, org.jboss.tools.cdi.core.IInjectionPoint)
*/
public Set<IBean> getBeans(boolean attemptToResolveAmbiguousDependency, IInjectionPoint injectionPoint) {
- if(injectionPoint.getDeclaringProject() != this) {
+ if(injectionPoint.getDeclaringProject() != getDeclaringProject()) {
return injectionPoint.getDeclaringProject().getBeans(attemptToResolveAmbiguousDependency, injectionPoint);
}
Set<IBean> result = new HashSet<IBean>();
@@ -1028,7 +1048,7 @@
@Override
public ICDIProject getDeclaringProject() {
- return this;
+ return declaringProject;
}
@Override
Modified: trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProjectAsYouType.java
===================================================================
--- trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProjectAsYouType.java 2012-06-20 23:06:12 UTC (rev 42124)
+++ trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/impl/CDIProjectAsYouType.java 2012-06-20 23:09:21 UTC (rev 42125)
@@ -25,6 +25,18 @@
import org.eclipse.jdt.core.IMember;
import org.eclipse.jdt.core.IPackageDeclaration;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
+import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
+import org.eclipse.jdt.ui.IWorkingCopyManager;
+import org.eclipse.jdt.ui.JavaUI;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorReference;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IBean;
@@ -49,6 +61,7 @@
import org.jboss.tools.cdi.internal.core.scanner.CDIBuilderDelegate;
import org.jboss.tools.cdi.internal.core.scanner.FileSet;
import org.jboss.tools.cdi.internal.core.scanner.ImplementationCollector;
+import org.jboss.tools.common.CommonPlugin;
import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.common.java.IJavaReference;
import org.jboss.tools.common.java.IParametedType;
@@ -77,13 +90,17 @@
} catch (CoreException e) {
CDICorePlugin.getDefault().logError(e);
}
+ CDIProject p = ((CDIProject)project).getModifiedCopy(file, beans);
+ if(p != null) {
+ this.project = p;
+ }
}
private void build() throws CoreException {
DefinitionContext context = project.getNature().getDefinitions().getCleanCopy();
FileSet fileSet = new FileSet();
if(file.getName().endsWith(".java")) {
- ICompilationUnit unit = EclipseUtil.getCompilationUnit(file);
+ ICompilationUnit unit = findCompilationUnit();// EclipseUtil.getCompilationUnit(file);
if(unit!=null) {
if(file.getName().equals("package-info.java")) {
IPackageDeclaration[] pkg = unit.getPackageDeclarations();
@@ -112,6 +129,48 @@
}
+ private ICompilationUnit findCompilationUnit() {
+ IWorkbench workbench = CommonPlugin.getDefault().getWorkbench();
+ if(workbench != null) {
+ IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
+ for (IWorkbenchWindow window: windows) {
+ if(window.getShell() != null) {
+ IWorkbenchPage[] pages = window.getPages();
+ for (IWorkbenchPage page: pages) {
+ IEditorReference[] rs = page.getEditorReferences();
+ for (IEditorReference r: rs) {
+ IEditorPart part = r.getEditor(false);
+ if(part != null) {
+ IFile file = getFile(part);
+ if(file != null && file.equals(this.file) && part instanceof CompilationUnitEditor) {
+ IWorkingCopyManager manager= JavaUI.getWorkingCopyManager();
+ ICompilationUnit unit= manager.getWorkingCopy(part.getEditorInput());
+ if(unit != null) {
+ try {
+ unit.reconcile(ICompilationUnit.NO_AST,
+ false /* don't force problem detection */,
+ null /* use primary owner */,
+ null /* no progress monitor */);
+ } catch (JavaModelException e) {
+ CDICorePlugin.getDefault().logError(e);
+ }
+ return unit;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ private IFile getFile(IEditorPart part) {
+ IEditorInput input = part.getEditorInput();
+ return (input instanceof IFileEditorInput) ? ((IFileEditorInput)input).getFile() : null;
+ }
+
synchronized void rebuildAnnotationTypes(List<AnnotationDefinition> ds) {
for (AnnotationDefinition d: ds) {
if(d.getResource() == null || !d.getResource().getFullPath().equals(file.getFullPath())) {
@@ -183,7 +242,7 @@
if(!typeDefinition.isVetoed()
//Type is defined in another project and modified/replaced in config in this (dependent) project
//We should reject type definition based on type, but we have to accept
- && (/*!vetoedTypes.contains(typeName) &&*/ getNature().getDefinitions().getTypeDefinition(typeName) == null && typeDefinition.getOriginalDefinition() == null)) {
+ && !(/*vetoedTypes.contains(typeName)*/false && getNature().getDefinitions().getTypeDefinition(typeName) == null && typeDefinition.getOriginalDefinition() == null)) {
if(typeDefinition.hasBeanConstructor()) {
beans.add(bean);
newClassBeans.put(typeDefinition.getType(), bean);
More information about the jbosstools-commits
mailing list