Author: dazarov
Date: 2010-12-17 10:06:47 -0500 (Fri, 17 Dec 2010)
New Revision: 27590
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsMarkerResolution.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsProcessor.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionRefactoringProcessor.java
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/Goose_Broken.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerAnnotationsProcessor.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerDuplicantMarkerResolution.java
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java
Log:
https://issues.jboss.org/browse/JBIDE-7675
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-12-17
15:05:26 UTC (rev 27589)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2010-12-17
15:06:47 UTC (rev 27590)
@@ -739,7 +739,7 @@
*/
if(injects.size()>1) {
for (IAnnotationDeclaration inject : injects) {
- addError(CDIValidationMessages.MULTIPLE_INJECTION_CONSTRUCTORS,
CDIPreferences.MULTIPLE_INJECTION_CONSTRUCTORS, inject, bean.getResource());
+ addError(CDIValidationMessages.MULTIPLE_INJECTION_CONSTRUCTORS,
CDIPreferences.MULTIPLE_INJECTION_CONSTRUCTORS, inject, bean.getResource(),
MULTIPLE_INJECTION_CONSTRUCTORS_ID);
}
}
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java 2010-12-17
15:05:26 UTC (rev 27589)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java 2010-12-17
15:06:47 UTC (rev 27590)
@@ -23,6 +23,7 @@
public static final int ILLEGAL_DISPOSER_IN_SESSION_BEAN_ID = 3;
public static final int ILLEGAL_OBSERVER_IN_SESSION_BEAN_ID = 4;
public static final int MULTIPLE_DISPOSERS_FOR_PRODUCER_ID = 5;
+ public static final int MULTIPLE_INJECTION_CONSTRUCTORS_ID = 6;
/*
* (non-Javadoc)
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-17
15:05:26 UTC (rev 27589)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2010-12-17
15:06:47 UTC (rev 27590)
@@ -83,6 +83,7 @@
public static String MAKE_METHOD_BUSINESS_MARKER_RESOLUTION_TITLE;
public static String ADD_LOCAL_BEAN_MARKER_RESOLUTION_TITLE;
public static String DELETE_ALL_DISPOSER_DUPLICANT_MARKER_RESOLUTION_TITLE;
+ public static String DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE;
public static String CDI_GENERATE_BEANS_XML;
public static String CDI_INSTALL_WIZARD_PAGE_FACET;
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-17
15:05:26 UTC (rev 27589)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2010-12-17
15:06:47 UTC (rev 27590)
@@ -67,6 +67,7 @@
MAKE_METHOD_BUSINESS_MARKER_RESOLUTION_TITLE=Add ''{0}'' method to
''{1}'' interface
ADD_LOCAL_BEAN_MARKER_RESOLUTION_TITLE=Add @LocalBean annotation to
''{0}'' class
DELETE_ALL_DISPOSER_DUPLICANT_MARKER_RESOLUTION_TITLE=Delete @Disposes annotations from
all methods except ''{0}'' method
+DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE=Delete @Inject annotations from
all constructors except ''{0}'' constructor
CDI_GENERATE_BEANS_XML=Generate beans.xml file:
CDI_INSTALL_WIZARD_PAGE_FACET=Context and Dependency Injection (CDI) Facet
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2010-12-17
15:05:26 UTC (rev 27589)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2010-12-17
15:06:47 UTC (rev 27590)
@@ -100,6 +100,13 @@
new DeleteAllDisposerDuplicantMarkerResolution(method, file)
};
}
+ }else if (messageId == CDIValidationErrorManager.MULTIPLE_INJECTION_CONSTRUCTORS_ID)
{
+ IMethod method = findMethod(file, start);
+ if(method != null){
+ return new IMarkerResolution[] {
+ new DeleteAllInjectedConstructorsMarkerResolution(method, file)
+ };
+ }
}
}
return new IMarkerResolution[] {};
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerAnnotationsProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerAnnotationsProcessor.java 2010-12-17
15:05:26 UTC (rev 27589)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerAnnotationsProcessor.java 2010-12-17
15:06:47 UTC (rev 27590)
@@ -10,79 +10,36 @@
******************************************************************************/
package org.jboss.tools.cdi.ui.marker;
-import java.text.MessageFormat;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.jdt.core.IMethod;
-import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.CompositeChange;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
import org.eclipse.ltk.core.refactoring.TextFileChange;
import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
-import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
-import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
-import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
-import org.eclipse.ltk.internal.core.refactoring.Messages;
import org.eclipse.text.edits.MultiTextEdit;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
import org.jboss.tools.cdi.core.CDIConstants;
-import org.jboss.tools.cdi.core.CDICoreMessages;
-import org.jboss.tools.cdi.core.CDICoreNature;
-import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.CDIUtil;
-import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IBeanMethod;
-import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IClassBean;
import org.jboss.tools.cdi.core.IProducer;
import org.jboss.tools.cdi.core.IProducerMethod;
-import org.jboss.tools.cdi.ui.CDIUIMessages;
import org.jboss.tools.common.text.ITextSourceReference;
-public class DeleteAllDisposerAnnotationsProcessor extends RefactoringProcessor {
- protected static final RefactoringParticipant[] EMPTY_REF_PARTICIPANT = new
RefactoringParticipant[0];
- private IFile file;
- private IMethod method;
- private RefactoringStatus status;
-
- private CompositeChange rootChange;
- private TextFileChange change;
- private IClassBean bean;
+public class DeleteAllDisposerAnnotationsProcessor extends
MarkerResolutionRefactoringProcessor {
- public DeleteAllDisposerAnnotationsProcessor(IFile file, IMethod method){
- this.file = file;
- this.method = method;
+ public DeleteAllDisposerAnnotationsProcessor(IFile file, IMethod method, String label){
+ super(file, method, label);
}
- private IClassBean findClassBean(){
- CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), true);
- if(cdiNature == null)
- return null;
-
- ICDIProject cdiProject = cdiNature.getDelegate();
-
- if(cdiProject == null)
- return null;
-
- Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
-
- for(IBean bean : beans){
- if(bean instanceof IClassBean)
- return (IClassBean)bean;
- }
-
- return null;
- }
-
private void changeDisposers(IClassBean bean) {
Set<IBeanMethod> disposers = bean.getDisposers();
if (disposers.isEmpty()) {
@@ -96,14 +53,12 @@
IProducerMethod producerMethod = (IProducerMethod) producer;
Set<IBeanMethod> disposerMethods =
producer.getCDIProject().resolveDisposers(producerMethod);
boundDisposers.addAll(disposerMethods);
- if (disposerMethods.size() > 1) {
- for (IBeanMethod disposerMethod : disposerMethods) {
- if(!disposerMethod.getMethod().isSimilar(method)){
- Set<ITextSourceReference> disposerDeclarations =
CDIUtil.getAnnotationPossitions(disposerMethod,
CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
- for (ITextSourceReference declaration : disposerDeclarations) {
- TextEdit edit = new ReplaceEdit(declaration.getStartPosition(),
declaration.getLength(), "");
- change.addEdit(edit);
- }
+ for (IBeanMethod disposerMethod : disposerMethods) {
+ if(!disposerMethod.getMethod().isSimilar(method)){
+ Set<ITextSourceReference> disposerDeclarations =
CDIUtil.getAnnotationPossitions(disposerMethod,
CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME);
+ for (ITextSourceReference declaration : disposerDeclarations) {
+ TextEdit edit = new ReplaceEdit(declaration.getStartPosition(),
declaration.getLength(), "");
+ change.addEdit(edit);
}
}
}
@@ -111,59 +66,12 @@
}
}
- private boolean isFileCorrect(IFile file){
- if(!file.isSynchronized(IResource.DEPTH_ZERO)){
- status.addFatalError(Messages.format(CDICoreMessages.CDI_RENAME_PROCESSOR_OUT_OF_SYNC_FILE,
file.getFullPath().toString()));
- return false;
- }else if(file.isPhantom()){
- status.addFatalError(Messages.format(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_PHANTOM_FILE,
file.getFullPath().toString()));
- return false;
- }else if(file.isReadOnly()){
- status.addFatalError(Messages.format(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE,
file.getFullPath().toString()));
- return false;
- }
- return true;
- }
-
@Override
- public Object[] getElements() {
- return null;
- }
-
- @Override
- public String getIdentifier() {
- return "";
- }
-
- @Override
- public String getProcessorName() {
- return
MessageFormat.format(CDIUIMessages.DELETE_ALL_DISPOSER_DUPLICANT_MARKER_RESOLUTION_TITLE,
new Object[]{method.getElementName()});
- }
-
- @Override
- public boolean isApplicable() throws CoreException {
- return true;
- }
-
- @Override
- public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
- throws CoreException, OperationCanceledException {
- status = new RefactoringStatus();
-
- if(isFileCorrect(file)){
- bean = findClassBean();
- }else
- status.addFatalError("CDI Bean Class not found");
-
- return status;
- }
-
- @Override
public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
CheckConditionsContext context) throws CoreException,
OperationCanceledException {
- rootChange = new
CompositeChange(MessageFormat.format(CDIUIMessages.DELETE_ALL_DISPOSER_DUPLICANT_MARKER_RESOLUTION_TITLE,
new Object[]{method.getElementName()}));
+ rootChange = new CompositeChange(label);
change = new TextFileChange(file.getName(), file);
MultiTextEdit root = new MultiTextEdit();
change.setEdit(root);
@@ -175,16 +83,4 @@
return status;
}
- @Override
- public Change createChange(IProgressMonitor pm) throws CoreException,
- OperationCanceledException {
- return rootChange;
- }
-
- @Override
- public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
- SharableParticipants sharedParticipants) throws CoreException {
- return EMPTY_REF_PARTICIPANT;
- }
-
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerDuplicantMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerDuplicantMarkerResolution.java 2010-12-17
15:05:26 UTC (rev 27589)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllDisposerDuplicantMarkerResolution.java 2010-12-17
15:06:47 UTC (rev 27590)
@@ -45,7 +45,7 @@
public void run(IMarker marker) {
- DeleteAllDisposerAnnotationsProcessor processor = new
DeleteAllDisposerAnnotationsProcessor(file, method);
+ DeleteAllDisposerAnnotationsProcessor processor = new
DeleteAllDisposerAnnotationsProcessor(file, method, label);
ProcessorBasedRefactoring refactoring = new ProcessorBasedRefactoring(processor);
DeletePreviewWizard wizard = new DeletePreviewWizard(refactoring,
RefactoringWizard.WIZARD_BASED_USER_INTERFACE);
RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
@@ -60,7 +60,7 @@
}
public RefactoringProcessor getRefactoringProcessor(){
- return new DeleteAllDisposerAnnotationsProcessor(file, method);
+ return new DeleteAllDisposerAnnotationsProcessor(file, method, label);
}
public String getDescription() {
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsMarkerResolution.java 2010-12-17
15:06:47 UTC (rev 27590)
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.ui.marker;
+
+import java.text.MessageFormat;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IMarker;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.Signature;
+import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;
+import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizard;
+import org.eclipse.ltk.ui.refactoring.RefactoringWizardOpenOperation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IMarkerResolution2;
+import org.eclipse.ui.internal.Workbench;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+
+/**
+ * @author Daniel Azarov
+ */
+public class DeleteAllInjectedConstructorsMarkerResolution implements IMarkerResolution2,
TestableResolutionWithRefactoringProcessor {
+ private String label;
+ private IMethod method;
+ private IFile file;
+
+ public DeleteAllInjectedConstructorsMarkerResolution(IMethod method, IFile file){
+ StringBuffer buffer = new StringBuffer();
+ buffer.append(method.getElementName()+"(");
+ String[] types = method.getParameterTypes();
+ for(int i = 0; i < types.length; i++){
+ if(i > 0)
+ buffer.append(", ");
+ buffer.append(Signature.getSignatureSimpleName(types[i]));
+ }
+ buffer.append(")");
+ this.label =
MessageFormat.format(CDIUIMessages.DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE,
new Object[]{buffer.toString()});
+ this.method = method;
+ this.file = file;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+
+ public void run(IMarker marker) {
+ DeleteAllInjectedConstructorsProcessor processor = new
DeleteAllInjectedConstructorsProcessor(file, method, label);
+ ProcessorBasedRefactoring refactoring = new ProcessorBasedRefactoring(processor);
+ DeletePreviewWizard wizard = new DeletePreviewWizard(refactoring,
RefactoringWizard.WIZARD_BASED_USER_INTERFACE);
+ RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
+ Shell shell = Workbench.getInstance().getActiveWorkbenchWindow().getShell();
+ try {
+ String titleForFailedChecks = CDIUIMessages.CDI_REFACTOR_CONTRIBUTOR_ERROR;
+ op.run(shell, titleForFailedChecks);
+ } catch (final InterruptedException irex) {
+ // operation was canceled
+ }
+
+ }
+
+ public RefactoringProcessor getRefactoringProcessor(){
+ return new DeleteAllInjectedConstructorsProcessor(file, method, label);
+ }
+
+ public String getDescription() {
+ return null;
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsMarkerResolution.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsProcessor.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsProcessor.java 2010-12-17
15:06:47 UTC (rev 27590)
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.ui.marker;
+
+import java.text.MessageFormat;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.text.edits.MultiTextEdit;
+import org.eclipse.text.edits.ReplaceEdit;
+import org.eclipse.text.edits.TextEdit;
+import org.jboss.tools.cdi.core.CDIConstants;
+import org.jboss.tools.cdi.core.IAnnotationDeclaration;
+import org.jboss.tools.cdi.core.IBeanMethod;
+import org.jboss.tools.cdi.core.IClassBean;
+
+public class DeleteAllInjectedConstructorsProcessor extends
MarkerResolutionRefactoringProcessor {
+
+
+ public DeleteAllInjectedConstructorsProcessor(IFile file, IMethod method, String
label){
+ super(file, method, label);
+ }
+
+ private void changeConstructors(IClassBean bean) {
+ Set<IBeanMethod> constructors = bean.getBeanConstructors();
+ if(constructors.size()>1) {
+ Set<IAnnotationDeclaration> injects = new
HashSet<IAnnotationDeclaration>();
+ for (IBeanMethod constructor : constructors) {
+ if(!constructor.getMethod().isSimilar(method)){
+ IAnnotationDeclaration inject =
constructor.getAnnotation(CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
+ if(inject!=null) {
+ injects.add(inject);
+ }
+ }
+ }
+ for (IAnnotationDeclaration inject : injects) {
+ TextEdit edit = new ReplaceEdit(inject.getStartPosition(), inject.getLength(),
"");
+ change.addEdit(edit);
+ }
+ }
+ }
+
+
+ @Override
+ public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
+ CheckConditionsContext context) throws CoreException,
+ OperationCanceledException {
+
+ rootChange = new CompositeChange(label);
+ change = new TextFileChange(file.getName(), file);
+ MultiTextEdit root = new MultiTextEdit();
+ change.setEdit(root);
+ rootChange.add(change);
+
+ if(bean != null)
+ changeConstructors(bean);
+
+ return status;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionRefactoringProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionRefactoringProcessor.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionRefactoringProcessor.java 2010-12-17
15:06:47 UTC (rev 27590)
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.cdi.ui.marker;
+
+import java.util.Set;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.TextFileChange;
+import org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant;
+import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
+import org.eclipse.ltk.core.refactoring.participants.SharableParticipants;
+import org.eclipse.ltk.internal.core.refactoring.Messages;
+import org.jboss.tools.cdi.core.CDICoreMessages;
+import org.jboss.tools.cdi.core.CDICoreNature;
+import org.jboss.tools.cdi.core.CDICorePlugin;
+import org.jboss.tools.cdi.core.IBean;
+import org.jboss.tools.cdi.core.ICDIProject;
+import org.jboss.tools.cdi.core.IClassBean;
+
+public abstract class MarkerResolutionRefactoringProcessor extends RefactoringProcessor
{
+ protected static final RefactoringParticipant[] EMPTY_REF_PARTICIPANT = new
RefactoringParticipant[0];
+ protected IFile file;
+ protected IMethod method;
+ protected RefactoringStatus status;
+ protected String label;
+
+ protected CompositeChange rootChange;
+ protected TextFileChange change;
+ protected IClassBean bean;
+
+
+ public MarkerResolutionRefactoringProcessor(IFile file, IMethod method, String label){
+ this.file = file;
+ this.method = method;
+ this.label = label;
+ }
+
+ private IClassBean findClassBean(){
+ CDICoreNature cdiNature = CDICorePlugin.getCDI(file.getProject(), true);
+ if(cdiNature == null)
+ return null;
+
+ ICDIProject cdiProject = cdiNature.getDelegate();
+
+ if(cdiProject == null)
+ return null;
+
+ Set<IBean> beans = cdiProject.getBeans(file.getFullPath());
+
+ for(IBean bean : beans){
+ if(bean instanceof IClassBean)
+ return (IClassBean)bean;
+ }
+
+ return null;
+ }
+
+
+ private boolean isFileCorrect(IFile file){
+ if(!file.isSynchronized(IResource.DEPTH_ZERO)){
+ status.addFatalError(Messages.format(CDICoreMessages.CDI_RENAME_PROCESSOR_OUT_OF_SYNC_FILE,
file.getFullPath().toString()));
+ return false;
+ }else if(file.isPhantom()){
+ status.addFatalError(Messages.format(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_PHANTOM_FILE,
file.getFullPath().toString()));
+ return false;
+ }else if(file.isReadOnly()){
+ status.addFatalError(Messages.format(CDICoreMessages.CDI_RENAME_PROCESSOR_ERROR_READ_ONLY_FILE,
file.getFullPath().toString()));
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public Object[] getElements() {
+ return null;
+ }
+
+ @Override
+ public String getIdentifier() {
+ return "";
+ }
+
+ @Override
+ public String getProcessorName() {
+ return label;
+ }
+
+ @Override
+ public boolean isApplicable() throws CoreException {
+ return true;
+ }
+
+ @Override
+ public RefactoringStatus checkInitialConditions(IProgressMonitor pm)
+ throws CoreException, OperationCanceledException {
+ status = new RefactoringStatus();
+
+ if(isFileCorrect(file)){
+ bean = findClassBean();
+ }else
+ status.addFatalError("CDI Bean Class not found");
+
+ return status;
+ }
+
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+ return rootChange;
+ }
+
+ @Override
+ public RefactoringParticipant[] loadParticipants(RefactoringStatus status,
+ SharableParticipants sharedParticipants) throws CoreException {
+ return EMPTY_REF_PARTICIPANT;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionRefactoringProcessor.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/Goose_Broken.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/Goose_Broken.java
(rev 0)
+++
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/Goose_Broken.java 2010-12-17
15:06:47 UTC (rev 27590)
@@ -0,0 +1,19 @@
+package org.jboss.jsr299.tck.tests.jbt.quickfixes;
+
+import javax.inject.Inject;
+
+class Goose_Broken
+{
+
+ @Inject
+ public Goose_Broken(String foo)
+ {
+ }
+
+ @Inject
+ public Goose_Broken(String foo, Double bar)
+ {
+
+ }
+
+}
Property changes on:
trunk/cdi/tests/org.jboss.tools.cdi.core.test/resources/tck/tests/jbt/quickfixes/Goose_Broken.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java
===================================================================
---
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java 2010-12-17
15:05:26 UTC (rev 27589)
+++
trunk/cdi/tests/org.jboss.tools.cdi.ui.test/src/org/jboss/tools/cdi/ui/test/marker/CDIMarkerResolutionTest.java 2010-12-17
15:06:47 UTC (rev 27590)
@@ -31,6 +31,7 @@
import org.jboss.tools.cdi.internal.core.validation.CDIValidationErrorManager;
import org.jboss.tools.cdi.ui.marker.AddLocalBeanMarkerResolution;
import org.jboss.tools.cdi.ui.marker.DeleteAllDisposerDuplicantMarkerResolution;
+import org.jboss.tools.cdi.ui.marker.DeleteAllInjectedConstructorsMarkerResolution;
import org.jboss.tools.cdi.ui.marker.MakeFieldStaticMarkerResolution;
import org.jboss.tools.cdi.ui.marker.MakeMethodBusinessMarkerResolution;
import org.jboss.tools.cdi.ui.marker.MakeMethodPublicMarkerResolution;
@@ -352,4 +353,18 @@
DeleteAllDisposerDuplicantMarkerResolution.class);
}
+ public void testDeleteAllInjectedConstructorsResolution() throws CoreException {
+ checkResolution(tckProject,
+ new String[]{
+ "JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/Goose_Broken.java"
+ },
+// new String[]{
+// "JavaSource/org/jboss/jsr299/tck/tests/jbt/quickfixes/Goose_Broken.qfxresult"
+// },
+ MARKER_TYPE,
+ CDIValidationErrorManager.MESSAGE_ID_ATTRIBUTE_NAME,
+ CDIValidationErrorManager.MULTIPLE_INJECTION_CONSTRUCTORS_ID,
+ DeleteAllInjectedConstructorsMarkerResolution.class);
+ }
+
}