Package org.eclipse.jdt.internal.compiler.env

Examples of org.eclipse.jdt.internal.compiler.env.IBinaryType


    if (method == null || knownMethods.addIfNotIncluded(method) == null) return;
 
    IResource resource = type.getResource();
    if (resource == null)
      resource = type.getJavaProject().getProject();
    IBinaryType info = locator.getBinaryInfo((org.eclipse.jdt.internal.core.ClassFile)type.getClassFile(), resource);
    locator.reportBinaryMemberDeclaration(resource, method, methodBinding, info, SearchMatch.A_ACCURATE);
    return;
  }

  // When source is available, report match if method is found in the declaring type
View Full Code Here


  IType type = locator.lookupType(typeBinding);
  if (type == null) return; // case of a secondary type

  IResource resource = type.getResource();
  boolean isBinary = type.isBinary();
  IBinaryType info = null;
  if (isBinary) {
    if (resource == null)
      resource = type.getJavaProject().getProject();
    info = locator.getBinaryInfo((org.eclipse.jdt.internal.core.ClassFile) type.getClassFile(), resource);
  }
View Full Code Here

*/
Compiler getCompiler(ICompilerRequestor compilerRequestor) {
  Compiler compiler = super.getCompiler(compilerRequestor);

  // Initialize the compiler's lookup environment with the already compiled super class
  IBinaryType binaryType = this.context.getRootCodeSnippetBinary();
  if (binaryType != null) {
    compiler.lookupEnvironment.cacheBinaryType(binaryType, null /*no access restriction*/);
  }

  // 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
      }
View Full Code Here

  };

  CompletionEngine engine = new CompletionEngine(environment, mapper.getCompletionRequestor(requestor), options, project, owner, monitor);

  if (this.installedVars != null) {
    IBinaryType binaryType = getRootCodeSnippetBinary();
    if (binaryType != null) {
      engine.lookupEnvironment.cacheBinaryType(binaryType, null /*no access restriction*/);
    }

    ClassFile[] classFiles = this.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
      }
View Full Code Here

            break;
          case IPackageFragmentRoot.K_BINARY:
            NameEnvironmentAnswer answer =
              nameEnvironment.findType(TypeConstants.PACKAGE_INFO_NAME, this.binding.compoundName);
            if (answer != null && answer.isBinaryType()) {
              IBinaryType type = answer.getBinaryType();
              char[][][] missingTypeNames = type.getMissingTypeNames();
              IBinaryAnnotation[] binaryAnnotations = type.getAnnotations();
              org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] binaryInstances =
                BinaryTypeBinding.createAnnotations(binaryAnnotations, this.binding.environment, missingTypeNames);
              org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding[] allInstances =
                org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding.addStandardAnnotations(binaryInstances, type.getTagBits(), this.binding.environment);
              int total = allInstances.length;
              IAnnotationBinding[] domInstances = new AnnotationBinding[total];
              for (int a = 0; a < total; a++) {
                final IAnnotationBinding annotationInstance = this.resolver.getAnnotationInstance(allInstances[a]);
                if (annotationInstance == null) {// not resolving binding
View Full Code Here

              if (sourceString == null) {
                throw new IllegalStateException();
              }
              PackageFragment packageFragment = (PackageFragment) this.typeRoot.getParent();
              BinaryType type = (BinaryType) this.typeRoot.findPrimaryType();
              IBinaryType binaryType = (IBinaryType) type.getElementInfo();
              // file name is used to recreate the Java element, so it has to be the toplevel .class file name
              char[] fileName = binaryType.getFileName();
              int firstDollar = CharOperation.indexOf('$', fileName);
              if (firstDollar != -1) {
                char[] suffix = SuffixConstants.SUFFIX_class;
                int suffixLength = suffix.length;
                char[] newFileName = new char[firstDollar + suffixLength];
View Full Code Here

        case SOURCE :
          CompilationUnit unit = new CompilationUnit(null, _fileName, null /* encoding */);
          _filer.addNewUnit(unit);
          break;
        case CLASS :
          IBinaryType binaryType = null;
          try {
            binaryType = ClassFileReader.read(_fileName);
          } catch (ClassFormatException e) {
            // ignore
          } catch (IOException e) {
            // ignore
          }
          if (binaryType != null) {
            char[] name = binaryType.getName();
            ReferenceBinding type = this._filer._env._compiler.lookupEnvironment.getType(CharOperation.splitOn('/', name));
            if (type != null && type.isValidBinding() && type.isBinaryBinding()) {
              _filer.addNewClassFile(type);
            }
          }
View Full Code Here

  if (mapper != null) {
    char[][] paramNames = mapper.getMethodParameterNames(this);

    // map source and try to find parameter names
    if(paramNames == null) {
      IBinaryType info = (IBinaryType) ((BinaryType) getDeclaringType()).getElementInfo();
      char[] source = mapper.findSource(type, info);
      if (source != null){
        mapper.mapSource(type, source, info);
      }
      paramNames = mapper.getMethodParameterNames(this);
    }

    // if parameter names exist, convert parameter names to String array
    if(paramNames != null) {
      String[] names = new String[paramNames.length];
      for (int i = 0; i < paramNames.length; i++) {
        names[i] = new String(paramNames[i]);
      }
      return this.parameterNames = names;
    }
  }

  // try to see if we can retrieve the names from the attached javadoc
  IBinaryMethod info = (IBinaryMethod) getElementInfo();
  // https://bugs.eclipse.org/bugs/show_bug.cgi?id=316937
  // Use Signature#getParameterCount() only if the argument names are not already available.
  int paramCount = Signature.getParameterCount(new String(info.getMethodDescriptor()));
  if (this.isConstructor()) {
    final IType declaringType = this.getDeclaringType();
    if (declaringType.isMember()
        && !Flags.isStatic(declaringType.getFlags())) {
      paramCount--; // remove synthetic argument from constructor param count
    }
  }

  if (paramCount != 0) {
    // don't try to look for javadoc for synthetic methods
    int modifiers = getFlags();
    if ((modifiers & ClassFileConstants.AccSynthetic) != 0) {
      return this.parameterNames = getRawParameterNames(paramCount);
    }
    JavadocContents javadocContents = null;
    IType declaringType = getDeclaringType();
    PerProjectInfo projectInfo = JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(getJavaProject().getProject());
    synchronized (projectInfo.javadocCache) {
      javadocContents = (JavadocContents) projectInfo.javadocCache.get(declaringType);
      if (javadocContents == null) {
        projectInfo.javadocCache.put(declaringType, BinaryType.EMPTY_JAVADOC);
      }
    }
   
    String methodDoc = null;
    if (javadocContents == null) {
      long timeOut = 50; // default value
      try {
        String option = getJavaProject().getOption(JavaCore.TIMEOUT_FOR_PARAMETER_NAME_FROM_ATTACHED_JAVADOC, true);
        if (option != null) {
          timeOut = Long.parseLong(option);
        }
      } catch(NumberFormatException e) {
        // ignore
      }
      if (timeOut == 0) {
        // don't try to fetch the values and don't cache either (https://bugs.eclipse.org/bugs/show_bug.cgi?id=329671)
        return getRawParameterNames(paramCount);
      }
      final class ParametersNameCollector {
        String javadoc;
        public void setJavadoc(String s) {
          this.javadoc = s;
        }
        public String getJavadoc() {
          return this.javadoc;
        }
      }
      /*
       * The declaring type is not in the cache yet. The thread wil retrieve the javadoc contents
       */
      final ParametersNameCollector nameCollector = new ParametersNameCollector();
      Thread collect = new Thread() {
        public void run() {
          try {
            // this call has a side-effect on the per project info cache
            nameCollector.setJavadoc(BinaryMethod.this.getAttachedJavadoc(null));
          } catch (JavaModelException e) {
            // ignore
          }
          synchronized(nameCollector) {
            nameCollector.notify();
          }
        }
      };
      collect.start();
      synchronized(nameCollector) {
        try {
          nameCollector.wait(timeOut);
        } catch (InterruptedException e) {
          // ignore
        }
      }
      methodDoc = nameCollector.getJavadoc();
    } else if (javadocContents != BinaryType.EMPTY_JAVADOC){
      // need to extract the part relative to the binary method since javadoc contains the javadoc for the declaring type
      try {
        methodDoc = javadocContents.getMethodDoc(this);
      } catch(JavaModelException e) {
        javadocContents = null;
      }
    }
    if (methodDoc != null) {
      final int indexOfOpenParen = methodDoc.indexOf('(');
      if (indexOfOpenParen != -1) {
        final int indexOfClosingParen = methodDoc.indexOf(')', indexOfOpenParen);
        if (indexOfClosingParen != -1) {
          final char[] paramsSource =
            CharOperation.replace(
              methodDoc.substring(indexOfOpenParen + 1, indexOfClosingParen).toCharArray(),
              "&nbsp;".toCharArray(), //$NON-NLS-1$
              new char[] {' '});
          final char[][] params = splitParameters(paramsSource, paramCount);
          final int paramsLength = params.length;
          String[] names = new String[paramsLength];
          for (int i = 0; i < paramsLength; i++) {
            final char[] param = params[i];
            int indexOfSpace = CharOperation.lastIndexOf(' ', param);
            if (indexOfSpace != -1) {
              names[i] = String.valueOf(param, indexOfSpace + 1, param.length - indexOfSpace -1);
            } else {
              names[i] = "arg" + i; //$NON-NLS-1$
            }
          }
          return this.parameterNames = names;
        }
      }
    }
    // let's see if we can retrieve them from the debug infos
    char[][] argumentNames = info.getArgumentNames();
    if (argumentNames != null && argumentNames.length == paramCount) {
      String[] names = new String[paramCount];
      for (int i = 0; i < paramCount; i++) {
        names[i] = new String(argumentNames[i]);
      }
View Full Code Here

/*
* @see IType#isAnonymous()
*/
public boolean isAnonymous() throws JavaModelException {
  IBinaryType info = (IBinaryType) getElementInfo();
  return info.isAnonymous();
}
View Full Code Here

}
/*
* @see IType#isClass()
*/
public boolean isClass() throws JavaModelException {
  IBinaryType info = (IBinaryType) getElementInfo();
  return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.CLASS_DECL;

}
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.internal.compiler.env.IBinaryType

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.