Author: dazarov
Date: 2012-01-11 13:28:31 -0500 (Wed, 11 Jan 2012)
New Revision: 37774
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNameMarkerResolution.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/ChangeAnnotationMarkerResolution.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java
Log:
Quick fix for "Injection point other than injected field must not declare a @Named
annotation that does not specify the value member [JSR-299 ?\194?\1673.11]" error
marker
https://issues.jboss.org/browse/JBIDE-7638
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-11
17:07:12 UTC (rev 37773)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDICoreValidator.java 2012-01-11
18:28:31 UTC (rev 37774)
@@ -1554,7 +1554,7 @@
if (named != null) {
boolean valueExists = named.getMemberValue(null) != null;
if (!valueExists) {
- addError(CDIValidationMessages.PARAM_INJECTION_DECLARES_EMPTY_NAME,
CDIPreferences.PARAM_INJECTION_DECLARES_EMPTY_NAME, named, initializer.getResource());
+ addError(CDIValidationMessages.PARAM_INJECTION_DECLARES_EMPTY_NAME,
CDIPreferences.PARAM_INJECTION_DECLARES_EMPTY_NAME, named, initializer.getResource(),
PARAM_INJECTION_DECLARES_EMPTY_NAME_ID);
}
}
@@ -1594,7 +1594,8 @@
addError(CDIValidationMessages.PARAM_INJECTION_DECLARES_EMPTY_NAME,
CDIPreferences.PARAM_INJECTION_DECLARES_EMPTY_NAME,
named,
- injection.getResource());
+ injection.getResource(),
+ PARAM_INJECTION_DECLARES_EMPTY_NAME_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-11
17:07:12 UTC (rev 37773)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.core/src/org/jboss/tools/cdi/internal/core/validation/CDIValidationErrorManager.java 2012-01-11
18:28:31 UTC (rev 37774)
@@ -69,6 +69,7 @@
public static final int UNKNOWN_INTERCEPTOR_CLASS_NAME_ID = 48;
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;
/*
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-11
17:07:12 UTC (rev 37773)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.java 2012-01-11
18:28:31 UTC (rev 37774)
@@ -113,6 +113,7 @@
public static String CREATE_STEREOTYPE_TITLE;
public static String CREATE_INTERCEPTOR_TITLE;
public static String CREATE_DECORATOR_TITLE;
+ public static String ADD_NAME_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-11
17:07:12 UTC (rev 37773)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2012-01-11
18:28:31 UTC (rev 37774)
@@ -77,26 +77,27 @@
MESSAGE_BEAN_SHOULD_BE_SERIALIZABLE=Bean with selected scope should implement
java.io.Serializable.
-MAKE_FIELD_STATIC_MARKER_RESOLUTION_TITLE=Make ''{0}'' field static
-MAKE_METHOD_PUBLIC_MARKER_RESOLUTION_TITLE=Make ''{0}'' method public
-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
-MAKE_INJECTED_POINT_UNAMBIGUOUS_TITLE=Specify ''{0}'' bean for injection
to the injection point
+MAKE_FIELD_STATIC_MARKER_RESOLUTION_TITLE=Make field ''{0}'' static
+MAKE_METHOD_PUBLIC_MARKER_RESOLUTION_TITLE=Make method ''{0}'' public
+MAKE_METHOD_BUSINESS_MARKER_RESOLUTION_TITLE=Add method ''{0}'' to
interface ''{1}''
+ADD_LOCAL_BEAN_MARKER_RESOLUTION_TITLE=Add @LocalBean annotation to class
''{0}''
+DELETE_ALL_DISPOSER_DUPLICANT_MARKER_RESOLUTION_TITLE=Delete annotations @Disposes from
all methods except method ''{0}''
+DELETE_ALL_INJECTED_CONSTRUCTORS_MARKER_RESOLUTION_TITLE=Delete annotations @Inject from
all constructors except constructor ''{0}''
+MAKE_INJECTED_POINT_UNAMBIGUOUS_TITLE=Specify bean ''{0}'' for injection
to the injection point
SELECT_BEAN_TITLE=Select bean to configure the injection point
-ADD_SERIALIZABLE_INTERFACE_MARKER_RESOLUTION_TITLE=Add java.io.Serializable interface to
''{0}'' class
-MAKE_BEAN_SCOPED_DEPENDENT_MARKER_RESOLUTION_TITLE=Make ''{0}'' bean
scoped @Dependent
-MAKE_FIELD_PROTECTED_MARKER_RESOLUTION_TITLE=Make ''{0}'' field
protected
-ADD_RETENTION_MARKER_RESOLUTION_TITLE=Add @Retention(RUNTIME) annotation to
''{0}'' class
-ADD_TARGET_MARKER_RESOLUTION_TITLE=Add @Target({0}) annotation to ''{1}''
class
-ADD_ANNOTATION_MARKER_RESOLUTION_TITLE=Add @{0} annotation to ''{1}''
{2}
-DELETE_ANNOTATION_MARKER_RESOLUTION_TITLE=Delete @{0} annotation from
''{1}'' {2}
-CHANGE_ANNOTATION_MARKER_RESOLUTION_TITLE=Change ''{0}'' annotation to
{1}
-CREATE_BEAN_CLASS_TITLE=Create ''{0}'' CDI Bean Class
-CREATE_STEREOTYPE_TITLE=Create ''{0}'' CDI Stereotype
-CREATE_INTERCEPTOR_TITLE=Create ''{0}'' CDI Interceptor
-CREATE_DECORATOR_TITLE=Create ''{0}'' CDI Decorator
+ADD_SERIALIZABLE_INTERFACE_MARKER_RESOLUTION_TITLE=Add java.io.Serializable interface to
class ''{0}''
+MAKE_BEAN_SCOPED_DEPENDENT_MARKER_RESOLUTION_TITLE=Make bean ''{0}''
scoped @Dependent
+MAKE_FIELD_PROTECTED_MARKER_RESOLUTION_TITLE=Make field ''{0}''
protected
+ADD_RETENTION_MARKER_RESOLUTION_TITLE=Add annotation @Retention(RUNTIME) to class
''{0}''
+ADD_TARGET_MARKER_RESOLUTION_TITLE=Add annotation @Target({0}) to class
''{1}''
+ADD_ANNOTATION_MARKER_RESOLUTION_TITLE=Add annotation @{0} to {2} ''{1}''
+DELETE_ANNOTATION_MARKER_RESOLUTION_TITLE=Delete annotation @{0} from {2}
''{1}''
+CHANGE_ANNOTATION_MARKER_RESOLUTION_TITLE=Change annotation ''{0}'' to
{1}
+CREATE_BEAN_CLASS_TITLE=Create CDI Bean Class ''{0}''
+CREATE_STEREOTYPE_TITLE=Create CDI Stereotype ''{0}''
+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
CDI_QUICK_FIXES_ANNOTATION=annotation
CDI_QUICK_FIXES_INTERFACE=interface
Added:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNameMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNameMarkerResolution.java
(rev 0)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNameMarkerResolution.java 2012-01-11
18:28:31 UTC (rev 37774)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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 org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.graphics.Image;
+import org.jboss.tools.cdi.core.CDIImages;
+import org.jboss.tools.cdi.ui.CDIUIMessages;
+
+public class AddNameMarkerResolution extends ChangeAnnotationMarkerResolution {
+ private String parameter;
+
+ public AddNameMarkerResolution(IAnnotation annotation, String parameter) {
+ super(annotation, "\""+parameter+"\"");
+ this.parameter = parameter;
+ }
+
+ @Override
+ public String getLabel() {
+ return NLS.bind(CDIUIMessages.ADD_NAME_MARKER_RESOLUTION_TITLE, parameter);
+ }
+
+ @Override
+ public String getDescription() {
+ return NLS.bind(CDIUIMessages.ADD_NAME_MARKER_RESOLUTION_TITLE, parameter);
+ }
+
+ @Override
+ public Image getImage() {
+ return CDIImages.QUICKFIX_ADD;
+ }
+}
Property changes on:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/AddNameMarkerResolution.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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-11
17:07:12 UTC (rev 37773)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/CDIProblemMarkerResolutionGenerator.java 2012-01-11
18:28:31 UTC (rev 37774)
@@ -483,6 +483,16 @@
};
}
}
+ }else if(messageId ==
CDIValidationErrorManager.PARAM_INJECTION_DECLARES_EMPTY_NAME_ID){
+ ILocalVariable parameter = findParameter(file, start);
+ if(parameter != null){
+ IAnnotation namedAnnotation = getAnnotation(parameter,
CDIConstants.NAMED_QUALIFIER_TYPE_NAME);
+ if(namedAnnotation != null){
+ return new IMarkerResolution[] {
+ new AddNameMarkerResolution(namedAnnotation, parameter.getElementName())
+ };
+ }
+ }
}
}else if (XML_EXTENSION.equals(file.getFileExtension())){
FileEditorInput input = new FileEditorInput(file);
@@ -798,6 +808,22 @@
}
+ private ILocalVariable findParameter(IFile file, int start){
+ IJavaElement element = findJavaElement(file, start);
+ if(element instanceof IMethod){
+ try {
+ for(ILocalVariable parameter : ((IMethod) element).getParameters()){
+ if(parameter.getSourceRange().getOffset() <= start &&
parameter.getSourceRange().getOffset()+parameter.getSourceRange().getLength() >
start){
+ return parameter;
+ }
+ }
+ } catch (JavaModelException ex) {
+ CDIUIPlugin.getDefault().logError(ex);
+ }
+ }
+ return null;
+ }
+
private List<IType> findLocalAnnotattedInterfaces(IMethod method) throws
JavaModelException{
ArrayList<IType> types = new ArrayList<IType>();
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java 2012-01-11
17:07:12 UTC (rev 37773)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/ChangeAnnotationMarkerResolution.java 2012-01-11
18:28:31 UTC (rev 37774)
@@ -23,7 +23,6 @@
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.ui.IMarkerResolution2;
-import org.jboss.tools.cdi.core.CDIConstants;
import org.jboss.tools.cdi.core.CDIImages;
import org.jboss.tools.cdi.internal.core.refactoring.CDIMarkerResolutionUtils;
import org.jboss.tools.cdi.ui.CDIUIMessages;
@@ -33,8 +32,8 @@
IMarkerResolution2 {
private IAnnotation annotation;
- private String sourceString = "";
- private String changeString = CDIMarkerResolutionUtils.AT;
+ protected String sourceString = "";
+ protected String changeString = CDIMarkerResolutionUtils.AT;
private boolean useBraces = true;
private String[] qualifiedNames = new String[0];
@@ -93,7 +92,6 @@
MultiTextEdit edit = new MultiTextEdit();
change.setEdit(edit);
- CDIMarkerResolutionUtils.addImport(CDIConstants.TARGET_ANNOTATION_TYPE_NAME,
compilationUnit, edit);
for(String qualifiedName : qualifiedNames){
CDIMarkerResolutionUtils.addImport(qualifiedName, compilationUnit, true, edit);
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java 2012-01-11
17:07:12 UTC (rev 37773)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/refactoring/MarkerResolutionUtils.java 2012-01-11
18:28:31 UTC (rev 37774)
@@ -134,7 +134,7 @@
}
public static boolean addImport(String qualifiedName, ICompilationUnit compilationUnit,
boolean staticFlag, MultiTextEdit rootEdit) throws JavaModelException{
- if(primitives.contains(qualifiedName))
+ if(primitives.contains(qualifiedName) || qualifiedName.indexOf(DOT) < 0)
return false;
if(qualifiedName != null){
@@ -143,20 +143,18 @@
IPackageDeclaration[] packages = compilationUnit.getPackageDeclarations();
// local classes do not need to be imported
- if(qualifiedName.indexOf(DOT) >= 0){
- String typePackage = qualifiedName.substring(0,qualifiedName.lastIndexOf(DOT));
-
- for(IPackageDeclaration packageDeclaration : packages){
- if(packageDeclaration.getElementName().equals(typePackage))
- return false;
- }
-
- for(IPackageDeclaration packageDeclaration : packages){
- IType type =
compilationUnit.getJavaProject().findType(packageDeclaration.getElementName()+DOT+shortName);
- if(type != null && type.exists())
- return true;
- }
+ String typePackage = qualifiedName.substring(0,qualifiedName.lastIndexOf(DOT));
+
+ for(IPackageDeclaration packageDeclaration : packages){
+ if(packageDeclaration.getElementName().equals(typePackage))
+ return false;
}
+
+ for(IPackageDeclaration packageDeclaration : packages){
+ IType type =
compilationUnit.getJavaProject().findType(packageDeclaration.getElementName()+DOT+shortName);
+ if(type != null && type.exists())
+ return true;
+ }
IImportDeclaration[] importDeclarations = compilationUnit.getImports();