unit.scope.verifyMethods(lookupEnvironment.methodVerifier());
try { if (packageName.length != 0) { aPackage = environment.createPackage(packageName); } else { aPackage = null; final MissingTypeBinding declaringType = environment.createMissingType(aPackage, className); this.jdtTreeBuilder.getContextBuilder().ignoreComputeImports = true; final CtTypeReference<Object> typeReference = getTypeReference(declaringType); } else { try { packageBinding = environment.createPackage(chars); } catch (NullPointerException e) { packageBinding = null;
public ReferenceBinding getResolvedType(char[][] compoundName, Scope scope) { ReferenceBinding type = getType(compoundName); if (type != null) return type; // create a proxy for the missing BinaryType // report the missing class file first this.problemReporter.isClassPathCorrect( compoundName, scope == null ? this.unitBeingCompleted : scope.referenceCompilationUnit(), this.missingClassFileLocation); return createMissingType(null, compoundName); }
@Override public TypeBinding withoutToplevelNullAnnotation() { if (!hasNullTypeAnnotations()) return this; ReferenceBinding unannotatedGenericType = (ReferenceBinding) this.environment.getUnannotatedType(this.type); AnnotationBinding[] newAnnotations = this.environment.filterNullTypeAnnotations(this.typeAnnotations); return this.environment.createParameterizedType(unannotatedGenericType, this.arguments, this.enclosingType, newAnnotations); }
@Override public TypeBinding withoutToplevelNullAnnotation() { if (!hasNullTypeAnnotations()) return this; AnnotationBinding[] newAnnotations = this.environment.filterNullTypeAnnotations(this.typeAnnotations); return this.environment.createArrayType(this.leafComponentType, this.dimensions, newAnnotations); } @Override
static class IntArrayList { public int[] list = new int[5]; public int length = 0; public void add(int i) { if (this.list.length == this.length) { System.arraycopy(this.list, 0, this.list = new int[this.length*2], 0, this.length); } this.list[this.length++] = i; } }
@Override public void accept(ICompilationUnit unit, AccessRestriction accessRestriction) { CompilationResult unitResult = new CompilationResult(unit, 1, 1, this.options.maxProblemsPerUnit); CompilationUnitDeclaration parsedUnit = this.basicParser.dietParse(unit, unitResult); this.lookupEnvironment.buildTypeBindings(parsedUnit, accessRestriction); this.lookupEnvironment.completeTypeBindings(parsedUnit, true); }
@Override public TypeBinding withoutToplevelNullAnnotation() { if (!hasNullTypeAnnotations()) return this; ReferenceBinding unannotatedGenericType = (ReferenceBinding) this.environment.getUnannotatedType(this.genericType()); AnnotationBinding[] newAnnotations = this.environment.filterNullTypeAnnotations(this.typeAnnotations); return this.environment.createRawType(unannotatedGenericType, this.enclosingType(), newAnnotations); }
/** Apply the given type arguments on the (declaring class of the) actual constructor being represented by this factory method and if method type arguments is not empty materialize the parameterized generic constructor * @param targetType */ public ParameterizedMethodBinding applyTypeArgumentsOnConstructor(TypeBinding[] typeArguments, TypeBinding[] constructorTypeArguments, boolean inferredWithUncheckedConversion, TypeBinding targetType) { ReferenceBinding parameterizedType = typeArguments == null ? this.environment.createRawType(this.declaringClass, this.enclosingType) : this.environment.createParameterizedType(this.declaringClass, typeArguments, this.enclosingType); for (MethodBinding parameterizedMethod : parameterizedType.methods()) { if (parameterizedMethod.original() == this.staticFactoryFor) return (constructorTypeArguments.length > 0 || inferredWithUncheckedConversion) ? this.environment.createParameterizedGenericMethod(parameterizedMethod, constructorTypeArguments, inferredWithUncheckedConversion, false, targetType) : (ParameterizedMethodBinding) parameterizedMethod; if (parameterizedMethod instanceof ProblemMethodBinding) { MethodBinding closestMatch = ((ProblemMethodBinding)parameterizedMethod).closestMatch; if (closestMatch instanceof ParameterizedMethodBinding && closestMatch.original() == this.staticFactoryFor) return (ParameterizedMethodBinding) closestMatch; } } throw new IllegalArgumentException("Type doesn't have its own method?"); //$NON-NLS-1$ } }
@Override public TypeElement boxedClass(PrimitiveType p) { PrimitiveTypeImpl primitiveTypeImpl = (PrimitiveTypeImpl) p; BaseTypeBinding baseTypeBinding = (BaseTypeBinding)primitiveTypeImpl._binding; TypeBinding boxed = _env.getLookupEnvironment().computeBoxingType(baseTypeBinding); return (TypeElement) _env.getFactory().newElement(boxed); }
private TypeBinding getArrayBinding(int dim, TypeBinding binding) { if (binding == null) return null; if (dim == 0) return binding; return this.environment.createArrayType(binding, dim); }
@Override public PackageElement getPackageElement(CharSequence name) { LookupEnvironment le = _env.getLookupEnvironment(); if (name.length() == 0) { return new PackageElementImpl(_env, le.defaultPackage); } char[] packageName = name.toString().toCharArray(); PackageBinding packageBinding = le.createPackage(CharOperation.splitOn('.', packageName)); if (packageBinding == null) { return null; } return new PackageElementImpl(_env, packageBinding); }
public TypeBinding erasure() { // lazily initialize field that may be required in super.erasure(): if (this.superclass == null) this.superclass = this.environment.getType(TypeConstants.JAVA_LANG_OBJECT); return super.erasure(); } }
@Override public TypeBinding withoutToplevelNullAnnotation() { if (!hasNullTypeAnnotations()) return this; AnnotationBinding[] newAnnotations = this.environment.filterNullTypeAnnotations(getTypeAnnotations()); return this.environment.createWildcard(this.genericType, this.rank, this.bound, this.otherBounds, this.boundKind, newAnnotations); } @Override
@Override public synchronized boolean registerCompilationUnitOverride(String packageName, String fileName, char[] src) { Validate.notNull(fileName); Validate.notNull(src); StringBasedJdtCompilationUnit cu = new StringBasedJdtCompilationUnit(packageName, fileName, src); boolean reloadRequired = m_nameEnv.overrideSupport().addCompilationUnit(cu); String fqn = getFqn(packageName, cu); m_performanceCache.remove(createTypeKey(fqn));// clear cache info for this element if (!reloadRequired) { // if not used in name-env: also check in compiler reloadRequired = m_compiler.lookupEnvironment.getCachedType(CharOperation.splitOn('.', fqn.toCharArray())) != null; } // ensure the package of the new override CU exists. It may be in the lookupEnv cache as 'notExisting' from a call before where it really did not exist. if (!StringUtils.isEmpty(packageName)) { m_compiler.lookupEnvironment.createPackage(CharOperation.splitOn('.', packageName.toCharArray())); } return reloadRequired; }
public TypeBinding substitute(TypeVariableBinding typeVariable) { if (typeVariable.rank >= this.variables.length || this.variables[typeVariable.rank] != typeVariable) { // not kosher, don't touch. return typeVariable; } if (this.substitutes != null) { return Scope.substitute(new LingeringTypeVariableEliminator(this.variables, null, this.scope), this.substitutes[typeVariable.rank]); } ReferenceBinding genericType = (ReferenceBinding) (typeVariable.declaringElement instanceof ReferenceBinding ? typeVariable.declaringElement : null); return this.scope.environment().createWildcard(genericType, typeVariable.rank, null, null, Wildcard.UNBOUND); }
private static TypeBinding getRealErasure(TypeBinding type, LookupEnvironment environment) { TypeBinding erasure = type.erasure(); // could still be / contain a generic type that needs to be converted to raw: TypeBinding erasedLeaf = erasure.leafComponentType(); if (erasedLeaf.isGenericType()) erasedLeaf = environment.convertToRawType(erasedLeaf, false); if (erasure.isArrayType()) return environment.createArrayType(erasedLeaf, erasure.dimensions()); return erasedLeaf; }
/** Apply the given type arguments on the (declaring class of the) actual constructor being represented by this factory method. */ public ParameterizedMethodBinding applyTypeArgumentsOnConstructor(TypeBinding[] typeArguments) { ReferenceBinding parameterizedType = this.environment.createParameterizedType(this.declaringClass, typeArguments, this.enclosingType); for (MethodBinding parameterizedMethod : parameterizedType.methods()) { if (parameterizedMethod.original() == this.staticFactoryFor) return (ParameterizedMethodBinding) parameterizedMethod; } throw new IllegalArgumentException("Type doesn't have its own method?"); //$NON-NLS-1$ } }
/** * In no classpath mode, when we build a field access, we have a binding typed by ProblemBinding. * We try to get all information we can get from this binding. * * @param qualifiedNameReference * Used to get the problem binding of the field access and the name of the declaring type. * @return a field access. */ <T> CtFieldAccess<T> createFieldAccessNoClasspath(QualifiedNameReference qualifiedNameReference) { boolean fromAssignment = isLhsAssignment(jdtTreeBuilder.getContextBuilder(), qualifiedNameReference); CtFieldAccess<T> fieldAccess = createFieldAccess(jdtTreeBuilder.getReferencesBuilder().<T>getVariableReference((ProblemBinding) qualifiedNameReference.binding), null, fromAssignment); // In no classpath mode and with qualified name, the type given by JDT is wrong... final char[][] declaringClass = CharOperation.subarray(qualifiedNameReference.tokens, 0, qualifiedNameReference.tokens.length - 1); final MissingTypeBinding declaringType = jdtTreeBuilder.getContextBuilder().compilationunitdeclaration.scope.environment.createMissingType(null, declaringClass); final CtTypeReference<T> declaringRef = jdtTreeBuilder.getReferencesBuilder().getTypeReference(declaringType); fieldAccess.getVariable().setDeclaringType(declaringRef); fieldAccess.getVariable().setStatic(true); fieldAccess.setTarget(jdtTreeBuilder.getFactory().Code().createTypeAccess(declaringRef)); // In no classpath mode and with qualified name, the binding doesn't have a good name. fieldAccess.getVariable() .setSimpleName(createQualifiedTypeName(CharOperation.subarray(qualifiedNameReference.tokens, qualifiedNameReference.tokens.length - 1, qualifiedNameReference.tokens.length))); return fieldAccess; }
@SuppressWarnings("resource") public AstCompiler(INameEnvironment nameEnv) { super(nameEnv, DefaultErrorHandlingPolicies.proceedWithAllProblems(), opts, new P_EmptyCompilerRequestor(), new CollectingProblemFactory(), new P_EmptyPrintWriter(), null); lookupEnvironment.completeTypeBindings(); // must be called once so that the initial state is ready }