Java Code Examples for org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#JDK1_6

The following examples show how to use org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#JDK1_6 . 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: Eclipse.java    From EasyMPermission with MIT License 6 votes vote down vote up
public static long getLatestEcjCompilerVersionConstant() {
	if (latestEcjCompilerVersionConstantCached != 0) return latestEcjCompilerVersionConstantCached;
	
	int highestVersionSoFar = 0;
	for (Field f : ClassFileConstants.class.getDeclaredFields()) {
		try {
			if (f.getName().startsWith("JDK1_")) {
				int thisVersion = Integer.parseInt(f.getName().substring("JDK1_".length()));
				if (thisVersion > highestVersionSoFar) {
					highestVersionSoFar = thisVersion;
					latestEcjCompilerVersionConstantCached = (Long) f.get(null);
				}
			}
		} catch (Exception ignore) {}
	}
	
	if (highestVersionSoFar > 6 && !ecjSupportsJava7Features()) {
		latestEcjCompilerVersionConstantCached = ClassFileConstants.JDK1_6;
	}
	return latestEcjCompilerVersionConstantCached;
}
 
Example 2
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 3
Source File: MethodVerifier15.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
boolean detectNameClash(MethodBinding current, MethodBinding inherited, boolean treatAsSynthetic) {
	MethodBinding methodToCheck = inherited;
	MethodBinding original = methodToCheck.original(); // can be the same as inherited
	if (!current.areParameterErasuresEqual(original))
		return false;
	int severity = ProblemSeverities.Error;
	if (this.environment.globalOptions.complianceLevel == ClassFileConstants.JDK1_6) {
		// for 1.6 return types also need to be checked
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=317719
		if (TypeBinding.notEquals(current.returnType.erasure(), original.returnType.erasure()))
			severity = ProblemSeverities.Warning;
	}
	if (!treatAsSynthetic) {
		// For a user method, see if current class overrides the inherited method. If it does,
		// then any grievance we may have ought to be against the current class's method and
		// NOT against any super implementations. https://bugs.eclipse.org/bugs/show_bug.cgi?id=293615
		
		// https://bugs.eclipse.org/bugs/show_bug.cgi?id=315978 : we now defer this rather expensive
		// check to just before reporting (the incorrect) name clash. In the event there is no name
		// clash to report to begin with (the common case), no penalty needs to be paid.  
		MethodBinding[] currentNamesakes = (MethodBinding[]) this.currentMethods.get(inherited.selector);
		if (currentNamesakes.length > 1) { // we know it ought to at least one and that current is NOT the override
			for (int i = 0, length = currentNamesakes.length; i < length; i++) {
				MethodBinding currentMethod = currentNamesakes[i];
				if (currentMethod != current && doesMethodOverride(currentMethod, inherited)) {
					methodToCheck = currentMethod;
					break;
				}
			}
		}
	}
	original = methodToCheck.original(); // can be the same as inherited
	if (!current.areParameterErasuresEqual(original))
		return false;
	original = inherited.original();  // For error reporting use, inherited.original()
	problemReporter(current).methodNameClash(current, inherited.declaringClass.isRawType() ? inherited : original, severity);
	if (severity == ProblemSeverities.Warning) return false;
	return true;
}
 
Example 4
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 5
Source File: CompilerOptions.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public static long versionToJdkLevel(Object versionID) {
	if (versionID instanceof String) {
		String version = (String) versionID;
		// verification is optimized for all versions with same length and same "1." prefix
		if (version.length() == 3 && version.charAt(0) == '1' && version.charAt(1) == '.') {
			switch (version.charAt(2)) {
				case '1':
					return ClassFileConstants.JDK1_1;
				case '2':
					return ClassFileConstants.JDK1_2;
				case '3':
					return ClassFileConstants.JDK1_3;
				case '4':
					return ClassFileConstants.JDK1_4;
				case '5':
					return ClassFileConstants.JDK1_5;
				case '6':
					return ClassFileConstants.JDK1_6;
				case '7':
					return ClassFileConstants.JDK1_7;
				case '8':
					return ClassFileConstants.JDK1_8;
				default:
					return 0; // unknown
			}
		}
		if (VERSION_JSR14.equals(versionID)) {
			return ClassFileConstants.JDK1_4;
		}
		if (VERSION_CLDC1_1.equals(versionID)) {
			return ClassFileConstants.CLDC_1_1;
		}
	}
	return 0; // unknown
}
 
Example 6
Source File: DefaultCodeFormatter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private TextEdit probeFormatting(String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) {
	if (PROBING_SCANNER == null) {
		// scanner use to check if the kind could be K_JAVA_DOC, K_MULTI_LINE_COMMENT or K_SINGLE_LINE_COMMENT
		// do not tokenize white spaces to get single comments even with spaces before...
		PROBING_SCANNER = new Scanner(true, false/*do not tokenize whitespaces*/, false/*nls*/, ClassFileConstants.JDK1_6, ClassFileConstants.JDK1_6, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/);
	}
	PROBING_SCANNER.setSource(source.toCharArray());

	IRegion coveredRegion = getCoveredRegion(regions);
	int offset = coveredRegion.getOffset();
	int length = coveredRegion.getLength();

	PROBING_SCANNER.resetTo(offset, offset + length - 1);
	try {
		int kind = -1;
		switch(PROBING_SCANNER.getNextToken()) {
			case ITerminalSymbols.TokenNameCOMMENT_BLOCK :
				if (PROBING_SCANNER.getNextToken() == TerminalTokens.TokenNameEOF) {
					kind = K_MULTI_LINE_COMMENT;
				}
				break;
			case ITerminalSymbols.TokenNameCOMMENT_LINE :
				if (PROBING_SCANNER.getNextToken() == TerminalTokens.TokenNameEOF) {
					kind = K_SINGLE_LINE_COMMENT;
				}
				break;
			case ITerminalSymbols.TokenNameCOMMENT_JAVADOC :
				if (PROBING_SCANNER.getNextToken() == TerminalTokens.TokenNameEOF) {
					kind = K_JAVA_DOC;
				}
				break;
		}
		if (kind != -1) {
			return formatComment(kind, source, indentationLevel, lineSeparator, regions);
		}
	} catch (InvalidInputException e) {
		// ignore
	}
	PROBING_SCANNER.setSource((char[]) null);

	// probe for expression
	Expression expression = this.codeSnippetParsingUtil.parseExpression(source.toCharArray(), getDefaultCompilerOptions(), true);
	if (expression != null) {
		return internalFormatExpression(source, indentationLevel, lineSeparator, expression, regions, includeComments);
	}

	// probe for body declarations (fields, methods, constructors)
	ASTNode[] bodyDeclarations = this.codeSnippetParsingUtil.parseClassBodyDeclarations(source.toCharArray(), getDefaultCompilerOptions(), true);
	if (bodyDeclarations != null) {
		return internalFormatClassBodyDeclarations(source, indentationLevel, lineSeparator, bodyDeclarations, regions, includeComments);
	}

	// probe for statements
	ConstructorDeclaration constructorDeclaration = this.codeSnippetParsingUtil.parseStatements(source.toCharArray(), getDefaultCompilerOptions(), true, false);
	if (constructorDeclaration.statements != null) {
		return internalFormatStatements(source, indentationLevel, lineSeparator, constructorDeclaration, regions, includeComments);
	}

	// this has to be a compilation unit
	return formatCompilationUnit(source, indentationLevel, lineSeparator, regions, includeComments);
}
 
Example 7
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Return true if and only if the running VM supports the given minimal version.
 *
 * <p>This only checks the major version, since the minor version is always 0 (at least for the useful cases).</p>
 * <p>The given minimalSupportedVersion is one of the constants:</p>
 * <ul>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_1</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_2</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_3</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_4</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_5</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_6</code></li>
 * <li><code>org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants.JDK1_7</code></li>
 * </ul>
 * @param minimalSupportedVersion the given minimal version
 * @return true if and only if the running VM supports the given minimal version, false otherwise
 */
private boolean checkVMVersion(long minimalSupportedVersion) {
	// the format of this property is supposed to be xx.x where x are digits.
	String classFileVersion = System.getProperty("java.class.version"); //$NON-NLS-1$
	if (classFileVersion == null) {
		// by default we don't support a class file version we cannot recognize
		return false;
	}
	int index = classFileVersion.indexOf('.');
	if (index == -1) {
		// by default we don't support a class file version we cannot recognize
		return false;
	}
	int majorVersion;
	try {
		majorVersion = Integer.parseInt(classFileVersion.substring(0, index));
	} catch (NumberFormatException e) {
		// by default we don't support a class file version we cannot recognize
		return false;
	}
	switch(majorVersion) {
		case ClassFileConstants.MAJOR_VERSION_1_1 : // 1.0 and 1.1
			return ClassFileConstants.JDK1_1 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_2 : // 1.2
			return ClassFileConstants.JDK1_2 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_3 : // 1.3
			return ClassFileConstants.JDK1_3 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_4 : // 1.4
			return ClassFileConstants.JDK1_4 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_5 : // 1.5
			return ClassFileConstants.JDK1_5 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_6 : // 1.6
			return ClassFileConstants.JDK1_6 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_7 : // 1.7
			return ClassFileConstants.JDK1_7 >= minimalSupportedVersion;
		case ClassFileConstants.MAJOR_VERSION_1_8: // 1.8
			return ClassFileConstants.JDK1_8 >= minimalSupportedVersion;
	}
	// unknown version
	return false;
}
 
Example 8
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public void performCompilation() {

	this.startTime = System.currentTimeMillis();

	FileSystem environment = getLibraryAccess();
	this.compilerOptions = new CompilerOptions(this.options);
	this.compilerOptions.performMethodsFullRecovery = false;
	this.compilerOptions.performStatementsRecovery = false;
	this.batchCompiler =
		new Compiler(
			environment,
			getHandlingPolicy(),
			this.compilerOptions,
			getBatchRequestor(),
			getProblemFactory(),
			this.out,
			this.progress);
	this.batchCompiler.remainingIterations = this.maxRepetition-this.currentRepetition/*remaining iterations including this one*/;
	// temporary code to allow the compiler to revert to a single thread
	String setting = System.getProperty("jdt.compiler.useSingleThread"); //$NON-NLS-1$
	this.batchCompiler.useSingleThread = setting != null && setting.equals("true"); //$NON-NLS-1$

	if (this.compilerOptions.complianceLevel >= ClassFileConstants.JDK1_6
			&& this.compilerOptions.processAnnotations) {
		if (checkVMVersion(ClassFileConstants.JDK1_6)) {
			initializeAnnotationProcessorManager();
			if (this.classNames != null) {
				this.batchCompiler.setBinaryTypes(processClassNames(this.batchCompiler.lookupEnvironment));
			}
		} else {
			// report a warning
			this.logger.logIncorrectVMVersionForAnnotationProcessing();
		}
	}

	// set the non-externally configurable options.
	this.compilerOptions.verbose = this.verbose;
	this.compilerOptions.produceReferenceInfo = this.produceRefInfo;
	try {
		this.logger.startLoggingSources();
		this.batchCompiler.compile(getCompilationUnits());
	} finally {
		this.logger.endLoggingSources();
	}

	if (this.extraProblems != null) {
		loggingExtraProblems();
		this.extraProblems = null;
	}
	if (this.compilerStats != null) {
		this.compilerStats[this.currentRepetition] = this.batchCompiler.stats;
	}
	this.logger.printStats();

	// cleanup
	environment.cleanup();
}
 
Example 9
Source File: ScannerHelper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isJavaIdentifierPart(long complianceLevel, int codePoint) {
	if (complianceLevel <= ClassFileConstants.JDK1_6) {
		if (Tables == null) {
			initializeTable();
		}
		switch((codePoint & 0x1F0000) >> 16) {
			case 0 :
				return isBitSet(Tables[PART_INDEX][0], codePoint & 0xFFFF);
			case 1 :
				return isBitSet(Tables[PART_INDEX][1], codePoint & 0xFFFF);
			case 2 :
				return isBitSet(Tables[PART_INDEX][2], codePoint & 0xFFFF);
			case 14 :
				return isBitSet(Tables[PART_INDEX][3], codePoint & 0xFFFF);
		}
	} else if (complianceLevel <= ClassFileConstants.JDK1_7) {
		// java 7 supports Unicode 6
		if (Tables7 == null) {
			initializeTable17();
		}
		switch((codePoint & 0x1F0000) >> 16) {
			case 0 :
				return isBitSet(Tables7[PART_INDEX][0], codePoint & 0xFFFF);
			case 1 :
				return isBitSet(Tables7[PART_INDEX][1], codePoint & 0xFFFF);
			case 2 :
				return isBitSet(Tables7[PART_INDEX][2], codePoint & 0xFFFF);
			case 14 :
				return isBitSet(Tables7[PART_INDEX][3], codePoint & 0xFFFF);
		}
	} else {
		// java 7 supports Unicode 6.2
		if (Tables8 == null) {
			initializeTable18();
		}
		switch((codePoint & 0x1F0000) >> 16) {
			case 0 :
				return isBitSet(Tables8[PART_INDEX][0], codePoint & 0xFFFF);
			case 1 :
				return isBitSet(Tables8[PART_INDEX][1], codePoint & 0xFFFF);
			case 2 :
				return isBitSet(Tables8[PART_INDEX][2], codePoint & 0xFFFF);
			case 14 :
				return isBitSet(Tables8[PART_INDEX][3], codePoint & 0xFFFF);
		}
	}
	return false;
}
 
Example 10
Source File: ScannerHelper.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public static boolean isJavaIdentifierStart(long complianceLevel, int codePoint) {
	if (complianceLevel <= ClassFileConstants.JDK1_6) {
		if (Tables == null) {
			initializeTable();
		}
		switch((codePoint & 0x1F0000) >> 16) {
			case 0 :
				return isBitSet(Tables[START_INDEX][0], codePoint & 0xFFFF);
			case 1 :
				return isBitSet(Tables[START_INDEX][1], codePoint & 0xFFFF);
			case 2 :
				return isBitSet(Tables[START_INDEX][2], codePoint & 0xFFFF);
		}
	} else if (complianceLevel <= ClassFileConstants.JDK1_7) {
		// java 7 supports Unicode 6
		if (Tables7 == null) {
			initializeTable17();
		}
		switch((codePoint & 0x1F0000) >> 16) {
			case 0 :
				return isBitSet(Tables7[START_INDEX][0], codePoint & 0xFFFF);
			case 1 :
				return isBitSet(Tables7[START_INDEX][1], codePoint & 0xFFFF);
			case 2 :
				return isBitSet(Tables7[START_INDEX][2], codePoint & 0xFFFF);
		}
	} else {
		// java 7 supports Unicode 6
		if (Tables8 == null) {
			initializeTable18();
		}
		switch((codePoint & 0x1F0000) >> 16) {
			case 0 :
				return isBitSet(Tables8[START_INDEX][0], codePoint & 0xFFFF);
			case 1 :
				return isBitSet(Tables8[START_INDEX][1], codePoint & 0xFFFF);
			case 2 :
				return isBitSet(Tables8[START_INDEX][2], codePoint & 0xFFFF);
		}
	}
	return false;
}