Examples of ICompilationUnit


Examples of org.aspectj.org.eclipse.jdt.core.ICompilationUnit

  /**
   * Deletes this element from its compilation unit.
   * @see MultiOperation
   */
  protected void processElement(IJavaElement element) throws JavaModelException {
    ICompilationUnit cu = (ICompilationUnit) element;
 
    // keep track of the import statements - if all are removed, delete
    // the import container (and report it in the delta)
    int numberOfImports = cu.getImports().length;
 
    JavaElementDelta delta = new JavaElementDelta(cu);
    IJavaElement[] cuElements = ((IRegion) childrenToRemove.get(cu)).getElements();
    for (int i = 0, length = cuElements.length; i < length; i++) {
      IJavaElement e = cuElements[i];
      if (e.exists()) {
        deleteElement(e, cu);
        delta.removed(e);
        if (e.getElementType() == IJavaElement.IMPORT_DECLARATION) {
          numberOfImports--;
          if (numberOfImports == 0) {
            delta.removed(cu.getImportContainer());
          }
        }
      }
    }
    if (delta.getAffectedChildren().length > 0) {
      cu.save(getSubProgressMonitor(1), force);
      if (!cu.isWorkingCopy()) { // if unit is working copy, then save will have already fired the delta
        addDelta(delta);
        setAttribute(HAS_MODIFIED_RESOURCE_ATTR, TRUE);
      }
    }
  }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.ICompilationUnit

 
  if (kind == IPackageFragmentRoot.K_SOURCE) {
    // add primary compilation units
    ICompilationUnit[] primaryCompilationUnits = getCompilationUnits(DefaultWorkingCopyOwner.PRIMARY);
    for (int i = 0, length = primaryCompilationUnits.length; i < length; i++) {
      ICompilationUnit primary = primaryCompilationUnits[i];
      vChildren.add(primary);
    }
  }
 
  IJavaElement[] children = new IJavaElement[vChildren.size()];
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.ICompilationUnit

  if (workingCopies == null) return JavaModelManager.NO_WORKING_COPY;
  int length = workingCopies.length;
  ICompilationUnit[] result = new ICompilationUnit[length];
  int index = 0;
  for (int i = 0; i < length; i++) {
    ICompilationUnit wc = workingCopies[i];
    if (equals(wc.getParent()) && !Util.isExcluded(wc)) { // 59933 - excluded wc shouldn't be answered back
      result[index++] = wc;
    }
  }
  if (index != length) {
    System.arraycopy(result, 0, result = new ICompilationUnit[index], 0, index);
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.ICompilationUnit

        // case of a working copy without a resource
        workingCopy.getBuffer().save(this.progressMonitor, this.force);
        return;
      }
     
      ICompilationUnit primary = workingCopy.getPrimary();
      boolean isPrimary = workingCopy.isPrimary();

      JavaElementDeltaBuilder deltaBuilder = null;
      PackageFragmentRoot root = (PackageFragmentRoot)workingCopy.getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT);
      boolean isIncluded = !Util.isExcluded(workingCopy);
      IFile resource = (IFile)workingCopy.getResource();
      IJavaProject project = root.getJavaProject();
      if (isPrimary || (root.validateOnClasspath().isOK() && isIncluded && resource.isAccessible() && Util.isValidCompilationUnitName(workingCopy.getElementName(), project.getOption(JavaCore.COMPILER_SOURCE, true), project.getOption(JavaCore.COMPILER_COMPLIANCE, true)))) {
       
        // force opening so that the delta builder can get the old info
        if (!isPrimary && !primary.isOpen()) {
          primary.open(null);
        }

        // creates the delta builder (this remembers the content of the cu) if:
        // - it is not excluded
        // - and it is not a primary or it is a non-consistent primary
        if (isIncluded && (!isPrimary || !workingCopy.isConsistent())) {
          deltaBuilder = new JavaElementDeltaBuilder(primary);
        }
     
        // save the cu
        IBuffer primaryBuffer = primary.getBuffer();
        if (!isPrimary) {
          if (primaryBuffer == null) return;
          char[] primaryContents = primaryBuffer.getCharacters();
          boolean hasSaved = false;
          try {
            IBuffer workingCopyBuffer = workingCopy.getBuffer();
            if (workingCopyBuffer == null) return;
            primaryBuffer.setContents(workingCopyBuffer.getCharacters());
            primaryBuffer.save(this.progressMonitor, this.force);
            primary.makeConsistent(this);
            hasSaved = true;
          } finally {
            if (!hasSaved){
              // restore original buffer contents since something went wrong
              primaryBuffer.setContents(primaryContents);
            }
          }
        } else {
          // for a primary working copy no need to set the content of the buffer again
          primaryBuffer.save(this.progressMonitor, this.force);
          primary.makeConsistent(this);
        }
      } else {
        // working copy on cu outside classpath OR resource doesn't exist yet
        String encoding = null;
        try {
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.ICompilationUnit

      if (this.type.isBinary()) {
        BinaryTypeBinding binding = this.locator.cacheBinaryType(this.type, null);
        if (binding != null)
          collectSuperTypeNames(binding);
      } else {
        ICompilationUnit unit = this.type.getCompilationUnit();
        SourceType sourceType = (SourceType) this.type;
        boolean isTopLevelOrMember = sourceType.getOuterMostLocalContext() == null;
        CompilationUnitDeclaration parsedUnit = buildBindings(unit, isTopLevelOrMember);
        if (parsedUnit != null) {
          TypeDeclaration typeDecl = new ASTNodeFinder(parsedUnit).findType(this.type);
          if (typeDecl != null && typeDecl.binding != null)
            collectSuperTypeNames(typeDecl.binding);
        }
      }
    } catch (AbortCompilation e) {
      // problem with classpath: report inacurrate matches
      return null;
    }
    if (this.result.length > this.resultIndex)
      System.arraycopy(this.result, 0, this.result = new char[this.resultIndex][][], 0, this.resultIndex);
    return this.result;
  }

  // Collect the paths of the cus that declare a type which matches declaringQualification + declaringSimpleName
  String[] paths = this.getPathsOfDeclaringType();
  if (paths == null) return null;

  // Create bindings from source types and binary types and collect super type names of the type declaration
  // that match the given declaring type
  Util.sort(paths); // sort by projects
  JavaProject previousProject = null;
  this.result = new char[1][][];
  this.resultIndex = 0;
  for (int i = 0, length = paths.length; i < length; i++) {
    try {
      Openable openable = this.locator.handleFactory.createOpenable(paths[i], this.locator.scope);
      if (openable == null) continue; // outside classpath

      IJavaProject project = openable.getJavaProject();
      if (!project.equals(previousProject)) {
        previousProject = (JavaProject) project;
        this.locator.initialize(previousProject, 0);
      }
      if (openable instanceof ICompilationUnit) {
        ICompilationUnit unit = (ICompilationUnit) openable;
        CompilationUnitDeclaration parsedUnit = buildBindings(unit, true /*only toplevel and member types are visible to the focus type*/);
        if (parsedUnit != null)
          parsedUnit.traverse(new TypeDeclarationVisitor(), parsedUnit.scope);
      } else if (openable instanceof IClassFile) {
        IClassFile classFile = (IClassFile) openable;
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.ICompilationUnit

    if (pkgEnd == -1)
      return null;
    IPackageFragment pkg = getPackageFragment(slashSeparatedFileName, pkgEnd, -1/*no jar separator for .java files*/);
    if (pkg == null) return null;
    int start;
    ICompilationUnit cu = pkg.getCompilationUnit(new String(slashSeparatedFileName, start =  pkgEnd+1, slashSeparatedFileName.length - start));
    if (this.resolver instanceof DefaultBindingResolver) {
      ICompilationUnit workingCopy = cu.findWorkingCopy(((DefaultBindingResolver) this.resolver).workingCopyOwner);
      if (workingCopy != null)
        return workingCopy;
    }
    return cu;
  }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.ICompilationUnit

        pkgEnd = CharOperation.lastIndexOf('/', constantPoolName);
        char[] classFileName = CharOperation.subarray(constantPoolName, pkgEnd+1, constantPoolName.length);
        ClassFile classFile = (ClassFile) pkg.getClassFile(new String(classFileName) + SuffixConstants.SUFFIX_STRING_class);
        return (JavaElement) classFile.getType();
      }
      ICompilationUnit cu = getCompilationUnit(fileName);
      if (cu == null) return null;
      // must use getElementAt(...) as there is no back pointer to the defining method (scope is null after resolution has ended)
      try {
        int sourceStart = ((LocalTypeBinding) referenceBinding).sourceStart;
        return (JavaElement) cu.getElementAt(sourceStart);
      } catch (JavaModelException e) {
        // does not exist
        return null;
      }
    } else if (referenceBinding.isTypeVariable()) {
      // type parameter
      final String typeVariableName = new String(referenceBinding.sourceName());
      Binding declaringElement = ((TypeVariableBinding) referenceBinding).declaringElement;
      IBinding declaringTypeBinding = null;
      if (declaringElement instanceof MethodBinding) {
        declaringTypeBinding = this.resolver.getMethodBinding((MethodBinding) declaringElement);
        IMethod declaringMethod = (IMethod) declaringTypeBinding.getJavaElement();
        return (JavaElement) declaringMethod.getTypeParameter(typeVariableName);
      } else {
        ITypeBinding typeBinding2 = this.resolver.getTypeBinding((org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding) declaringElement);
        if (typeBinding2 == null) return null;
        declaringTypeBinding = typeBinding2;
        IType declaringType = (IType) declaringTypeBinding.getJavaElement();
        return (JavaElement) declaringType.getTypeParameter(typeVariableName);
      }
    } else {
      if (fileName == null) return null; // case of a WilCardBinding that doesn't have a corresponding Java element
      // member or top level type
      ITypeBinding declaringTypeBinding = null;
      if (this.isArray()) {
        declaringTypeBinding = this.getElementType().getDeclaringClass();
      } else {
        declaringTypeBinding = this.getDeclaringClass();
      }
      if (declaringTypeBinding == null) {
        // top level type
        if (Util.isClassFileName(fileName)) {
          ClassFile classFile = (ClassFile) getClassFile(fileName);
          if (classFile == null) return null;
          return (JavaElement) classFile.getType();
        }
        ICompilationUnit cu = getCompilationUnit(fileName);
        if (cu == null) return null;
        return (JavaElement) cu.getType(new String(referenceBinding.sourceName()));
      } else {
        // member type
        IType declaringType = (IType) declaringTypeBinding.getJavaElement();
        if (declaringType == null) return null;
        return (JavaElement) declaringType.getType(new String(referenceBinding.sourceName()));
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.ICompilationUnit

        pkgFragment= ((PackageFragmentRoot) this.lastPkgFragmentRoot).getPackageFragment(pkgName);
        this.packageHandles.put(pkgName, pkgFragment);
      }
      String simpleName= simpleNames[length];
      if (org.aspectj.org.eclipse.jdt.internal.core.util.Util.isJavaLikeFileName(simpleName)) {
        ICompilationUnit unit= pkgFragment.getCompilationUnit(simpleName);
        return (Openable) unit;
      } else {
        IClassFile classFile= pkgFragment.getClassFile(simpleName);
        return (Openable) classFile;
      }
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.ICompilationUnit

* <li> if no type, after the package statement
* <li> and if no package statement - first thing in the CU
*/
protected void initializeDefaultPosition() {
  try {
    ICompilationUnit cu = getCompilationUnit();
    IImportDeclaration[] imports = cu.getImports();
    if (imports.length > 0) {
      createAfter(imports[imports.length - 1]);
      return;
    }
    IType[] types = cu.getTypes();
    if (types.length > 0) {
      createBefore(types[0]);
      return;
    }
    IJavaElement[] children = cu.getChildren();
    //look for the package declaration
    for (int i = 0; i < children.length; i++) {
      if (children[i].getElementType() == IJavaElement.PACKAGE_DECLARATION) {
        createAfter(children[i]);
        return;
View Full Code Here

Examples of org.aspectj.org.eclipse.jdt.core.ICompilationUnit

      for (int i = 0, len = pkgs.length; i < len; i++) {
        int fragType = pkgs[i].getKind();
        switch(fragType) {
          case IPackageFragmentRoot.K_SOURCE:
            String unitName = "package-info.java"; //$NON-NLS-1$
            ICompilationUnit unit = pkgs[i].getCompilationUnit(unitName);
            if (unit != null) {
              ASTParser p = ASTParser.newParser(AST.JLS3);
              p.setSource(unit);
              p.setResolveBindings(true);
              p.setUnitName(unitName);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.