Author: dazarov
Date: 2010-11-01 10:34:45 -0400 (Mon, 01 Nov 2010)
New Revision: 26163
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/SeamProblemMarkerResolutionGenerator.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/AddSetterMarkerResolution.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddSetterMarkerResolution.java 2010-11-01
14:17:36 UTC (rev 26162)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/AddSetterMarkerResolution.java 2010-11-01
14:34:45 UTC (rev 26163)
@@ -11,20 +11,24 @@
package org.jboss.tools.seam.ui.marker;
import java.text.MessageFormat;
+import java.util.Hashtable;
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.IBuffer;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IField;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
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.common.java.generation.JavaPropertyGenerator;
import org.jboss.tools.seam.core.ISeamJavaComponentDeclaration;
import org.jboss.tools.seam.core.ISeamProperty;
import org.jboss.tools.seam.ui.SeamGuiPlugin;
@@ -55,8 +59,19 @@
ICompilationUnit original = EclipseUtil.getCompilationUnit(file);
ICompilationUnit compilationUnit = original.getWorkingCopy(new
NullProgressMonitor());
- String lineDelim= compilationUnit.findRecommendedLineSeparator();
+ String lineDelim= JavaPropertyGenerator.getLineDelimiterUsed(compilationUnit);
+ Hashtable<String, String> options = JavaCore.getOptions();
+
+ int tabSize = new
Integer(options.get("org.eclipse.jdt.core.formatter.tabulation.size"));
+
+ StringBuffer tabBuf = new StringBuffer();
+
+ for(int i = 0;i<tabSize;i++)
+ tabBuf.append(" ");
+
+ String tab = tabBuf.toString();
+
IType type = compilationUnit.findPrimaryType();
IField field = type.getField(property.getName());
@@ -69,17 +84,42 @@
StringBuffer buf= new StringBuffer();
- buf.append("private "+propertyType+"
"+property.getName()+";"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ buf.append(tab+"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());
+ if(field != null){
+ IBuffer buffer = compilationUnit.getBuffer();
+
+ buffer.replace(field.getSourceRange().getOffset(),
field.getSourceRange().getLength(), buf.toString());
+ synchronized(compilationUnit) {
+ compilationUnit.reconcile(ICompilationUnit.NO_AST, true, null, null);
+ }
+ }
}
- String setterName = GetterSetterUtil.getSetterName(field, null);
IMethod oldMethod = GetterSetterUtil.getSetter(field);
if(oldMethod == null || !oldMethod.exists()){
+ String setterName = GetterSetterUtil.getSetterName(field, null);
+ //JavaPropertyGenerator.createSetter(compilationUnit, type, "public",
field.getTypeSignature(), setterName, lineDelim);
+
String stub = GetterSetterUtil.getSetterStub(field, setterName, true,
Flags.AccPublic);
- type.createMethod(stub, null, false, new NullProgressMonitor());
+ IMethod newMethod = type.createMethod(stub, null, false, new NullProgressMonitor());
+ if(newMethod != null){
+ IBuffer buffer = compilationUnit.getBuffer();
+ // format
+ StringBuffer buf= new StringBuffer();
+
+ buf.append(lineDelim);
+ buf.append(tab+"public void "+setterName+"("+propertyType+"
"+property.getName()+"){"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ buf.append(lineDelim);
+ buf.append(tab+tab+"this."+property.getName()+" =
"+property.getName()+";");
+ buf.append(lineDelim);
+ buf.append(tab+"}");
+ buf.append(lineDelim);
+
+ buffer.replace(newMethod.getSourceRange().getOffset(),
newMethod.getSourceRange().getLength(), buf.toString());
+ }
}
compilationUnit.commitWorkingCopy(false, new NullProgressMonitor());
Modified:
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java 2010-11-01
14:17:36 UTC (rev 26162)
+++
trunk/seam/plugins/org.jboss.tools.seam.ui/src/org/jboss/tools/seam/ui/marker/SeamProblemMarkerResolutionGenerator.java 2010-11-01
14:34:45 UTC (rev 26163)
@@ -217,7 +217,7 @@
if(project == null)
return null;
- ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, false);
+ ISeamProject seamProject = SeamCorePlugin.getSeamProject(project, true);
if(seamProject == null)
return null;