Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 3 commits
  • 15 files changed
  • 0 commit comments
  • 1 contributor
View
92 org.erlide.core.tests/src/org/erlide/core/ParsingTests.java
@@ -3,7 +3,8 @@
*/
package org.erlide.core;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Collection;
@@ -27,53 +28,54 @@
*/
public class ParsingTests {
- IErlModule module;
+ IErlModule module;
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- final IErlModel model = ErlModelManager.getErlangModel();
- module = model.getModuleFromText(model, "testing", "", null);
- }
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ final IErlModel model = ErlModelManager.getErlangModel();
+ module = model.getModuleFromText(model, "testing", "", null);
+ }
- /**
- * @throws java.lang.Exception
- */
- @After
- public void tearDown() throws Exception {
- module.dispose();
- module = null;
- }
+ /**
+ * @throws java.lang.Exception
+ */
+ @After
+ public void tearDown() throws Exception {
+ module.dispose();
+ module = null;
+ }
- private boolean parse(final String s) {
- final String scannerModuleName = module.getScannerName();
- ErlideScanner.create(scannerModuleName);
- boolean result = false;
- try {
- ErlideScanner.initialScan(scannerModuleName, "", s, false);
- final IErlParser parser = ErlModelManager.getErlangModel()
- .getParser();
- result = parser.parse(module, scannerModuleName, false, "", false);
- } finally {
- ErlideScanner.dispose(scannerModuleName);
- }
- return result;
- }
+ private boolean parse(final String s) {
+ final String scannerModuleName = module.getScannerName();
+ ErlideScanner.create(scannerModuleName);
+ boolean result = false;
+ try {
+ ErlideScanner.initialScan(scannerModuleName, "", s, false);
+ final IErlParser parser = ErlModelManager.getErlangModel()
+ .getParser();
+ result = parser.parse(module, scannerModuleName, false, "", s,
+ false);
+ } finally {
+ ErlideScanner.dispose(scannerModuleName);
+ }
+ return result;
+ }
- @Test
- public void parseCompileDirective() throws ErlModelException {
- final String sourceContent = "[inline,{hipe,[{regalloc,linear_scan}]}]";
- final String source = "-compile(" + sourceContent + ").";
- assertTrue(parse(source));
- final IErlElement attribute = TestingSupport.createErlAttribute(module,
- "compile", null, sourceContent, 0, 50);
- final List<IErlElement> expected = new ArrayList<IErlElement>(1);
- expected.add(attribute);
- final Collection<IErlElement> actual = module.getChildren();
- // assertEquals(expected, actual);
- assertEquals(expected.toString(), actual.toString());
- }
+ @Test
+ public void parseCompileDirective() throws ErlModelException {
+ final String sourceContent = "[inline,{hipe,[{regalloc,linear_scan}]}]";
+ final String source = "-compile(" + sourceContent + ").";
+ assertTrue(parse(source));
+ final IErlElement attribute = TestingSupport.createErlAttribute(module,
+ "compile", null, sourceContent, 0, 50);
+ final List<IErlElement> expected = new ArrayList<IErlElement>(1);
+ expected.add(attribute);
+ final Collection<IErlElement> actual = module.getChildren();
+ // assertEquals(expected, actual);
+ assertEquals(expected.toString(), actual.toString());
+ }
}
View
38 org.erlide.kernel.ide/src/parsing/erlide_noparse.erl
@@ -9,7 +9,7 @@
%%
%% called from Java
--export([initial_parse/5, reparse/2, remove_cache_files/2]).
+-export([initial_parse/6, reparse/2, remove_cache_files/2]).
%% called from Erlang
-export([get_module_refs/4]).
@@ -20,7 +20,7 @@
%% -define(DEBUG, 1).
--define(CACHE_VERSION, 29).
+-define(CACHE_VERSION, 30).
-define(SERVER, erlide_noparse).
-include("erlide.hrl").
@@ -32,17 +32,19 @@
%% API Functions
%%
--spec initial_parse(atom(), string(), string(), boolean(), boolean()) ->
+-spec initial_parse(atom(), string(), string(), string(), boolean(), boolean()) ->
{ok, #model{}, cached | renewing | dont_use_cache, [#ref{}]}
| {error, term(), term()}.
-initial_parse(ScannerName, ModuleFileName, StateDir, UseCache,
+initial_parse(ScannerName, ModuleFileName, InitialText, StateDir, UseCache,
UpdateSearchServer) ->
try
+ ?D({ScannerName, ModuleFileName, UseCache, UpdateSearchServer}),
BaseName = filename:join(StateDir, atom_to_list(ScannerName)),
RefsFileName = BaseName ++ ".refs",
RenewFun = fun(_F) ->
- Tokens = get_tokens(ScannerName, ModuleFileName, StateDir),
+ Tokens = get_tokens(ScannerName, ModuleFileName,
+ InitialText, StateDir),
{Model, Refs} =
do_parse(ScannerName, RefsFileName, Tokens, StateDir,
UpdateSearchServer),
@@ -82,8 +84,14 @@ get_module_refs(ScannerName, ModulePath, StateDir, UpdateSearchServer) ->
{ok, Binary} ->
binary_to_term(Binary);
_ ->
- {ok, _, _, Refs= initial_parse(ScannerName, ModulePath, StateDir,
- true, UpdateSearchServer),
+ InitialText = case file:read_file(ModulePath) of
+ {ok, InitialTextBin} ->
+ binary_to_list(InitialTextBin);
+ _ ->
+ ""
+ end,
+ {ok, _, _, Refs= initial_parse(ScannerName, ModulePath, InitialText,
+ StateDir, true, UpdateSearchServer),
Refs
end.
@@ -102,27 +110,21 @@ remove_cache_files(ScannerName, StateDir) ->
%% Internal functions
%%
-get_tokens(ScannerName, ModuleFileName, StateDir) ->
+get_tokens(ScannerName, ModuleFileName, InitialText, StateDir) ->
case whereis(ScannerName) of
undefined ->
- case file:read_file(ModuleFileName) of
- {ok, InitialTextBin} ->
- InitialText = binary_to_list(InitialTextBin),
- {{_Cached, Module}, _Text} = erlide_scanner:initial_scan(ScannerName, ModuleFileName, InitialText, StateDir, true),
- erlide_scan_model:get_all_tokens(Module);
- {error, Error} ->
- erlide_log:log({"Module not found: ", ModuleFileName, Error}),
- %% not much to do here
- []
- end;
+ {{_Cached, Module}, _Text} = erlide_scanner:initial_scan(ScannerName, ModuleFileName, InitialText, StateDir, true),
+ erlide_scan_model:get_all_tokens(Module);
_ ->
erlide_scanner:get_tokens(ScannerName)
end.
do_parse(ScannerName, RefsFileName, Tokens, StateDir, UpdateSearchServer) ->
{Forms, Comments, References} = erlide_np:parse(Tokens),
+ ?D(Forms),
Model = #model{forms=Forms, comments=Comments},
CompactModel = erlide_np_util:compact_model(Model),
+ ?D(CompactModel),
case StateDir of
"" -> ok;
_ ->
View
65 org.erlide.kernel.ide/src/parsing/erlide_scan_model.erl
@@ -28,7 +28,7 @@
do_scan(ScannerName, InitialText) ->
?D(do_scan),
- Lines = split_lines_w_lengths(InitialText),
+ Lines = erlide_scan_util:split_lines_w_lengths(InitialText),
LineTokens = [scan_line(L) || L <- Lines],
?D([ScannerName]), % , InitialText, LineTokens]),
#module{name=ScannerName, lines=Lines, tokens=LineTokens}.
@@ -56,7 +56,7 @@ get_token_window(Module, Offset, Before, After) ->
{A, B}.
get_token_at(Module, Offset) ->
- case find_line_w_offset(Offset, Module#module.tokens) of
+ case erlide_scan_util:find_line_w_offset(Offset, Module#module.tokens) of
{N, Pos, _Length, Tokens, false} ->
case get_token_at_aux(Tokens, Offset - Pos) of
token_not_found ->
@@ -76,59 +76,16 @@ get_text(#module{lines=Lines}) ->
%% Local Functions
%%
+replace_between(_From, _Length, With, []) ->
+ %% allow for special case when replacing empty set
+ %% (the Length may be 1 from replace_between_lines)
+ With;
replace_between(From, Length, With, In) ->
+ ?D({From, Length, With, In}),
{A, B} = lists:split(From, In),
{_, C} = lists:split(Length, B),
A++With++C.
-%% [{Length, TextIncNL}...]
-split_lines_w_lengths(Text) ->
- split_lines_w_lengths(Text, 0, [], []).
-
-split_lines_w_lengths("", _Length, [], Acc) ->
- lists:reverse(Acc);
-split_lines_w_lengths("", Length, LineAcc, Acc) ->
- lists:reverse(Acc, [{Length, lists:reverse(LineAcc)}]);
-split_lines_w_lengths("\r\n" ++ Text, Length, LineAcc, Acc) ->
- split_lines_w_lengths(Text, 0, [],
- [{Length+2, lists:reverse(LineAcc, "\r\n")} | Acc]);
-split_lines_w_lengths("\n" ++ Text, Length, LineAcc, Acc) ->
- split_lines_w_lengths(Text, 0, [],
- [{Length+1, lists:reverse(LineAcc, "\n")} | Acc]);
-split_lines_w_lengths("\r" ++ Text, Length, LineAcc, Acc) ->
- split_lines_w_lengths(Text, 0, [],
- [{Length+1, lists:reverse(LineAcc, "\r")} | Acc]);
-split_lines_w_lengths([C | Text], Length, LineAcc, Acc) ->
- split_lines_w_lengths(Text, Length+1, [C | LineAcc], Acc).
-
-%% Find a line from [{Length, Line
-
-find_line_w_offset(Offset, Lines) ->
- find_line_w_offset(Offset, 0, 0, Lines).
-
-find_line_w_offset(0, _Pos, _N, []) ->
- {0, 0, 0, "", on_eof};
-find_line_w_offset(_Offset, _Pos, _N, []) ->
- not_found;
-find_line_w_offset(Offset, Pos, N, [{Length, _Line} | Lines]) when Offset >= Pos+Length, Lines =/= [] ->
- find_line_w_offset(Offset, Pos+Length, N+1, Lines);
-find_line_w_offset(Offset, Pos, N, [{Length, Line} |_]) when Pos =< Offset, Offset < Pos + Length ->
- {N, Pos, Length, Line, false};
-find_line_w_offset(Offset, Pos, N, [{Length, Line}]) ->
- case ends_with_newline(Line) orelse Offset > Pos + Length of
- true ->
- {N+1, Pos+Length, 0, "", beyond_eof};
- false ->
- {N, Pos+Length, Length, Line, on_eof}
- end.
-
-ends_with_newline("") -> false;
-ends_with_newline("\n") -> true;
-ends_with_newline("\r") -> true;
-ends_with_newline("\r\n") -> true;
-ends_with_newline([_C | R]) ->
- ends_with_newline(R).
-
%%
%% Nicer version of string:substring/2 accepting out-of-bounds parameters
%% (should be removed eventually)
@@ -154,7 +111,7 @@ substr(Text, Start, Length) ->
string:substr(Text, Start, Length).
replace_between_lines(From, Length, With, Lines) ->
- {LineNo1, Pos1, _Length1, Line1, Beyond1} = find_line_w_offset(From, Lines),
+ {LineNo1, Pos1, _Length1, Line1, Beyond1} = erlide_scan_util:find_line_w_offset(From, Lines),
?D({LineNo1, Pos1, _Length1, Line1, Beyond1}),
FirstPiece = substr(Line1, 1, From-Pos1),
{LineNo2, Pos2, _Length2, Line2, Beyond2} =
@@ -162,7 +119,7 @@ replace_between_lines(From, Length, With, Lines) ->
0 ->
{LineNo1, Pos1, unused, Line1, Beyond1};
_ ->
- find_line_w_offset(From+Length, Lines)
+ erlide_scan_util:find_line_w_offset(From+Length, Lines)
end,
?D({LineNo2, Pos2, _Length2, Line2, Beyond2}),
LastPiece = substr(Line2, From+Length-Pos2+1),
@@ -178,7 +135,7 @@ replace_between_lines(From, Length, With, Lines) ->
_ ->
{FirstPiece++With++LastPiece, LineNo2-LineNo1+1}
end,
- WLines = split_lines_w_lengths(NewText),
+ WLines = erlide_scan_util:split_lines_w_lengths(NewText),
?D(WLines),
{LineNo1, NOldLines, WLines,
replace_between(LineNo1, NOldLines, WLines, Lines)}.
@@ -269,7 +226,7 @@ get_tokens_at(Module, Offset, N) ->
get_tokens_at(_Module, _Offset, 0, Acc) ->
lists:reverse(Acc);
get_tokens_at(Module, Offset, N, Acc0) ->
- case find_line_w_offset(Offset, Module#module.tokens) of
+ case erlide_scan_util:find_line_w_offset(Offset, Module#module.tokens) of
{LineNo, Pos, Length, Tokens, false} ->
{M, Ts} = get_tokens_at_aux(Tokens, Offset - Pos, N),
Acc1 =
View
55 org.erlide.kernel.ide/src/parsing/erlide_scan_util.erl
@@ -0,0 +1,55 @@
+%% @author jakob
+%% @doc @todo Add description to erlide_scan_util.
+
+
+-module(erlide_scan_util).
+
+-export([split_lines_w_lengths/1, find_line_w_offset/2]).
+
+%% [{Length, TextIncNL}...]
+split_lines_w_lengths(Text) ->
+ split_lines_w_lengths(Text, 0, [], []).
+
+split_lines_w_lengths("", _Length, [], Acc) ->
+ lists:reverse(Acc);
+split_lines_w_lengths("", Length, LineAcc, Acc) ->
+ lists:reverse(Acc, [{Length, lists:reverse(LineAcc)}]);
+split_lines_w_lengths("\r\n" ++ Text, Length, LineAcc, Acc) ->
+ split_lines_w_lengths(Text, 0, [],
+ [{Length+2, lists:reverse(LineAcc, "\r\n")} | Acc]);
+split_lines_w_lengths("\n" ++ Text, Length, LineAcc, Acc) ->
+ split_lines_w_lengths(Text, 0, [],
+ [{Length+1, lists:reverse(LineAcc, "\n")} | Acc]);
+split_lines_w_lengths("\r" ++ Text, Length, LineAcc, Acc) ->
+ split_lines_w_lengths(Text, 0, [],
+ [{Length+1, lists:reverse(LineAcc, "\r")} | Acc]);
+split_lines_w_lengths([C | Text], Length, LineAcc, Acc) ->
+ split_lines_w_lengths(Text, Length+1, [C | LineAcc], Acc).
+
+%% Find a line from [{Length, Line
+
+find_line_w_offset(Offset, Lines) ->
+ find_line_w_offset(Offset, 0, 0, Lines).
+
+find_line_w_offset(0, _Pos, _N, []) ->
+ {0, 0, 0, "", on_eof};
+find_line_w_offset(_Offset, _Pos, _N, []) ->
+ not_found;
+find_line_w_offset(Offset, Pos, N, [{Length, _Line} | Lines]) when Offset >= Pos+Length, Lines =/= [] ->
+ find_line_w_offset(Offset, Pos+Length, N+1, Lines);
+find_line_w_offset(Offset, Pos, N, [{Length, Line} |_]) when Pos =< Offset, Offset < Pos + Length ->
+ {N, Pos, Length, Line, false};
+find_line_w_offset(Offset, Pos, N, [{Length, Line}]) ->
+ case ends_with_newline(Line) orelse Offset > Pos + Length of
+ true ->
+ {N+1, Pos+Length, 0, "", beyond_eof};
+ false ->
+ {N, Pos+Length, Length, Line, on_eof}
+ end.
+
+ends_with_newline("") -> false;
+ends_with_newline("\n") -> true;
+ends_with_newline("\r") -> true;
+ends_with_newline("\r\n") -> true;
+ends_with_newline([_C | R]) ->
+ ends_with_newline(R).
View
17 org.erlide.kernel.ide/src/parsing/erlide_scanner.erl
@@ -26,7 +26,7 @@
%% API Functions
%%
--define(CACHE_VERSION, 22).
+-define(CACHE_VERSION, 24).
light_scan_string(B, latin1) ->
S = binary_to_list(B),
@@ -42,13 +42,14 @@ scan_string(L) when is_list(L) ->
erlide_scan_model:get_all_tokens(M).
initial_scan(ScannerName, ModuleFileName, InitialText, StateDir, UseCache) ->
- Text = case InitialText of
- "" ->
- {ok, B} = file:read_file(ModuleFileName),
- binary_to_list(B);
- _ ->
- InitialText
- end,
+%% Text = case InitialText of
+%% "" ->
+%% {ok, B} = file:read_file(ModuleFileName),
+%% binary_to_list(B);
+%% _ ->
+%% InitialText
+%% end,
+ Text = InitialText,
CacheFileName = filename:join(StateDir, atom_to_list(ScannerName) ++ ".scan"),
RenewFun = fun(_F) -> erlide_scan_model:do_scan(ScannerName, Text) end,
{erlide_util:check_and_renew_cached(ModuleFileName, CacheFileName, ?CACHE_VERSION, RenewFun, UseCache), Text}.
View
6 org.erlide.model.api/src/org/erlide/model/erlang/IErlParser.java
@@ -2,8 +2,8 @@
public interface IErlParser {
- public abstract boolean parse(final IErlModule module,
- final String scannerName, final boolean initialParse,
- final String path, boolean updateSearchServer);
+ public abstract boolean parse(final IErlModule module,
+ final String scannerName, final boolean initialParse,
+ final String path, String initialText, boolean updateSearchServer);
}
View
252 org.erlide.model.api/src/org/erlide/model/root/IErlModel.java
@@ -42,130 +42,130 @@
* @see ErlangCore#create(org.eclipse.core.resources.IWorkspaceRoot)
*/
public interface IErlModel extends IErlElement, IOpenable, IParent,
- IErlElementLocator {
-
- /**
- * Returns the Erlang project with the given name. This is a handle-only
- * method. The project may or may not exist.
- *
- * @param project
- * the name of the Erlang project
- * @return the Erlang project with the given name
- */
- IErlProject getErlangProject(IProject project);
-
- /**
- * Returns the Erlang projects in this Erlang model, or an empty array if
- * there are none.
- *
- * @return the Erlang projects in this Erlang model, or an empty array if
- * there are none
- * @throws ErlModelException
- * if this request fails.
- */
- Collection<IErlProject> getErlangProjects() throws ErlModelException;
-
- void addModelChangeListener(IErlModelChangeListener listener);
-
- void removeModelChangeListener(IErlModelChangeListener listener);
-
- IErlElement innermostThat(final IErlElement el,
- final Predicate<IErlElement> firstThat);
-
- OtpErlangList getPathVars();
-
- IErlProject newProject(final String name, final String path)
- throws ErlModelException;
-
- void notifyChange(IErlElement element);
-
- /**
- * Returns the Erlang element corresponding to the given file, its project
- * being the given project. Returns <code>null</code> if unable to associate
- * the given file with a Erlang element.
- * <p>
- * The file must be one of:
- * <ul>
- * <li>a <code>.erl</code> file - the element returned is the corresponding
- * <code>IErlModule</code></li>
- * </ul>
- * <p>
- * Creating a Erlang element has the side effect of creating and opening all
- * of the element's parents if they are not yet open.
- */
- IErlElement create(IResource resource);
-
- /**
- * Adds the given listener for changes to Erlang elements. Has no effect if
- * an identical listener is already registered. After completion of this
- * method, the given listener will be registered for exactly the specified
- * events. If they were previously registered for other events, they will be
- * deregistered.
- * <p>
- * Once registered, a listener starts receiving notification of changes to
- * Erlang elements in the model. The listener continues to receive
- * notifications until it is replaced or removed.
- * </p>
- * <p>
- * Listeners can listen for several types of event as defined in
- * <code>ElementChangeEvent</code>. Clients are free to register for any
- * number of event types however if they register for more than one, it is
- * their responsibility to ensure they correctly handle the case where the
- * same Erlang element change shows up in multiple notifications. Clients
- * are guaranteed to receive only the events for which they are registered.
- * </p>
- *
- * @param listener
- * the listener
- * @param eventMask
- * the bit-wise OR of all event types of interest to the listener
- * @see IElementChangedListener
- * @see ElementChangedEvent
- * @see #removeElementChangedListener(IElementChangedListener)
- */
- void addElementChangedListener(IElementChangedListener listener,
- int eventMask);
-
- /**
- * Removes the given element changed listener. Has no affect if an identical
- * listener is not registered.
- *
- * @param listener
- * the listener
- */
- void removeElementChangedListener(IElementChangedListener listener);
-
- /**
- * Adds the given listener for changes to Erlang elements. Has no effect if
- * an identical listener is already registered.
- *
- * This listener will only be notified during the POST_CHANGE resource
- * change notification and any reconcile operation (POST_RECONCILE). For
- * finer control of the notification, use
- * <code>addElementChangedListener(IElementChangedListener,int)</code>,
- * which allows to specify a different eventMask.
- *
- * @param listener
- * the listener
- * @see ElementChangedEvent
- */
- void addElementChangedListener(IElementChangedListener listener);
-
- void registerModelDelta(IErlElementDelta delta);
-
- IErlModule getModuleFromFile(IParent parent, String name,
- String initialText, String path, String key);
-
- IErlModule getModuleFromText(IParent parent, String name,
- String initialText, String key);
-
- public void removeModule(final IErlModule module);
-
- void putEdited(String path, IErlModule module);
-
- IErlParser getParser();
-
- ErlangToolkit getToolkit();
-
- Object getModelLock();
+ IErlElementLocator {
+
+ /**
+ * Returns the Erlang project with the given name. This is a handle-only
+ * method. The project may or may not exist.
+ *
+ * @param project
+ * the name of the Erlang project
+ * @return the Erlang project with the given name
+ */
+ IErlProject getErlangProject(IProject project);
+
+ /**
+ * Returns the Erlang projects in this Erlang model, or an empty array if
+ * there are none.
+ *
+ * @return the Erlang projects in this Erlang model, or an empty array if
+ * there are none
+ * @throws ErlModelException
+ * if this request fails.
+ */
+ Collection<IErlProject> getErlangProjects() throws ErlModelException;
+
+ void addModelChangeListener(IErlModelChangeListener listener);
+
+ void removeModelChangeListener(IErlModelChangeListener listener);
+
+ IErlElement innermostThat(final IErlElement el,
+ final Predicate<IErlElement> firstThat);
+
+ OtpErlangList getPathVars();
+
+ IErlProject newProject(final String name, final String path)
+ throws ErlModelException;
+
+ void notifyChange(IErlElement element);
+
+ /**
+ * Returns the Erlang element corresponding to the given file, its project
+ * being the given project. Returns <code>null</code> if unable to associate
+ * the given file with a Erlang element.
+ * <p>
+ * The file must be one of:
+ * <ul>
+ * <li>a <code>.erl</code> file - the element returned is the corresponding
+ * <code>IErlModule</code></li>
+ * </ul>
+ * <p>
+ * Creating a Erlang element has the side effect of creating and opening all
+ * of the element's parents if they are not yet open.
+ */
+ IErlElement create(IResource resource);
+
+ /**
+ * Adds the given listener for changes to Erlang elements. Has no effect if
+ * an identical listener is already registered. After completion of this
+ * method, the given listener will be registered for exactly the specified
+ * events. If they were previously registered for other events, they will be
+ * deregistered.
+ * <p>
+ * Once registered, a listener starts receiving notification of changes to
+ * Erlang elements in the model. The listener continues to receive
+ * notifications until it is replaced or removed.
+ * </p>
+ * <p>
+ * Listeners can listen for several types of event as defined in
+ * <code>ElementChangeEvent</code>. Clients are free to register for any
+ * number of event types however if they register for more than one, it is
+ * their responsibility to ensure they correctly handle the case where the
+ * same Erlang element change shows up in multiple notifications. Clients
+ * are guaranteed to receive only the events for which they are registered.
+ * </p>
+ *
+ * @param listener
+ * the listener
+ * @param eventMask
+ * the bit-wise OR of all event types of interest to the listener
+ * @see IElementChangedListener
+ * @see ElementChangedEvent
+ * @see #removeElementChangedListener(IElementChangedListener)
+ */
+ void addElementChangedListener(IElementChangedListener listener,
+ int eventMask);
+
+ /**
+ * Removes the given element changed listener. Has no affect if an identical
+ * listener is not registered.
+ *
+ * @param listener
+ * the listener
+ */
+ void removeElementChangedListener(IElementChangedListener listener);
+
+ /**
+ * Adds the given listener for changes to Erlang elements. Has no effect if
+ * an identical listener is already registered.
+ *
+ * This listener will only be notified during the POST_CHANGE resource
+ * change notification and any reconcile operation (POST_RECONCILE). For
+ * finer control of the notification, use
+ * <code>addElementChangedListener(IElementChangedListener,int)</code>,
+ * which allows to specify a different eventMask.
+ *
+ * @param listener
+ * the listener
+ * @see ElementChangedEvent
+ */
+ void addElementChangedListener(IElementChangedListener listener);
+
+ void registerModelDelta(IErlElementDelta delta);
+
+ IErlModule getModuleFromFile(IParent parent, String name, String path,
+ String encoding, String key);
+
+ IErlModule getModuleFromText(IParent parent, String name,
+ String initialText, String key);
+
+ public void removeModule(final IErlModule module);
+
+ void putEdited(String path, IErlModule module);
+
+ IErlParser getParser();
+
+ ErlangToolkit getToolkit();
+
+ Object getModelLock();
}
View
4 org.erlide.model/src/org/erlide/model/internal/erlang/ErlExternalReferenceEntry.java
@@ -52,8 +52,8 @@ protected boolean buildStructure(final IProgressMonitor pm)
final List<IErlModule> children = Lists
.newArrayListWithCapacity(files.size());
for (final String file : files) {
- children.add(new ErlModule(this, getName(file), null, null,
- file));
+ children.add(new ErlModule(this, getName(file), file, null,
+ null));
}
setChildren(children);
return true;
View
86 org.erlide.model/src/org/erlide/model/internal/erlang/ErlModule.java
@@ -10,6 +10,9 @@
*******************************************************************************/
package org.erlide.model.internal.erlang;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -53,6 +56,7 @@
import org.erlide.model.util.ModelUtils;
import org.erlide.util.ErlLogger;
import org.erlide.util.SystemConfiguration;
+import org.erlide.util.Util;
import com.ericsson.otp.erlang.OtpErlangAtom;
import com.ericsson.otp.erlang.OtpErlangObject;
@@ -67,7 +71,7 @@
"export_all");
private static final boolean logging = false;
private long timestamp = IResource.NULL_STAMP;
- private IFile fFile;
+ private IFile file;
private final ModuleKind moduleKind;
protected String path;
private String initialText;
@@ -75,14 +79,26 @@
private final String scannerName;
private final Collection<IErlComment> comments;
private IErlScanner scanner;
+ private final String encoding;
+
+ public ErlModule(final IParent parent, final String name, final IFile file) {
+ this(parent, name, file, null, null, null);
+ }
public ErlModule(final IParent parent, final String name,
- final String initialText, final IFile file, final String path) {
+ final String path, final String encoding, final String initialText) {
+ this(parent, name, null, path, encoding, initialText);
+ }
+
+ private ErlModule(final IParent parent, final String name,
+ final IFile file, final String path, final String encoding,
+ final String initialText) {
super(parent, name);
- fFile = file;
- moduleKind = ModuleKind.nameToModuleKind(name);
+ this.file = file;
this.path = path;
+ this.encoding = encoding;
this.initialText = initialText;
+ moduleKind = ModuleKind.nameToModuleKind(name);
parsed = false;
scannerName = createScannerName();
comments = Lists.newArrayList();
@@ -95,9 +111,51 @@ public ErlModule(final IParent parent, final String name,
}
public boolean internalBuildStructure(final IProgressMonitor pm) {
- final IErlParser parser = ErlModelManager.getErlangModel().getParser();
- parsed = parser.parse(this, scannerName, !parsed, getFilePath(), true);
- return parsed;
+ final String text = getInitialText();
+ if (text != null) {
+ final IErlParser parser = ErlModelManager.getErlangModel()
+ .getParser();
+ parsed = parser.parse(this, scannerName, !parsed, getFilePath(),
+ text, true);
+ return parsed;
+ } else {
+ setChildren(null);
+ return true;
+ }
+ }
+
+ private String getInitialText() {
+ String charset;
+ if (initialText != null) {
+ return initialText;
+ } else if (file != null) {
+ if (file.isAccessible() && file.isSynchronized(0)) {
+ try {
+ charset = file.getCharset();
+ final String initialText = Util.getInputStreamAsString(
+ file.getContents(), charset);
+ return initialText;
+ } catch (final CoreException e) {
+ ErlLogger.warn(e);
+ }
+ }
+ } else if (path != null) {
+ try {
+ if (encoding != null) {
+ charset = encoding;
+ } else {
+ charset = ModelUtils.getProject(this).getWorkspaceProject()
+ .getDefaultCharset();
+ }
+ Util.getInputStreamAsString(
+ new FileInputStream(new File(path)), charset);
+ } catch (final CoreException e) {
+ ErlLogger.warn(e);
+ } catch (final FileNotFoundException e) {
+ ErlLogger.warn(e);
+ }
+ }
+ return null;
}
@Override
@@ -121,8 +179,8 @@ protected synchronized boolean buildStructure(final IProgressMonitor pm)
@Override
public String getFilePath() {
- if (fFile != null) {
- final IPath location = fFile.getLocation();
+ if (file != null) {
+ final IPath location = file.getLocation();
if (location != null) {
return location.toString();
}
@@ -180,7 +238,7 @@ public IResource getResource() {
@Override
public IResource getCorrespondingResource() {
- return fFile;
+ return file;
}
public ISourceRange getSourceRange() throws ErlModelException {
@@ -445,7 +503,7 @@ public synchronized void resetAndCacheScannerAndParser(final String newText)
@Override
public void setResource(final IFile file) {
- fFile = file;
+ this.file = file;
}
@Override
@@ -476,11 +534,9 @@ private IErlScanner getNewScanner() {
if (filePath == null) {
return null;
}
- if (initialText == null) {
- initialText = "";
- }
+ final String text = initialText == null ? "" : initialText;
return ErlModelManager.getErlangModel().getToolkit()
- .createScanner(scannerName, initialText, filePath, logging);
+ .createScanner(scannerName, text, filePath, logging);
}
@Override
View
8 org.erlide.model/src/org/erlide/model/internal/erlang/ErlParser.java
@@ -77,7 +77,7 @@ public ErlParser() {
@Override
public boolean parse(final IErlModule module, final String scannerName,
final boolean initialParse, final String path,
- final boolean updateSearchServer) {
+ final String initialText, final boolean updateSearchServer) {
if (module == null) {
return false;
}
@@ -89,7 +89,7 @@ public boolean parse(final IErlModule module, final String scannerName,
final String stateDir = ModelPlugin.getDefault().getStateLocation()
.toString();
res = ErlideNoparse.initialParse(backend, scannerName, path,
- stateDir, updateSearchServer);
+ initialText, stateDir, updateSearchServer);
} else {
res = ErlideNoparse.reparse(backend, scannerName,
updateSearchServer);
@@ -129,6 +129,10 @@ public boolean parse(final IErlModule module, final String scannerName,
module.setComments(moduleComments);
}
fixFunctionComments(module);
+ final String cached = res.arity() > 2 ? ((OtpErlangAtom) res
+ .elementAt(2)).atomValue() : "reparsed";
+ ErlLogger.debug("Parsed %d forms and %d comments (%s)", forms.arity(),
+ comments.arity(), cached);
return forms != null && comments != null;
}
View
7 org.erlide.model/src/org/erlide/model/internal/erlang/ErlideNoparse.java
@@ -19,12 +19,13 @@
public static OtpErlangTuple initialParse(final IRpcSite b,
final String scannerModuleName, final String moduleFileName,
- final String stateDir, final boolean updateRefs) {
+ final String initialText, final String stateDir,
+ final boolean updateRefs) {
OtpErlangTuple res = null;
try {
res = (OtpErlangTuple) b.call(200000, ERLIDE_NOPARSE,
- "initial_parse", "assoo", scannerModuleName,
- moduleFileName, stateDir, true, updateRefs);
+ "initial_parse", "asssoo", scannerModuleName,
+ moduleFileName, initialText, stateDir, true, updateRefs);
} catch (final RpcTimeoutException e) {
ErlLogger.warn(e);
} catch (final RpcException e) {
View
5 org.erlide.model/src/org/erlide/model/internal/erlang/ErlideScanner.java
@@ -100,11 +100,6 @@ public static void replaceText(final String module, final int offset,
final int removeLength, String newText) {
final IRpcSite backend = ModelPlugin.getDefault().getIdeBackend();
try {
- // ErlLogger.debug("replaceText %s %d %d <length %d>", module,
- // offset,
- // removeLength, newTextLen);
- // ErlLogger.debug("replaceText %s %d %d \"%s\"", module, offset,
- // removeLength, newText);
if (newText == null) {
newText = "";
}
View
31 org.erlide.model/src/org/erlide/model/internal/root/ErlModel.java
@@ -524,12 +524,25 @@ public void addElementChangedListener(final IElementChangedListener listener) {
@Override
public IErlModule getModuleFromFile(final IParent parent,
- final String name, final String initialText, final String path,
+ final String name, final String path, final String encoding,
final String key) {
+ return getModuleWithoutResource(parent, name, path, encoding, null, key);
+ }
+
+ @Override
+ public IErlModule getModuleFromText(final IParent parent,
+ final String name, final String initialText, final String key) {
+ return getModuleWithoutResource(parent, name, null, null, initialText,
+ key);
+ }
+
+ private IErlModule getModuleWithoutResource(final IParent parent,
+ final String name, final String path, final String encoding,
+ final String initialText, final String key) {
IErlModule m = moduleMap.get(key);
if (m == null) {
final IParent parent2 = parent == null ? this : parent;
- m = new ErlModule(parent2, name, initialText, null, path);
+ m = new ErlModule(parent2, name, path, encoding, initialText);
if (key != null) {
moduleMap.put(key, m);
mapModule.put(m, key);
@@ -549,12 +562,6 @@ public void removeModule(final IErlModule module) {
}
@Override
- public IErlModule getModuleFromText(final IParent parent,
- final String name, final String initialText, final String key) {
- return getModuleFromFile(parent, name, initialText, "", key);
- }
-
- @Override
public void putEdited(final String path, final IErlModule module) {
ErlModel.getErlModelCache().putEdited(path, module);
}
@@ -691,7 +698,7 @@ public IErlElement createFile(final IFile file, IParent parent) {
}
}
if (CommonUtils.isErlangFileContentFileName(file.getName())) {
- return createModuleFrom(file, parent);
+ return createModuleFromFile(file, parent);
}
return null;
}
@@ -711,14 +718,14 @@ public IErlFolder createFolder(final IFolder folder, final IParent parent) {
return f;
}
- public IErlModule createModuleFrom(final IFile file, final IParent parent) {
+ public IErlModule createModuleFromFile(final IFile file,
+ final IParent parent) {
if (file == null) {
return null;
}
final String name = file.getName();
if (CommonUtils.isErlangFileContentFileName(name)) {
- final IErlModule module = new ErlModule(parent, name, null, file,
- null);
+ final IErlModule module = new ErlModule(parent, name, file);
if (parent != null) {
parent.addChild(module);
}
View
3  org.erlide.ui/src/org/erlide/ui/editors/internal/reconciling/ErlReconciler.java
@@ -298,6 +298,8 @@ public void documentAboutToBeChanged(final DocumentEvent e) {
*/
@Override
public void documentChanged(final DocumentEvent e) {
+ ErlLogger.debug("documentChanged %d %d %d", e.getOffset(),
+ e.getLength(), e.getText().length());
if (!fThread.isDirty() && fThread.isAlive()) {
if (!fIsAllowedToModifyDocument
&& Thread.currentThread() == fThread) {
@@ -728,6 +730,7 @@ public void reconcileNow() {
}
public void reset() {
+ ErlLogger.debug("reset");
if (fIsIncrementalReconciler) {
synchronized (fDirtyRegionQueue) {
fDirtyRegionQueue.purgeQueue();
View
14 org.erlide.ui/src/org/erlide/ui/util/ErlModelUtils.java
@@ -38,7 +38,6 @@
import org.erlide.ui.editors.erl.AbstractErlangEditor;
import org.erlide.ui.editors.util.EditorUtility;
import org.erlide.ui.editors.util.ErlangExternalEditorInput;
-import org.erlide.util.Util;
public class ErlModelUtils {
@@ -130,8 +129,9 @@ public static IErlModule getModule(final IEditorInput editorInput)
return module;
}
final String path = file.getLocation().toPortableString();
- module = model.getModuleFromFile(model, file.getName(), null, path,
- path);
+ // TODO shouldn't we use the resource directly below?
+ module = model.getModuleFromFile(model, file.getName(), path,
+ file.getCharset(), path);
module.setResource(file);
return module;
}
@@ -139,22 +139,20 @@ public static IErlModule getModule(final IEditorInput editorInput)
final ErlangExternalEditorInput erlangExternalEditorInput = (ErlangExternalEditorInput) editorInput;
return erlangExternalEditorInput.getModule();
}
- String path = null, initialText = null;
+ String path = null;
+ String encoding = null;
if (editorInput instanceof IStorageEditorInput) {
final IStorageEditorInput sei = (IStorageEditorInput) editorInput;
try {
final IStorage storage = sei.getStorage();
final IPath p = storage.getFullPath();
path = p.toPortableString();
- String encoding;
if (storage instanceof IEncodedStorage) {
final IEncodedStorage encodedStorage = (IEncodedStorage) storage;
encoding = encodedStorage.getCharset();
} else {
encoding = ResourcesPlugin.getEncoding();
}
- initialText = Util.getInputStreamAsString(
- storage.getContents(), encoding);
} catch (final CoreException e) {
}
}
@@ -171,7 +169,7 @@ public static IErlModule getModule(final IEditorInput editorInput)
}
final IPath p = new Path(path);
return ErlModelManager.getErlangModel().getModuleFromFile(null,
- p.lastSegment(), initialText, path, path);
+ p.lastSegment(), path, encoding, path);
}
return null;
}

No commit comments for this range

Something went wrong with that request. Please try again.