Java Code Examples for org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#JDK1_7
The following examples show how to use
org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants#JDK1_7 .
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: AddJarFileToIndex.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private boolean isValidPackageNameForClass(String className) { char[] classNameArray = className.toCharArray(); // use 1.7 as the source level as there are more valid identifiers in 1.7 mode // https://bugs.eclipse.org/bugs/show_bug.cgi?id=376673 if (this.scanner == null) this.scanner = new Scanner(false /* comment */, true /* whitespace */, false /* nls */, ClassFileConstants.JDK1_7/* sourceLevel */, null/* taskTag */, null/* taskPriorities */, true /* taskCaseSensitive */); this.scanner.setSource(classNameArray); this.scanner.eofPosition = classNameArray.length - SuffixConstants.SUFFIX_CLASS.length; try { if (isIdentifier()) { while (this.scanner.eofPosition > this.scanner.currentPosition) { if (this.scanner.getNextChar() != '/' || this.scanner.eofPosition <= this.scanner.currentPosition) { return false; } if (!isIdentifier()) return false; } return true; } } catch (InvalidInputException e) { // invalid class name } return false; }
Example 2
Source File: PublicScanner.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private final void consumeDigits(int radix, boolean expectingDigitFirst) throws InvalidInputException { final int USING_UNDERSCORE = 1; final int INVALID_POSITION = 2; switch(consumeDigits0(radix, USING_UNDERSCORE, INVALID_POSITION, expectingDigitFirst)) { case USING_UNDERSCORE : if (this.sourceLevel < ClassFileConstants.JDK1_7) { throw new InvalidInputException(UNDERSCORES_IN_LITERALS_NOT_BELOW_17); } break; case INVALID_POSITION : if (this.sourceLevel < ClassFileConstants.JDK1_7) { throw new InvalidInputException(UNDERSCORES_IN_LITERALS_NOT_BELOW_17); } throw new InvalidInputException(INVALID_UNDERSCORE); } }
Example 3
Source File: MethodVerifier15.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
void checkInheritedMethods(MethodBinding inheritedMethod, MethodBinding otherInheritedMethod) { // the 2 inherited methods clash because of a parameterized type overrides a raw type // interface I { void foo(A a); } // class Y { void foo(A<String> a) {} } // abstract class X extends Y implements I { } // class A<T> {} // in this case the 2 inherited methods clash because of type variables // interface I { <T, S> void foo(T t); } // class Y { <T> void foo(T t) {} } // abstract class X extends Y implements I {} if (inheritedMethod.isStatic()) return; if (this.environment.globalOptions.complianceLevel < ClassFileConstants.JDK1_7 && inheritedMethod.declaringClass.isInterface()) return; // JDK7 checks for name clashes in interface inheritance, while JDK6 and below don't. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=354229 detectInheritedNameClash(inheritedMethod.original(), otherInheritedMethod.original()); }
Example 4
Source File: Scanner.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private final void consumeDigits(int radix, boolean expectingDigitFirst) throws InvalidInputException { final int USING_UNDERSCORE = 1; final int INVALID_POSITION = 2; switch(consumeDigits0(radix, USING_UNDERSCORE, INVALID_POSITION, expectingDigitFirst)) { case USING_UNDERSCORE : if (this.sourceLevel < ClassFileConstants.JDK1_7) { throw new InvalidInputException(UNDERSCORES_IN_LITERALS_NOT_BELOW_17); } break; case INVALID_POSITION : if (this.sourceLevel < ClassFileConstants.JDK1_7) { throw new InvalidInputException(UNDERSCORES_IN_LITERALS_NOT_BELOW_17); } throw new InvalidInputException(INVALID_UNDERSCORE); } }
Example 5
Source File: DocCommentParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
DocCommentParser(AST ast, Scanner scanner, boolean check) { super(null); this.ast = ast; this.scanner = scanner; switch(this.ast.apiLevel()) { case AST.JLS2_INTERNAL : this.sourceLevel = ClassFileConstants.JDK1_3; break; case AST.JLS3_INTERNAL: this.sourceLevel = ClassFileConstants.JDK1_5; break; default: // AST.JLS4 for now this.sourceLevel = ClassFileConstants.JDK1_7; } this.checkDocComment = check; this.kind = DOM_PARSER | TEXT_PARSE; }
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: CompilationUtils.java From steady with Apache License 2.0 | 5 votes |
private static CompilerOptions getDefaultCompilerOptions() { CompilerOptions options = new CompilerOptions(); options.docCommentSupport = true; options.complianceLevel = ClassFileConstants.JDK1_7; options.sourceLevel = ClassFileConstants.JDK1_7; options.targetJDK = ClassFileConstants.JDK1_7; return options; }
Example 8
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 9
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 10
Source File: InternalExtendedCompletionContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
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 11
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Create the default compiler options */ public static CompilerOptions createCompilerOptions() { CompilerOptions options = new CompilerOptions(); // Always using JDK 7 rather than basing it on project metadata since we // don't do compilation error validation in lint (we leave that to the IDE's // error parser or the command line build's compilation step); we want an // AST that is as tolerant as possible. long languageLevel = ClassFileConstants.JDK1_7; options.complianceLevel = languageLevel; options.sourceLevel = languageLevel; options.targetJDK = languageLevel; options.originalComplianceLevel = languageLevel; options.originalSourceLevel = languageLevel; options.inlineJsrBytecode = true; // >1.5 options.parseLiteralExpressionsAsConstants = true; options.analyseResourceLeaks = false; options.docCommentSupport = false; options.defaultEncoding = UTF_8; options.suppressOptionalErrors = true; options.generateClassFiles = false; options.isAnnotationBasedNullAnalysisEnabled = false; options.reportUnusedDeclaredThrownExceptionExemptExceptionAndThrowable = false; options.reportUnusedDeclaredThrownExceptionIncludeDocCommentReference = false; options.reportUnusedDeclaredThrownExceptionWhenOverriding = false; options.reportUnusedParameterIncludeDocCommentReference = false; options.reportUnusedParameterWhenImplementingAbstract = false; options.reportUnusedParameterWhenOverridingConcrete = false; options.suppressWarnings = true; options.processAnnotations = true; options.storeAnnotations = true; options.verbose = false; return options; }
Example 12
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 13
Source File: ScannerHelper.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
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 14
Source File: ScannerHelper.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
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; }
Example 15
Source File: CompoundAssignment.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public TypeBinding resolveType(BlockScope scope) { this.constant = Constant.NotAConstant; if (!(this.lhs instanceof Reference) || this.lhs.isThis()) { scope.problemReporter().expressionShouldBeAVariable(this.lhs); return null; } boolean expressionIsCast = this.expression instanceof CastExpression; if (expressionIsCast) this.expression.bits |= ASTNode.DisableUnnecessaryCastCheck; // will check later on TypeBinding originalLhsType = this.lhs.resolveType(scope); TypeBinding originalExpressionType = this.expression.resolveType(scope); if (originalLhsType == null || originalExpressionType == null) return null; // autoboxing support LookupEnvironment env = scope.environment(); TypeBinding lhsType = originalLhsType, expressionType = originalExpressionType; boolean use15specifics = scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5; boolean unboxedLhs = false; if (use15specifics) { if (!lhsType.isBaseType() && expressionType.id != T_JavaLangString && expressionType.id != T_null) { TypeBinding unboxedType = env.computeBoxingType(lhsType); if (TypeBinding.notEquals(unboxedType, lhsType)) { lhsType = unboxedType; unboxedLhs = true; } } if (!expressionType.isBaseType() && lhsType.id != T_JavaLangString && lhsType.id != T_null) { expressionType = env.computeBoxingType(expressionType); } } if (restrainUsageToNumericTypes() && !lhsType.isNumericType()) { scope.problemReporter().operatorOnlyValidOnNumericType(this, lhsType, expressionType); return null; } int lhsID = lhsType.id; int expressionID = expressionType.id; if (lhsID > 15 || expressionID > 15) { if (lhsID != T_JavaLangString) { // String += Thread is valid whereas Thread += String is not scope.problemReporter().invalidOperator(this, lhsType, expressionType); return null; } expressionID = T_JavaLangObject; // use the Object has tag table } // the code is an int // (cast) left Op (cast) rigth --> result // 0000 0000 0000 0000 0000 // <<16 <<12 <<8 <<4 <<0 // the conversion is stored INTO the reference (info needed for the code gen) int result = OperatorExpression.OperatorSignatures[this.operator][ (lhsID << 4) + expressionID]; if (result == T_undefined) { scope.problemReporter().invalidOperator(this, lhsType, expressionType); return null; } if (this.operator == PLUS){ if(lhsID == T_JavaLangObject && (scope.compilerOptions().complianceLevel < ClassFileConstants.JDK1_7)) { // <Object> += <String> is illegal (39248) for compliance < 1.7 scope.problemReporter().invalidOperator(this, lhsType, expressionType); return null; } else { // <int | boolean> += <String> is illegal if ((lhsType.isNumericType() || lhsID == T_boolean) && !expressionType.isNumericType()){ scope.problemReporter().invalidOperator(this, lhsType, expressionType); return null; } } } TypeBinding resultType = TypeBinding.wellKnownType(scope, result & 0x0000F); if (checkCastCompatibility()) { if (originalLhsType.id != T_JavaLangString && resultType.id != T_JavaLangString) { if (!checkCastTypesCompatibility(scope, originalLhsType, resultType, null)) { scope.problemReporter().invalidOperator(this, originalLhsType, expressionType); return null; } } } this.lhs.computeConversion(scope, TypeBinding.wellKnownType(scope, (result >>> 16) & 0x0000F), originalLhsType); this.expression.computeConversion(scope, TypeBinding.wellKnownType(scope, (result >>> 8) & 0x0000F), originalExpressionType); this.preAssignImplicitConversion = (unboxedLhs ? BOXING : 0) | (lhsID << 4) | (result & 0x0000F); if (unboxedLhs) scope.problemReporter().autoboxing(this, lhsType, originalLhsType); if (expressionIsCast) CastExpression.checkNeedForArgumentCasts(scope, this.operator, result, this.lhs, originalLhsType.id, false, this.expression, originalExpressionType.id, true); return this.resolvedType = originalLhsType; }
Example 16
Source File: AllocationExpression.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
public void checkTypeArgumentRedundancy(ParameterizedTypeBinding allocationType, ReferenceBinding enclosingType, TypeBinding[] argumentTypes, final BlockScope scope) { if ((scope.problemReporter().computeSeverity(IProblem.RedundantSpecificationOfTypeArguments) == ProblemSeverities.Ignore) || scope.compilerOptions().sourceLevel < ClassFileConstants.JDK1_7) return; if (allocationType.arguments == null) return; // raw binding if (this.genericTypeArguments != null) return; // diamond can't occur with explicit type args for constructor if (this.type == null) return; if (argumentTypes == Binding.NO_PARAMETERS && this.typeExpected instanceof ParameterizedTypeBinding) { ParameterizedTypeBinding expected = (ParameterizedTypeBinding) this.typeExpected; if (expected.arguments != null && allocationType.arguments.length == expected.arguments.length) { // check the case when no ctor takes no params and inference uses the expected type directly // eg. X<String> x = new X<String>() int i; for (i = 0; i < allocationType.arguments.length; i++) { if (TypeBinding.notEquals(allocationType.arguments[i], expected.arguments[i])) break; } if (i == allocationType.arguments.length) { scope.problemReporter().redundantSpecificationOfTypeArguments(this.type, allocationType.arguments); return; } } } TypeBinding [] inferredTypes; int previousBits = this.type.bits; try { // checking for redundant type parameters must fake a diamond, // so we infer the same results as we would get with a diamond in source code: this.type.bits |= IsDiamond; inferredTypes = inferElidedTypes(allocationType, enclosingType, argumentTypes, scope); } finally { // reset effects of inference this.type.bits = previousBits; } if (inferredTypes == null) { return; } for (int i = 0; i < inferredTypes.length; i++) { if (TypeBinding.notEquals(inferredTypes[i], allocationType.arguments[i])) return; } scope.problemReporter().redundantSpecificationOfTypeArguments(this.type, allocationType.arguments); }
Example 17
Source File: BlockScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * At the end of a block check the closing-status of all tracked closeables that are declared in this block. * Also invoked when entering unreachable code. */ public void checkUnclosedCloseables(FlowInfo flowInfo, FlowContext flowContext, ASTNode location, BlockScope locationScope) { if (!compilerOptions().analyseResourceLeaks) return; if (this.trackingVariables == null) { // at a method return we also consider enclosing scopes if (location != null && this.parent instanceof BlockScope) ((BlockScope) this.parent).checkUnclosedCloseables(flowInfo, flowContext, location, locationScope); return; } if (location != null && flowInfo.reachMode() != 0) return; FakedTrackingVariable returnVar = (location instanceof ReturnStatement) ? FakedTrackingVariable.getCloseTrackingVariable(((ReturnStatement)location).expression, flowInfo, flowContext) : null; Set varSet = new HashSet(this.trackingVariables); FakedTrackingVariable trackingVar; // pick one outer-most variable from the set at a time while ((trackingVar = FakedTrackingVariable.pickVarForReporting(varSet, this, location != null)) != null) { if (returnVar != null && trackingVar.isResourceBeingReturned(returnVar)) { continue; } if (location != null && trackingVar.hasDefinitelyNoResource(flowInfo)) { continue; // reporting against a specific location, there is no resource at this flow, don't complain } if (location != null && flowContext != null && flowContext.recordExitAgainstResource(this, flowInfo, trackingVar, location)) { continue; // handled by the flow context } // compute the most specific null status for this resource, int status = trackingVar.findMostSpecificStatus(flowInfo, this, locationScope); if (status == FlowInfo.NULL) { // definitely unclosed: highest priority reportResourceLeak(trackingVar, location, status); continue; } if (location == null) // at end of block and not definitely unclosed { // problems at specific locations: medium priority if (trackingVar.reportRecordedErrors(this, status)) // ... report previously recorded errors continue; } if (status == FlowInfo.POTENTIALLY_NULL) { // potentially unclosed: lower priority reportResourceLeak(trackingVar, location, status); } else if (status == FlowInfo.NON_NULL) { // properly closed but not managed by t-w-r: lowest priority if (environment().globalOptions.complianceLevel >= ClassFileConstants.JDK1_7) trackingVar.reportExplicitClosing(problemReporter()); } } if (location == null) { // when leaving this block dispose off all tracking variables: for (int i=0; i<this.localIndex; i++) this.locals[i].closeTracker = null; this.trackingVariables = null; } else { int size = this.trackingVariables.size(); for (int i=0; i<size; i++) { FakedTrackingVariable tracker = (FakedTrackingVariable) this.trackingVariables.get(i); tracker.resetReportingBits(); } } }
Example 18
Source File: AST.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Creates a new Java abstract syntax tree * (AST) following the specified set of API rules. * * @param level the API level; one of the <code>JLS*</code> level constants * @since 3.0 */ private AST(int level) { switch(level) { case JLS2_INTERNAL : case JLS3_INTERNAL : this.apiLevel = level; // initialize a scanner this.scanner = new Scanner( true /*comment*/, true /*whitespace*/, false /*nls*/, ClassFileConstants.JDK1_3 /*sourceLevel*/, ClassFileConstants.JDK1_5 /*complianceLevel*/, null/*taskTag*/, null/*taskPriorities*/, true/*taskCaseSensitive*/); break; case JLS4_INTERNAL : this.apiLevel = level; // initialize a scanner this.scanner = new Scanner( true /*comment*/, true /*whitespace*/, false /*nls*/, ClassFileConstants.JDK1_7 /*sourceLevel*/, ClassFileConstants.JDK1_7 /*complianceLevel*/, null/*taskTag*/, null/*taskPriorities*/, true/*taskCaseSensitive*/); break; case JLS8 : this.apiLevel = level; // initialize a scanner this.scanner = new Scanner( true /*comment*/, true /*whitespace*/, false /*nls*/, ClassFileConstants.JDK1_8 /*sourceLevel*/, ClassFileConstants.JDK1_8 /*complianceLevel*/, null/*taskTag*/, null/*taskPriorities*/, true/*taskCaseSensitive*/); break; default: throw new IllegalArgumentException("Unsupported JLS level"); //$NON-NLS-1$ } }
Example 19
Source File: MethodScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
/** * Error management: * keep null for all the errors that prevent the method to be created * otherwise return a correct method binding (but without the element * that caused the problem) : i.e. Incorrect thrown exception */ MethodBinding createMethod(AbstractMethodDeclaration method) { // is necessary to ensure error reporting this.referenceContext = method; method.scope = this; SourceTypeBinding declaringClass = referenceType().binding; int modifiers = method.modifiers | ExtraCompilerModifiers.AccUnresolved; if (method.isConstructor()) { if (method.isDefaultConstructor()) modifiers |= ExtraCompilerModifiers.AccIsDefaultConstructor; method.binding = new MethodBinding(modifiers, null, null, declaringClass); checkAndSetModifiersForConstructor(method.binding); } else { if (declaringClass.isInterface()) {// interface or annotation type if (method.isDefaultMethod() || method.isStatic()) { modifiers |= ClassFileConstants.AccPublic; // default method is not abstract } else { modifiers |= ClassFileConstants.AccPublic | ClassFileConstants.AccAbstract; } } method.binding = new MethodBinding(modifiers, method.selector, null, null, null, declaringClass); checkAndSetModifiersForMethod(method.binding); } this.isStatic = method.binding.isStatic(); Argument[] argTypes = method.arguments; int argLength = argTypes == null ? 0 : argTypes.length; long sourceLevel = compilerOptions().sourceLevel; if (argLength > 0) { Argument argument = argTypes[--argLength]; if (argument.isVarArgs() && sourceLevel >= ClassFileConstants.JDK1_5) method.binding.modifiers |= ClassFileConstants.AccVarargs; if (CharOperation.equals(argument.name, ConstantPool.This)) { problemReporter().illegalThisDeclaration(argument); } while (--argLength >= 0) { argument = argTypes[argLength]; if (argument.isVarArgs() && sourceLevel >= ClassFileConstants.JDK1_5) problemReporter().illegalVararg(argument, method); if (CharOperation.equals(argument.name, ConstantPool.This)) { problemReporter().illegalThisDeclaration(argument); } } } if (method.receiver != null) { if (sourceLevel <= ClassFileConstants.JDK1_7) { problemReporter().illegalSourceLevelForThis(method.receiver); } if (method.receiver.annotations != null) { method.bits |= ASTNode.HasTypeAnnotations; } } TypeParameter[] typeParameters = method.typeParameters(); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, If they exist at all, process type parameters irrespective of source level. if (typeParameters == null || typeParameters.length == 0) { method.binding.typeVariables = Binding.NO_TYPE_VARIABLES; } else { method.binding.typeVariables = createTypeVariables(typeParameters, method.binding); method.binding.modifiers |= ExtraCompilerModifiers.AccGenericSignature; } return method.binding; }