Package org.aspectj.org.eclipse.jdt.internal.compiler

Examples of org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile


        boolean hasErrors = unitResult.hasErrors();
        if (!hasErrors || proceedOnError()) {
          Collection<ClassFile> classFiles = unitResult.compiledTypes.values();
          boolean shouldAddAspectName = (buildConfig.getOutxmlName() != null);
          for (Iterator<ClassFile> iter = classFiles.iterator(); iter.hasNext();) {
            ClassFile classFile = iter.next();
            String filename = new String(classFile.fileName());
            String classname = filename.replace('/', '.');
            filename = filename.replace('/', File.separatorChar) + ".class";

            try {
              if (buildConfig.getOutputJar() == null) {
                String outfile = writeDirectoryEntry(unitResult, classFile, filename);
                getWorld().classWriteEvent(classFile.getCompoundName());
                if (environmentSupportsIncrementalCompilation) {
                  if (!classname.endsWith("$ajcMightHaveAspect")) {
                    ResolvedType type = getBcelWorld().resolve(classname);
                    if (type.isAspect()) {
                      state.recordAspectClassFile(outfile);
                    }
                  }
                }
              } else {
                writeZipEntry(classFile, filename);
              }
              if (shouldAddAspectName && !classname.endsWith("$ajcMightHaveAspect")) {
                addAspectName(classname, unitResult.getFileName());
              }
            } catch (IOException ex) {
              IMessage message = EclipseAdapterUtils.makeErrorMessage(new String(unitResult.fileName),
                  CANT_WRITE_RESULT, ex);
              handler.handleMessage(message);
            }

          }
          state.noteNewResult(unitResult);
          unitResult.compiledTypes.clear(); // free up references to AjClassFile instances
        }

        if (unitResult.hasProblems() || unitResult.hasTasks()) {
          IProblem[] problems = unitResult.getAllProblems();
          for (int i = 0; i < problems.length; i++) {
            IMessage message = EclipseAdapterUtils.makeMessage(unitResult.compilationUnit, problems[i], getBcelWorld(),
                progressListener);
            handler.handleMessage(message);
          }
        }

      }

      private String writeDirectoryEntry(CompilationResult unitResult, ClassFile classFile, String filename)
          throws IOException {
        File destinationPath = buildConfig.getOutputDir();
        if (buildConfig.getCompilationResultDestinationManager() != null) {
          destinationPath = buildConfig.getCompilationResultDestinationManager().getOutputLocationForClass(
              new File(new String(unitResult.fileName)));
        }
        String outFile;
        if (destinationPath == null) {
          outFile = new File(filename).getName();
          outFile = new File(extractDestinationPathFromSourceFile(unitResult), outFile).getPath();
        } else {
          outFile = new File(destinationPath, filename).getPath();
        }

        try {
          BufferedOutputStream os = FileUtil.makeOutputStream(new File(outFile));
          os.write(classFile.getBytes());
          os.close();
        } catch (FileNotFoundException fnfe) {
          IMessage msg = new Message("unable to write out class file: '" + filename + "' - reason: " + fnfe.getMessage(),
              IMessage.ERROR, null, new SourceLocation(new File(outFile), 0));
          handler.handleMessage(msg);
        }

        if (buildConfig.getCompilationResultDestinationManager() != null) {
          buildConfig.getCompilationResultDestinationManager().reportFileWrite(outFile,
              CompilationResultDestinationManager.FILETYPE_CLASS);
        }
        return outFile;
      }

      private void writeZipEntry(ClassFile classFile, String name) throws IOException {
        name = name.replace(File.separatorChar, '/');
        ZipEntry newEntry = new ZipEntry(name); // ??? get compression scheme right

        zos.putNextEntry(newEntry);
        zos.write(classFile.getBytes());
        zos.closeEntry();
      }

      private void addAspectName(String name, char[] fileContainingAspect) {
        BcelWorld world = getBcelWorld();
View Full Code Here


    compilationResult.recoveryScannerData = null; // recovery is already done

    ClassFile[] classFiles = compilationResult.getClassFiles();
    for (int i = 0, max = classFiles.length; i < max; i++) {
      // clear the classFile back pointer to the bindings
      ClassFile classFile = classFiles[i];
      // null out the classfile backpointer to a type binding
      classFile.referenceBinding = null;
      classFile.innerClassesBindings = null;
    }
  }
View Full Code Here

  // and the installed global variable classes
  VariablesInfo installedVars = this.context.installedVars;
  if (installedVars != null) {
    ClassFile[] classFiles = installedVars.classFiles;
    for (int i = 0; i < classFiles.length; i++) {
      ClassFile classFile = classFiles[i];
      IBinaryType binary = null;
      try {
        binary = new ClassFileReader(classFile.getBytes(), null);
      } catch (ClassFormatException e) {
        e.printStackTrace(); // Should never happen since we compiled this type
      }
      compiler.lookupEnvironment.cacheBinaryType(binary, null /*no access restriction*/);
    }
 
View Full Code Here

  // retrieve the enclosing one guaranteed to be the one matching the propagated flow info
  // 1FF9ZBU: LFCOM:ALL - Local variable attributes busted (Sanity check)
  if (this.enclosingClassFile == null) {
    this.codeStream.maxFieldCount = aType.scope.referenceType().maxFieldCount;
  } else {
    ClassFile outermostClassFile = this.outerMostEnclosingClassFile();
    this.codeStream.maxFieldCount = outermostClassFile.codeStream.maxFieldCount;
  }
}
View Full Code Here

* @param typeDeclaration org.aspectj.org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
* @param unitResult org.aspectj.org.eclipse.jdt.internal.compiler.CompilationUnitResult
*/
public static void createProblemType(TypeDeclaration typeDeclaration, CompilationResult unitResult) {
  SourceTypeBinding typeBinding = typeDeclaration.binding;
  ClassFile classFile = new CodeSnippetClassFile(typeBinding, null, true);

  // inner attributes
  if (typeBinding.isNestedType()) {
    classFile.recordInnerClasses(typeBinding);
  }

  // add its fields
  FieldBinding[] fields = typeBinding.fields();
  if ((fields != null) && (fields != Binding.NO_FIELDS)) {
    classFile.addFieldInfos();
  } else {
    // we have to set the number of fields to be equals to 0
    classFile.contents[classFile.contentsOffset++] = 0;
    classFile.contents[classFile.contentsOffset++] = 0;
  }
  // leave some space for the methodCount
  classFile.setForMethodInfos();
  // add its user defined methods
  int problemsLength;
  CategorizedProblem[] problems = unitResult.getErrors();
  if (problems == null) {
    problems = new CategorizedProblem[0];
  }
  CategorizedProblem[] problemsCopy = new CategorizedProblem[problemsLength = problems.length];
  System.arraycopy(problems, 0, problemsCopy, 0, problemsLength);
  AbstractMethodDeclaration[] methodDecls = typeDeclaration.methods;
  if (methodDecls != null) {
    if (typeBinding.isInterface()) {
      // we cannot create problem methods for an interface. So we have to generate a clinit
      // which should contain all the problem
      classFile.addProblemClinit(problemsCopy);
      for (int i = 0, length = methodDecls.length; i < length; i++) {
        AbstractMethodDeclaration methodDecl = methodDecls[i];
        MethodBinding method = methodDecl.binding;
        if (method == null || method.isConstructor()) continue;
        classFile.addAbstractMethod(methodDecl, method);
      }   
    } else {
      for (int i = 0, length = methodDecls.length; i < length; i++) {
        AbstractMethodDeclaration methodDecl = methodDecls[i];
        MethodBinding method = methodDecl.binding;
        if (method == null) continue;
        if (method.isConstructor()) {
          classFile.addProblemConstructor(methodDecl, method, problemsCopy);
        } else {
          classFile.addProblemMethod(methodDecl, method, problemsCopy);
        }
      }
    }
    // add abstract methods
    classFile.addDefaultAbstractMethods();
  }
  // propagate generation of (problem) member types
  if (typeDeclaration.memberTypes != null) {
    for (int i = 0, max = typeDeclaration.memberTypes.length; i < max; i++) {
      TypeDeclaration memberType = typeDeclaration.memberTypes[i];
      if (memberType.binding != null) {
        ClassFile.createProblemType(memberType, unitResult);
      }
    }
  }
  classFile.addAttributes();
  unitResult.record(typeBinding.constantPoolName(), classFile);
}
View Full Code Here

    String sig = typeX.getSignature();
    return sig.substring(1, sig.length()-1).toCharArray();
  }

  public void generateClass(CompilationResult result, ClassFile enclosingClassFile) {
    ClassFile classFile = new ClassFile(this);
    classFile.initialize(this, enclosingClassFile, false);
    classFile.recordInnerClasses(this);

    //classFile.addFieldInfos();
    classFile.contents[classFile.contentsOffset++] = (byte) 0;
    classFile.contents[classFile.contentsOffset++] = (byte) 0;
   
    classFile.setForMethodInfos();
    for (Iterator i = methods.iterator(); i.hasNext(); ) {
      MethodBinding b = (MethodBinding)i.next();
      generateMethod(classFile, b);
    }

    classFile.addAttributes();
     
    result.record(this.constantPoolName(), classFile);
  }
View Full Code Here

        // this is either a jar file or a file in a directory
        if (!(unitResult.hasErrors() && !proceedOnError())) {     
          Collection classFiles = unitResult.compiledTypes.values();
          boolean shouldAddAspectName = (buildConfig.getOutxmlName() != null);
          for (Iterator iter = classFiles.iterator(); iter.hasNext();) {
            ClassFile classFile = (ClassFile) iter.next();         
            String filename = new String(classFile.fileName());
            String classname = filename.replace('/', '.');
            filename = filename.replace('/', File.separatorChar) + ".class";
            try {
              if (buildConfig.getOutputJar() == null) {
                writeDirectoryEntry(unitResult, classFile,filename);
              } else {
                writeZipEntry(classFile,filename);
              }
              if (shouldAddAspectName) addAspectName(classname);
            } catch (IOException ex) {
              IMessage message = EclipseAdapterUtils.makeErrorMessage(
                  new String(unitResult.fileName),
                  CANT_WRITE_RESULT,
                  ex);
              handler.handleMessage(message);
            }

          }
        }
       
        if (unitResult.hasProblems() || unitResult.hasTasks()) {
          IProblem[] problems = unitResult.getAllProblems();
          for (int i=0; i < problems.length; i++) {
            IMessage message =
              EclipseAdapterUtils.makeMessage(unitResult.compilationUnit, problems[i]);
            handler.handleMessage(message);
          }
        }

      }
     
      private void writeDirectoryEntry(
          CompilationResult unitResult,
          ClassFile classFile,
          String filename)
      throws IOException {
        File destinationPath = buildConfig.getOutputDir();
        String outFile;
        if (destinationPath == null) {
          outFile = new File(filename).getName();
          outFile = new File(extractDestinationPathFromSourceFile(unitResult), outFile).getPath();
        } else {
          outFile = new File(destinationPath, filename).getPath();
        }
        BufferedOutputStream os =
          FileUtil.makeOutputStream(new File(outFile));
        os.write(classFile.getBytes());
        os.close();
      }
     
      private void writeZipEntry(ClassFile classFile, String name)
      throws IOException {
        name = name.replace(File.separatorChar,'/');
        ZipEntry newEntry = new ZipEntry(name)//??? get compression scheme right
       
        zos.putNextEntry(newEntry);
        zos.write(classFile.getBytes());
        zos.closeEntry();
      }
     
      private void addAspectName (String name) {
        BcelWorld world = getBcelWorld();
View Full Code Here

    String sig = typeX.getSignature();
    return sig.substring(1, sig.length()-1).toCharArray();
  }

  public void generateClass(CompilationResult result, ClassFile enclosingClassFile) {
    ClassFile classFile = new ClassFile(this, enclosingClassFile, false);
    classFile.addFieldInfos();

    classFile.setForMethodInfos();
    for (Iterator i = methods.iterator(); i.hasNext(); ) {
      MethodBinding b = (MethodBinding)i.next();
      generateMethod(classFile, b);
    }

    classFile.addAttributes();
     
    result.record(this.constantPoolName(), classFile);
  }
View Full Code Here

TOP

Related Classes of org.aspectj.org.eclipse.jdt.internal.compiler.ClassFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.