Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveeclipse committed Oct 2, 2010
1 parent 21e459a commit a475b6c
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 169 deletions.
4 changes: 2 additions & 2 deletions FileSync-test/.settings/org.eclipse.jdt.ui.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ org.eclipse.jdt.ui.overrideannotation=true
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return the ${bare_field_name}\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} the ${bare_field_name} to set\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*******************************************************************************\r\n * Copyright (c) 2009 Andrei Loskutov.\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n *\r\n * Contributors\:\r\n * Andrei Loskutov - initial API and implementation\r\n *******************************************************************************/</template><template autoinsert\="true" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author ${user}\r\n *\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</template><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=false
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
Expand Down
175 changes: 88 additions & 87 deletions FileSync-test/src/test/CopyDelegate2.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,99 +31,100 @@
* @author Andrei
*/
public class CopyDelegate2 extends CopyDelegate {
private Map/*<Pattern, String>*/ patternToValue;
private Map/*<Pattern, String>*/ patternToKey;
private Map<Pattern, String> patternToValue;
private Map<Pattern, String> patternToKey;

public void setPropertiesMap(Properties propertiesMap) {
if(getPropertiesMap() != propertiesMap) {
super.setPropertiesMap(propertiesMap);
initPatterns();
}
}
@Override
public void setPropertiesMap(Properties propertiesMap) {
if(getPropertiesMap() != propertiesMap) {
super.setPropertiesMap(propertiesMap);
initPatterns();
}
}

/**
* Single file copy operation with replacement of variables on the fly.
* Implementation reads and writes line by line, so that bug files could be proceeded
* @param source - should be file only
* @param destination - should be already created
* @return true if source was successfully copied
*/
protected boolean copyInternal(File source, File destination) {
/**
* Single file copy operation with replacement of variables on the fly.
* Implementation reads and writes line by line, so that bug files could be proceeded
* @param source - should be file only
* @param destination - should be already created
* @return true if source was successfully copied
*/
@Override
protected boolean copyInternal(File source, File destination) {

boolean success = true;
FileInputStream fin = null;
FileOutputStream fout = null;
boolean success = true;
FileInputStream fin = null;
FileOutputStream fout = null;

try {
// Open the file and then get a channel from the stream
fin = new FileInputStream(source);
fout = new FileOutputStream(destination);
try {
// Open the file and then get a channel from the stream
fin = new FileInputStream(source);
fout = new FileOutputStream(destination);

LineReader reader = new LineReader(fin, encoding);
LineWriter writer = new LineWriter(fout, encoding);
String line = null;
while((line = reader.readLineToString()) != null){
for (Iterator i = patternToValue.keySet().iterator(); i.hasNext();) {
Pattern pattern = (Pattern) i.next();
if(line.indexOf((String) patternToKey.get(pattern)) < 0 ){
continue;
}
String value = (String) patternToValue.get(pattern);
line = pattern.matcher(line).replaceAll(value);
}
writer.writeLine(line);
}
writer.flush();
} catch (IOException e) {
if (FS.enableLogging) {
FileSyncPlugin.log("Could not copy file '" + source + "' to '"
+ destination + "'", e, IStatus.WARNING);
}
success = false;
} finally {
// Always close input and output streams.
if (fin != null) {
try {
fin.close();
} catch (IOException e) {
if (FS.enableLogging) {
FileSyncPlugin.log("Could not close file stream for file '"
+ source + "'", e, IStatus.WARNING);
}
success = false;
}
}
if (fout != null) {
try {
fout.close();
if (!useCurrentDateForDestinationFiles) {
destination.setLastModified(source.lastModified());
} else {
// should be updated by system I/O
}
} catch (IOException e) {
if (FS.enableLogging) {
FileSyncPlugin.log("Could not close file stream for file '"
+ destination + "'", e, IStatus.WARNING);
}
success = false;
}
}
}
return success;
}
LineReader reader = new LineReader(fin, encoding);
LineWriter writer = new LineWriter(fout, encoding);
String line = null;
while((line = reader.readLineToString()) != null){
for (Iterator i = patternToValue.keySet().iterator(); i.hasNext();) {
Pattern pattern = (Pattern) i.next();
if(line.indexOf(patternToKey.get(pattern)) < 0 ){
continue;
}
String value = patternToValue.get(pattern);
line = pattern.matcher(line).replaceAll(value);
}
writer.writeLine(line);
}
writer.flush();
} catch (IOException e) {
if (FS.enableLogging) {
FileSyncPlugin.log("Could not copy file '" + source + "' to '"
+ destination + "'", e, IStatus.WARNING);
}
success = false;
} finally {
// Always close input and output streams.
if (fin != null) {
try {
fin.close();
} catch (IOException e) {
if (FS.enableLogging) {
FileSyncPlugin.log("Could not close file stream for file '"
+ source + "'", e, IStatus.WARNING);
}
success = false;
}
}
if (fout != null) {
try {
fout.close();
if (!useCurrentDateForDestinationFiles) {
destination.setLastModified(source.lastModified());
} else {
// should be updated by system I/O
}
} catch (IOException e) {
if (FS.enableLogging) {
FileSyncPlugin.log("Could not close file stream for file '"
+ destination + "'", e, IStatus.WARNING);
}
success = false;
}
}
}
return success;
}

private void initPatterns() {
patternToValue = new HashMap();
patternToKey = new HashMap();
Set keySet = variablesMap.keySet();
for (Iterator i = keySet.iterator(); i.hasNext();) {
String key = (String) i.next();
Pattern pattern = Pattern.compile("\\$\\{" + key + "\\}");
patternToValue.put(pattern, variablesMap.get(key));
patternToKey.put(pattern, key);
}
}
private void initPatterns() {
patternToValue = new HashMap<Pattern, String>();
patternToKey = new HashMap<Pattern, String>();
Set<String> keySet = variablesMap.stringPropertyNames();
for (String key : keySet) {
Pattern pattern = Pattern.compile("\\$\\{" + key + "\\}");
patternToValue.put(pattern, variablesMap.getProperty(key));
patternToKey.put(pattern, key);
}
}


}
5 changes: 3 additions & 2 deletions FileSync-test/src/test/TestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -710,9 +710,10 @@ public boolean visit(IResource resource) throws CoreException {
if (!absolutePath.endsWith(SUFFIX_ORIG_FILE)) {
File origFile = new File(absolutePath + SUFFIX_ORIG_FILE);
if (origFile.exists()) {
assertEquals(origFile.length(), destFile.length());
String message = "File content differ: Expected: " + origFile + ", \n\tSeen: " + destFile;
assertEquals(message, origFile.length(), destFile.length());
boolean same = TestFS.isSame(destFile, origFile, true, false);
assertTrue(same);
assertTrue(message, same);
} else {
assertEquals(srcFile.length(), destFile.length());
}
Expand Down
125 changes: 63 additions & 62 deletions FileSync/.settings/org.eclipse.jdt.ui.prefs
Original file line number Diff line number Diff line change
@@ -1,62 +1,63 @@
#Sun May 30 17:21:00 CEST 2010
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_Andrei (Eclipse [built-in])
formatter_settings_version=11
internal.default.compliance=default
org.eclipse.jdt.ui.exception.name=e
org.eclipse.jdt.ui.gettersetter.use.is=true
org.eclipse.jdt.ui.keywordthis=false
org.eclipse.jdt.ui.overrideannotation=true
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=false
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=false
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=true
sp_cleanup.format_source_code=false
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.make_local_variable_final=false
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=true
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=true
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=true
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=false
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=true
sp_cleanup.remove_unused_imports=true
sp_cleanup.remove_unused_local_variables=true
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=true
sp_cleanup.remove_unused_private_methods=false
sp_cleanup.remove_unused_private_types=false
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_blocks=true
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=false
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
#Sat Oct 02 13:19:37 CEST 2010
cleanup_settings_version=2
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_Andrei (Eclipse [built-in])
formatter_settings_version=11
internal.default.compliance=default
org.eclipse.jdt.ui.exception.name=e
org.eclipse.jdt.ui.gettersetter.use.is=true
org.eclipse.jdt.ui.keywordthis=false
org.eclipse.jdt.ui.overrideannotation=true
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_missing_override_annotations_interface_methods=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=true
sp_cleanup.format_source_code=false
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.make_local_variable_final=false
sp_cleanup.make_parameters_final=false
sp_cleanup.make_private_fields_final=true
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=true
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=true
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=false
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=true
sp_cleanup.remove_unused_imports=true
sp_cleanup.remove_unused_local_variables=true
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=true
sp_cleanup.remove_unused_private_methods=false
sp_cleanup.remove_unused_private_types=false
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_blocks=true
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=false
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=false
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
Loading

0 comments on commit a475b6c

Please sign in to comment.