Skip to content
Browse files

Made sure that no empty .noparse cache-files were created

  • Loading branch information...
1 parent a933e59 commit 3bceb01d17e6f9e68120812cf7f39932b6d112cc @jakobc jakobc committed Mar 8, 2013
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
87 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,22 +71,34 @@
"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;
private boolean parsed;
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,10 +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(),
- initialText, 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
@@ -122,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();
}
@@ -181,7 +238,7 @@ public IResource getResource() {
@Override
public IResource getCorrespondingResource() {
- return fFile;
+ return file;
}
public ISourceRange getSourceRange() throws ErlModelException {
@@ -446,7 +503,7 @@ public synchronized void resetAndCacheScannerAndParser(final String newText)
@Override
public void setResource(final IFile file) {
- fFile = file;
+ this.file = file;
}
@Override
@@ -477,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
43 org.erlide.model/src/org/erlide/model/internal/root/ErlModel.java
@@ -67,7 +67,6 @@
import org.erlide.model.util.ResourceUtil;
import org.erlide.util.ErlLogger;
import org.erlide.util.SystemConfiguration;
-import org.erlide.util.Util;
import com.ericsson.otp.erlang.OtpErlangList;
import com.ericsson.otp.erlang.OtpErlangObject;
@@ -526,12 +525,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);
@@ -551,12 +563,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);
}
@@ -693,7 +699,7 @@ public IErlElement createFile(final IFile file, IParent parent) {
}
}
if (CommonUtils.isErlangFileContentFileName(file.getName())) {
- return createModuleFrom(file, parent);
+ return createModuleFromFile(file, parent);
}
return null;
}
@@ -713,25 +719,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)) {
- String initialText = "";
- String charset;
- if (file.isAccessible() && file.isSynchronized(0)) {
- try {
- charset = file.getCharset();
- initialText = Util.getInputStreamAsString(
- file.getContents(), charset);
- } catch (final CoreException e) {
- ErlLogger.warn(e);
- }
- }
- final IErlModule module = new ErlModule(parent, name, initialText,
- file, null);
+ final IErlModule module = new ErlModule(parent, name, file);
if (parent != null) {
parent.addChild(module);
}
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,31 +129,30 @@ 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;
}
if (editorInput instanceof ErlangExternalEditorInput) {
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;
}

0 comments on commit 3bceb01

Please sign in to comment.
Something went wrong with that request. Please try again.