org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants. 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: AbstractCommentParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected AbstractCommentParser(Parser sourceParser) {
	this.sourceParser = sourceParser;
	this.scanner = new Scanner(false, false, false, ClassFileConstants.JDK1_3, null, null, true/*taskCaseSensitive*/);
	this.identifierStack = new char[20][];
	this.identifierPositionStack = new long[20];
	this.identifierLengthStack = new int[10];
	this.astStack = new Object[30];
	this.astLengthStack = new int[20];
	this.reportProblems = sourceParser != null;
	if (sourceParser != null) {
		this.checkDocComment = this.sourceParser.options.docCommentSupport;
		this.sourceLevel = this.sourceParser.options.sourceLevel;
		this.scanner.sourceLevel = this.sourceLevel;
		this.complianceLevel = this.sourceParser.options.complianceLevel;
	}
}
 
Example #2
Source File: Util.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the outer most enclosing type's visibility for the given TypeDeclaration
 * and visibility based on compiler options.
 */
public static int computeOuterMostVisibility(TypeDeclaration typeDeclaration, int visibility) {
	while (typeDeclaration != null) {
		switch (typeDeclaration.modifiers & ExtraCompilerModifiers.AccVisibilityMASK) {
			case ClassFileConstants.AccPrivate:
				visibility = ClassFileConstants.AccPrivate;
				break;
			case ClassFileConstants.AccDefault:
				if (visibility != ClassFileConstants.AccPrivate) {
					visibility = ClassFileConstants.AccDefault;
				}
				break;
			case ClassFileConstants.AccProtected:
				if (visibility == ClassFileConstants.AccPublic) {
					visibility = ClassFileConstants.AccProtected;
				}
				break;
		}
		typeDeclaration = typeDeclaration.enclosingType;
	}
	return visibility;
}
 
Example #3
Source File: BlockScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public final ReferenceBinding findLocalType(char[] name) {
	long compliance = compilerOptions().complianceLevel;
	for (int i = this.subscopeCount-1; i >= 0; i--) {
		if (this.subscopes[i] instanceof ClassScope) {
			LocalTypeBinding sourceType = (LocalTypeBinding)((ClassScope) this.subscopes[i]).referenceContext.binding;
			// from 1.4 on, local types should not be accessed across switch case blocks (52221)
			if (compliance >= ClassFileConstants.JDK1_4 && sourceType.enclosingCase != null) {
				if (!isInsideCase(sourceType.enclosingCase)) {
					continue;
				}
			}
			if (CharOperation.equals(sourceType.sourceName(), name))
				return sourceType;
		}
	}
	return null;
}
 
Example #4
Source File: MissingTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Special constructor for constructing proxies of missing types (114349)
 * @param packageBinding
 * @param compoundName
 * @param environment
 */
public MissingTypeBinding(PackageBinding packageBinding, char[][] compoundName, LookupEnvironment environment) {
	this.compoundName = compoundName;
	computeId();
	this.tagBits |= TagBits.IsBinaryBinding | TagBits.HierarchyHasProblems | TagBits.HasMissingType;
	this.environment = environment;
	this.fPackage = packageBinding;
	this.fileName = CharOperation.concatWith(compoundName, '/');
	this.sourceName = compoundName[compoundName.length - 1]; // [java][util][Map$Entry]
	this.modifiers = ClassFileConstants.AccPublic;
	this.superclass = null; // will be fixed up using #setMissingSuperclass(...)
	this.superInterfaces = Binding.NO_SUPERINTERFACES;
	this.typeVariables = Binding.NO_TYPE_VARIABLES;
	this.memberTypes = Binding.NO_MEMBER_TYPES;
	this.fields = Binding.NO_FIELDS;
	this.methods = Binding.NO_METHODS;
}
 
Example #5
Source File: ExplicitConstructorCall.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) {
	if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0)	{
		// if constructor from parameterized type got found, use the original constructor at codegen time
		MethodBinding codegenBinding = this.binding.original();

		// perform some emulation work in case there is some and we are inside a local type only
		if (this.binding.isPrivate() && this.accessMode != ExplicitConstructorCall.This) {
			ReferenceBinding declaringClass = codegenBinding.declaringClass;
			// from 1.4 on, local type constructor can lose their private flag to ease emulation
			if ((declaringClass.tagBits & TagBits.IsLocalType) != 0 && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) {
				// constructor will not be dumped as private, no emulation required thus
				codegenBinding.tagBits |= TagBits.ClearPrivateModifier;
			} else {
				this.syntheticAccessor = ((SourceTypeBinding) declaringClass).addSyntheticMethod(codegenBinding, isSuperAccess());
				currentScope.problemReporter().needToEmulateMethodAccess(codegenBinding, this);
			}
		}
	}
}
 
Example #6
Source File: TypeDeclarationPattern.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
protected void decodeModifiers() {

	// Extract suffix from modifiers instead of index key
	switch (this.modifiers & (ClassFileConstants.AccInterface|ClassFileConstants.AccEnum|ClassFileConstants.AccAnnotation)) {
		case ClassFileConstants.AccAnnotation:
		case ClassFileConstants.AccAnnotation+ClassFileConstants.AccInterface:
			this.typeSuffix = ANNOTATION_TYPE_SUFFIX;
			break;
		case ClassFileConstants.AccEnum:
			this.typeSuffix = ENUM_SUFFIX;
			break;
		case ClassFileConstants.AccInterface:
			this.typeSuffix = INTERFACE_SUFFIX;
			break;
		default:
			this.typeSuffix = CLASS_SUFFIX;
			break;
	}
}
 
Example #7
Source File: HandleFieldDefaults.java    From EasyMPermission with MIT License 6 votes vote down vote up
public void setFieldDefaultsForField(EclipseNode fieldNode, ASTNode pos, AccessLevel level, boolean makeFinal) {
	FieldDeclaration field = (FieldDeclaration) fieldNode.get();
	if (level != null && level != AccessLevel.NONE) {
		if ((field.modifiers & (ClassFileConstants.AccPublic | ClassFileConstants.AccPrivate | ClassFileConstants.AccProtected)) == 0) {
			if (!hasAnnotation(PackagePrivate.class, fieldNode)) {
				field.modifiers |= EclipseHandlerUtil.toEclipseModifier(level);
			}
		}
	}
	
	if (makeFinal && (field.modifiers & ClassFileConstants.AccFinal) == 0) {
		if (!hasAnnotation(NonFinal.class, fieldNode)) {
			field.modifiers |= ClassFileConstants.AccFinal;
		}
	}
	
	fieldNode.rebuild();
}
 
Example #8
Source File: RecoveredMethod.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
void attach(TypeParameter[] parameters, int startPos) {
	if(this.methodDeclaration.modifiers != ClassFileConstants.AccDefault) return;

	int lastParameterEnd = parameters[parameters.length - 1].sourceEnd;

	Parser parser = parser();
	Scanner scanner = parser.scanner;
	if(Util.getLineNumber(this.methodDeclaration.declarationSourceStart, scanner.lineEnds, 0, scanner.linePtr)
			!= Util.getLineNumber(lastParameterEnd, scanner.lineEnds, 0, scanner.linePtr)) return;

	if(parser.modifiersSourceStart > lastParameterEnd
			&& parser.modifiersSourceStart < this.methodDeclaration.declarationSourceStart) return;

	if (this.methodDeclaration instanceof MethodDeclaration) {
		((MethodDeclaration)this.methodDeclaration).typeParameters = parameters;
		this.methodDeclaration.declarationSourceStart = startPos;
	} else if (this.methodDeclaration instanceof ConstructorDeclaration){
		((ConstructorDeclaration)this.methodDeclaration).typeParameters = parameters;
		this.methodDeclaration.declarationSourceStart = startPos;
	}
}
 
Example #9
Source File: SourceTypeBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Compute the tagbits for standard annotations. For source types, these could require
 * lazily resolving corresponding annotation nodes, in case of forward references.
 * For type use bindings, this method still returns the tagbits corresponding to the type 
 * declaration binding.
 * @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits()
 */
public long getAnnotationTagBits() {
	if (!isPrototype())
		return this.prototype.getAnnotationTagBits();
	
	if ((this.tagBits & TagBits.AnnotationResolved) == 0 && this.scope != null) {
		TypeDeclaration typeDecl = this.scope.referenceContext;
		boolean old = typeDecl.staticInitializerScope.insideTypeAnnotation;
		try {
			typeDecl.staticInitializerScope.insideTypeAnnotation = true;
			ASTNode.resolveAnnotations(typeDecl.staticInitializerScope, typeDecl.annotations, this);
		} finally {
			typeDecl.staticInitializerScope.insideTypeAnnotation = old;
		}
		if ((this.tagBits & TagBits.AnnotationDeprecated) != 0)
			this.modifiers |= ClassFileConstants.AccDeprecated;
		evaluateNullAnnotations(this.tagBits);
	}
	return this.tagBits;
}
 
Example #10
Source File: CompilationUnitScope.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Binding findSingleImport(char[][] compoundName, int mask, boolean findStaticImports) {
	if (compoundName.length == 1) {
		// findType records the reference
		// the name cannot be a package
		if (compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4)
			return new ProblemReferenceBinding(compoundName, null, ProblemReasons.NotFound);
		ReferenceBinding typeBinding = findType(compoundName[0], this.environment.defaultPackage, this.fPackage);
		if (typeBinding == null)
			return new ProblemReferenceBinding(compoundName, null, ProblemReasons.NotFound);
		return typeBinding;
	}

	if (findStaticImports)
		return findSingleStaticImport(compoundName, mask);
	return findImport(compoundName, compoundName.length);
}
 
Example #11
Source File: ExtraFlags.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static int getExtraFlags(TypeDeclaration typeDeclaration) {
	int extraFlags = 0;
	
	if (typeDeclaration.enclosingType != null) {
		extraFlags |= ExtraFlags.IsMemberType;
	}
	TypeDeclaration[] memberTypes = typeDeclaration.memberTypes;
	int memberTypeCounter = memberTypes == null ? 0 : memberTypes.length;
	if (memberTypeCounter > 0) {
		done : for (int i = 0; i < memberTypeCounter; i++) {
			int modifiers = memberTypes[i].modifiers;
			// if the member type is static and not private
			if ((modifiers & ClassFileConstants.AccStatic) != 0 && (modifiers & ClassFileConstants.AccPrivate) == 0) {
				extraFlags |= ExtraFlags.HasNonPrivateStaticMemberTypes;
				break done;
			}
		}
	}
	
	return extraFlags;
}
 
Example #12
Source File: ReturnStatement.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
void checkAgainstNullAnnotation(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) {
	int nullStatus = this.expression.nullStatus(flowInfo, flowContext);
	long tagBits;
	MethodBinding methodBinding = null;
	boolean useTypeAnnotations = scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8;
	try {
		methodBinding = scope.methodScope().referenceMethodBinding();
		tagBits = (useTypeAnnotations) ? methodBinding.returnType.tagBits : methodBinding.tagBits;
	} catch (NullPointerException npe) {
		// chain of references in try-block has several potential nulls;
		// any null means we cannot perform the following check
		return;			
	}
	if (useTypeAnnotations) {
		checkAgainstNullTypeAnnotation(scope, methodBinding.returnType, this.expression, flowContext, flowInfo);
	} else if (nullStatus != FlowInfo.NON_NULL) {
		// if we can't prove non-null check against declared null-ness of the enclosing method:
		if ((tagBits & TagBits.AnnotationNonNull) != 0) {
			flowContext.recordNullityMismatch(scope, this.expression, this.expression.resolvedType, methodBinding.returnType, nullStatus);
		}
	}
}
 
Example #13
Source File: Argument.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public TypeBinding createBinding(MethodScope scope, TypeBinding typeBinding) {
	if (this.binding == null) {
		// for default constructors and fake implementation of abstract methods 
		this.binding = new LocalVariableBinding(this, typeBinding, this.modifiers, scope);
	} else if (!this.binding.type.isValidBinding()) {
		AbstractMethodDeclaration methodDecl = scope.referenceMethod();
		if (methodDecl != null) {
			MethodBinding methodBinding = methodDecl.binding;
			if (methodBinding != null) {
				methodBinding.tagBits |= TagBits.HasUnresolvedArguments;
			}
		}
	}
	if ((this.binding.tagBits & TagBits.AnnotationResolved) == 0) {
		resolveAnnotations(scope, this.annotations, this.binding, true);
		if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8) {
			Annotation.isTypeUseCompatible(this.type, scope, this.annotations);
			scope.validateNullAnnotation(this.binding.tagBits, this.type, this.annotations);
		}
	}
	this.binding.declaration = this;
	return this.binding.type; // might have been updated during resolveAnnotations (for typeAnnotations)
}
 
Example #14
Source File: SingleNameReference.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean checkNPE(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) {
	if (!super.checkNPE(scope, flowContext, flowInfo)) {
		CompilerOptions compilerOptions = scope.compilerOptions();
		if (compilerOptions.isAnnotationBasedNullAnalysisEnabled) {
			VariableBinding var = nullAnnotatedVariableBinding(compilerOptions.sourceLevel >= ClassFileConstants.JDK1_8);
			if (var instanceof FieldBinding) {
				checkNullableFieldDereference(scope, (FieldBinding) var, ((long)this.sourceStart<<32)+this.sourceEnd);
				return true;
			}
		}
	}
	return false;
}
 
Example #15
Source File: LambdaExpression.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
	if (this.shouldCaptureInstance) {
		this.binding.modifiers &= ~ClassFileConstants.AccStatic;
	} else {
		this.binding.modifiers |= ClassFileConstants.AccStatic;
	}
	SourceTypeBinding sourceType = currentScope.enclosingSourceType();
	this.binding = sourceType.addSyntheticMethod(this);
	int pc = codeStream.position;
	StringBuffer signature = new StringBuffer();
	signature.append('(');
	if (this.shouldCaptureInstance) {
		codeStream.aload_0();
		signature.append(sourceType.signature());
	}
	for (int i = 0, length = this.outerLocalVariables == null ? 0 : this.outerLocalVariables.length; i < length; i++) {
		SyntheticArgumentBinding syntheticArgument = this.outerLocalVariables[i];
		if (this.shouldCaptureInstance) {
			syntheticArgument.resolvedPosition++;
		}
		signature.append(syntheticArgument.type.signature());
		LocalVariableBinding capturedOuterLocal = syntheticArgument.actualOuterLocalVariable;
		VariableBinding[] path = currentScope.getEmulationPath(capturedOuterLocal);
		codeStream.generateOuterAccess(path, this, capturedOuterLocal, currentScope);
	}
	signature.append(')');
	if (this.expectedType instanceof IntersectionCastTypeBinding) {
		signature.append(((IntersectionCastTypeBinding)this.expectedType).getSAMType(currentScope).signature());
	} else {
		signature.append(this.expectedType.signature());
	}
	int invokeDynamicNumber = codeStream.classFile.recordBootstrapMethod(this);
	codeStream.invokeDynamic(invokeDynamicNumber, (this.shouldCaptureInstance ? 1 : 0) + this.outerLocalVariablesSlotSize, 1, this.descriptor.selector, signature.toString().toCharArray());
	if (!valueRequired)
		codeStream.pop();
	codeStream.recordPositionsFrom(pc, this.sourceStart);		
}
 
Example #16
Source File: EclipseGuavaSingularizer.java    From EasyMPermission with MIT License 5 votes vote down vote up
void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
	boolean mapMode = isMap();
	
	MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
	md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
	md.modifiers = ClassFileConstants.AccPublic;
	
	List<Statement> statements = new ArrayList<Statement>();
	statements.add(createConstructBuilderVarIfNeeded(data, builderType));
	
	FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
	thisDotField.receiver = new ThisReference(0, 0);
	MessageSend thisDotFieldDotAddAll = new MessageSend();
	thisDotFieldDotAddAll.arguments = new Expression[] {new SingleNameReference(data.getPluralName(), 0L)};
	thisDotFieldDotAddAll.receiver = thisDotField;
	thisDotFieldDotAddAll.selector = (mapMode ? "putAll" : "addAll").toCharArray();
	statements.add(thisDotFieldDotAddAll);
	if (returnStatement != null) statements.add(returnStatement);
	
	md.statements = statements.toArray(new Statement[statements.size()]);
	
	TypeReference paramType;
	if (mapMode) {
		paramType = new QualifiedTypeReference(JAVA_UTIL_MAP, NULL_POSS);
		paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs());
	} else {
		paramType = new QualifiedTypeReference(TypeConstants.JAVA_LANG_ITERABLE, NULL_POSS);
		paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs());
	}
	Argument param = new Argument(data.getPluralName(), 0, paramType, 0);
	md.arguments = new Argument[] {param};
	md.returnType = returnType;
	md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName(mapMode ? "putAll" : "addAll", new String(data.getPluralName())).toCharArray();
	
	data.setGeneratedByRecursive(md);
	injectMethod(builderType, md);
}
 
Example #17
Source File: EclipseHandlerUtil.java    From EasyMPermission with MIT License 5 votes vote down vote up
public static boolean filterField(FieldDeclaration declaration, boolean skipStatic) {
	// Skip the fake fields that represent enum constants.
	if (declaration.initialization instanceof AllocationExpression &&
			((AllocationExpression)declaration.initialization).enumConstant != null) return false;
	
	if (declaration.type == null) return false;
	
	// Skip fields that start with $
	if (declaration.name.length > 0 && declaration.name[0] == '$') return false;
	
	// Skip static fields.
	if (skipStatic && (declaration.modifiers & ClassFileConstants.AccStatic) != 0) return false;
	
	return true;
}
 
Example #18
Source File: CaptureBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public CaptureBinding(WildcardBinding wildcard, ReferenceBinding sourceType, int position, int captureID) {
	super(TypeConstants.WILDCARD_CAPTURE_NAME_PREFIX, null, 0, wildcard.environment);
	this.wildcard = wildcard;
	this.modifiers = ClassFileConstants.AccPublic | ExtraCompilerModifiers.AccGenericSignature; // treat capture as public
	this.fPackage = wildcard.fPackage;
	this.sourceType = sourceType;
	this.position = position;
	this.captureID = captureID;
	this.tagBits |= TagBits.HasCapturedWildcard;
	if (wildcard.hasTypeAnnotations()) {
		setTypeAnnotations(wildcard.getTypeAnnotations(), wildcard.environment.globalOptions.isAnnotationBasedNullAnalysisEnabled);
		if (wildcard.hasNullTypeAnnotations())
			this.tagBits |= TagBits.HasNullTypeAnnotation;
	}
}
 
Example #19
Source File: BaseProcessingEnvImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public SourceVersion getSourceVersion() {
	if (this._compiler.options.sourceLevel <= ClassFileConstants.JDK1_5) {
		return SourceVersion.RELEASE_5;
	}
	if (this._compiler.options.sourceLevel == ClassFileConstants.JDK1_6) {
		return SourceVersion.RELEASE_6;
	}
	try {
		return SourceVersion.valueOf("RELEASE_7"); //$NON-NLS-1$
	} catch(IllegalArgumentException e) {
		// handle call on a JDK 6
		return SourceVersion.RELEASE_6;
	}
}
 
Example #20
Source File: AST.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new, empty abstract syntax tree using the given options.
 * <p>
 * Following option keys are significant:
 * <ul>
 * <li><code>"org.eclipse.jdt.core.compiler.source"</code> -
 *    indicates source compatibility mode (as per <code>JavaCore</code>);
 *    <code>"1.3"</code> means the source code is as per JDK 1.3;
 *    <code>"1.4"</code> means the source code is as per JDK 1.4
 *    (<code>"assert"</code> is now a keyword);
 *    <code>"1.5"</code> means the source code is as per JDK 1.5
 *    (<code>"enum"</code> is now a keyword);
 *    <code>"1.7"</code> means the source code is as per JDK 1.7;
 *    additional legal values may be added later. </li>
 * </ul>
 * Options other than the above are ignored.
 * </p>
 *
 * @param options the table of options (key type: <code>String</code>;
 *    value type: <code>String</code>)
 * @see JavaCore#getDefaultOptions()
 * @deprecated Clients should port their code to use the new JLS4 AST API and call
 *    {@link #newAST(int) AST.newAST(AST.JLS4)} instead of using this constructor.
 */
public AST(Map options) {
	this(JLS2);
	Object sourceLevelOption = options.get(JavaCore.COMPILER_SOURCE);
	long sourceLevel = ClassFileConstants.JDK1_3;
	if (JavaCore.VERSION_1_4.equals(sourceLevelOption)) {
		sourceLevel = ClassFileConstants.JDK1_4;
	} else if (JavaCore.VERSION_1_5.equals(sourceLevelOption)) {
		sourceLevel = ClassFileConstants.JDK1_5;
	} else if (JavaCore.VERSION_1_7.equals(sourceLevelOption)) {
		sourceLevel = ClassFileConstants.JDK1_7;
	}
	Object complianceLevelOption = options.get(JavaCore.COMPILER_COMPLIANCE);
	long complianceLevel = ClassFileConstants.JDK1_3;
	if (JavaCore.VERSION_1_4.equals(complianceLevelOption)) {
		complianceLevel = ClassFileConstants.JDK1_4;
	} else if (JavaCore.VERSION_1_5.equals(complianceLevelOption)) {
		complianceLevel = ClassFileConstants.JDK1_5;
	} else if (JavaCore.VERSION_1_7.equals(complianceLevelOption)) {
		complianceLevel = ClassFileConstants.JDK1_7;
	}
	// override scanner if 1.4 or 1.5 asked for
	this.scanner = new Scanner(
		true /*comment*/,
		true /*whitespace*/,
		false /*nls*/,
		sourceLevel /*sourceLevel*/,
		complianceLevel /*complianceLevel*/,
		null/*taskTag*/,
		null/*taskPriorities*/,
		true/*taskCaseSensitive*/);
}
 
Example #21
Source File: InternalExtendedCompletionContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public boolean canUseDiamond(String[] parameterTypes, char[] fullyQualifiedTypeName) {
	TypeBinding guessedType = null;
	char[][] cn = CharOperation.splitOn('.', fullyQualifiedTypeName);
	Scope scope = this.assistScope;
	if (scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_7) return false;
	// If no LHS or return type expected, then we can safely use diamond
	char[][] expectedTypekeys= this.completionContext.getExpectedTypesKeys();
	if (expectedTypekeys == null || expectedTypekeys.length == 0)
		return true;
	// Next, find out whether any of the constructor parameters are the same as one of the 
	// class type variables. If yes, diamond cannot be used.
	TypeReference ref;
	if (cn.length == 1) {
		ref = new SingleTypeReference(cn[0], 0);
	} else {
		ref = new QualifiedTypeReference(cn,new long[cn.length]);
	}
	switch (scope.kind) {
		case Scope.METHOD_SCOPE :
		case Scope.BLOCK_SCOPE :
			guessedType = ref.resolveType((BlockScope)scope);
			break;
		case Scope.CLASS_SCOPE :
			guessedType = ref.resolveType((ClassScope)scope);
			break;
	}
	if (guessedType != null && guessedType.isValidBinding()) {
		// the erasure must be used because guessedType can be a RawTypeBinding
		guessedType = guessedType.erasure();
		TypeVariableBinding[] typeVars = guessedType.typeVariables();
		for (int i = 0; i < parameterTypes.length; i++) {
			for (int j = 0; j < typeVars.length; j++) {
				if (CharOperation.equals(parameterTypes[i].toCharArray(), typeVars[j].sourceName))
					return false;
			}
		}
		return true;
	}
	return false;
}
 
Example #22
Source File: NullAnnotationMatching.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/** Check null-ness of 'var' against a possible null annotation */
public static int checkAssignment(BlockScope currentScope, FlowContext flowContext,
								   VariableBinding var, int nullStatus, Expression expression, TypeBinding providedType)
{
	long lhsTagBits = 0L;
	boolean hasReported = false;
	if (currentScope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_8) {
		lhsTagBits = var.tagBits & TagBits.AnnotationNullMASK;
	} else {
		if (expression instanceof ConditionalExpression && expression.isPolyExpression()) {
			// drill into both branches:
			ConditionalExpression ce = ((ConditionalExpression) expression);
			int status1 = NullAnnotationMatching.checkAssignment(currentScope, flowContext, var, ce.ifTrueNullStatus, ce.valueIfTrue, ce.valueIfTrue.resolvedType);
			int status2 = NullAnnotationMatching.checkAssignment(currentScope, flowContext, var, ce.ifFalseNullStatus, ce.valueIfFalse, ce.valueIfFalse.resolvedType);
			if (status1 == status2)
				return status1;
			return nullStatus; // if both branches disagree use the precomputed & merged nullStatus
		}
		lhsTagBits = var.type.tagBits & TagBits.AnnotationNullMASK;
		NullAnnotationMatching annotationStatus = analyse(var.type, providedType, nullStatus);
		if (annotationStatus.isDefiniteMismatch()) {
			currentScope.problemReporter().nullityMismatchingTypeAnnotation(expression, providedType, var.type, annotationStatus);
			hasReported = true;
		} else if (annotationStatus.isUnchecked()) {
			flowContext.recordNullityMismatch(currentScope, expression, providedType, var.type, nullStatus);
			hasReported = true;
		} else if (annotationStatus.nullStatus != FlowInfo.UNKNOWN) {
			return annotationStatus.nullStatus;
		}
	}
	if (lhsTagBits == TagBits.AnnotationNonNull && nullStatus != FlowInfo.NON_NULL) {
		if (!hasReported)
			flowContext.recordNullityMismatch(currentScope, expression, providedType, var.type, nullStatus);
		return FlowInfo.NON_NULL;
	} else if (lhsTagBits == TagBits.AnnotationNullable && nullStatus == FlowInfo.UNKNOWN) {	// provided a legacy type?
		return FlowInfo.POTENTIALLY_NULL;			// -> use more specific info from the annotation
	}
	return nullStatus;
}
 
Example #23
Source File: DocumentElementParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
protected void consumeStaticInitializer() {
	// StaticInitializer ::=  StaticOnly Block
	//push an Initializer
	//optimize the push/pop
	super.consumeStaticInitializer();
	Initializer initializer = (Initializer) this.astStack[this.astPtr];
	this.requestor.acceptInitializer(
		initializer.declarationSourceStart,
		initializer.declarationSourceEnd,
		this.intArrayStack[this.intArrayPtr--],
		ClassFileConstants.AccStatic,
		this.intStack[this.intPtr--],
		initializer.block.sourceStart,
		initializer.declarationSourceEnd);
}
 
Example #24
Source File: CompilerOptions.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static String versionFromJdkLevel(long jdkLevel) {
	switch ((int)(jdkLevel>>16)) {
		case ClassFileConstants.MAJOR_VERSION_1_1 :
			if (jdkLevel == ClassFileConstants.JDK1_1)
				return VERSION_1_1;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_2 :
			if (jdkLevel == ClassFileConstants.JDK1_2)
				return VERSION_1_2;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_3 :
			if (jdkLevel == ClassFileConstants.JDK1_3)
				return VERSION_1_3;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_4 :
			if (jdkLevel == ClassFileConstants.JDK1_4)
				return VERSION_1_4;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_5 :
			if (jdkLevel == ClassFileConstants.JDK1_5)
				return VERSION_1_5;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_6 :
			if (jdkLevel == ClassFileConstants.JDK1_6)
				return VERSION_1_6;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_7 :
			if (jdkLevel == ClassFileConstants.JDK1_7)
				return VERSION_1_7;
			break;
		case ClassFileConstants.MAJOR_VERSION_1_8 :
			if (jdkLevel == ClassFileConstants.JDK1_8)
				return VERSION_1_8;
			break;
	}
	return Util.EMPTY_STRING; // unknown version
}
 
Example #25
Source File: HierarchyBinaryType.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String toString() {
	StringBuffer buffer = new StringBuffer();
	if (this.modifiers == ClassFileConstants.AccPublic) {
		buffer.append("public "); //$NON-NLS-1$
	}
	switch (TypeDeclaration.kind(this.modifiers)) {
		case TypeDeclaration.CLASS_DECL :
			buffer.append("class "); //$NON-NLS-1$
			break;
		case TypeDeclaration.INTERFACE_DECL :
			buffer.append("interface "); //$NON-NLS-1$
			break;
		case TypeDeclaration.ENUM_DECL :
			buffer.append("enum "); //$NON-NLS-1$
			break;
	}
	if (this.name != null) {
		buffer.append(this.name);
	}
	if (this.superclass != null) {
		buffer.append("\n  extends "); //$NON-NLS-1$
		buffer.append(this.superclass);
	}
	int length;
	if (this.superInterfaces != null && (length = this.superInterfaces.length) != 0) {
		buffer.append("\n implements "); //$NON-NLS-1$
		for (int i = 0; i < length; i++) {
			buffer.append(this.superInterfaces[i]);
			if (i != length - 1) {
				buffer.append(", "); //$NON-NLS-1$
			}
		}
	}
	return buffer.toString();
}
 
Example #26
Source File: BinaryTypeConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ImportReference[] buildImports(ClassFileReader reader) {
	// add remaining references to the list of type names
	// (code extracted from BinaryIndexer#extractReferenceFromConstantPool(...))
	int[] constantPoolOffsets = reader.getConstantPoolOffsets();
	int constantPoolCount = constantPoolOffsets.length;
	for (int i = 0; i < constantPoolCount; i++) {
		int tag = reader.u1At(constantPoolOffsets[i]);
		char[] name = null;
		switch (tag) {
			case ClassFileConstants.MethodRefTag :
			case ClassFileConstants.InterfaceMethodRefTag :
				int constantPoolIndex = reader.u2At(constantPoolOffsets[i] + 3);
				int utf8Offset = constantPoolOffsets[reader.u2At(constantPoolOffsets[constantPoolIndex] + 3)];
				name = reader.utf8At(utf8Offset + 3, reader.u2At(utf8Offset + 1));
				break;
			case ClassFileConstants.ClassTag :
				utf8Offset = constantPoolOffsets[reader.u2At(constantPoolOffsets[i] + 1)];
				name = reader.utf8At(utf8Offset + 3, reader.u2At(utf8Offset + 1));
				break;
		}
		if (name == null || (name.length > 0 && name[0] == '['))
			break; // skip over array references
		this.typeNames.add(CharOperation.splitOn('/', name));
	}

	// convert type names into import references
	int typeNamesLength = this.typeNames.size();
	ImportReference[] imports = new ImportReference[typeNamesLength];
	char[][][] set = this.typeNames.set;
	int index = 0;
	for (int i = 0, length = set.length; i < length; i++) {
		char[][] typeName = set[i];
		if (typeName != null) {
			imports[index++] = new ImportReference(typeName, new long[typeName.length]/*dummy positions*/, false/*not on demand*/, 0);
		}
	}
	return imports;
}
 
Example #27
Source File: BinaryTypeConverter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Convert a binary type into an AST type declaration and put it in the given compilation unit.
 */
public TypeDeclaration buildTypeDeclaration(IType type, CompilationUnitDeclaration compilationUnit)  throws JavaModelException {
	PackageFragment pkg = (PackageFragment) type.getPackageFragment();
	char[][] packageName = Util.toCharArrays(pkg.names);

	if (packageName.length > 0) {
		compilationUnit.currentPackage = new ImportReference(packageName, new long[]{0}, false, ClassFileConstants.AccDefault);
	}

	/* convert type */
	TypeDeclaration typeDeclaration = convert(type, null, null);

	IType alreadyComputedMember = type;
	IType parent = type.getDeclaringType();
	TypeDeclaration previousDeclaration = typeDeclaration;
	while(parent != null) {
		TypeDeclaration declaration = convert(parent, alreadyComputedMember, previousDeclaration);

		alreadyComputedMember = parent;
		previousDeclaration = declaration;
		parent = parent.getDeclaringType();
	}

	compilationUnit.types = new TypeDeclaration[]{previousDeclaration};

	return typeDeclaration;
}
 
Example #28
Source File: DOMMember.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see IDOMMember#setComment(String)
 */
public void setComment(String comment) {
	becomeDetailed();
	this.fComment= comment;
	fragment();
	setHasComment(comment != null);
	/* see 1FVIJAH */
	if (comment != null && comment.indexOf("@deprecated") >= 0) { //$NON-NLS-1$
		this.fFlags= this.fFlags | ClassFileConstants.AccDeprecated;
		return;
	}
	this.fFlags= this.fFlags & (~ClassFileConstants.AccDeprecated);
}
 
Example #29
Source File: DOMMember.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see IDOMMember#setFlags(int)
 */
public void setFlags(int flags) {
	becomeDetailed();
	if (Flags.isDeprecated(this.fFlags)) {
		this.fFlags= flags | ClassFileConstants.AccDeprecated;
	} else {
		this.fFlags= flags & (~ClassFileConstants.AccDeprecated);
	}
	fragment();
	this.fModifiers= generateFlags();
}
 
Example #30
Source File: SyntheticMethodBinding.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Construct $deserializeLambda$ method
 */
public SyntheticMethodBinding(SourceTypeBinding declaringClass) {
	this.declaringClass = declaringClass;
	this.selector = TypeConstants.DESERIALIZE_LAMBDA;
	this.modifiers = ClassFileConstants.AccPrivate | ClassFileConstants.AccStatic | ClassFileConstants.AccSynthetic;
	this.tagBits |= (TagBits.AnnotationResolved | TagBits.DeprecatedAnnotationResolved);
	this.thrownExceptions = Binding.NO_EXCEPTIONS;
	this.returnType = declaringClass.scope.getJavaLangObject();
    this.parameters = new TypeBinding[]{declaringClass.scope.getJavaLangInvokeSerializedLambda()};
    this.purpose = SyntheticMethodBinding.DeserializeLambda;
	SyntheticMethodBinding[] knownAccessMethods = declaringClass.syntheticMethods();
	int methodId = knownAccessMethods == null ? 0 : knownAccessMethods.length;
	this.index = methodId;
}