Java Code Examples for org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#JDK1_4
The following examples show how to use
org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#JDK1_4 .
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: BlockScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 2
Source File: CompilationUnitScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 3
Source File: AllocationExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void manageSyntheticAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) != 0) return; // if constructor from parameterized type got found, use the original constructor at codegen time MethodBinding codegenBinding = this.binding.original(); ReferenceBinding declaringClass; if (codegenBinding.isPrivate() && TypeBinding.notEquals(currentScope.enclosingSourceType(), (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 4
Source File: ExplicitConstructorCall.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
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 5
Source File: EmptyStatement.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public int complainIfUnreachable(FlowInfo flowInfo, BlockScope scope, int complaintLevel, boolean endOfBlock) { // before 1.4, empty statements are tolerated anywhere if (scope.compilerOptions().complianceLevel < ClassFileConstants.JDK1_4) { return complaintLevel; } return super.complainIfUnreachable(flowInfo, scope, complaintLevel, endOfBlock); }
Example 6
Source File: CompilerOptions.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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 7
Source File: CompilerOptions.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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 8
Source File: FieldReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) { boolean nonStatic = !this.binding.isStatic(); this.receiver.analyseCode(currentScope, flowContext, flowInfo, nonStatic); if (nonStatic) { this.receiver.checkNPE(currentScope, flowContext, flowInfo); } if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) { manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/); } return flowInfo; }
Example 9
Source File: SingleNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) { switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD : // reading a field if (valueRequired || currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) { manageSyntheticAccessIfNecessary(currentScope, flowInfo, true /*read-access*/); } // check if reading a final blank field FieldBinding fieldBinding = (FieldBinding) this.binding; if (fieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) { FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo); if (!fieldInits.isDefinitelyAssigned(fieldBinding)) { currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this); } } break; case Binding.LOCAL : // reading a local variable LocalVariableBinding localBinding; if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) this.binding)) { currentScope.problemReporter().uninitializedLocalVariable(localBinding, this); } if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { localBinding.useFlag = LocalVariableBinding.USED; } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) { localBinding.useFlag = LocalVariableBinding.FAKE_USED; } } if (valueRequired) { manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo); } return flowInfo; }
Example 10
Source File: AST.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * 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 11
Source File: ToolFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Create a scanner, indicating the level of detail requested for tokenizing. The scanner can then be * used to tokenize some source in a Java aware way. * Here is a typical scanning loop: * * <code> * <pre> * IScanner scanner = ToolFactory.createScanner(false, false, false, false); * scanner.setSource("int i = 0;".toCharArray()); * while (true) { * int token = scanner.getNextToken(); * if (token == ITerminalSymbols.TokenNameEOF) break; * System.out.println(token + " : " + new String(scanner.getCurrentTokenSource())); * } * </pre> * </code> * * <p>By default the compliance used to create the scanner is the workspace's compliance when running inside the IDE * or 1.4 if running from outside of a headless eclipse. * </p> * * @param tokenizeComments if set to <code>false</code>, comments will be silently consumed * @param tokenizeWhiteSpace if set to <code>false</code>, white spaces will be silently consumed, * @param assertMode if set to <code>false</code>, occurrences of 'assert' will be reported as identifiers * ({@link ITerminalSymbols#TokenNameIdentifier}), whereas if set to <code>true</code>, it * would report assert keywords ({@link ITerminalSymbols#TokenNameassert}). Java 1.4 has introduced * a new 'assert' keyword. * @param recordLineSeparator if set to <code>true</code>, the scanner will record positions of encountered line * separator ends. In case of multi-character line separators, the last character position is considered. These positions * can then be extracted using {@link IScanner#getLineEnds()}. Only non-unicode escape sequences are * considered as valid line separators. * @return a scanner * @see org.eclipse.jdt.core.compiler.IScanner * @see #createScanner(boolean, boolean, boolean, String, String) */ public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean assertMode, boolean recordLineSeparator){ // use default workspace compliance long complianceLevelValue = CompilerOptions.versionToJdkLevel(JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); if (complianceLevelValue == 0) complianceLevelValue = ClassFileConstants.JDK1_4; // fault-tolerance PublicScanner scanner = new PublicScanner( tokenizeComments, tokenizeWhiteSpace, false/*nls*/, assertMode ? ClassFileConstants.JDK1_4 : ClassFileConstants.JDK1_3/*sourceLevel*/, complianceLevelValue, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/); scanner.recordLineSeparator = recordLineSeparator; return scanner; }
Example 12
Source File: QualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo, boolean valueRequired) { // determine the rank until which we now we do not need any actual value for the field access int otherBindingsCount = this.otherBindings == null ? 0 : this.otherBindings.length; boolean needValue = otherBindingsCount == 0 ? valueRequired : !this.otherBindings[0].isStatic(); boolean complyTo14 = currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4; switch (this.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD : // reading a field if (needValue || complyTo14) { manageSyntheticAccessIfNecessary(currentScope, (FieldBinding) this.binding, 0, flowInfo); } FieldBinding fieldBinding = (FieldBinding) this.binding; if (this.indexOfFirstFieldBinding == 1) { // was an implicit reference to the first field binding // check if reading a final blank field if (fieldBinding.isBlankFinal() && currentScope.needBlankFinalFieldInitializationCheck(fieldBinding)) { FlowInfo fieldInits = flowContext.getInitsForFinalBlankInitializationCheck(fieldBinding.declaringClass.original(), flowInfo); if (!fieldInits.isDefinitelyAssigned(fieldBinding)) { currentScope.problemReporter().uninitializedBlankFinalField(fieldBinding, this); } } } break; case Binding.LOCAL : // reading a local variable LocalVariableBinding localBinding; if (!flowInfo.isDefinitelyAssigned(localBinding = (LocalVariableBinding) this.binding)) { currentScope.problemReporter().uninitializedLocalVariable(localBinding, this); } if ((flowInfo.tagBits & FlowInfo.UNREACHABLE) == 0) { localBinding.useFlag = LocalVariableBinding.USED; } else if (localBinding.useFlag == LocalVariableBinding.UNUSED) { localBinding.useFlag = LocalVariableBinding.FAKE_USED; } } if (needValue) { checkInternalNPE(currentScope, flowContext, flowInfo, true); } if (needValue) { manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo); // only for first binding (if value needed only) } if (this.otherBindings != null) { for (int i = 0; i < otherBindingsCount; i++) { needValue = i < otherBindingsCount-1 ? !this.otherBindings[i+1].isStatic() : valueRequired; if (needValue || complyTo14) { manageSyntheticAccessIfNecessary(currentScope, this.otherBindings[i], i + 1, flowInfo); } } } return flowInfo; }
Example 13
Source File: QualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { int pc = codeStream.position; if (this.constant != Constant.NotAConstant) { if (valueRequired) { codeStream.generateConstant(this.constant, this.implicitConversion); } } else { FieldBinding lastFieldBinding = generateReadSequence(currentScope, codeStream); if (lastFieldBinding != null) { boolean isStatic = lastFieldBinding.isStatic(); Constant fieldConstant = lastFieldBinding.constant(); if (fieldConstant != Constant.NotAConstant) { if (!isStatic){ codeStream.invokeObjectGetClass(); codeStream.pop(); } if (valueRequired) { // inline the last field constant codeStream.generateConstant(fieldConstant, this.implicitConversion); } } else { boolean isFirst = lastFieldBinding == this.binding && (this.indexOfFirstFieldBinding == 1 || TypeBinding.equalsEquals(lastFieldBinding.declaringClass, currentScope.enclosingReceiverType())) && this.otherBindings == null; // could be dup: next.next.next TypeBinding requiredGenericCast = getGenericCast(this.otherBindings == null ? 0 : this.otherBindings.length); if (valueRequired || (!isFirst && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) || ((this.implicitConversion & TypeIds.UNBOXING) != 0) || requiredGenericCast != null) { int lastFieldPc = codeStream.position; if (lastFieldBinding.declaringClass == null) { // array length codeStream.arraylength(); if (valueRequired) { codeStream.generateImplicitConversion(this.implicitConversion); } else { // could occur if !valueRequired but compliance >= 1.4 codeStream.pop(); } } else { SyntheticMethodBinding accessor = this.syntheticReadAccessors == null ? null : this.syntheticReadAccessors[this.syntheticReadAccessors.length - 1]; if (accessor == null) { TypeBinding constantPoolDeclaringClass = CodeStream.getConstantPoolDeclaringClass(currentScope, lastFieldBinding, getFinalReceiverType(), isFirst); if (isStatic) { codeStream.fieldAccess(Opcodes.OPC_getstatic, lastFieldBinding, constantPoolDeclaringClass); } else { codeStream.fieldAccess(Opcodes.OPC_getfield, lastFieldBinding, constantPoolDeclaringClass); } } else { codeStream.invoke(Opcodes.OPC_invokestatic, accessor, null /* default declaringClass */); } if (requiredGenericCast != null) codeStream.checkcast(requiredGenericCast); if (valueRequired) { codeStream.generateImplicitConversion(this.implicitConversion); } else { boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0; // conversion only generated if unboxing if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion); switch (isUnboxing ? postConversionType(currentScope).id : lastFieldBinding.type.id) { case T_long : case T_double : codeStream.pop2(); break; default : codeStream.pop(); break; } } } int fieldPosition = (int) (this.sourcePositions[this.sourcePositions.length - 1] >>> 32); codeStream.recordPositionsFrom(lastFieldPc, fieldPosition); } else { if (!isStatic){ codeStream.invokeObjectGetClass(); // perform null check codeStream.pop(); } } } } } codeStream.recordPositionsFrom(pc, this.sourceStart); }
Example 14
Source File: CompilationUnitScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private Binding findImport(char[][] compoundName, int length) { recordQualifiedReference(compoundName); Binding binding = this.environment.getTopLevelPackage(compoundName[0]); int i = 1; foundNothingOrType: if (binding != null) { PackageBinding packageBinding = (PackageBinding) binding; while (i < length) { binding = packageBinding.getTypeOrPackage(compoundName[i++]); if (binding == null || !binding.isValidBinding()) { binding = null; break foundNothingOrType; } if (!(binding instanceof PackageBinding)) break foundNothingOrType; packageBinding = (PackageBinding) binding; } return packageBinding; } ReferenceBinding type; if (binding == null) { if (compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, i), null, ProblemReasons.NotFound); type = findType(compoundName[0], this.environment.defaultPackage, this.environment.defaultPackage); if (type == null || !type.isValidBinding()) return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, i), null, ProblemReasons.NotFound); i = 1; // reset to look for member types inside the default package type } else { type = (ReferenceBinding) binding; } while (i < length) { type = (ReferenceBinding)this.environment.convertToRawType(type, false /*do not force conversion of enclosing types*/); // type imports are necessarily raw for all except last if (!type.canBeSeenBy(this.fPackage)) return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, i), type, ProblemReasons.NotVisible); char[] name = compoundName[i++]; // does not look for inherited member types on purpose, only immediate members type = type.getMemberType(name); if (type == null) return new ProblemReferenceBinding(CharOperation.subarray(compoundName, 0, i), null, ProblemReasons.NotFound); } if (!type.canBeSeenBy(this.fPackage)) return new ProblemReferenceBinding(compoundName, type, ProblemReasons.NotVisible); return type; }
Example 15
Source File: Main.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * 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 16
Source File: CodeSnippetQualifiedNameReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { int pc = codeStream.position; if ((this.bits & Binding.VARIABLE) == 0) { // nothing to do if type ref codeStream.recordPositionsFrom(pc, this.sourceStart); return; } FieldBinding lastFieldBinding = this.otherBindings == null ? (FieldBinding) this.binding : this.otherBindings[this.otherBindings.length-1]; if (lastFieldBinding.canBeSeenBy(getFinalReceiverType(), this, currentScope)) { super.generateCode(currentScope, codeStream, valueRequired); return; } lastFieldBinding = generateReadSequence(currentScope, codeStream); if (lastFieldBinding != null) { boolean isStatic = lastFieldBinding.isStatic(); Constant fieldConstant = lastFieldBinding.constant(); if (fieldConstant != Constant.NotAConstant) { if (!isStatic){ codeStream.invokeObjectGetClass(); codeStream.pop(); } if (valueRequired) { // inline the last field constant codeStream.generateConstant(fieldConstant, this.implicitConversion); } } else { boolean isFirst = lastFieldBinding == this.binding && (this.indexOfFirstFieldBinding == 1 || TypeBinding.equalsEquals(lastFieldBinding.declaringClass, currentScope.enclosingReceiverType())) && this.otherBindings == null; // could be dup: next.next.next TypeBinding requiredGenericCast = getGenericCast(this.otherBindings == null ? 0 : this.otherBindings.length); if (valueRequired || (!isFirst && currentScope.compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) || ((this.implicitConversion & TypeIds.UNBOXING) != 0) || requiredGenericCast != null) { int lastFieldPc = codeStream.position; if (lastFieldBinding.declaringClass == null) { // array length codeStream.arraylength(); if (valueRequired) { codeStream.generateImplicitConversion(this.implicitConversion); } else { // could occur if !valueRequired but compliance >= 1.4 codeStream.pop(); } } else { codeStream.generateEmulatedReadAccessForField(lastFieldBinding); if (requiredGenericCast != null) codeStream.checkcast(requiredGenericCast); if (valueRequired) { codeStream.generateImplicitConversion(this.implicitConversion); } else { boolean isUnboxing = (this.implicitConversion & TypeIds.UNBOXING) != 0; // conversion only generated if unboxing if (isUnboxing) codeStream.generateImplicitConversion(this.implicitConversion); switch (isUnboxing ? postConversionType(currentScope).id : lastFieldBinding.type.id) { case T_long : case T_double : codeStream.pop2(); break; default : codeStream.pop(); } } } int fieldPosition = (int) (this.sourcePositions[this.sourcePositions.length - 1] >>> 32); codeStream.recordPositionsFrom(lastFieldPc, fieldPosition); } else { if (!isStatic){ codeStream.invokeObjectGetClass(); // perform null check codeStream.pop(); } } } } codeStream.recordPositionsFrom(pc, this.sourceStart); }
Example 17
Source File: ToolFactory.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Create a scanner, indicating the level of detail requested for tokenizing. The scanner can then be * used to tokenize some source in a Java aware way. * Here is a typical scanning loop: * * <code> * <pre> * IScanner scanner = ToolFactory.createScanner(false, false, false, false); * scanner.setSource("int i = 0;".toCharArray()); * while (true) { * int token = scanner.getNextToken(); * if (token == ITerminalSymbols.TokenNameEOF) break; * System.out.println(token + " : " + new String(scanner.getCurrentTokenSource())); * } * </pre> * </code> * * <p>By default the compliance used to create the scanner is the workspace's compliance when running inside the IDE * or 1.4 if running from outside of a headless eclipse. * </p> * * @param tokenizeComments if set to <code>false</code>, comments will be silently consumed * @param tokenizeWhiteSpace if set to <code>false</code>, white spaces will be silently consumed, * @param recordLineSeparator if set to <code>true</code>, the scanner will record positions of encountered line * separator ends. In case of multi-character line separators, the last character position is considered. These positions * can then be extracted using {@link IScanner#getLineEnds()}. Only non-unicode escape sequences are * considered as valid line separators. * @param sourceLevel if set to <code>"1.3"</code> or <code>null</code>, occurrences of 'assert' will be reported as identifiers * ({@link ITerminalSymbols#TokenNameIdentifier}), whereas if set to <code>"1.4"</code>, it * would report assert keywords ({@link ITerminalSymbols#TokenNameassert}). Java 1.4 has introduced * a new 'assert' keyword. * @return a scanner * @see org.eclipse.jdt.core.compiler.IScanner * @see #createScanner(boolean, boolean, boolean, String, String) * @since 3.0 */ public static IScanner createScanner(boolean tokenizeComments, boolean tokenizeWhiteSpace, boolean recordLineSeparator, String sourceLevel) { // use default workspace compliance long complianceLevelValue = CompilerOptions.versionToJdkLevel(JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); if (complianceLevelValue == 0) complianceLevelValue = ClassFileConstants.JDK1_4; // fault-tolerance long sourceLevelValue = CompilerOptions.versionToJdkLevel(sourceLevel); if (sourceLevelValue == 0) sourceLevelValue = ClassFileConstants.JDK1_3; // fault-tolerance PublicScanner scanner = new PublicScanner( tokenizeComments, tokenizeWhiteSpace, false/*nls*/, sourceLevelValue /*sourceLevel*/, complianceLevelValue, null/*taskTags*/, null/*taskPriorities*/, true/*taskCaseSensitive*/); scanner.recordLineSeparator = recordLineSeparator; return scanner; }