1 11 package org.eclipse.jdt.internal.core.eval; 12 13 import org.eclipse.core.resources.IMarker; 14 import org.eclipse.core.resources.ResourcesPlugin; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.jdt.core.IJavaModelMarker; 17 import org.eclipse.jdt.core.compiler.CategorizedProblem; 18 import org.eclipse.jdt.core.eval.ICodeSnippetRequestor; 19 import org.eclipse.jdt.internal.compiler.ClassFile; 20 import org.eclipse.jdt.internal.core.builder.JavaBuilder; 21 import org.eclipse.jdt.internal.eval.IRequestor; 22 23 public class RequestorWrapper implements IRequestor { 24 25 ICodeSnippetRequestor requestor; 26 27 public RequestorWrapper(ICodeSnippetRequestor requestor) { 28 this.requestor = requestor; 29 } 30 33 public boolean acceptClassFiles(ClassFile[] classFiles, char[] codeSnippetClassName) { 34 int length = classFiles.length; 35 byte[][] classFileBytes = new byte[length][]; 36 String [][] compoundNames = new String [length][]; 37 for (int i = 0; i < length; i++) { 38 ClassFile classFile = classFiles[i]; 39 classFileBytes[i] = classFile.getBytes(); 40 char[][] classFileCompundName = classFile.getCompoundName(); 41 int length2 = classFileCompundName.length; 42 String [] compoundName = new String [length2]; 43 for (int j = 0; j < length2; j++){ 44 compoundName[j] = new String (classFileCompundName[j]); 45 } 46 compoundNames[i] = compoundName; 47 } 48 return this.requestor.acceptClassFiles(classFileBytes, compoundNames, codeSnippetClassName == null ? null : new String (codeSnippetClassName)); 49 } 50 53 public void acceptProblem(CategorizedProblem problem, char[] fragmentSource, int fragmentKind) { 54 try { 55 IMarker marker = ResourcesPlugin.getWorkspace().getRoot().createMarker(IJavaModelMarker.TRANSIENT_PROBLEM); 56 marker.setAttribute(IJavaModelMarker.ID, problem.getID()); 57 marker.setAttribute(IMarker.CHAR_START, problem.getSourceStart()); 58 marker.setAttribute(IMarker.CHAR_END, problem.getSourceEnd() + 1); 59 marker.setAttribute(IMarker.LINE_NUMBER, problem.getSourceLineNumber()); 60 marker.setAttribute(IMarker.MESSAGE, problem.getMessage()); 62 marker.setAttribute(IMarker.SEVERITY, (problem.isWarning() ? IMarker.SEVERITY_WARNING : IMarker.SEVERITY_ERROR)); 63 marker.setAttribute(IMarker.SOURCE_ID, JavaBuilder.SOURCE_ID); 64 this.requestor.acceptProblem(marker, new String (fragmentSource), fragmentKind); 65 } catch (CoreException e) { 66 e.printStackTrace(); 67 } 68 } 69 } 70 | Popular Tags |