Author: dazarov
Date: 2011-05-18 18:39:31 -0400 (Wed, 18 May 2011)
New Revision: 31360
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/marker/MarkerResolutionUtils.java
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/xpl/AddQualifiersToBeanComposite.java
Log:
https://issues.jboss.org/browse/JBIDE-8957
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 2011-05-18
19:45:26 UTC (rev 31359)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/CDIUIMessages.properties 2011-05-18
22:39:31 UTC (rev 31360)
@@ -104,7 +104,7 @@
ADD_QUALIFIERS_TO_BEAN_WIZARD_ADD_ALL=Add All >>
ADD_QUALIFIERS_TO_BEAN_WIZARD_REMOVE=< Remove
ADD_QUALIFIERS_TO_BEAN_WIZARD_REMOVE_ALL=<< Remove All
-ADD_QUALIFIERS_TO_BEAN_WIZARD_CREATE_NEW_QUALIFIER=Create New Qualifier
+ADD_QUALIFIERS_TO_BEAN_WIZARD_CREATE_NEW_QUALIFIER=Create New Qualifier...
ADD_QUALIFIERS_TO_BEAN_WIZARD_SET_IS_NOT_UNIQUE=This set of qualifiers is not unique
ADD_QUALIFIERS_TO_BEAN_WIZARD_ENTER_QUALIFIER_NAME=Enter CDI Qualifier name prefix or
pattern (? = any character, * = any string):
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java 2011-05-18
19:45:26 UTC (rev 31359)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java 2011-05-18
22:39:31 UTC (rev 31360)
@@ -280,14 +280,11 @@
IBuffer buffer = compilationUnit.getBuffer();
- MethodStructure ms = parseMethod(m, buffer.getContents());
- if(ms == null)
- return;
-
- for(Parameter parameter : ms.getParameters()){
- if(parameter.getName().equals(paramName)){
+ ILocalVariable[] parameters = m.getParameters();
+ for(int index = 0; index < parameters.length; index++){
+ if(parameters[index].getElementName().equals(paramName)){
StringBuffer b = new StringBuffer();
- if(parameter.getIndex() > 0)
+ if(index > 0)
b.append(SPACE);
for(IQualifier qualifier : qualifiers){
String qualifierName = qualifier.getSourceType().getFullyQualifiedName();
@@ -297,14 +294,14 @@
if(duplicant)
annotation = qualifierName;
if(qualifierName.equals(CDIConstants.NAMED_QUALIFIER_TYPE_NAME))
- b.append(AT+annotation+"(\""+parameter.getName()+"\")"+SPACE);
+ b.append(AT+annotation+"(\""+parameters[index].getElementName()+"\")"+SPACE);
else
b.append(AT+annotation+SPACE);
}
}
- b.append(parameter.getType()+SPACE);
- b.append(parameter.getName());
- buffer.replace(parameter.getOffset(), parameter.getLength(), b.toString());
+ b.append(Signature.getSignatureSimpleName(parameters[index].getTypeSignature())+SPACE);
+ b.append(parameters[index].getElementName());
+ buffer.replace(parameters[index].getSourceRange().getOffset(),
parameters[index].getSourceRange().getLength(), b.toString());
}
}
@@ -322,12 +319,9 @@
IBuffer buffer = compilationUnit.getBuffer();
- MethodStructure ms = parseMethod(method, buffer.getContents());
- if(ms == null)
- return null;
- for(Parameter parameter : ms.getParameters()){
- if(parameter.getName().equals(paramName)){
- return new SourceRange(parameter.getOffset(), parameter.getLength());
+ for(ILocalVariable parameter : method.getParameters()){
+ if(parameter.getElementName().equals(paramName)){
+ return new SourceRange(parameter.getSourceRange().getOffset(),
parameter.getSourceRange().getLength());
}
}
}catch(JavaModelException ex){
@@ -348,78 +342,7 @@
return null;
}
- static void getParams(IMethod method, MethodStructure ms, String paramsString, int
offset) throws JavaModelException{
- String[] types = method.getParameterTypes();
- String[] names = method.getParameterNames();
-
- int paramIndex = 0;
- int paramPosition = 0;
- int i = 0;
- int c1 = 0;
- int c2 = 0;
- char quote = '\0';
- StringBuffer sb = new StringBuffer();
- while(i < paramsString.length()) {
- char c = paramsString.charAt(i);
- if(c == ',' && c1 == 0 && c2 == 0 && quote ==
'\0') {
- if(sb.toString().trim().length() > 0) {
- String param = sb.toString();
- Parameter parameter = new Parameter(paramIndex,
Signature.getSignatureSimpleName(types[paramIndex]), names[paramIndex],
offset+paramPosition, param.length());
- paramIndex++;
- ms.addParameter(parameter);
- paramPosition = i+1;
- }
- sb.setLength(0);
- i++;
- continue;
- } else if(c == '(' && quote == '\0') {
- c1++;
- } else if(c == ')' && quote == '\0') {
- c1--;
- } else if(c == '<' && quote == '\0') {
- c2++;
- } else if(c == '>' && quote == '\0') {
- c2--;
- } else if((c == '\'' || c == '"') && quote ==
'\0') {
- quote = c;
- } else if(quote == c) {
- quote = '\0';
- }
- sb.append(c);
- i++;
- }
- if(sb.length() > 0) {
- String param = sb.toString();
- Parameter parameter = new Parameter(paramIndex,
Signature.getSignatureSimpleName(types[paramIndex]), names[paramIndex],
offset+paramPosition, param.length());
- paramIndex++;
- ms.addParameter(parameter);
- paramPosition = i+1;
- }
- }
-
- private static MethodStructure parseMethod(IMethod method, String text){
- try{
- MethodStructure ms = new MethodStructure();
- ISourceRange range = method.getSourceRange();
- ISourceRange nameRange = method.getNameRange();
- if(nameRange != null) range = nameRange;
- int paramStart = text.indexOf('(', range.getOffset());
- if(paramStart < 0) return null;
- int declEnd = text.indexOf('{', paramStart);
- if(declEnd < 0) return null;
- int paramEnd = text.lastIndexOf(')', declEnd);
- if(paramEnd < 0) return null;
- String paramsString = text.substring(paramStart + 1, paramEnd);
- getParams(method, ms, paramsString, paramStart+1);
-
- return ms;
- }catch(JavaModelException ex){
- CDIUIPlugin.getDefault().logError(ex);
- }
- return null;
- }
-
public static void addQualifiersToInjectedPoint(IInjectionPoint injectionPoint, IBean
bean){
try{
ICompilationUnit original =
injectionPoint.getClassBean().getBeanClass().getCompilationUnit();
@@ -527,52 +450,4 @@
}
return null;
}
-
- static class MethodStructure{
- List<Parameter> parameters = new ArrayList<Parameter>();
-
- public List<Parameter> getParameters(){
- return parameters;
- }
-
- public void addParameter(Parameter parameter){
- parameters.add(parameter);
- }
- }
-
- static class Parameter{
- String type;
- String name;
- int offset, length;
- int index;
-
- public Parameter(int index, String type, String name, int offset, int length){
- this.index = index;
- this.type = type;
- this.name = name;
- this.offset = offset;
- this.length = length;
- }
-
- public int getOffset(){
- return offset;
- }
-
- public int getLength(){
- return length;
- }
-
- public String getType(){
- return type;
- }
-
- public String getName(){
- return name;
- }
-
- public int getIndex(){
- return index;
- }
- }
-
}
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/xpl/AddQualifiersToBeanComposite.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/xpl/AddQualifiersToBeanComposite.java 2011-05-18
19:45:26 UTC (rev 31359)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/wizard/xpl/AddQualifiersToBeanComposite.java 2011-05-18
22:39:31 UTC (rev 31360)
@@ -12,6 +12,7 @@
*******************************************************************************/
package org.jboss.tools.cdi.ui.wizard.xpl;
+import java.lang.reflect.InvocationTargetException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashSet;
@@ -19,11 +20,13 @@
import java.util.Set;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.IDoubleClickListener;
@@ -61,6 +64,8 @@
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.SearchPattern;
+import org.jboss.tools.cdi.core.CDICoreMessages;
+import org.jboss.tools.cdi.core.CDICorePlugin;
import org.jboss.tools.cdi.core.IBean;
import org.jboss.tools.cdi.core.IInjectionPoint;
import org.jboss.tools.cdi.core.IQualifier;
@@ -99,6 +104,8 @@
private Label nLabel;
protected boolean isComplete = true;
+
+ private ILabelProvider labelProvider;
public AddQualifiersToBeanComposite(Composite parent, WizardPage wizard) {
super(parent, SWT.NONE);
@@ -120,13 +127,15 @@
qualifiers.clear();
loadAvailableQualifiers();
+ availableListViewer.setInput(qualifiers);
if(nLabel != null)
nLabel.setText(MessageFormat.format(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_MESSAGE,
new Object[]{bean.getBeanClass().getElementName()}));
refresh();
}
- private void loadAvailableQualifiers(){
+ private IQualifier loadAvailableQualifiers(){
+ IQualifier lastQualifier = null;
String beanTypeName = bean.getBeanClass().getFullyQualifiedName();
String beanPackage =
beanTypeName.substring(0,beanTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
@@ -136,10 +145,9 @@
boolean samePackage = beanPackage.equals(injectionPointPackage);
IQualifier[] qs = bean.getCDIProject().getQualifiers();
- qualifiers = new ArrayList<IQualifier>();
for(IQualifier q : qs){
- if(!originalQualifiers.contains(q)){
+ if(!contains(originalQualifiers, q) && !contains(qualifiers, q) &&
!contains(deployed, q)){
boolean isPublic = true;
try{
isPublic = Flags.isPublic(q.getSourceType().getFlags());
@@ -148,13 +156,24 @@
}
String qualifierTypeName = q.getSourceType().getFullyQualifiedName();
String qualifierPackage =
qualifierTypeName.substring(0,qualifierTypeName.lastIndexOf(MarkerResolutionUtils.DOT));
- if(isPublic || (samePackage &&
injectionPointPackage.equals(qualifierPackage)))
+ if((isPublic || (samePackage &&
injectionPointPackage.equals(qualifierPackage))) ){
qualifiers.add(q);
+ lastQualifier = q;
+ }
}
}
- availableListViewer.setInput(qualifiers);
-
+ return lastQualifier;
}
+
+ private boolean contains(ArrayList<IQualifier> qualifiers, IQualifier qualifier){
+ String qualifierText = labelProvider.getText(qualifier);
+ for(IQualifier q : qualifiers){
+ String qText = labelProvider.getText(q);
+ if(qText.equals(qualifierText))
+ return true;
+ }
+ return false;
+ }
public void setVisible(boolean visible) {
if (visible)
@@ -275,7 +294,7 @@
availableList.setLayoutData(data);
availableListViewer = new ListViewer(availableList);
- ILabelProvider labelProvider = new QualifiersListLabelProvider();
+ labelProvider = new QualifiersListLabelProvider();
availableListViewer.setLabelProvider(labelProvider);
IContentProvider contentProvider = new QualifiersListContentProvider();
availableListViewer.setContentProvider(contentProvider);
@@ -390,6 +409,13 @@
}
});
+ label = new Label(this, SWT.NONE);
+ label.setText("");
+
+ label = new Label(this, SWT.NONE);
+ label.setText("");
+
+
final Button createQualifier = new Button(this, SWT.PUSH);
createQualifier.setText(CDIUIMessages.ADD_QUALIFIERS_TO_BEAN_WIZARD_CREATE_NEW_QUALIFIER);
@@ -404,23 +430,40 @@
int status = dialog.open();
if(status == WizardDialog.OK){
// reload qualifiers
- try {
- Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
- } catch (InterruptedException e) {
- // do nothing
+ if (Display.getCurrent() != null) {
+ try{
+ PlatformUI.getWorkbench().getProgressService().busyCursorWhile(new
IRunnableWithProgress(){
+ public void run(IProgressMonitor monitor)
+ throws InvocationTargetException, InterruptedException {
+ monitor.beginTask(CDICoreMessages.CDI_UTIL_BUILD_CDI_MODEL, 10);
+ monitor.worked(3);
+
+ try {
+ Job.getJobManager().join(ResourcesPlugin.FAMILY_AUTO_BUILD, null);
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+
+ monitor.worked(7);
+ }
+ });
+ }catch(InterruptedException ie){
+ CDICorePlugin.getDefault().logError(ie);
+ }catch(InvocationTargetException ite){
+ CDICorePlugin.getDefault().logError(ite);
+ }
}
- qualifiers.clear();
+ IQualifier q = loadAvailableQualifiers();
- loadAvailableQualifiers();
-
- refresh();
+ if(q != null){
+ moveAll(new IQualifier[]{q}, true);
+ }
}
}
});
setEnablement();
- //availableList.setFocus();
Dialog.applyDialogFont(this);
}
@@ -456,7 +499,7 @@
for (int i = 0; i < ms.length; i++) {
IQualifier qualifier = ms[i];
if (qualifier != null) {
- if (qualifiers.contains(qualifier)) {
+ if (contains(qualifiers, qualifier)) {
enabled = true;
}else{
enabled = false;
@@ -475,7 +518,7 @@
boolean enabled = false;
for (int i = 0; i < ms.length; i++) {
IQualifier qualifier = ms[i];
- if (qualifier != null && deployed.contains(qualifier)) {
+ if (qualifier != null && contains(deployed, qualifier)) {
enabled = true;
}
else{
@@ -524,7 +567,7 @@
int size = mods.length;
ArrayList<IQualifier> list = new ArrayList<IQualifier>();
for (int i = 0; i < size; i++) {
- if (!list.contains(mods[i]))
+ if (!contains(list, mods[i]))
list.add(mods[i]);
}
@@ -553,7 +596,7 @@
Iterator iterator = originalQualifiers.iterator();
while (iterator.hasNext()) {
IQualifier qualifier = (IQualifier) iterator.next();
- if (!deployed.contains(qualifier))
+ if (!contains(deployed, qualifier))
list.add(qualifier);
}
return list;
@@ -564,7 +607,7 @@
Iterator iterator = deployed.iterator();
while (iterator.hasNext()) {
IQualifier qualifier = (IQualifier) iterator.next();
- if (!originalQualifiers.contains(qualifier))
+ if (!contains(originalQualifiers, qualifier))
list.add(qualifier);
}
return list;