|
From: <caw...@us...> - 2007-06-11 16:22:29
|
Revision: 2595
http://svn.sourceforge.net/rubyeclipse/?rev=2595&view=rev
Author: cawilliams
Date: 2007-06-11 09:22:28 -0700 (Mon, 11 Jun 2007)
Log Message:
-----------
fix Trac ticket #4599, #4365
Modified Paths:
--------------
trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/RubyRedPreferenceInitializer.java
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java 2007-06-08 00:26:05 UTC (rev 2594)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java 2007-06-11 16:22:28 UTC (rev 2595)
@@ -3,16 +3,25 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IPreferencesService;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
+import org.rubypeople.rdt.internal.core.RubyModelManager.EclipsePreferencesListener;
import org.rubypeople.rdt.internal.launching.LaunchingPlugin;
import org.rubypeople.rdt.internal.ui.IRubyStatusConstants;
@@ -29,6 +38,14 @@
// The plug-in ID
public static final String PLUGIN_ID = "com.aptana.rdt";
+
+ // Preferences
+ public HashSet optionNames = new HashSet(20);
+ public Hashtable<String, String> optionsCache;
+
+ public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
+ static final int PREF_INSTANCE = 0;
+ static final int PREF_DEFAULT = 1;
/**
* Possible configurable option ID.
@@ -216,6 +233,7 @@
public void start(BundleContext context) throws Exception {
super.start(context);
context.registerService(IGemManager.class.getName(), GemManager.getInstance(), null);
+ initializePreferences();
boolean rubyDebugInstalled = GemManager.getInstance().gemInstalled("ruby-debug-ide");
// FIXME What if user has explicity disabled using ruby-debug?!
@@ -248,6 +266,40 @@
}
}
+ private void initializePreferences() {
+ // Create lookups
+ preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(PLUGIN_ID);
+ preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(PLUGIN_ID);
+
+ // Listen to instance preferences node removal from parent in order to refresh stored one
+ IEclipsePreferences.INodeChangeListener listener = new IEclipsePreferences.INodeChangeListener() {
+ public void added(IEclipsePreferences.NodeChangeEvent event) {
+ // do nothing
+ }
+ public void removed(IEclipsePreferences.NodeChangeEvent event) {
+ if (event.getChild() == preferencesLookup[PREF_INSTANCE]) {
+ preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(PLUGIN_ID);
+ preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(new EclipsePreferencesListener());
+ }
+ }
+ };
+ ((IEclipsePreferences) preferencesLookup[PREF_INSTANCE].parent()).addNodeChangeListener(listener);
+ preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(new EclipsePreferencesListener());
+
+ // Listen to default preferences node removal from parent in order to refresh stored one
+ listener = new IEclipsePreferences.INodeChangeListener() {
+ public void added(IEclipsePreferences.NodeChangeEvent event) {
+ // do nothing
+ }
+ public void removed(IEclipsePreferences.NodeChangeEvent event) {
+ if (event.getChild() == preferencesLookup[PREF_DEFAULT]) {
+ preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(PLUGIN_ID);
+ }
+ }
+ };
+ ((IEclipsePreferences) preferencesLookup[PREF_DEFAULT].parent()).addNodeChangeListener(listener);
+ }
+
protected void setRubyDebugAsDefault() {
LaunchingPlugin.getDefault().getPluginPreferences().setValue(org.rubypeople.rdt.internal.launching.PreferenceConstants.USE_RUBY_DEBUG, true);
}
@@ -308,4 +360,30 @@
public static String getPluginId() {
return PLUGIN_ID;
}
+
+ public Hashtable<String, String> getOptions() {
+
+ // return cached options if already computed
+// if (this.optionsCache != null) return new Hashtable<String, String>(this.optionsCache);
+
+ // init
+ Hashtable<String, String> options = new Hashtable<String, String>(10);
+ IPreferencesService service = Platform.getPreferencesService();
+
+ // set options using preferences service lookup
+ Iterator iterator = optionNames.iterator();
+ while (iterator.hasNext()) {
+ String propertyName = (String) iterator.next();
+ String propertyValue = service.get(propertyName, null, this.preferencesLookup);
+ if (propertyValue != null) {
+ options.put(propertyName, propertyValue);
+ }
+ }
+
+ // store built map in cache
+ this.optionsCache = new Hashtable<String, String>(options);
+
+ // return built map
+ return options;
+ }
}
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/RubyRedPreferenceInitializer.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/RubyRedPreferenceInitializer.java 2007-06-08 00:26:05 UTC (rev 2594)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/RubyRedPreferenceInitializer.java 2007-06-11 16:22:28 UTC (rev 2595)
@@ -1,5 +1,6 @@
package com.aptana.rdt.internal.core;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
@@ -13,6 +14,7 @@
public class RubyRedPreferenceInitializer extends AbstractPreferenceInitializer {
public void initializeDefaultPreferences() {
+ HashSet optionNames = AptanaRDTPlugin.getDefault().optionNames;
// Lint visitor settings
Map defaultOptionsMap = new LintOptions().getMap(); // compiler defaults
@@ -22,8 +24,9 @@
Map.Entry entry = (Map.Entry) iter.next();
String optionName = (String) entry.getKey();
defaultPreferences.put(optionName, (String) entry.getValue());
+ optionNames.add(optionName);
}
-
+ AptanaRDTPlugin.getDefault().optionsCache = null;
}
}
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java 2007-06-08 00:26:05 UTC (rev 2594)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java 2007-06-11 16:22:28 UTC (rev 2595)
@@ -1,6 +1,8 @@
package com.aptana.rdt.internal.parser.warnings;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.jruby.ast.CaseNode;
import org.jruby.ast.DefnNode;
@@ -25,11 +27,11 @@
private int maxLocals;
private int returnCount;
private int branchCount;
- private int locals;
+ private Set locals;
private Map fOptions;
public CodeComplexityVisitor(String contents) {
- this(RubyModelManager.getRubyModelManager().getOptions(), contents);
+ this(AptanaRDTPlugin.getDefault().getOptions(), contents);
}
public CodeComplexityVisitor(Map options, String contents) {
@@ -61,7 +63,7 @@
public Instruction visitDefnNode(DefnNode iVisited) {
returnCount = 0;
branchCount = 0;
- locals = 0;
+ locals = new HashSet();
String[] args = ASTUtil.getArgs(iVisited.getArgsNode(), iVisited.getScope());
if (args != null && args.length > maxArgLength) {
@@ -70,7 +72,7 @@
ISourcePosition pos = iVisited.getPosition();
int lines = (pos.getEndLine() - pos.getStartLine()) - 1;
if (lines > maxLines) {
- createProblem(iVisited.getPosition(), "Too many lines in method: " + lines);
+ createProblem(iVisited.getNameNode().getPosition(), "Too many lines in method: " + lines);
}
return super.visitDefnNode(iVisited);
}
@@ -99,7 +101,7 @@
@Override
public Instruction visitLocalAsgnNode(LocalAsgnNode iVisited) {
- locals++;
+ locals.add(iVisited.getName());
return super.visitLocalAsgnNode(iVisited);
}
@@ -110,12 +112,12 @@
if (branchCount > maxBranches) {
createProblem(iVisited.getPosition(), "Too many branches: " + branchCount);
}
- if (locals > maxLocals) {
- createProblem(iVisited.getPosition(), "Too many local variables: " + locals);
+ if (locals.size() > maxLocals) {
+ createProblem(iVisited.getPosition(), "Too many local variables: " + locals.size());
}
returnCount = 0;
branchCount = 0;
- locals = 0;
+ locals.clear();
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|