Changeset 3778
- Timestamp:
- May 24, 2008, 1:34:12 PM (13 years ago)
- Location:
- devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/core
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/core/RfpBuilder.java
r3766 r3778 1 1 package org.refal.rfpdt.core; 2 2 3 import java.io.ByteArrayInputStream;4 3 import java.io.InputStream; 5 4 import java.io.InputStreamReader; … … 57 56 } 58 57 59 private void createClassFile (String className, byte[] bytes) {60 try {61 IFile classFile = getRfpProject().getClassFile(className);62 if (classFile.exists())63 classFile.delete(true, false, null);64 InputStream inputStream = new ByteArrayInputStream(bytes);65 classFile.create(inputStream, true, null);66 classFile.setDerived(true);67 inputStream.close();68 } catch (Exception e) {69 RfpCore.log(e);70 }71 }72 73 58 private void deleteClassFiles (IFile file) { 74 59 RfpProject rfpProject = getRfpProject(); … … 76 61 if (moduleName == null) 77 62 return; 78 IFile classFile = rfpProject.getClassFile(moduleName); 79 try { 80 for (int i = 0; true; i++) { 81 if (classFile.exists()) 82 classFile.delete(true, false, null); 83 else 84 break; 85 classFile = rfpProject.getClassFile(moduleName + "$" + i); 86 } 87 } catch (CoreException e) { 88 RfpCore.log(e); 89 } 63 rfpProject.deleteClassFiles(moduleName); 90 64 } 91 65 … … 354 328 .toExpr(rfpProject.getCompilerOptionAddLineNumber()), Native.toExpr(rfpProject 355 329 .getCompilerOptionAddSource()), ast, res); 356 // rfpc.CompileASToJBC(ast, res);357 330 deleteClassFiles(file); 358 331 for (Comparable<?> p : res.getExpr()) { 359 332 Expr e = (Expr) p; 360 createClassFile((String) e.at(0), (byte[]) ((Reference) e.at(1)).object);333 getRfpProject().writeClassFile((String) e.at(0), (byte[]) ((Reference) e.at(1)).object); 361 334 } 362 335 } catch (RefalException e) { -
devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/core/RfpPreBuilder.java
r3704 r3778 1 1 package org.refal.rfpdt.core; 2 2 3 import java.io.ByteArrayInputStream;4 import java.io.InputStream;5 3 import java.io.InputStreamReader; 6 4 import java.io.Reader; … … 39 37 } 40 38 41 private void createClassFile (String className, byte[] bytes) {42 try {43 IFile classFile = getRfpProject().getClassFile(className);44 if (classFile.exists())45 classFile.delete(true, false, null);46 InputStream inputStream = new ByteArrayInputStream(bytes);47 classFile.create(inputStream, true, null);48 classFile.setDerived(true);49 inputStream.close();50 } catch (Exception e) {51 RfpCore.log(e);52 }53 }54 55 private void deleteClassFiles (String moduleName) {56 RfpProject rfpProject = getRfpProject();57 IFile classFile = rfpProject.getClassFile(moduleName);58 try {59 for (int i = 0; true; i++) {60 if (classFile.exists())61 classFile.delete(true, false, null);62 else63 break;64 classFile = rfpProject.getClassFile(moduleName + "$" + i);65 }66 } catch (CoreException e) {67 RfpCore.log(e);68 }69 }70 71 39 private static class IdeCompilerEnvironment implements CompilerEnvironment { 72 40 private final RfpProject project; … … 156 124 157 125 private void checkAndCompileModuleImplem (String moduleName) { 158 deleteClassFiles(moduleName);126 getRfpProject().deleteClassFiles(moduleName); 159 127 IdeCompilerEnvironment env = new IdeCompilerEnvironment(getRfpProject(), moduleName); 160 128 AstImplem astImplem = Checker.getModuleImplementation(env); 161 129 byte[] jbc = RefalInterfaceComplier.compile(astImplem); 162 createClassFile(moduleName, jbc);130 getRfpProject().writeClassFile(moduleName, jbc); 163 131 } 164 132 -
devel-tools/trunk/eclipse/org.refal.rfpdt.core/src/org/refal/rfpdt/core/RfpProject.java
r3766 r3778 1 1 package org.refal.rfpdt.core; 2 2 3 import java.io.ByteArrayInputStream; 4 3 5 import org.eclipse.core.resources.IFile; 6 import org.eclipse.core.resources.IFolder; 4 7 import org.eclipse.core.resources.IProject; 8 import org.eclipse.core.resources.IResource; 9 import org.eclipse.core.resources.IResourceStatus; 5 10 import org.eclipse.core.resources.IWorkspaceRoot; 11 import org.eclipse.core.runtime.CoreException; 6 12 import org.eclipse.core.runtime.IPath; 7 13 import org.eclipse.jdt.core.IClasspathEntry; 8 14 import org.eclipse.jdt.core.IJavaProject; 9 15 import org.eclipse.jdt.core.JavaCore; 16 import org.eclipse.jdt.core.JavaModelException; 10 17 11 18 public class RfpProject { … … 27 34 return javaProject; 28 35 } 29 36 30 37 public IFile getFile (String fileName) { 31 38 return project.getFile(fileName); … … 36 43 } 37 44 38 public IFile getClassFile (String moduleName) { 45 public void writeClassFile (String className, byte[] bytes) { 46 try { 47 IFile classFile = getClassFile(className); 48 if (classFile == null) 49 return; 50 if (classFile.exists()) { 51 if (!classFile.isDerived()) 52 classFile.setDerived(true); 53 classFile.setContents(new ByteArrayInputStream(bytes), IResource.FORCE, null); 54 } else { 55 try { 56 classFile.create(new ByteArrayInputStream(bytes), IResource.FORCE | IResource.DERIVED, null); 57 } catch (CoreException e) { 58 if (e.getStatus().getCode() == IResourceStatus.RESOURCE_NOT_FOUND) { 59 String[] paths = className.split("\\."); 60 IPath path = javaProject.getOutputLocation(); 61 for (int i = 0; i < paths.length - 1; i++) { 62 path = path.append(paths[i]); 63 IFolder folder = workspaceRoot.getFolder(path); 64 if (!folder.exists()) 65 folder.create(IResource.FORCE | IResource.DERIVED, false, null); 66 } 67 classFile.create(new ByteArrayInputStream(bytes), IResource.FORCE | IResource.DERIVED, null); 68 } else 69 throw e; 70 } 71 } 72 } catch (CoreException e) { 73 RfpCore.log(e); 74 } 75 } 76 77 public void deleteClassFiles (String moduleName) { 78 try { 79 IFile classFile = getClassFile(moduleName); 80 for (int i = 0; true; i++) { 81 if (classFile == null) 82 return; 83 if (classFile.exists()) 84 classFile.delete(true, false, null); 85 else 86 break; 87 classFile = getClassFile(moduleName + "$" + i); 88 } 89 } catch (CoreException e) { 90 RfpCore.log(e); 91 } 92 } 93 94 /** May return <code>null</code>! */ 95 private IFile getClassFile (String moduleName) { 39 96 try { 40 97 return workspaceRoot.getFile(javaProject.getOutputLocation() 41 98 .append(moduleName.replace('.', '/') + ".class")); 42 } catch ( Exception e) {99 } catch (JavaModelException e) { 43 100 RfpCore.log(e); 44 101 } … … 46 103 } 47 104 105 /** May return <code>null</code>! */ 48 106 public IFile getSource (String moduleName, String ext) { 49 107 try { … … 55 113 return file; 56 114 } 57 } catch ( Exception e) {115 } catch (JavaModelException e) { 58 116 RfpCore.log(e); 59 117 } … … 65 123 return rfpProject == null ? null : rfpProject.getModuleName(file); 66 124 } 67 125 68 126 /** May return <code>null</code>! */ 69 127 public String getModuleName (IFile file) { … … 76 134 return filePath.removeFirstSegments(entryPath.segmentCount()).toString().replace('/', '.'); 77 135 } 78 } catch ( Exception e) {136 } catch (JavaModelException e) { 79 137 RfpCore.log(e); 80 138 } 81 139 return null; 82 140 } 83 141 84 142 private boolean addLineNumber = true; 85 143 private boolean addVariableNames = true; 86 144 private boolean addSource = true; 87 145 88 146 public boolean getCompilerOptionAddLineNumber () { 89 147 return addLineNumber;
Note: See TracChangeset
for help on using the changeset viewer.