aboutsummaryrefslogtreecommitdiff
path: root/src/lombok/eclipse/Eclipse.java
blob: 961b9536f3aafa19b0a5aa200e4ee149ffc94d26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package lombok.eclipse;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.Bundle;

public class Eclipse {
	private static final String DEFAULT_BUNDLE = "org.eclipse.jdt.core";
	public static void error(String message) {
		error(message, DEFAULT_BUNDLE, null);
	}
	
	public static void error(String message, Throwable error) {
		error(message, DEFAULT_BUNDLE, error);
	}
	
	public static void error(String message, String bundleName) {
		error(message, bundleName, null);
	}
	
	public static void error(String message, String bundleName, Throwable error) {
		Bundle bundle = Platform.getBundle(bundleName);
		if ( bundle == null ) {
			System.err.printf("Can't find bundle %s while trying to report error:\n%s\n", bundleName, message);
			return;
		}
		
		ILog log = Platform.getLog(bundle);
		
		log.log(new Status(IStatus.ERROR, bundleName, message, error));
	}
	
	static String toQualifiedName(char[][] typeName) {
		StringBuilder sb = new StringBuilder();
		boolean first = true;
		for ( char[] c : typeName ) {
			sb.append(first ? "" : ".").append(c);
			first = false;
		}
		return sb.toString();
	}
}