org.eclipse.jdt.internal.compiler.problem.AbortCompilation Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.problem.AbortCompilation. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QualifiedTypeReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected TypeBinding findNextTypeBinding(int tokenIndex, Scope scope, PackageBinding packageBinding) {
	LookupEnvironment env = scope.environment();
	try {
		env.missingClassFileLocation = this;
		if (this.resolvedType == null) {
			this.resolvedType = scope.getType(this.tokens[tokenIndex], packageBinding);
		} else {
			this.resolvedType = scope.getMemberType(this.tokens[tokenIndex], (ReferenceBinding) this.resolvedType);
			if (!this.resolvedType.isValidBinding()) {
				this.resolvedType = new ProblemReferenceBinding(
					CharOperation.subarray(this.tokens, 0, tokenIndex + 1),
					(ReferenceBinding)this.resolvedType.closestMatch(),
					this.resolvedType.problemId());
			}
		}
		return this.resolvedType;
	} catch (AbortCompilation e) {
		e.updateContext(this, scope.referenceCompilationUnit().compilationResult);
		throw e;
	} finally {
		env.missingClassFileLocation = null;
	}
}
 
Example #2
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected void createAnnotationValues(IBinding annotated, JvmAnnotationTarget result) {
	try {
		resolveAnnotations.start();
		IAnnotationBinding[] annotationBindings = annotated.getAnnotations();
		if (annotationBindings.length != 0) {
			InternalEList<JvmAnnotationReference> annotations = (InternalEList<JvmAnnotationReference>)result.getAnnotations();
			for (IAnnotationBinding annotation : annotationBindings) {
				annotations.addUnique(createAnnotationReference(annotation));
			}
		}
	} catch(AbortCompilation aborted) {
		if (aborted.problem.getID() == IProblem.IsClassPathCorrect) {
			// ignore
		} else {
			log.info("Couldn't resolve annotations of "+annotated, aborted);
		}
	} finally {
		resolveAnnotations.stop();
	}
}
 
Example #3
Source File: ArrayQualifiedTypeReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected TypeBinding getTypeBinding(Scope scope) {

		if (this.resolvedType != null)
			return this.resolvedType;
		if (this.dimensions > 255) {
			scope.problemReporter().tooManyDimensions(this);
		}
		LookupEnvironment env = scope.environment();
		try {
			env.missingClassFileLocation = this;
			TypeBinding leafComponentType = super.getTypeBinding(scope);
			if (leafComponentType != null) {
				return this.resolvedType = scope.createArrayType(leafComponentType, this.dimensions);
			}
			return null;
		} catch (AbortCompilation e) {
			e.updateContext(this, scope.referenceCompilationUnit().compilationResult);
			throw e;
		} finally {
			env.missingClassFileLocation = null;
		}
	}
 
Example #4
Source File: ClassScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
void connectTypeHierarchy() {
	SourceTypeBinding sourceType = this.referenceContext.binding;
	if ((sourceType.tagBits & TagBits.BeginHierarchyCheck) == 0) {
		sourceType.tagBits |= TagBits.BeginHierarchyCheck;
		environment().typesBeingConnected.add(sourceType);
		boolean noProblems = connectSuperclass();
		noProblems &= connectSuperInterfaces();
		environment().typesBeingConnected.remove(sourceType);
		sourceType.tagBits |= TagBits.EndHierarchyCheck;
		noProblems &= connectTypeVariables(this.referenceContext.typeParameters, false);
		sourceType.tagBits |= TagBits.TypeVariablesAreConnected;
		if (noProblems && sourceType.isHierarchyInconsistent())
			problemReporter().hierarchyHasProblems(sourceType);
	}
	connectMemberTypes();
	LookupEnvironment env = environment();
	try {
		env.missingClassFileLocation = this.referenceContext;
		checkForInheritedMemberTypes(sourceType);
	} catch (AbortCompilation e) {
		e.updateContext(this.referenceContext, referenceCompilationUnit().compilationResult);
		throw e;
	} finally {
		env.missingClassFileLocation = null;
	}
}
 
Example #5
Source File: ClassScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private ReferenceBinding findSupertype(TypeReference typeReference) {
	CompilationUnitScope unitScope = compilationUnitScope();
	LookupEnvironment env = unitScope.environment;
	try {
		env.missingClassFileLocation = typeReference;
		typeReference.aboutToResolve(this); // allows us to trap completion & selection nodes
		unitScope.recordQualifiedReference(typeReference.getTypeName());
		this.superTypeReference = typeReference;
		ReferenceBinding superType = (ReferenceBinding) typeReference.resolveSuperType(this);
		return superType;
	} catch (AbortCompilation e) {
		SourceTypeBinding sourceType = this.referenceContext.binding;
		if (sourceType.superInterfaces == null)  sourceType.setSuperInterfaces(Binding.NO_SUPERINTERFACES); // be more resilient for hierarchies (144976)
		e.updateContext(typeReference, referenceCompilationUnit().compilationResult);
		throw e;
	} finally {
		env.missingClassFileLocation = null;
		this.superTypeReference = null;
	}
}
 
Example #6
Source File: LookupEnvironment.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
ReferenceBinding askForType(PackageBinding packageBinding, char[] name) {
	if (packageBinding == null) {
		packageBinding = this.defaultPackage;
	}
	NameEnvironmentAnswer answer = this.nameEnvironment.findType(name, packageBinding.compoundName);
	if (answer == null)
		return null;

	if (answer.isBinaryType()) {
		// the type was found as a .class file
		this.typeRequestor.accept(answer.getBinaryType(), packageBinding, answer.getAccessRestriction());
	} else if (answer.isCompilationUnit()) {
		// the type was found as a .java file, try to build it then search the cache
		try {
			this.typeRequestor.accept(answer.getCompilationUnit(), answer.getAccessRestriction());
		} catch (AbortCompilation abort) {
			if (CharOperation.equals(name, TypeConstants.PACKAGE_INFO_NAME))
				return null; // silently, requestor may not be able to handle compilation units (HierarchyResolver)
			throw abort;
		}
	} else if (answer.isSourceType()) {
		// the type was found as a source model
		this.typeRequestor.accept(answer.getSourceTypes(), packageBinding, answer.getAccessRestriction());
	}
	return packageBinding.getType0(name);
}
 
Example #7
Source File: BatchProcessingEnvImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Parse the -A command line arguments so that they can be delivered to
 * processors with {@link javax.annotation.processing.ProcessingEnvironment#getOptions()}.  In Sun's Java 6
 * version of javac, unlike in the Java 5 apt tool, only the -A options are
 * passed to processors, not the other command line options; that behavior
 * is repeated here.
 * @param args the equivalent of the args array from the main() method.
 * @return a map of key to value, or key to null if there is no value for
 * a particular key.  The "-A" is stripped from the key, so a command-line
 * argument like "-Afoo=bar" will result in an entry with key "foo" and
 * value "bar".
 */
private Map<String, String> parseProcessorOptions(String[] args) {
	Map<String, String> options = new LinkedHashMap<String, String>();
	for (String arg : args) {
		if (!arg.startsWith("-A")) { //$NON-NLS-1$
			continue;
		}
		int equals = arg.indexOf('=');
		if (equals == 2) {
			// option begins "-A=" - not valid
			Exception e = new IllegalArgumentException("-A option must have a key before the equals sign"); //$NON-NLS-1$
			throw new AbortCompilation(null, e);
		}
		if (equals == arg.length() - 1) {
			// option ends with "=" - not valid
			options.put(arg.substring(2, equals), null);
		} else if (equals == -1) {
			// no value
			options.put(arg.substring(2), null);
		} else {
			// value and key
			options.put(arg.substring(2, equals), arg.substring(equals + 1));
		}
	}
	return options;
}
 
Example #8
Source File: JdtBasedTypeFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void setParameterNamesAndAnnotations(IMethodBinding method, ITypeBinding[] parameterTypes,
		String[] parameterNames, JvmExecutable result) {
	InternalEList<JvmFormalParameter> parameters = (InternalEList<JvmFormalParameter>)result.getParameters();
	for (int i = 0; i < parameterTypes.length; i++) {
		IAnnotationBinding[] parameterAnnotations;
		try {
			parameterAnnotations = method.getParameterAnnotations(i);
		} catch(AbortCompilation aborted) {
			parameterAnnotations = null;
		}
		ITypeBinding parameterType = parameterTypes[i];
		String parameterName = parameterNames == null ? null /* lazy */ : i < parameterNames.length ? parameterNames[i] : "arg" + i;
		JvmFormalParameter formalParameter = createFormalParameter(parameterType, parameterName, parameterAnnotations);
		parameters.addUnique(formalParameter);
	}
}
 
Example #9
Source File: AnnotationProcessorManager.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Processor next() {
  try {
    return (Processor) loader.loadClass(processors[idx++]).newInstance();
  } catch (ReflectiveOperationException e) {
    // TODO: better error handling
    throw new AbortCompilation(null, e);
  }
}
 
Example #10
Source File: NameEnvironmentWithProgress.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void checkCanceled() {
	if (this.monitor != null && this.monitor.isCanceled()) {
		if (NameLookup.VERBOSE) {
			System.out.println(Thread.currentThread() + " CANCELLING LOOKUP "); //$NON-NLS-1$
		}
		throw new AbortCompilation(true/*silent*/, new OperationCanceledException());
	}
}
 
Example #11
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void abort(int abortLevel, CategorizedProblem problem) {

	switch (abortLevel) {
		case AbortCompilation :
			throw new AbortCompilation(this.compilationResult, problem);
		case AbortCompilationUnit :
			throw new AbortCompilationUnit(this.compilationResult, problem);
		case AbortType :
			throw new AbortType(this.compilationResult, problem);
		default :
			throw new AbortMethod(this.compilationResult, problem);
	}
}
 
Example #12
Source File: DefaultBindingResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
synchronized IPackageBinding resolvePackage(PackageDeclaration pkg) {
	if (this.scope == null) return null;
	try {
		org.eclipse.jdt.internal.compiler.ast.ASTNode node = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(pkg);
		if (node instanceof ImportReference) {
			ImportReference importReference = (ImportReference) node;
			Binding binding = this.scope.getOnlyPackage(CharOperation.subarray(importReference.tokens, 0, importReference.tokens.length));
			if ((binding != null) && (binding.isValidBinding())) {
				if (binding instanceof ReferenceBinding) {
					// this only happens if a type name has the same name as its package
					ReferenceBinding referenceBinding = (ReferenceBinding) binding;
					binding = referenceBinding.fPackage;
				}
				if (binding instanceof org.eclipse.jdt.internal.compiler.lookup.PackageBinding) {
					IPackageBinding packageBinding = getPackageBinding((org.eclipse.jdt.internal.compiler.lookup.PackageBinding) binding);
					if (packageBinding == null) {
						return null;
					}
					this.bindingsToAstNodes.put(packageBinding, pkg);
					String key = packageBinding.getKey();
					if (key != null) {
						this.bindingTables.bindingKeysToBindings.put(key, packageBinding);
					}
					return packageBinding;
				}
			}
		}
	} catch (AbortCompilation e) {
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=53357
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=63550
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=64299
	}
	return null;
}
 
Example #13
Source File: MethodBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isSubsignature(IMethodBinding otherMethod) {
	try {
		LookupEnvironment lookupEnvironment = this.resolver.lookupEnvironment();
		return lookupEnvironment != null
			&& lookupEnvironment.methodVerifier().isMethodSubsignature(this.binding, ((MethodBinding) otherMethod).binding);
	} catch (AbortCompilation e) {
		// don't surface internal exception to clients
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013
		return false;
	}
}
 
Example #14
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isSubTypeCompatible(ITypeBinding type) {
	try {
		if (this == type) return true; //$IDENTITY-COMPARISON$
		if (this.binding.isBaseType()) return false;
		if (!(type instanceof TypeBinding)) return false;
		TypeBinding other = (TypeBinding) type;
		if (other.binding.isBaseType()) return false;
		return this.binding.isCompatibleWith(other.binding);
	} catch (AbortCompilation e) {
		// don't surface internal exception to clients
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013
		return false;
	}
}
 
Example #15
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isCastCompatible(ITypeBinding type) {
	try {
		Scope scope = this.resolver.scope();
		if (scope == null) return false;
		if (!(type instanceof TypeBinding)) return false;
		org.eclipse.jdt.internal.compiler.lookup.TypeBinding expressionType = ((TypeBinding) type).binding;
		// simulate capture in case checked binding did not properly get extracted from a reference
		expressionType = expressionType.capture(scope, 0);
		return TypeBinding.EXPRESSION.checkCastTypesCompatibility(scope, this.binding, expressionType, null);
	} catch (AbortCompilation e) {
		// don't surface internal exception to clients
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013
		return false;
	}
}
 
Example #16
Source File: TypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isAssignmentCompatible(ITypeBinding type) {
	try {
		if (this == type) return true; //$IDENTITY-COMPARISON$
		if (!(type instanceof TypeBinding)) return false;
		TypeBinding other = (TypeBinding) type;
		Scope scope = this.resolver.scope();
		if (scope == null) return false;
		return this.binding.isCompatibleWith(other.binding) || scope.isBoxingCompatibleWith(this.binding, other.binding);
	} catch (AbortCompilation e) {
		// don't surface internal exception to clients
		// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=143013
		return false;
	}
}
 
Example #17
Source File: CompilationUnitResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void handleInternalException(
		AbortCompilation abortException,
		CompilationUnitDeclaration unit) {
	super.handleInternalException(abortException, unit);
	if (unit != null) {
		removeUnresolvedBindings(unit);
	}
	this.hasCompilationAborted = true;
	this.abortProblem = abortException.problem;
}
 
Example #18
Source File: SourceFile.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public char[] getContents() {

	try {
		return Util.getResourceContentsAsCharArray(this.resource);
	} catch (CoreException e) {
		throw new AbortCompilation(true, new MissingSourceFileException(this.resource.getFullPath().toString()));
	}
}
 
Example #19
Source File: BuildNotifier.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check whether the build has been canceled.
 * Must use this call instead of checkCancel() when within the compiler.
 */
public void checkCancelWithinCompiler() {
	if (this.monitor != null && this.monitor.isCanceled() && !this.cancelling) {
		// Once the compiler has been canceled, don't check again.
		setCancelling(true);
		// Only AbortCompilation can stop the compiler cleanly.
		// We check cancelation again following the call to compile.
		throw new AbortCompilation(true, null);
	}
}
 
Example #20
Source File: CancelableNameEnvironment.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private void checkCanceled() {
	if (this.monitor != null && this.monitor.isCanceled()) {
		if (NameLookup.VERBOSE)
			System.out.println(Thread.currentThread() + " CANCELLING LOOKUP "); //$NON-NLS-1$
		throw new AbortCompilation(true/*silent*/, new OperationCanceledException());
	}
}
 
Example #21
Source File: HierarchyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean subOrSuperOfFocus(ReferenceBinding typeBinding) {
	if (this.focusType == null) return true; // accept all types (case of hierarchy in a region)
	try {
		if (subTypeOfType(this.focusType, typeBinding)) return true;
		if (!this.superTypesOnly && subTypeOfType(typeBinding, this.focusType)) return true;
	} catch (AbortCompilation e) {
		// unresolved superclass/superinterface -> ignore
	}
	return false;
}
 
Example #22
Source File: HierarchyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add additional source types
 * @param sourceTypes
 * @param packageBinding
 */
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	IProgressMonitor progressMonitor = this.builder.hierarchy.progressMonitor;
	if (progressMonitor != null && progressMonitor.isCanceled())
		throw new OperationCanceledException();

	// find most enclosing type first (needed when explicit askForType(...) is done
	// with a member type (e.g. p.A$B))
	ISourceType sourceType = sourceTypes[0];
	while (sourceType.getEnclosingType() != null)
		sourceType = sourceType.getEnclosingType();

	// build corresponding compilation unit
	CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, this.options.maxProblemsPerUnit);
	CompilationUnitDeclaration unit =
		SourceTypeConverter.buildCompilationUnit(
			new ISourceType[] {sourceType}, // ignore secondary types, to improve laziness
			SourceTypeConverter.MEMBER_TYPE | (this.lookupEnvironment.globalOptions.sourceLevel >= ClassFileConstants.JDK1_8 ? SourceTypeConverter.METHOD : 0), // need member types
			// no need for field initialization
			this.lookupEnvironment.problemReporter,
			result);

	// build bindings
	if (unit != null) {
		try {
			this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);

			org.eclipse.jdt.core.ICompilationUnit cu = ((SourceTypeElementInfo)sourceType).getHandle().getCompilationUnit();
			rememberAllTypes(unit, cu, false);

			this.lookupEnvironment.completeTypeBindings(unit, true/*build constructor only*/);
		} catch (AbortCompilation e) {
			// missing 'java.lang' package: ignore
		}
	}
}
 
Example #23
Source File: HierarchyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add an additional binary type
 * @param binaryType
 * @param packageBinding
 */
public void accept(IBinaryType binaryType, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	IProgressMonitor progressMonitor = this.builder.hierarchy.progressMonitor;
	if (progressMonitor != null && progressMonitor.isCanceled())
		throw new OperationCanceledException();

	BinaryTypeBinding typeBinding = this.lookupEnvironment.createBinaryTypeFrom(binaryType, packageBinding, accessRestriction);
	try {
		this.remember(binaryType, typeBinding);
	} catch (AbortCompilation e) {
		// ignore
	}
}
 
Example #24
Source File: NameEnvironment.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private NameEnvironmentAnswer findClass(String qualifiedTypeName, char[] typeName) {
	if (this.notifier != null)
		this.notifier.checkCancelWithinCompiler();

	if (this.initialTypeNames != null && this.initialTypeNames.includes(qualifiedTypeName)) {
		if (this.isIncrementalBuild)
			// catch the case that a type inside a source file has been renamed but other class files are looking for it
			throw new AbortCompilation(true, new AbortIncrementalBuildException(qualifiedTypeName));
		return null; // looking for a file which we know was provided at the beginning of the compilation
	}

	if (this.additionalUnits != null && this.sourceLocations.length > 0) {
		// if an additional source file is waiting to be compiled, answer it BUT not if this is a secondary type search
		// if we answer X.java & it no longer defines Y then the binary type looking for Y will think the class path is wrong
		// let the recompile loop fix up dependents when the secondary type Y has been deleted from X.java
		// Only enclosing type names are present in the additional units table, so strip off inner class specifications
		// when doing the lookup (https://bugs.eclipse.org/372418). 
		// Also take care of $ in the name of the class (https://bugs.eclipse.org/377401)
		// and prefer name with '$' if unit exists rather than failing to search for nested class (https://bugs.eclipse.org/392727)
		SourceFile unit = (SourceFile) this.additionalUnits.get(qualifiedTypeName); // doesn't have file extension
		if (unit != null)
			return new NameEnvironmentAnswer(unit, null /*no access restriction*/);
		int index = qualifiedTypeName.indexOf('$');
		if (index > 0) {
			String enclosingTypeName = qualifiedTypeName.substring(0, index);
			unit = (SourceFile) this.additionalUnits.get(enclosingTypeName); // doesn't have file extension
			if (unit != null)
				return new NameEnvironmentAnswer(unit, null /*no access restriction*/);
		}
	}

	String qBinaryFileName = qualifiedTypeName + SUFFIX_STRING_class;
	String binaryFileName = qBinaryFileName;
	String qPackageName =  ""; //$NON-NLS-1$
	if (qualifiedTypeName.length() > typeName.length) {
		int typeNameStart = qBinaryFileName.length() - typeName.length - 6; // size of ".class"
		qPackageName =  qBinaryFileName.substring(0, typeNameStart - 1);
		binaryFileName = qBinaryFileName.substring(typeNameStart);
	}

	// NOTE: the output folders are added at the beginning of the binaryLocations
	NameEnvironmentAnswer suggestedAnswer = null;
	for (int i = 0, l = this.binaryLocations.length; i < l; i++) {
		NameEnvironmentAnswer answer = this.binaryLocations[i].findClass(binaryFileName, qPackageName, qBinaryFileName);
		if (answer != null) {
			if (!answer.ignoreIfBetter()) {
				if (answer.isBetter(suggestedAnswer))
					return answer;
			} else if (answer.isBetter(suggestedAnswer))
				// remember suggestion and keep looking
				suggestedAnswer = answer;
		}
	}
	if (suggestedAnswer != null)
		// no better answer was found
		return suggestedAnswer;
	return null;
}
 
Example #25
Source File: CancelableProblemFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public CategorizedProblem createProblem(char[] originatingFileName, int problemId, String[] problemArguments, int elaborationId, String[] messageArguments, int severity, int startPosition, int endPosition, int lineNumber, int columnNumber) {
	if (this.monitor != null && this.monitor.isCanceled())
		throw new AbortCompilation(true/*silent*/, new OperationCanceledException());
	return super.createProblem(originatingFileName, problemId, problemArguments, elaborationId, messageArguments, severity, startPosition, endPosition, lineNumber, columnNumber);
}
 
Example #26
Source File: DefaultBindingResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
synchronized ITypeBinding resolveExpressionType(Expression expression) {
	try {
		switch(expression.getNodeType()) {
			case ASTNode.CLASS_INSTANCE_CREATION :
				org.eclipse.jdt.internal.compiler.ast.ASTNode astNode = (org.eclipse.jdt.internal.compiler.ast.ASTNode) this.newAstToOldAst.get(expression);
				if (astNode instanceof org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) {
					// anonymous type case
					org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration = (org.eclipse.jdt.internal.compiler.ast.TypeDeclaration) astNode;
					ITypeBinding typeBinding = this.getTypeBinding(typeDeclaration.binding);
					if (typeBinding != null) {
						return typeBinding;
					}
				} else if (astNode instanceof AllocationExpression) {
					// should be an AllocationExpression
					AllocationExpression allocationExpression = (AllocationExpression) astNode;
					return this.getTypeBinding(allocationExpression.resolvedType);
				}
				break;
			case ASTNode.SIMPLE_NAME :
			case ASTNode.QUALIFIED_NAME :
				return resolveTypeBindingForName((Name) expression);
			case ASTNode.ARRAY_INITIALIZER :
			case ASTNode.ARRAY_CREATION :
			case ASTNode.ASSIGNMENT :
			case ASTNode.POSTFIX_EXPRESSION :
			case ASTNode.PREFIX_EXPRESSION :
			case ASTNode.CAST_EXPRESSION :
			case ASTNode.TYPE_LITERAL :
			case ASTNode.INFIX_EXPRESSION :
			case ASTNode.INSTANCEOF_EXPRESSION :
			case ASTNode.LAMBDA_EXPRESSION:
			case ASTNode.CREATION_REFERENCE:
			case ASTNode.EXPRESSION_METHOD_REFERENCE:
			case ASTNode.TYPE_METHOD_REFERENCE:
			case ASTNode.SUPER_METHOD_REFERENCE :
			case ASTNode.FIELD_ACCESS :
			case ASTNode.SUPER_FIELD_ACCESS :
			case ASTNode.ARRAY_ACCESS :
			case ASTNode.METHOD_INVOCATION :
			case ASTNode.SUPER_METHOD_INVOCATION :
			case ASTNode.CONDITIONAL_EXPRESSION :
			case ASTNode.MARKER_ANNOTATION :
			case ASTNode.NORMAL_ANNOTATION :
			case ASTNode.SINGLE_MEMBER_ANNOTATION :
				org.eclipse.jdt.internal.compiler.ast.Expression compilerExpression = (org.eclipse.jdt.internal.compiler.ast.Expression) this.newAstToOldAst.get(expression);
				if (compilerExpression != null) {
					return this.getTypeBinding(compilerExpression.resolvedType);
				}
				break;
			case ASTNode.STRING_LITERAL :
				if (this.scope != null) {
					return this.getTypeBinding(this.scope.getJavaLangString());
				}
				break;
			case ASTNode.BOOLEAN_LITERAL :
			case ASTNode.NULL_LITERAL :
			case ASTNode.CHARACTER_LITERAL :
			case ASTNode.NUMBER_LITERAL :
				Literal literal = (Literal) this.newAstToOldAst.get(expression);
				if (literal != null) {
					return this.getTypeBinding(literal.literalType(null));
				}
				break;
			case ASTNode.THIS_EXPRESSION :
				ThisReference thisReference = (ThisReference) this.newAstToOldAst.get(expression);
				BlockScope blockScope = (BlockScope) this.astNodesToBlockScope.get(expression);
				if (blockScope != null) {
					return this.getTypeBinding(thisReference.resolveType(blockScope));
				}
				break;
			case ASTNode.PARENTHESIZED_EXPRESSION :
				ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression;
				return resolveExpressionType(parenthesizedExpression.getExpression());
			case ASTNode.VARIABLE_DECLARATION_EXPRESSION :
				VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression) expression;
				Type type = variableDeclarationExpression.getType();
				if (type != null) {
					return type.resolveBinding();
				}
				break;
		}
	} catch (AbortCompilation e) {
		// handle missing types
	}
	return null;
}
 
Example #27
Source File: CancelableProblemFactory.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public CategorizedProblem createProblem(char[] originatingFileName, int problemId, String[] problemArguments, String[] messageArguments, int severity, int startPosition, int endPosition, int lineNumber, int columnNumber) {
	if (this.monitor != null && this.monitor.isCanceled())
		throw new AbortCompilation(true/*silent*/, new OperationCanceledException());
	return super.createProblem(originatingFileName, problemId, problemArguments, messageArguments, severity, startPosition, endPosition, lineNumber, columnNumber);
}
 
Example #28
Source File: DefaultBindingResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
synchronized ITypeBinding resolveWellKnownType(String name) {
	if (this.scope == null) return null;
	ITypeBinding typeBinding = null;
	try {
		if (("boolean".equals(name))//$NON-NLS-1$
			|| ("char".equals(name))//$NON-NLS-1$
			|| ("byte".equals(name))//$NON-NLS-1$
			|| ("short".equals(name))//$NON-NLS-1$
			|| ("int".equals(name))//$NON-NLS-1$
			|| ("long".equals(name))//$NON-NLS-1$
			|| ("float".equals(name))//$NON-NLS-1$
			|| ("double".equals(name))//$NON-NLS-1$
			|| ("void".equals(name))) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(Scope.getBaseType(name.toCharArray()));
		} else if ("java.lang.Object".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getJavaLangObject());
		} else if ("java.lang.String".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getJavaLangString());
		} else if ("java.lang.StringBuffer".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_STRINGBUFFER, 3));
		} else if ("java.lang.Throwable".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getJavaLangThrowable());
		} else if ("java.lang.Exception".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_EXCEPTION, 3));
		} else if ("java.lang.RuntimeException".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_RUNTIMEEXCEPTION, 3));
		} else if ("java.lang.Error".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_ERROR, 3));
		} else if ("java.lang.Class".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getJavaLangClass());
		} else if ("java.lang.Cloneable".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getJavaLangCloneable());
		} else if ("java.io.Serializable".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getJavaIoSerializable());
		} else if ("java.lang.Boolean".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_BOOLEAN, 3));
		} else if ("java.lang.Byte".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_BYTE, 3));
		} else if ("java.lang.Character".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_CHARACTER, 3));
		} else if ("java.lang.Double".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_DOUBLE, 3));
		} else if ("java.lang.Float".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_FLOAT, 3));
		} else if ("java.lang.Integer".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_INTEGER, 3));
		} else if ("java.lang.Long".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_LONG, 3));
		} else if ("java.lang.Short".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_SHORT, 3));
		} else if ("java.lang.Void".equals(name)) {//$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_VOID, 3));
		} else if ("java.lang.AssertionError".equals(name)) { //$NON-NLS-1$
			typeBinding = this.getTypeBinding(this.scope.getType(TypeConstants.JAVA_LANG_ASSERTIONERROR, 3));
		}
	} catch (AbortCompilation e) {
		// ignore missing types
	}
	if (typeBinding != null && !typeBinding.isRecovered()) {
		return typeBinding;
	}
	return null;
}
 
Example #29
Source File: AssistParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Parse the block statements inside the given method declaration and try to complete at the
 * cursor location.
 */
public void parseBlockStatements(MethodDeclaration md, CompilationUnitDeclaration unit) {
	//only parse the method body of md
	//fill out method statements

	//convert bugs into parse error

	if (md.isAbstract())
		return;
	if (md.isNative())
		return;
	if ((md.modifiers & ExtraCompilerModifiers.AccSemicolonBody) != 0)
		return;

	initialize();
	// set the lastModifiers to reflect the modifiers of the method whose
	// block statements are being parsed
	// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634
	this.lastModifiers = md.modifiers;
	this.lastModifiersStart = md.modifiersSourceStart;
	// simulate goForMethodBody except that we don't want to balance brackets because they are not going to be balanced
	goForBlockStatementsopt();

	this.referenceContext = md;
	this.compilationUnit = unit;

	this.scanner.resetTo(md.bodyStart, bodyEnd(md)); // reset the scanner to parser from { down to the cursor location
	consumeNestedMethod();
	try {
		parse();
	} catch (AbortCompilation ex) {
		this.lastAct = ERROR_ACTION;
	} finally {
		this.nestedMethod[this.nestedType]--;
	}

	if (this.lastAct == ERROR_ACTION) {
		md.bits |= ASTNode.HasSyntaxErrors;
		return;
	}

	// attach the statements as we might be searching for a reference to a local type
	md.explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
	int length;
	if ((length = this.astLengthStack[this.astLengthPtr--]) != 0) {
		System.arraycopy(
			this.astStack,
			(this.astPtr -= length) + 1,
			md.statements = new Statement[length],
			0,
			length);
	} else {
		if (!containsComment(md.bodyStart, md.bodyEnd)) {
			md.bits |= ASTNode.UndocumentedEmptyBlock;
		}
	}

}
 
Example #30
Source File: AssistParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Parse the block statements inside the given initializer and try to complete at the
 * cursor location.
 */
public void parseBlockStatements(
	Initializer initializer,
	TypeDeclaration type,
	CompilationUnitDeclaration unit) {

	initialize();
	// set the lastModifiers to reflect the modifiers of the initializer whose
	// block statements are being parsed
	// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=202634
	this.lastModifiers = initializer.modifiers;
	this.lastModifiersStart = initializer.modifiersSourceStart;
	// simulate goForInitializer except that we don't want to balance brackets because they are not going to be balanced
	goForBlockStatementsopt();

	this.referenceContext = type;
	this.compilationUnit = unit;

	this.scanner.resetTo(initializer.sourceStart, bodyEnd(initializer)); // just after the beginning {
	consumeNestedMethod();
	try {
		parse();
	} catch (AbortCompilation ex) {
		this.lastAct = ERROR_ACTION;
	} finally {
		this.nestedMethod[this.nestedType]--;
	}

	if (this.lastAct == ERROR_ACTION) {
		initializer.bits |= ASTNode.HasSyntaxErrors;
		return;
	}

	// attach the statements as we might be searching for a reference to a local type
	initializer.block.explicitDeclarations = this.realBlockStack[this.realBlockPtr--];
	int length;
	if ((length = this.astLengthStack[this.astLengthPtr--]) > 0) {
		System.arraycopy(this.astStack, (this.astPtr -= length) + 1, initializer.block.statements = new Statement[length], 0, length);
	} else {
		// check whether this block at least contains some comment in it
		if (!containsComment(initializer.block.sourceStart, initializer.block.sourceEnd)) {
			initializer.block.bits |= ASTNode.UndocumentedEmptyBlock;
		}
	}

	// mark initializer with local type if one was found during parsing
	if ((type.bits & ASTNode.HasLocalType) != 0) {
		initializer.bits |= ASTNode.HasLocalType;
	}
}