Author: dazarov
Date: 2011-11-29 14:49:41 -0500 (Tue, 29 Nov 2011)
New Revision: 36744
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/refactoring/CDIRefactoringProcessor.java
Log:
Quickfix and Wizard for fixing ambigious injection warning is confusing
https://issues.jboss.org/browse/JBIDE-9940
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-11-29
19:19:22 UTC (rev 36743)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/marker/MarkerResolutionUtils.java 2011-11-29
19:49:41 UTC (rev 36744)
@@ -177,7 +177,8 @@
}else{
String text =
compilationUnit.findRecommendedLineSeparator()+IMPORT+SPACE+qualifiedName+SEMICOLON;
if(!isDuplicate(rootEdit, text)){
- TextEdit edit = new
InsertEdit(compilationUnit.getImportContainer().getSourceRange().getOffset()+compilationUnit.getImportContainer().getSourceRange().getLength(),
text);
+ int importPosition = findPositionForImport(compilationUnit);
+ TextEdit edit = new InsertEdit(importPosition, text);
rootEdit.addChild(edit);
}
}
@@ -185,6 +186,23 @@
return false;
}
+
+ private static int findPositionForImport(ICompilationUnit compilationUnit) throws
JavaModelException{
+ if(compilationUnit.getImportContainer().exists()){
+ return
compilationUnit.getImportContainer().getSourceRange().getOffset()+compilationUnit.getImportContainer().getSourceRange().getLength();
+ }else{
+ IPackageDeclaration[] packageDeclarations = compilationUnit.getPackageDeclarations();
+ if(packageDeclarations.length == 0){
+ return 0;
+ }
+ int position = 0;
+ for(IPackageDeclaration declaration : packageDeclarations){
+ position =
declaration.getSourceRange().getOffset()+declaration.getSourceRange().getLength();
+ }
+ return position;
+ }
+ }
+
private static boolean isDuplicate(MultiTextEdit rootEdit, String text){
for(TextEdit edit : rootEdit.getChildren()){
if(edit instanceof InsertEdit && ((InsertEdit) edit).getText().equals(text))
Modified:
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactoringProcessor.java
===================================================================
---
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactoringProcessor.java 2011-11-29
19:19:22 UTC (rev 36743)
+++
trunk/cdi/plugins/org.jboss.tools.cdi.ui/src/org/jboss/tools/cdi/ui/refactoring/CDIRefactoringProcessor.java 2011-11-29
19:49:41 UTC (rev 36744)
@@ -33,8 +33,6 @@
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.wst.sse.ui.StructuredTextEditor;
import org.jboss.tools.cdi.core.CDICoreMessages;
import org.jboss.tools.cdi.core.CDICoreNature;
import org.jboss.tools.cdi.core.CDICorePlugin;
@@ -42,7 +40,6 @@
import org.jboss.tools.cdi.core.ICDIProject;
import org.jboss.tools.cdi.core.IClassBean;
import org.jboss.tools.cdi.ui.CDIUIPlugin;
-import org.jboss.tools.common.text.ext.IMultiPageEditor;
public abstract class CDIRefactoringProcessor extends RefactoringProcessor {
protected static final RefactoringParticipant[] EMPTY_REF_PARTICIPANT = new
RefactoringParticipant[0];
@@ -186,7 +183,9 @@
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IEditorPart editor = getEditor(getFile());
- editor.doSave(new NullProgressMonitor());
+ if(editor != null){
+ editor.doSave(new NullProgressMonitor());
+ }
}
});