-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor LineList class to AbstractLineList to implement it and do tests
easily for synch between IDocument and LineList. See #5
- Loading branch information
1 parent
2641154
commit 5d846ac
Showing
9 changed files
with
164 additions
and
110 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/AbstractLineList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/** | ||
* Copyright (c) 2015-2017 Angelo ZERR. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Angelo Zerr <[email protected]> - initial API and implementation | ||
*/ | ||
package org.eclipse.tm4e.core.model; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
/** | ||
* Abstract class for Model lines used by the TextMate model. Implementation | ||
* class must : | ||
* | ||
* <ul> | ||
* <li>synchronizes lines with the lines of the editor content when it changed.</li> | ||
* <li>call {@link AbstractLineList#invalidateLine(int)} with the first changed line.</li> | ||
* </ul> | ||
* | ||
*/ | ||
public abstract class AbstractLineList implements IModelLines { | ||
|
||
private final List<ModelLine> list = Collections.synchronizedList(new ArrayList<>()); | ||
|
||
private TMModel model; | ||
|
||
public AbstractLineList() { | ||
} | ||
|
||
void setModel(TMModel model) { | ||
this.model = model; | ||
} | ||
|
||
@Override | ||
public void addLine(int line) { | ||
try { | ||
this.list.add(line, new ModelLine()); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public void removeLine(int line) { | ||
this.list.remove(line); | ||
} | ||
|
||
@Override | ||
public void updateLine(int line) { | ||
try { | ||
// this.list.get(line).text = this.lineToTextResolver.apply(line); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
@Override | ||
public ModelLine get(int index) { | ||
return this.list.get(index); | ||
} | ||
|
||
@Override | ||
public int getSize() { | ||
return this.list.size(); | ||
} | ||
|
||
@Override | ||
public void forEach(Consumer<ModelLine> consumer) { | ||
this.list.forEach(consumer); | ||
} | ||
|
||
protected void invalidateLine(int lineIndex) { | ||
if (model != null) { | ||
model.invalidateLine(lineIndex); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 0 additions & 53 deletions
53
org.eclipse.tm4e.core/src/main/java/org/eclipse/tm4e/core/model/LineList.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
|
||
import java.util.List; | ||
|
||
class ModelLine { | ||
public class ModelLine { | ||
|
||
//String text; | ||
boolean isInvalid; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.