...
 
Commits (6)
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>eclipse.platform.text</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>
......@@ -90,6 +90,7 @@
<make-bundle name="org.eclipse.ui.genericeditor" basedir="." depends="org.eclipse.jface.text,org.eclipse.text,org.eclipse.ui.editors,org.eclipse.ui.workbench.texteditor">
<pathelement path="/usr/share/java/eclipse-core-commands.jar"/>
<pathelement path="/usr/share/java/eclipse-core-contenttype.jar"/>
<pathelement path="/usr/share/java/eclipse-core-expressions.jar"/>
<pathelement path="/usr/share/java/eclipse-core-filebuffers.jar"/>
<pathelement path="/usr/share/java/eclipse-core-jobs.jar"/>
<pathelement path="/usr/share/java/eclipse-core-resources.jar"/>
......@@ -98,6 +99,7 @@
<pathelement path="/usr/share/java/eclipse-ui-ide.jar"/>
<pathelement path="/usr/share/java/eclipse-ui-workbench.jar"/>
<pathelement path="/usr/share/java/equinox-common.jar"/>
<pathelement path="/usr/share/java/equinox-preferences.jar"/>
<pathelement path="/usr/share/java/equinox-registry.jar"/>
<pathelement path="/usr/share/java/swt4.jar"/>
</make-bundle>
......
eclipse-platform-text (4.8-1) unstable; urgency=medium
* New upstream release
- Fixed a compilation error in org.eclipse.jface.text
- Depend on libswt-gtk-4-java (>= 4.8)
- Updated the bundle dependencies
-- Emmanuel Bourg <ebourg@apache.org> Wed, 28 Nov 2018 01:50:48 +0100
eclipse-platform-text (4.7.3-5) unstable; urgency=medium
* Build more bundles:
......
......@@ -26,7 +26,7 @@ Build-Depends:
libequinox-preferences-java,
libequinox-registry-java,
libicu4j-java,
libswt-gtk-4-java,
libswt-gtk-4-java (>= 4.8),
eclipse-debian-helper
Standards-Version: 4.2.1
Vcs-Git: https://salsa.debian.org/java-team/eclipse-platform-text.git
......@@ -59,7 +59,7 @@ Depends:
libeclipse-core-runtime-java,
libequinox-common-java,
libicu4j-java,
libswt-gtk-4-java
libswt-gtk-4-java (>= 4.8)
Description: Eclipse JFace Text
Eclipse Platform Text is part of the Platform UI project and provides
the basic building blocks for text and text editors within Eclipse and
......@@ -152,6 +152,7 @@ Depends:
${bundle:Depends},
libeclipse-core-commands-java,
libeclipse-core-contenttype-java,
libeclipse-core-expressions-java,
libeclipse-core-filebuffers-java,
libeclipse-core-jobs-java,
libeclipse-core-resources-java,
......@@ -160,6 +161,7 @@ Depends:
libeclipse-ui-ide-java,
libeclipse-ui-workbench-java,
libequinox-common-java,
libequinox-preferences-java,
libequinox-registry-java,
libswt-gtk-4-java
Description: EEclipse Generic and Extensible Text Editor
......@@ -186,7 +188,7 @@ Depends:
libequinox-preferences-java,
libequinox-registry-java,
libicu4j-java,
libswt-gtk-4-java
libswt-gtk-4-java (>= 4.8)
Description: Eclipse Text Editor Framework
Eclipse Platform Text is part of the Platform UI project and provides
the basic building blocks for text and text editors within Eclipse and
......
Description: Fixes a compilation error (maybe a difference between javac and ecj?)
Author: Emmanuel Bourg <ebourg@apache.org>
Forwarded: no
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/codemining/CodeMiningManager.java
@@ -182,8 +182,10 @@
return 0;
}
});
- return codeMinings.stream().collect(Collectors.groupingBy(ICodeMining::getPosition, LinkedHashMap::new,
- Collectors.mapping(Function.identity(), Collectors.toList())));
+
+ java.util.stream.Collector mappingCollector = Collectors.mapping(Function.identity(), Collectors.toList());
+ java.util.stream.Collector groupingCollector = Collectors.groupingBy(ICodeMining::getPosition, LinkedHashMap::new, mappingCollector);
+ return (Map) codeMinings.stream().collect(groupingCollector);
}
/**
01-fix-compilation-error.patch
......@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %Plugin.name
Bundle-SymbolicName: org.eclipse.core.filebuffers.tests;singleton:=true
Bundle-Version: 3.11.100.qualifier
Bundle-Version: 3.11.200.qualifier
Bundle-Activator: org.eclipse.core.filebuffers.tests.FileBuffersTestPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Plugin.providerName
......@@ -17,3 +17,4 @@ Require-Bundle:
org.junit;bundle-version="4.12.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Eclipse-BundleShape: dir
Automatic-Module-Name: org.eclipse.core.filebuffers.tests
......@@ -14,12 +14,12 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>eclipse.platform.text</groupId>
<version>4.7.3-SNAPSHOT</version>
<version>4.8.0-SNAPSHOT</version>
<relativePath>../tests-pom/</relativePath>
</parent>
<groupId>org.eclipse.core</groupId>
<artifactId>org.eclipse.core.filebuffers.tests</artifactId>
<version>3.11.100-SNAPSHOT</version>
<version>3.11.200-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<properties>
<testSuite>${project.artifactId}</testSuite>
......
......@@ -69,12 +69,12 @@ public class FileBufferCreation {
private IPath createLinkedFile(String linkedFileName, String linkedFileTarget) throws CoreException {
IFile linkedFile= ResourceHelper.createLinkedFile(fProject, new Path(linkedFileName), FileBuffersTestPlugin.getDefault(), new Path(linkedFileTarget));
return linkedFile != null ? linkedFile.getFullPath() : null;
return linkedFile.getFullPath();
}
private IPath createLinkedFolder(String linkedFolderName, String linkedFolderTarget) throws CoreException {
IFolder linkedFolder= ResourceHelper.createLinkedFolder(fProject, new Path(linkedFolderName), FileBuffersTestPlugin.getDefault(), new Path(linkedFolderTarget));
return linkedFolder != null ? linkedFolder.getFullPath() : null;
return linkedFolder.getFullPath();
}
/*
......
......@@ -862,7 +862,7 @@ public abstract class FileBufferFunctions {
IPath newLocation= moveUnderlyingFile();
if (newLocation != null) {
if (listener.count != 1 || listener.buffer != fileBuffer || !newLocation.equals(listener.newLocation)) {
StringBuffer buf= new StringBuffer();
StringBuilder buf= new StringBuilder();
buf.append("Wrong listener notifcation in " + getClass().getName() + ":\n");
buf.append("listener.count: " + listener.count + " (expected: 1)\n");
if (newLocation.equals(listener.newLocation))
......
......@@ -14,6 +14,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import org.junit.After;
import org.junit.Test;
......@@ -68,7 +70,11 @@ public class FileBuffersForNonExistingWorkspaceFiles extends FileBufferFunctions
@Test
public void testBug118199_fixed() throws Exception {
IFile file= getProject().getWorkspace().getRoot().getFileForLocation(getPath());
IPath location= getPath();
IFile file= getProject().getWorkspace().getRoot().getFileForLocation(location);
if (file == null) {
throw new IOException("File '" + location + "' can not be found."); //$NON-NLS-1$ //$NON-NLS-2$
}
IPath path= file.getFullPath();
assertFalse(file.exists());
fManager.connect(path, LocationKind.IFILE, null);
......
......@@ -12,6 +12,8 @@ package org.eclipse.core.filebuffers.tests;
import static org.junit.Assert.*;
import java.io.IOException;
import org.junit.After;
import org.junit.Test;
......@@ -66,7 +68,11 @@ public class FileStoreFileBuffersForNonExistingWorkspaceFiles extends FileStoreF
@Test
public void testBug118199_fixed() throws Exception {
IFile file= getProject().getWorkspace().getRoot().getFileForLocation(getPath());
IPath location= getPath();
IFile file= getProject().getWorkspace().getRoot().getFileForLocation(location);
if (file == null) {
throw new IOException("File '" + location + "' can not be found."); //$NON-NLS-1$ //$NON-NLS-2$
}
IPath path= file.getFullPath();
assertFalse(file.exists());
fManager.connect(path, LocationKind.IFILE, null);
......
......@@ -64,25 +64,8 @@ public class FileTool {
String entryName = entry.getName();
File file = new File(dstDir, changeSeparator(entryName, '/', File.separatorChar));
file.getParentFile().mkdirs();
InputStream src = null;
OutputStream dst = null;
try {
src = zipFile.getInputStream(entry);
dst = new FileOutputStream(file);
try (InputStream src= zipFile.getInputStream(entry); OutputStream dst= new FileOutputStream(file)) {
transferData(src, dst);
} finally {
if(dst != null){
try {
dst.close();
} catch(IOException e){
}
}
if(src != null){
try {
src.close();
} catch(IOException e){
}
}
}
}
} finally {
......@@ -162,6 +145,9 @@ public class FileTool {
public static void copy(File src, File dst) throws IOException {
if(src.isDirectory()){
String[] srcChildren = src.list();
if (srcChildren == null) {
throw new IOException("Content from directory '" + src.getAbsolutePath() + "' can not be listed."); //$NON-NLS-1$ //$NON-NLS-2$
}
for(int i = 0; i < srcChildren.length; ++i){
File srcChild= new File(src, srcChildren[i]);
File dstChild= new File(dst, srcChildren[i]);
......
......@@ -58,7 +58,7 @@ public class MockDocumentSetupParticipants {
@Override
public void setup(IDocument document, IPath location, LocationKind locationKind) {
if (locationKind == LocationKind.IFILE)
append(document, new StringBuffer(location.toPortableString()).reverse().toString());
append(document, new StringBuilder(location.toPortableString()).reverse().toString());
}
}
......@@ -66,7 +66,7 @@ public class MockDocumentSetupParticipants {
@Override
public void setup(IDocument document, IPath location, LocationKind locationKind) {
if (locationKind == LocationKind.LOCATION)
append(document, new StringBuffer(location.toPortableString()).reverse().toString());
append(document, new StringBuilder(location.toPortableString()).reverse().toString());
}
}
......@@ -74,7 +74,7 @@ public class MockDocumentSetupParticipants {
@Override
public void setup(IDocument document, IPath location, LocationKind locationKind) {
if (locationKind == LocationKind.NORMALIZE)
append(document, new StringBuffer(location.toPortableString()).reverse().toString());
append(document, new StringBuilder(location.toPortableString()).reverse().toString());
}
}
......
......@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.core.filebuffers; singleton:=true
Bundle-Version: 3.6.100.qualifier
Bundle-Version: 3.6.200.qualifier
Bundle-Activator: org.eclipse.core.internal.filebuffers.FileBuffersPlugin
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %providerName
......@@ -18,3 +18,4 @@ Require-Bundle:
org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: com.ibm.icu.text
Automatic-Module-Name: org.eclipse.core.filebuffers
Bug 534597 - Unanticipated comparator errors in I20180511-2000
\ No newline at end of file
......@@ -14,10 +14,10 @@
<parent>
<artifactId>eclipse.platform.text</artifactId>
<groupId>eclipse.platform.text</groupId>
<version>4.7.3-SNAPSHOT</version>
<version>4.8.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.core</groupId>
<artifactId>org.eclipse.core.filebuffers</artifactId>
<version>3.6.100-SNAPSHOT</version>
<version>3.6.200-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
......@@ -532,7 +532,7 @@ public class FileStoreTextFileBuffer extends FileStoreFileBuffer implements ITex
}
in= new BufferedReader(new InputStreamReader(contentStream, encoding), BUFFER_SIZE);
StringBuffer buffer= new StringBuffer(BUFFER_SIZE);
StringBuilder buffer= new StringBuilder(BUFFER_SIZE);
char[] readBuffer= new char[READER_CHUNK_SIZE];
int n= in.read(readBuffer);
while (n > 0) {
......
......@@ -521,7 +521,7 @@ public class ResourceTextFileBuffer extends ResourceFileBuffer implements ITextF
}
in= new BufferedReader(new InputStreamReader(contentStream, encoding), BUFFER_SIZE);
StringBuffer buffer= new StringBuffer(BUFFER_SIZE);
StringBuilder buffer= new StringBuilder(BUFFER_SIZE);
char[] readBuffer= new char[READER_CHUNK_SIZE];
int n= in.read(readBuffer);
while (n > 0) {
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/bin/
/target/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.jface.text.examples</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
eclipse.preferences.version=1
pluginProject.extensions=false
resolve.requirebundle=false
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CodeMinig Examples
Bundle-SymbolicName: org.eclipse.jface.text.examples
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.eclipse.jface.text,
org.eclipse.core.runtime,
org.eclipse.swt,
org.eclipse.jface;bundle-version="3.14.0"
Automatic-Module-Name: org.eclipse.jface.text.examples
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012, 2014 Eclipse Foundation and others.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Distribution License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/org/documents/edl-v10.php
Contributors:
Igor Fedorenko - initial implementation
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>eclipse.platform.text</artifactId>
<groupId>eclipse.platform.text</groupId>
<version>4.8.0-SNAPSHOT</version>
</parent>
<groupId>org.eclipse.core</groupId>
<artifactId>org.eclipse.jface.text.examples</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>
/**
* Copyright (c) 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 <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
*/
package org.eclipse.jface.text.examples.codemining;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
import org.eclipse.jface.text.codemining.LineHeaderCodeMining;
/**
* Abstract class for class name mining.
*
*/
public abstract class AbstractClassCodeMining extends LineHeaderCodeMining {
private final String className;
public AbstractClassCodeMining(String className, int afterLineNumber, IDocument document,
ICodeMiningProvider resolver) throws BadLocationException {
super(afterLineNumber, document, resolver);
this.className = className;
}
public String getClassName() {
return className;
}
public static String getLineText(IDocument document, int line) {
try {
int lo = document.getLineOffset(line);
int ll = document.getLineLength(line);
return document.get(lo, ll);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
/**
* Copyright (c) 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 <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
*/
package org.eclipse.jface.text.examples.codemining;
import java.util.concurrent.CompletableFuture;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
/**
* Class implementation mining.
*
*/
public class ClassImplementationCodeMining extends AbstractClassCodeMining {
public ClassImplementationCodeMining(String className, int afterLineNumber, IDocument document,
ICodeMiningProvider provider) throws BadLocationException {
super(className, afterLineNumber, document, provider);
}
@Override
protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
return CompletableFuture.runAsync(() -> {
IDocument document = viewer.getDocument();
String className = super.getClassName();
int refCount = 0;
int lineCount = document.getNumberOfLines();
for (int i = 0; i < lineCount; i++) {
// check if request was canceled.
monitor.isCanceled();
String line = getLineText(document, i);
refCount += line.contains("implements " + className) ? 1 : 0;
}
super.setLabel(refCount + " implementation");
});
}
}
/**
* Copyright (c) 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 <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
*/
package org.eclipse.jface.text.examples.codemining;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.codemining.AbstractCodeMiningProvider;
import org.eclipse.jface.text.codemining.ICodeMining;
/**
* Class implementation mining provider.
*
*/
public class ClassImplementationsCodeMiningProvider extends AbstractCodeMiningProvider {
@Override
public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
IProgressMonitor monitor) {
return CompletableFuture.supplyAsync(() -> {
IDocument document = viewer.getDocument();
List<ICodeMining> lenses = new ArrayList<>();
int lineCount = document.getNumberOfLines();
for (int i = 0; i < lineCount; i++) {
// check if request was canceled.
monitor.isCanceled();
updateContentMining(i, document, "class ", lenses);
updateContentMining(i, document, "interface ", lenses);
}
return lenses;
});
}
private void updateContentMining(int lineIndex, IDocument document, String token, List<ICodeMining> lenses) {
String line = AbstractClassCodeMining.getLineText(document, lineIndex).trim();
int index = line.indexOf(token);
if (index == 0) {
String className = line.substring(index + token.length(), line.length());
index = className.indexOf(" ");
if (index != -1) {
className = className.substring(0, index);
}
if (className.length() > 0) {
try {
lenses.add(new ClassImplementationCodeMining(className, lineIndex, document, this));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
}
}
/**
* Copyright (c) 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 <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
*/
package org.eclipse.jface.text.examples.codemining;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
/**
* Class reference mining.
*
*/
public class ClassReferenceCodeMining extends AbstractClassCodeMining {
private Object lock = new Object();
public ClassReferenceCodeMining(String className, int afterLineNumber, IDocument document, ICodeMiningProvider provider)
throws BadLocationException {
super(className, afterLineNumber, document, provider);
}
@Override
protected CompletableFuture<Void> doResolve(ITextViewer viewer, IProgressMonitor monitor) {
return CompletableFuture.runAsync(() -> {
IDocument document = viewer.getDocument();
String className = super.getClassName();
try {
int wait = Integer.parseInt(className);
try {
for (int i = 0; i < wait; i++) {
monitor.isCanceled();
synchronized (lock) {
lock.wait(1000);
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
} catch (NumberFormatException e) {
} catch (CancellationException e) {
e.printStackTrace();
throw e;
}
int refCount = 0;
int lineCount = document.getNumberOfLines();
for (int i = 0; i < lineCount; i++) {
// check if request was canceled.
monitor.isCanceled();
String line = getLineText(document, i);
refCount += line.contains("new " + className) ? 1 : 0;
}
super.setLabel(refCount + " references");
});
}
}
/**
* Copyright (c) 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 <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
*/
package org.eclipse.jface.text.examples.codemining;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.codemining.AbstractCodeMiningProvider;
import org.eclipse.jface.text.codemining.ICodeMining;
/**
* Class reference mining provider.
*
*/
public class ClassReferenceCodeMiningProvider extends AbstractCodeMiningProvider {
@Override
public CompletableFuture<List<? extends ICodeMining>> provideCodeMinings(ITextViewer viewer,
IProgressMonitor monitor) {
return CompletableFuture.supplyAsync(() -> {
IDocument document = viewer.getDocument();
List<ICodeMining> lenses = new ArrayList<>();
int lineCount = document.getNumberOfLines();
for (int i = 0; i < lineCount; i++) {
// check if request was canceled.
monitor.isCanceled();
String line = AbstractClassCodeMining.getLineText(document, i).trim();
int index = line.indexOf("class ");
if (index == 0) {
String className = line.substring(index + "class ".length(), line.length()).trim();
if (className.length() > 0) {
try {
lenses.add(new ClassReferenceCodeMining(className, i, document, this));
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
}
return lenses;
});
}
}
/**
* Copyright (c) 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 <angelo.zerr@gmail.com> - [CodeMining] Add CodeMining support in SourceViewer - Bug 527515
*/
package org.eclipse.jface.text.examples.codemining;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewerExtension2;
import org.eclipse.jface.text.codemining.ICodeMiningProvider;
import org.eclipse.jface.text.reconciler.DirtyRegion;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.jface.text.reconciler.MonoReconciler;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationModel;
import org.eclipse.jface.text.source.AnnotationPainter;
import org.eclipse.jface.text.source.IAnnotationAccess;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.ISourceViewerExtension5;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* A Code Mining demo with class references and implementations minings.
*
*/
public class CodeMiningDemo {
public static void main(String[] args) throws Exception {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());
shell.setText("Code Mining demo");
ISourceViewer sourceViewer = new SourceViewer(shell, null, SWT.V_SCROLL | SWT.BORDER);
sourceViewer.setDocument(
new Document("// Type class & new keyword and see references CodeMining\n"
+ "// Name class with a number N to emulate Nms before resolving the references CodeMining \n\n"
+ "class A\n" + "new A\n" + "new A\n\n" + "class 5\n" + "new 5\n" + "new 5\n" + "new 5"),
new AnnotationModel());
// Add AnnotationPainter (required by CodeMining)
addAnnotationPainter(sourceViewer);
// Initialize codemining providers
((ISourceViewerExtension5) sourceViewer).setCodeMiningProviders(new ICodeMiningProvider[] {
new ClassReferenceCodeMiningProvider(), new ClassImplementationsCodeMiningProvider() });
// Execute codemining in a reconciler
MonoReconciler reconciler = new MonoReconciler(new IReconcilingStrategy() {
@Override
public void setDocument(IDocument document) {
((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
}
@Override
public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
}
@Override
public void reconcile(IRegion partition) {
((ISourceViewerExtension5) sourceViewer).updateCodeMinings();
}
}, false);
reconciler.install(sourceViewer);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private static void addAnnotationPainter(ISourceViewer viewer) {
IAnnotationAccess annotationAccess = new IAnnotationAccess() {
@Override
public Object getType(Annotation annotation) {
return annotation.getType();
}
@Override
public boolean isMultiLine(Annotation annotation) {
return true;
}
@Override
public boolean isTemporary(Annotation annotation) {
return true;
}
};
AnnotationPainter painter = new AnnotationPainter(viewer, annotationAccess);
((ITextViewerExtension2) viewer).addPainter(painter);
// Register this annotation painter as CodeMining annotation painter.
((ISourceViewerExtension5) viewer).setCodeMiningAnnotationPainter(painter);
}
}
/**s
* Copyright (c) 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 <angelo.zerr@gmail.com> - [CodeMining] Provide inline annotations support - Bug 527675
*/
package org.eclipse.jface.text.examples.sources.inlined;
import java.util.function.Consumer;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.inlined.LineContentAnnotation;
import org.eclipse.jface.util.Geometry;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.FontMetrics;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.ColorDialog;
import org.eclipse.swt.widgets.Shell;
/**
* Color annotation displays a colorized square before the rgb declaration.
*/
public class ColorAnnotation extends LineContentAnnotation {
private Color color;
private Consumer<MouseEvent> action = e -> {
StyledText styledText = super.getTextWidget();
Shell shell = new Shell(styledText.getDisplay());
Rectangle location = Geometry.toDisplay(styledText, new Rectangle(e.x, e.y, 1, 1));
shell.setLocation(location.x, location.y);
// Open color dialog
ColorDialog dialog = new ColorDialog(shell);
// dialog.setRGB(annotation.getRGBA().rgb);
RGB color = dialog.open();
if (color != null) {
// Color was selected, update the viewer
try {
int offset = getPosition().getOffset();
IDocument document = getViewer().getDocument();
IRegion line = document.getLineInformation(document.getLineOfOffset(offset));
int length = line.getLength() - (offset - line.getOffset());
String rgb = formatToRGB(color);
document.replace(offset, length, rgb);
} catch (BadLocationException e1) {
}
}
};
/**
* Format the given rgb to hexa color.
*
* @param rgb
* @return the hexa color from the given rgb.
*/
private static String formatToRGB(RGB rgb) {
return new StringBuilder("rgb(").append(rgb.red).append(",").append(rgb.green).append(",").append(rgb.blue)
.append(")").toString();
}
public ColorAnnotation(Position pos, ISourceViewer viewer) {
super(pos, viewer);
}
public void setColor(Color color) {
this.color = color;
}
@Override
protected int drawAndComputeWidth(GC gc, StyledText textWidget, int offset, int length, Color color, int x, int y) {
FontMetrics fontMetrics = gc.getFontMetrics();
int size = getSquareSize(fontMetrics);
x += fontMetrics.getLeading();
y += fontMetrics.getDescent();
Rectangle rect = new Rectangle(x, y, size, size);
// Fill square
gc.setBackground(this.color);
gc.fillRectangle(rect);
// Draw square box
gc.setForeground(textWidget.getForeground());
gc.drawRectangle(rect);
return getSquareWidth(gc.getFontMetrics());
}
/**
* Returns the colorized square size.
*
* @param fontMetrics
* @return the colorized square size.
*/
public static int getSquareSize(FontMetrics fontMetrics) {
return fontMetrics.getHeight() - 2 * fontMetrics.getDescent();
}
/**
* Compute width of square
*
* @param styledText
* @return the width of square
*/
private static int getSquareWidth(FontMetrics fontMetrics) {
// width = 2 spaces + size width of square
int width = 2 * fontMetrics.getAverageCharWidth() + getSquareSize(fontMetrics);
return width;
}
@Override
public Consumer<MouseEvent> getAction(MouseEvent e) {
return action;
}
}
/**
* Copyright (c) 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 <angelo.zerr@gmail.com> - [CodeMining] Provide inline annotations support - Bug 527675
*/
package org.eclipse.jface.text.examples.sources.inlined;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.inlined.LineHeaderAnnotation;
/**
* Color status annotation shows the result of rgb parse before each line which
* defines 'color:'.
*/
public class ColorStatusAnnotation extends LineHeaderAnnotation {
public ColorStatusAnnotation(Position position, ISourceViewer viewer) {
super(position, viewer);
}
public void setStatus(String status) {
super.setText(status);
}
}
/**
* Copyright (c) 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 <angelo.zerr@gmail.com> - [CodeMining] Provide inline annotations support - Bug 527675
*/
package org.eclipse.jface.text.examples.sources.inlined;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewerExtension2;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.reconciler.DirtyRegion;
import org.eclipse.jface.text.reconciler.IReconcilingStrategy;
import org.eclipse.jface.text.reconciler.MonoReconciler;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.AnnotationModel;
import org.eclipse.jface.text.source.AnnotationPainter;
import org.eclipse.jface.text.source.IAnnotationAccess;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.text.source.inlined.AbstractInlinedAnnotation;
import org.eclipse.jface.text.source.inlined.InlinedAnnotationSupport;
import org.eclipse.jface.text.source.inlined.LineContentAnnotation;
import org.eclipse.jface.text.source.inlined.LineHeaderAnnotation;
import org.eclipse.jface.text.source.inlined.Positions;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* An inlined demo with {@link LineHeaderAnnotation} and
* {@link LineContentAnnotation} annotations both:
*
* <ul>
* <li>a status OK, NOK is displayed before the line which starts with 'color:'.
* This status is the result of the content after 'color' which must be a rgb
* content. Here {@link ColorStatusAnnotation} is used.</li>
* <li>a colorized square is displayed before the rgb declaration (inside the
* line content). Here {@link ColorAnnotation} is used.</li>
* </ul>
*
*/
public class InlinedAnnotationDemo {
public static void main(String[] args) throws Exception {
Display display = new Display();
Shell shell = new Shell(display);