Author: dazarov
Date: 2012-01-16 17:45:32 -0500 (Mon, 16 Jan 2012)
New Revision: 37882
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteOtherAnnotationsFromParametersProcessor.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllOtherAnnotationsFromParametersMarkerResolution.java
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteAllDisposerAnnotationsProcessor.java
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteAllInjectedConstructorsProcessor.java
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/DeleteAllInjectedConstructorsMarkerResolution.java
Log:
Quick fix for "Method has more than one parameter annotated @Disposes/@Observes
https://issues.jboss.org/browse/JBIDE-7670
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteAllDisposerAnnotationsProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteAllDisposerAnnotationsProcessor.java 2012-01-16
21:10:16 UTC (rev 37881)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteAllDisposerAnnotationsProcessor.java 2012-01-16
22:45:32 UTC (rev 37882)
@@ -56,11 +56,6 @@
for (IBeanMethod disposerMethod : disposerMethods) {
if(!disposerMethod.getMethod().isSimilar(method)){
CDIMarkerResolutionUtils.deleteAnnotation(CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME,
compilationUnit, disposerMethod.getMethod().getParameters()[0],
(MultiTextEdit)change.getEdit());
-// 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);
-// }
}
}
compilationUnit.discardWorkingCopy();
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteAllInjectedConstructorsProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteAllInjectedConstructorsProcessor.java 2012-01-16
21:10:16 UTC (rev 37881)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteAllInjectedConstructorsProcessor.java 2012-01-16
22:45:32 UTC (rev 37882)
@@ -38,23 +38,14 @@
private void changeConstructors(IClassBean bean) throws JavaModelException {
Set<IBeanMethod> constructors = bean.getBeanConstructors();
if(constructors.size()>1) {
- //Set<IAnnotationDeclaration> injects = new
HashSet<IAnnotationDeclaration>();
ICompilationUnit original =
constructors.iterator().next().getMethod().getCompilationUnit();
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
for (IBeanMethod constructor : constructors) {
if(!constructor.getMethod().isSimilar(method)){
CDIMarkerResolutionUtils.deleteAnnotation(CDIConstants.INJECT_ANNOTATION_TYPE_NAME,
compilationUnit, constructor.getMethod(), (MultiTextEdit)change.getEdit());
- //IAnnotationDeclaration inject =
constructor.getAnnotation(CDIConstants.INJECT_ANNOTATION_TYPE_NAME);
- //if(inject!=null) {
- // injects.add(inject);
- //}
}
}
compilationUnit.discardWorkingCopy();
- //for (IAnnotationDeclaration inject : injects) {
- // TextEdit edit = new ReplaceEdit(inject.getStartPosition(), inject.getLength(),
"");
- // change.addEdit(edit);
- //}
}
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteOtherAnnotationsFromParametersProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteOtherAnnotationsFromParametersProcessor.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteOtherAnnotationsFromParametersProcessor.java 2012-01-16
22:45:32 UTC (rev 37882)
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.internal.core.refactoring;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.text.edits.MultiTextEdit;
+
+public class DeleteOtherAnnotationsFromParametersProcessor extends
CDIRefactoringProcessor {
+ private ILocalVariable parameter;
+ private String annotationName;
+
+ public DeleteOtherAnnotationsFromParametersProcessor(IFile file, String annotationName,
ILocalVariable parameter, String label){
+ super(file, label);
+ this.parameter = parameter;
+ this.annotationName = annotationName;
+ }
+
+ private void change() throws JavaModelException {
+ if(parameter.getParent() instanceof IMethod){
+ IMethod method = (IMethod)parameter.getParent();
+ ICompilationUnit original = method.getCompilationUnit();
+ ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
+ for (ILocalVariable param : method.getParameters()) {
+ if(!param.getTypeSignature().equals(parameter.getTypeSignature()) ||
!param.getElementName().equals(parameter.getElementName())){
+ CDIMarkerResolutionUtils.deleteAnnotation(annotationName, compilationUnit, param,
(MultiTextEdit)change.getEdit());
+ }
+ }
+ compilationUnit.discardWorkingCopy();
+ }
+ }
+
+ @Override
+ public RefactoringStatus checkFinalConditions(IProgressMonitor pm,
+ CheckConditionsContext context) throws CoreException,
+ OperationCanceledException {
+
+ createRootChange();
+
+ change();
+
+ return status;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/refactoring/DeleteOtherAnnotationsFromParametersProcessor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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 2012-01-16
21:10:16 UTC (rev 37881)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2012-01-16
22:45:32 UTC (rev 37882)
@@ -997,7 +997,7 @@
*/
if(declarations.size()>1) {
for (ITextSourceReference declaration : declarations) {
- addError(CDIValidationMessages.MULTIPLE_OBSERVING_PARAMETERS,
CDIPreferences.MULTIPLE_OBSERVING_PARAMETERS, declaration, bean.getResource());
+ addError(CDIValidationMessages.MULTIPLE_OBSERVING_PARAMETERS,
CDIPreferences.MULTIPLE_OBSERVING_PARAMETERS, declaration, bean.getResource(),
MULTIPLE_OBSERVING_PARAMETERS_ID);
}
}
/*
@@ -1086,7 +1086,7 @@
}
if (disposerDeclarations.size() > 1) {
for (ITextSourceReference declaration : disposerDeclarations) {
- addError(CDIValidationMessages.MULTIPLE_DISPOSING_PARAMETERS,
CDIPreferences.MULTIPLE_DISPOSING_PARAMETERS, declaration, bean.getResource());
+ addError(CDIValidationMessages.MULTIPLE_DISPOSING_PARAMETERS,
CDIPreferences.MULTIPLE_DISPOSING_PARAMETERS, declaration, bean.getResource(),
MULTIPLE_DISPOSING_PARAMETERS_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 2012-01-16
21:10:16 UTC (rev 37881)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java 2012-01-16
22:45:32 UTC (rev 37882)
@@ -70,6 +70,8 @@
public static final int ILLEGAL_DECORATOR_BEAN_CLASS_ID = 49;
public static final int ILLEGAL_INTERCEPTOR_CLASS_ID = 50;
public static final int PARAM_INJECTION_DECLARES_EMPTY_NAME_ID = 51;
+ public static final int MULTIPLE_DISPOSING_PARAMETERS_ID = 52;
+ public static final int MULTIPLE_OBSERVING_PARAMETERS_ID = 53;
/*
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 2012-01-16
21:10:16 UTC (rev 37881)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2012-01-16
22:45:32 UTC (rev 37882)
@@ -114,6 +114,7 @@
public static String CREATE_INTERCEPTOR_TITLE;
public static String CREATE_DECORATOR_TITLE;
public static String ADD_NAME_MARKER_RESOLUTION_TITLE;
+ public static String DELETE_ALL_OTHER_ANNOTATIONS_MARKER_RESOLUTION_TITLE;
public static String CDI_QUICK_FIXES_ANNOTATION;
public static String CDI_QUICK_FIXES_INTERFACE;
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 2012-01-16
21:10:16 UTC (rev 37881)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2012-01-16
22:45:32 UTC (rev 37882)
@@ -98,6 +98,7 @@
CREATE_INTERCEPTOR_TITLE=Create CDI Interceptor ''{0}''
CREATE_DECORATOR_TITLE=Create CDI Decorator ''{0}''
ADD_NAME_MARKER_RESOLUTION_TITLE=Add name ''{0}'' to annotation @Named
+DELETE_ALL_OTHER_ANNOTATIONS_MARKER_RESOLUTION_TITLE=Delete annotations {0} from all
parameters except parameter ''{1}''
CDI_QUICK_FIXES_ANNOTATION=annotation
CDI_QUICK_FIXES_INTERFACE=interface
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 2012-01-16
21:10:16 UTC (rev 37881)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2012-01-16
22:45:32 UTC (rev 37882)
@@ -486,6 +486,20 @@
}else if(messageId ==
CDIValidationErrorManager.PARAM_INJECTION_DECLARES_EMPTY_NAME_ID){
List<IMarkerResolution> resolutions = getAddNameResolutions(file, start);
return resolutions.toArray(new IMarkerResolution[]{});
+ }else if(messageId == CDIValidationErrorManager.MULTIPLE_DISPOSING_PARAMETERS_ID){
+ ILocalVariable parameter = findParameter(file, start);
+ if(parameter != null){
+ return new IMarkerResolution[] {
+ new
DeleteAllOtherAnnotationsFromParametersMarkerResolution(CDIConstants.DISPOSES_ANNOTATION_TYPE_NAME,
parameter, file)
+ };
+ }
+ }else if(messageId == CDIValidationErrorManager.MULTIPLE_OBSERVING_PARAMETERS_ID){
+ ILocalVariable parameter = findParameter(file, start);
+ if(parameter != null){
+ return new IMarkerResolution[] {
+ new
DeleteAllOtherAnnotationsFromParametersMarkerResolution(CDIConstants.OBSERVERS_ANNOTATION_TYPE_NAME,
parameter, file)
+ };
+ }
}
}else if (XML_EXTENSION.equals(file.getFileExtension())){
FileEditorInput input = new FileEditorInput(file);
Modified:
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 2012-01-16
21:10:16 UTC (rev 37881)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllInjectedConstructorsMarkerResolution.java 2012-01-16
22:45:32 UTC (rev 37882)
@@ -59,7 +59,6 @@
DeleteAllInjectedConstructorsProcessor processor = new
DeleteAllInjectedConstructorsProcessor(file, method, label);
ProcessorBasedRefactoring refactoring = new ProcessorBasedRefactoring(processor);
DeletePreviewWizard wizard = new DeletePreviewWizard(refactoring);
- //RefactoringWizardOpenOperation op = new RefactoringWizardOpenOperation(wizard);
wizard.showWizard();
}
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllOtherAnnotationsFromParametersMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllOtherAnnotationsFromParametersMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllOtherAnnotationsFromParametersMarkerResolution.java 2012-01-16
22:45:32 UTC (rev 37882)
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * 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.ILocalVariable;
+import org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring;
+import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.ui.IMarkerResolution2;
+import org.jboss.tools.cdi.core.CDIImages;
+import org.jboss.tools.cdi.internal.core.refactoring.CDIMarkerResolutionUtils;
+import
org.jboss.tools.cdi.internal.core.refactoring.DeleteOtherAnnotationsFromParametersProcessor;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+import org.jboss.tools.cdi.ui.wizard.DeletePreviewWizard;
+
+/**
+ * @author Daniel Azarov
+ */
+public class DeleteAllOtherAnnotationsFromParametersMarkerResolution implements
IMarkerResolution2, TestableResolutionWithRefactoringProcessor {
+ private String label;
+ private String annotationName;
+ private ILocalVariable parameter;
+ private IFile file;
+
+ public DeleteAllOtherAnnotationsFromParametersMarkerResolution(String annotationName,
ILocalVariable parameter, IFile file){
+ String shortName = CDIMarkerResolutionUtils.AT +
CDIMarkerResolutionUtils.getShortName(annotationName);
+ this.label =
MessageFormat.format(CDIUIMessages.DELETE_ALL_OTHER_ANNOTATIONS_MARKER_RESOLUTION_TITLE,
new Object[]{shortName, parameter.getElementName()});
+ this.annotationName = annotationName;
+ this.parameter = parameter;
+ this.file = file;
+ }
+
+ @Override
+ public String getLabel() {
+ return label;
+ }
+
+
+ @Override
+ public void run(IMarker marker) {
+ DeleteOtherAnnotationsFromParametersProcessor processor = new
DeleteOtherAnnotationsFromParametersProcessor(file, annotationName, parameter, label);
+ ProcessorBasedRefactoring refactoring = new ProcessorBasedRefactoring(processor);
+ DeletePreviewWizard wizard = new DeletePreviewWizard(refactoring);
+ wizard.showWizard();
+ }
+
+ @Override
+ public RefactoringProcessor getRefactoringProcessor(){
+ return new DeleteOtherAnnotationsFromParametersProcessor(file, annotationName,
parameter, label);
+ }
+
+ @Override
+ public String getDescription() {
+ return label;
+ }
+
+ @Override
+ public Image getImage() {
+ return CDIImages.QUICKFIX_REMOVE;
+ }
+
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/DeleteAllOtherAnnotationsFromParametersMarkerResolution.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain