KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > core > eval > RequestorWrapper


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
31  * @see ICodeSnippetRequestor
32  */

33 public boolean acceptClassFiles(ClassFile[] classFiles, char[] codeSnippetClassName) {
34     int length = classFiles.length;
35     byte[][] classFileBytes = new byte[length][];
36     String JavaDoc[][] compoundNames = new String JavaDoc[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 JavaDoc[] compoundName = new String JavaDoc[length2];
43         for (int j = 0; j < length2; j++){
44             compoundName[j] = new String JavaDoc(classFileCompundName[j]);
45         }
46         compoundNames[i] = compoundName;
47     }
48     return this.requestor.acceptClassFiles(classFileBytes, compoundNames, codeSnippetClassName == null ? null : new String JavaDoc(codeSnippetClassName));
49 }
50 /**
51  * @see ICodeSnippetRequestor
52  */

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.LOCATION, "#" + problem.getSourceLineNumber());
61
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 JavaDoc(fragmentSource), fragmentKind);
65     } catch (CoreException e) {
66         e.printStackTrace();
67     }
68 }
69 }
70
Popular Tags