use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.
the class DSAnnotationErrorHandler method generateMarkerData.
@Override
public List<MarkerData> generateMarkerData(IProject project, Project model, Location location) throws Exception {
List<MarkerData> result = new ArrayList<MarkerData>();
DeclarativeServicesAnnotationError dsError = (DeclarativeServicesAnnotationError) location.details;
IJavaProject javaProject = JavaCore.create(project);
Map<String, Object> attribs = new HashMap<String, Object>();
attribs.put(IMarker.MESSAGE, location.message.trim());
MarkerData md = null;
if (dsError.className != null) {
if (dsError.methodName != null && dsError.methodSignature != null) {
md = createMethodMarkerData(javaProject, dsError.className, dsError.methodName, dsError.methodSignature, attribs, false);
}
if (dsError.fieldName != null) {
md = createFieldMarkerData(javaProject, dsError.className, dsError.fieldName, attribs, false);
}
if (md == null) {
md = createTypeMarkerData(javaProject, dsError.className, attribs, false);
}
}
if (md == null) {
// No other marker could be created, so add a marker to the bnd file
result.add(new MarkerData(getDefaultResource(project), attribs, false));
}
result.add(md);
return result;
}
use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.
the class BaselineErrorHandler method generateAddedMethodMarker.
/*
List<MarkerData> generateAddedTypeMarker(IJavaProject javaProject, String name, Delta ifAdded) {
// TODO Auto-generated method stub
return null;
}
*/
List<MarkerData> generateAddedMethodMarker(IJavaProject javaProject, String className, final String methodName, final Delta requiresDelta) throws JavaModelException {
final List<MarkerData> markers = new LinkedList<MarkerData>();
final CompilationUnit ast = createAST(javaProject, className);
if (ast != null) {
ast.accept(new ASTVisitor() {
@Override
public boolean visit(MethodDeclaration methodDecl) {
String signature = ASTUtil.buildMethodSignature(methodDecl);
if (signature.equals(methodName)) {
// Create the marker attribs here
Map<String, Object> attribs = new HashMap<String, Object>();
attribs.put(IMarker.CHAR_START, methodDecl.getStartPosition());
attribs.put(IMarker.CHAR_END, methodDecl.getStartPosition() + methodDecl.getLength());
String message = String.format("This method was added, which requires a %s change to the package.", requiresDelta);
attribs.put(IMarker.MESSAGE, message);
markers.add(new MarkerData(ast.getJavaElement().getResource(), attribs, false));
}
return false;
}
});
}
return markers;
}
use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.
the class BundleActivatorErrorHandler method generateMarkerData.
@Override
public List<MarkerData> generateMarkerData(IProject project, Project model, Location location) throws Exception {
List<MarkerData> result = new ArrayList<MarkerData>();
BundleActivatorError baError = (BundleActivatorError) location.details;
IJavaProject javaProject = JavaCore.create(project);
Map<String, Object> attribs = createMessageMarkerAttributes(baError, location.message);
//Eclipse line numbers are 1 indexed
attribs.put(IMarker.LINE_NUMBER, location.line + 1);
// Add a marker to the bnd file on the BundleActivator line
result.add(new MarkerData(getDefaultResource(project), attribs, false));
MarkerData md;
switch(baError.errorType) {
case NO_SUITABLE_CONSTRUCTOR:
md = createMethodMarkerData(javaProject, baError.activatorClassName, "<init>", "()V", createMessageMarkerAttributes(baError, location.message), false);
if (md != null) {
result.add(md);
break;
}
//$FALL-THROUGH$
case IS_INTERFACE:
case IS_ABSTRACT:
case NOT_PUBLIC:
case NOT_AN_ACTIVATOR:
case DEFAULT_PACKAGE:
case IS_IMPORTED:
md = createTypeMarkerData(javaProject, baError.activatorClassName, createMessageMarkerAttributes(baError, location.message), false);
if (md != null)
result.add(md);
break;
case NOT_ACCESSIBLE:
default:
//No file to mark
break;
}
return result;
}
use of org.bndtools.build.api.MarkerData in project bndtools by bndtools.
the class MarkerSupport method createMarker.
void createMarker(Processor model, int severity, String formatted, String markerType) throws Exception {
Location location = model != null ? model.getLocation(formatted) : null;
if (location != null) {
String type = location.details != null ? location.details.getClass().getName() : null;
BuildErrorDetailsHandler handler = BuildErrorDetailsHandlers.INSTANCE.findHandler(type);
List<MarkerData> markers = handler.generateMarkerData(project, model, location);
for (MarkerData markerData : markers) {
IResource resource = markerData.getResource();
if (resource != null && resource.exists()) {
String typeOverride = markerData.getTypeOverride();
IMarker marker = resource.createMarker(typeOverride != null ? typeOverride : markerType);
marker.setAttribute(IMarker.SEVERITY, severity);
marker.setAttribute("$bndType", type);
// Set location information
if (location.header != null)
marker.setAttribute(BNDTOOLS_MARKER_HEADER_ATTR, location.header);
if (location.context != null)
marker.setAttribute(BNDTOOLS_MARKER_CONTEXT_ATTR, location.context);
if (location.file != null)
marker.setAttribute(BNDTOOLS_MARKER_FILE_ATTR, location.file);
if (location.reference != null)
marker.setAttribute(BNDTOOLS_MARKER_REFERENCE_ATTR, location.reference);
marker.setAttribute(BuildErrorDetailsHandler.PROP_HAS_RESOLUTIONS, markerData.hasResolutions());
for (Entry<String, Object> attrib : markerData.getAttribs().entrySet()) marker.setAttribute(attrib.getKey(), attrib.getValue());
}
}
return;
}
String defaultResource = model instanceof Project ? Project.BNDFILE : model instanceof Workspace ? Workspace.BUILDFILE : null;
IResource resource = DefaultBuildErrorDetailsHandler.getDefaultResource(project, defaultResource);
if (resource.exists()) {
IMarker marker = resource.createMarker(markerType);
marker.setAttribute(IMarker.SEVERITY, severity);
marker.setAttribute(IMarker.MESSAGE, formatted);
}
}
Aggregations