Author: dazarov
Date: 2010-10-29 08:55:18 -0400 (Fri, 29 Oct 2010)
New Revision: 26131
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddSetterMarkerResolution.java
Log:
https://jira.jboss.org/browse/JBIDE-6872
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java 2010-10-29
11:18:47 UTC (rev 26130)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AbstractSeamMarkerResolution.java 2010-10-29
12:55:18 UTC (rev 26131)
@@ -83,6 +83,7 @@
importDeclaration.delete(false, new NullProgressMonitor());
}
compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
}
}
}
@@ -169,6 +170,7 @@
buffer.replace(type.getSourceRange().getOffset(), 0,
annotationString+name+lineDelim);
compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
}
}catch(CoreException ex){
SeamGuiPlugin.getPluginLog().logError(ex);
@@ -200,13 +202,14 @@
buf.append("public void "+methodName+"() {"); //$NON-NLS-1$
//$NON-NLS-2$
buf.append(lineDelim);
buf.append("}"); //$NON-NLS-1$
- type.createMethod(buf.toString(), null, false, null);
+ type.createMethod(buf.toString(), null, false, new NullProgressMonitor());
}else{
IBuffer buffer = compilationUnit.getBuffer();
buffer.replace(oldMethod.getSourceRange().getOffset(), 0,
"@"+annotation+lineDelim);
}
compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
}
}catch(CoreException ex){
SeamGuiPlugin.getPluginLog().logError(ex);
@@ -223,7 +226,7 @@
if(type != null){
IAnnotation annotation = findAnnotation(type, type);
if(annotation != null){
- IImportDeclaration importDeclaration = compilationUnit.getImport(qualifiedName);
+ IImportDeclaration importDeclaration = compilationUnit.getImport(qualifiedName);
if(importDeclaration == null || !importDeclaration.exists())
compilationUnit.createImport(qualifiedName, null, new NullProgressMonitor());
if(importName != null){
@@ -241,6 +244,7 @@
buffer.replace(annotation.getSourceRange().getOffset(),
annotation.getSourceRange().getLength(), annotationString+name);
compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
}
}
}catch(CoreException ex){
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddSetterMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddSetterMarkerResolution.java 2010-10-29
11:18:47 UTC (rev 26130)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddSetterMarkerResolution.java 2010-10-29
12:55:18 UTC (rev 26131)
@@ -12,9 +12,11 @@
import java.text.MessageFormat;
+import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jdt.core.Flags;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IMethod;
@@ -22,6 +24,7 @@
import org.eclipse.jdt.internal.corext.codemanipulation.GetterSetterUtil;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IMarkerResolution2;
+import org.jboss.tools.common.EclipseUtil;
import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
import org.jboss.tools.seam.core.ISeamProperty;
import org.jboss.tools.seam.ui.SeamGuiPlugin;
@@ -47,47 +50,46 @@
}
public void run(IMarker marker) {
- IType type = (IType)javaDeclaration.getSourceMember();
+ IFile file = (IFile)javaDeclaration.getResource();
try{
- ICompilationUnit original = type.getCompilationUnit();
+ ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
- IType createdType = compilationUnit.getType(type.getElementName());
- final String lineDelim= compilationUnit.findRecommendedLineSeparator();
+ String lineDelim= compilationUnit.findRecommendedLineSeparator();
- IField field = createdType.getField(property.getName());
+ IType type = compilationUnit.findPrimaryType();
+
+ IField field = type.getField(property.getName());
+
String propertyType="";
if(field != null && field.exists()){
propertyType = field.getTypeSignature();
}else{
- propertyType = "String";
- field = createdType.createField(lineDelim+"private "+propertyType+"
"+property.getName()+";", null, false, null);
-// synchronized(compilationUnit) {
-// compilationUnit.reconcile(ICompilationUnit.NO_AST, false, null, null);
-// }
+ propertyType = "String"; //$NON-NLS-1$
+
+ StringBuffer buf= new StringBuffer();
+
+ buf.append("private "+propertyType+"
"+property.getName()+";"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ buf.append(lineDelim);
+
+ field = type.createField(buf.toString(), null, false, new NullProgressMonitor());
}
+
String setterName = GetterSetterUtil.getSetterName(field, null);
+ IMethod oldMethod = GetterSetterUtil.getSetter(field);
+ if(oldMethod == null || !oldMethod.exists()){
+ String stub = GetterSetterUtil.getSetterStub(field, setterName, true,
Flags.AccPublic);
+ type.createMethod(stub, null, false, new NullProgressMonitor());
+ }
- createMethod(createdType, propertyType, setterName, lineDelim);
-
- compilationUnit.commitWorkingCopy(true, new NullProgressMonitor());
+ compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
+ compilationUnit.discardWorkingCopy();
+
}catch(CoreException ex){
SeamGuiPlugin.getPluginLog().logError(ex);
}
}
- private IMethod createMethod(IType type, String typeName, String methodName, String
lineDelim) throws CoreException{
- StringBuffer buf= new StringBuffer();
-
- buf.append(lineDelim);
- buf.append("public void "+methodName+"("+typeName+"
"+property.getName()+") {"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
- buf.append(lineDelim);
- buf.append("this."+property.getName()+" =
"+property.getName()+";"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- buf.append(lineDelim);
- buf.append("}"); //$NON-NLS-1$
- return type.createMethod(buf.toString(), null, false, null);
- }
-
public String getDescription() {
return null;
}