Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.ICompilationUnit


    public static final CompilationUnit createAST(IJavaProject javaProject, String className) throws JavaModelException {
        IType type = javaProject.findType(className);
        if (type == null)
            return null;

        final ICompilationUnit cunit = type.getCompilationUnit();
        if (cunit == null)
            return null; // not a source type

        ASTParser parser = ASTParser.newParser(AST.JLS4);
        parser.setKind(ASTParser.K_COMPILATION_UNIT);
View Full Code Here


            IJavaElement javaElement = JavaCore.create(resource);
            if (javaElement == null)
                return true;
            if (javaElement.getElementType() != IJavaElement.COMPILATION_UNIT)
                return true;
            ICompilationUnit compilationUnit = (ICompilationUnit) javaElement
                    .getAdapter(ICompilationUnit.class);
            return visit(compilationUnit);
        }
View Full Code Here

            IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
            IResource resource = root.findMember(new Path(fileName));
            IJavaElement create = JavaCore.create(resource);
           
            if (!(create instanceof ICompilationUnit)) continue;
            ICompilationUnit unit = (ICompilationUnit) create;
            try {
                IPackageDeclaration[] packageDeclarations = unit.getPackageDeclarations();
                if (packageDeclarations.length != 1) continue;
               
                IPackageDeclaration pack = packageDeclarations[0];
                String packageName = pack.getElementName();
               
View Full Code Here

                      JavaRenameProcessor javaProcessor = (JavaRenameProcessor)processor;
                      newName = javaProcessor.getNewElementName().replace(".java", "");
                        currentName = javaProcessor.getCurrentElementName();

                      try {
                          ICompilationUnit compilationUnit = (ICompilationUnit)javaProcessor.getElements()[0];
              packageName = compilationUnit.getPackageDeclarations()[0].getElementName();
              className = packageName + "." + currentName;
            } catch (Exception e) {
              return false;
            }
                       
View Full Code Here

  private boolean isImplicitImport(String qualifier) {
    if (JAVA_LANG.equals(qualifier)) {
      return true;
    }
    ICompilationUnit cu= this.compilationUnit;
    String packageName= cu.getParent().getElementName();
    if (qualifier.equals(packageName)) {
      return true;
    }
    String mainTypeName= JavaCore.removeJavaLikeExtension(cu.getElementName());
    if (packageName.length() == 0) {
      return qualifier.equals(mainTypeName);
    }
    return qualifier.equals(packageName +'.' + mainTypeName);
  }
View Full Code Here

    this.hasComputedEnclosingJavaElements = true;

    if (this.typeRoot == null) return;

    if (this.typeRoot.getElementType() == IJavaElement.COMPILATION_UNIT) {
       ICompilationUnit original = (org.eclipse.jdt.core.ICompilationUnit)this.typeRoot;

      HashMap handleToBinding = new HashMap();
      HashMap bindingToHandle = new HashMap();
      HashMap nodeWithProblemToHandle = new HashMap();
      HashMap handleToInfo = new HashMap();
View Full Code Here

        try {
          super.process(unit, i); // this.process(...) is optimized to not process already known units

          // requested AST
          char[] fileName = unit.compilationResult.getFileName();
          ICompilationUnit source = (ICompilationUnit) this.requestedSources.get(fileName);
          if (source != null) {
            // convert AST
            CompilationResult compilationResult = unit.compilationResult;
            org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit = compilationResult.compilationUnit;
            char[] contents = sourceUnit.getContents();
View Full Code Here

      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 = 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

      HashtableOfObjectToInt rootPositions = new HashtableOfObjectToInt();
      for (int i = 0, length = packageFragmentRoots.length; i < length; i++) {
        rootPositions.put(packageFragmentRoots[i], i);
      }
      for (int i = 0, length = workingCopies.length; i < length; i++) {
        ICompilationUnit workingCopy = workingCopies[i];
        PackageFragment pkg = (PackageFragment) workingCopy.getParent();
        IPackageFragmentRoot root = (IPackageFragmentRoot) pkg.getParent();
        int rootPosition = rootPositions.get(root);
        if (rootPosition == -1)
          continue; // working copy is not visible from this project (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=169970)
        HashMap typeMap = (HashMap) this.typesInWorkingCopies.get(pkg);
        if (typeMap == null) {
          typeMap = new HashMap();
          this.typesInWorkingCopies.put(pkg, typeMap);
        }
        try {
          IType[] types = workingCopy.getTypes();
          int typeLength = types.length;
          if (typeLength == 0) {
            String typeName = Util.getNameWithoutJavaLikeExtension(workingCopy.getElementName());
            typeMap.put(typeName, NO_TYPES);
          } else {
            for (int j = 0; j < typeLength; j++) {
              IType type = types[j];
              String typeName = type.getElementName();
View Full Code Here

        return findCompilationUnit(pkgName, cuName, (PackageFragmentRoot) value);
      } else {
        IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) value;
        for (int i= 0; i < roots.length; i++) {
          PackageFragmentRoot root= (PackageFragmentRoot) roots[i];
          ICompilationUnit cu = findCompilationUnit(pkgName, cuName, root);
          if (cu != null)
            return cu;
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.ICompilationUnit

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.