org.eclipse.jdt.internal.compiler.ast.TypeReference Java Examples
The following examples show how to use
org.eclipse.jdt.internal.compiler.ast.TypeReference.
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: SingletonEclipseHandler.java From tutorials with MIT License | 6 votes |
private FieldDeclaration addInstanceVar(ConstructorDeclaration constructor, TypeReference typeReference, TypeDeclaration innerClass) { FieldDeclaration field = new FieldDeclaration(); field.modifiers = AccPrivate | AccStatic | AccFinal; field.name = "INSTANCE".toCharArray(); field.type = typeReference; AllocationExpression exp = new AllocationExpression(); exp.type = typeReference; exp.binding = constructor.binding; exp.sourceStart = innerClass.sourceStart; exp.sourceEnd = innerClass.sourceEnd; field.initialization = exp; return field; }
Example #2
Source File: Eclipse.java From EasyMPermission with MIT License | 6 votes |
/** * Searches the given field node for annotations and returns each one that matches the provided regular expression pattern. * * Only the simple name is checked - the package and any containing class are ignored. */ public static Annotation[] findAnnotations(FieldDeclaration field, Pattern namePattern) { List<Annotation> result = new ArrayList<Annotation>(); if (field.annotations == null) return EMPTY_ANNOTATIONS_ARRAY; for (Annotation annotation : field.annotations) { TypeReference typeRef = annotation.type; if (typeRef != null && typeRef.getTypeName() != null) { char[][] typeName = typeRef.getTypeName(); String suspect = new String(typeName[typeName.length - 1]); if (namePattern.matcher(suspect).matches()) { result.add(annotation); } } } return result.toArray(EMPTY_ANNOTATIONS_ARRAY); }
Example #3
Source File: PatchVal.java From EasyMPermission with MIT License | 6 votes |
public static boolean handleValForForEach(ForeachStatement forEach, BlockScope scope) { if (forEach.elementVariable == null) return false; if (!isVal(forEach.elementVariable.type, scope)) return false; TypeBinding component = getForEachComponentType(forEach.collection, scope); if (component == null) return false; TypeReference replacement = makeType(component, forEach.elementVariable.type, false); forEach.elementVariable.modifiers |= ClassFileConstants.AccFinal; forEach.elementVariable.annotations = addValAnnotation(forEach.elementVariable.annotations, forEach.elementVariable.type, scope); forEach.elementVariable.type = replacement != null ? replacement : new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, poss(forEach.elementVariable.type, 3)); return false; }
Example #4
Source File: TypeAnnotationCodeStream.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void invokeDynamic(int bootStrapIndex, int argsSize, int returnTypeSize, char[] selector, char[] signature, boolean isConstructorReference, TypeReference lhsTypeReference, TypeReference [] typeArguments) { if (lhsTypeReference != null && (lhsTypeReference.bits & ASTNode.HasTypeAnnotations) != 0) { if (isConstructorReference) { addAnnotationContext(lhsTypeReference, this.position, 0, AnnotationTargetTypeConstants.CONSTRUCTOR_REFERENCE); } else { addAnnotationContext(lhsTypeReference, this.position, 0, AnnotationTargetTypeConstants.METHOD_REFERENCE); } } if (typeArguments != null) { int targetType = isConstructorReference ? AnnotationTargetTypeConstants.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT : AnnotationTargetTypeConstants.METHOD_REFERENCE_TYPE_ARGUMENT; for (int i = 0, max = typeArguments.length; i < max; i++) { TypeReference typeArgument = typeArguments[i]; if ((typeArgument.bits & ASTNode.HasTypeAnnotations) != 0) { addAnnotationContext(typeArgument, this.position, i, targetType); } } } super.invokeDynamic(bootStrapIndex, argsSize, returnTypeSize, selector, signature, isConstructorReference, lhsTypeReference, typeArguments); }
Example #5
Source File: SingletonEclipseHandler.java From tutorials with MIT License | 6 votes |
private void addFactoryMethod(EclipseNode singletonClass, TypeDeclaration astNode, TypeReference typeReference, TypeDeclaration innerClass, FieldDeclaration field) { MethodDeclaration factoryMethod = new MethodDeclaration(astNode.compilationResult); factoryMethod.modifiers = AccStatic | ClassFileConstants.AccPublic; factoryMethod.returnType = typeReference; factoryMethod.sourceStart = astNode.sourceStart; factoryMethod.sourceEnd = astNode.sourceEnd; factoryMethod.selector = "getInstance".toCharArray(); factoryMethod.bits = ECLIPSE_DO_NOT_TOUCH_FLAG; long pS = factoryMethod.sourceStart; long pE = factoryMethod.sourceEnd; long p = (long) pS << 32 | pE; FieldReference ref = new FieldReference(field.name, p); ref.receiver = new SingleNameReference(innerClass.name, p); ReturnStatement statement = new ReturnStatement(ref, astNode.sourceStart, astNode.sourceEnd); factoryMethod.statements = new Statement[]{statement}; EclipseHandlerUtil.injectMethod(singletonClass, factoryMethod); }
Example #6
Source File: SourceElementNotifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected char[][] getTypeParameterBounds(TypeParameter typeParameter) { TypeReference firstBound = typeParameter.type; TypeReference[] otherBounds = typeParameter.bounds; char[][] typeParameterBounds = null; if (firstBound != null) { if (otherBounds != null) { int otherBoundsLength = otherBounds.length; char[][] boundNames = new char[otherBoundsLength+1][]; boundNames[0] = CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.'); for (int j = 0; j < otherBoundsLength; j++) { boundNames[j+1] = CharOperation.concatWith(otherBounds[j].getParameterizedTypeName(), '.'); } typeParameterBounds = boundNames; } else { typeParameterBounds = new char[][] { CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.')}; } } else { typeParameterBounds = CharOperation.NO_CHAR_CHAR; } return typeParameterBounds; }
Example #7
Source File: SelectionOnParameterizedQualifiedTypeReference.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public StringBuffer printExpression(int indent, StringBuffer output) { output.append("<SelectOnType:");//$NON-NLS-1$ int length = this.tokens.length; for (int i = 0; i < length; i++) { if(i != 0) { output.append('.'); } output.append(this.tokens[i]); TypeReference[] typeArgument = this.typeArguments[i]; if (typeArgument != null) { output.append('<'); int max = typeArgument.length - 1; for (int j = 0; j < max; j++) { typeArgument[j].print(0, output); output.append(", ");//$NON-NLS-1$ } typeArgument[max].print(0, output); output.append('>'); } } output.append('>'); return output; }
Example #8
Source File: TypeAnnotationCodeStream.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public void checkcast(TypeReference typeReference, TypeBinding typeBinding) { /* We use a slightly sub-optimal generation for intersection casts by resorting to a runtime cast for every intersecting type, but in reality this should not matter. In its intended use form such as (I & Serializable) () -> {}, no cast is emitted at all. Also note intersection cast type references cannot nest i.e ((X & I) & J) is not valid syntax. */ if (typeReference != null) { TypeReference [] typeReferences = typeReference.getTypeReferences(); for (int i = typeReferences.length - 1; i >= 0; i--) { // need to emit right to left. typeReference = typeReferences[i]; if (typeReference != null) { if ((typeReference.bits & ASTNode.HasTypeAnnotations) != 0) addAnnotationContext(typeReference, this.position, i, AnnotationTargetTypeConstants.CAST); super.checkcast(typeReference, typeReference.resolvedType); } } } else { super.checkcast(null, typeBinding); } }
Example #9
Source File: TypeConverter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private TypeReference[] decodeTypeArguments(String typeSignature, int length, int start, int end) { ArrayList argumentList = new ArrayList(1); int count = 0; argumentsLoop: while (this.namePos < length) { TypeReference argument = decodeType(typeSignature, length, start, end); count++; argumentList.add(argument); if (this.namePos >= length) break argumentsLoop; if (typeSignature.charAt(this.namePos) == Signature.C_GENERIC_END) { break argumentsLoop; } } TypeReference[] typeArguments = new TypeReference[count]; argumentList.toArray(typeArguments); return typeArguments; }
Example #10
Source File: HandleBuilder.java From EasyMPermission with MIT License | 6 votes |
private MethodDeclaration generateCleanMethod(List<BuilderFieldData> builderFields, EclipseNode builderType, ASTNode source) { List<Statement> statements = new ArrayList<Statement>(); for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, builderType, statements); } } FieldReference thisUnclean = new FieldReference(CLEAN_FIELD_NAME, 0); thisUnclean.receiver = new ThisReference(0, 0); statements.add(new Assignment(thisUnclean, new FalseLiteral(0, 0), 0)); MethodDeclaration decl = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult); decl.selector = CLEAN_METHOD_NAME; decl.modifiers = ClassFileConstants.AccPrivate; decl.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; decl.returnType = TypeReference.baseTypeReference(TypeIds.T_void, 0); decl.statements = statements.toArray(new Statement[0]); decl.traverse(new SetGeneratedByVisitor(source), (ClassScope) null); return decl; }
Example #11
Source File: HandleEqualsAndHashCode.java From EasyMPermission with MIT License | 6 votes |
/** Give 2 clones! */ public Expression longToIntForHashCode(Expression ref1, Expression ref2, ASTNode source) { int pS = source.sourceStart, pE = source.sourceEnd; /* (int)(ref >>> 32 ^ ref) */ IntLiteral int32 = makeIntLiteral("32".toCharArray(), source); BinaryExpression higherBits = new BinaryExpression(ref1, int32, OperatorIds.UNSIGNED_RIGHT_SHIFT); setGeneratedBy(higherBits, source); BinaryExpression xorParts = new BinaryExpression(ref2, higherBits, OperatorIds.XOR); setGeneratedBy(xorParts, source); TypeReference intRef = TypeReference.baseTypeReference(TypeIds.T_int, 0); intRef.sourceStart = pS; intRef.sourceEnd = pE; setGeneratedBy(intRef, source); CastExpression expr = makeCastExpression(xorParts, intRef, source); expr.sourceStart = pS; expr.sourceEnd = pE; return expr; }
Example #12
Source File: EclipseSingularsRecipes.java From EasyMPermission with MIT License | 6 votes |
/** * Adds the requested number of type arguments to the provided type, copying each argument in {@code typeArgs}. If typeArgs is too long, the extra elements are ignored. * If {@code typeArgs} is null or too short, {@code java.lang.Object} will be substituted for each missing type argument. * * @param count The number of type arguments requested. * @param addExtends If {@code true}, all bounds are either '? extends X' or just '?'. If false, the reverse is applied, and '? extends Foo' is converted to Foo, '?' to Object, etc. * @param node Some node in the same AST. Just used to obtain makers and contexts and such. * @param type The type to add generics to. * @param typeArgs the list of type args to clone. * @param source The source annotation that is the root cause of this code generation. */ protected TypeReference addTypeArgs(int count, boolean addExtends, EclipseNode node, TypeReference type, List<TypeReference> typeArgs) { TypeReference[] clonedAndFixedArgs = createTypeArgs(count, addExtends, node, typeArgs); if (type instanceof SingleTypeReference) { type = new ParameterizedSingleTypeReference(((SingleTypeReference) type).token, clonedAndFixedArgs, 0, 0L); } else if (type instanceof QualifiedTypeReference) { QualifiedTypeReference qtr = (QualifiedTypeReference) type; TypeReference[][] trs = new TypeReference[qtr.tokens.length][]; trs[qtr.tokens.length - 1] = clonedAndFixedArgs; type = new ParameterizedQualifiedTypeReference(((QualifiedTypeReference) type).tokens, trs, 0, NULL_POSS); } else { node.addError("Don't know how to clone-and-parameterize type: " + type); } return type; }
Example #13
Source File: EclipseSingularsRecipes.java From EasyMPermission with MIT License | 6 votes |
protected TypeReference cloneParamType(int index, List<TypeReference> typeArgs, EclipseNode builderType) { if (typeArgs != null && typeArgs.size() > index) { TypeReference originalType = typeArgs.get(index); if (originalType instanceof Wildcard) { Wildcard wOriginalType = (Wildcard) originalType; if (wOriginalType.kind == Wildcard.EXTENDS) { try { return copyType(wOriginalType.bound); } catch (Exception e) { // fallthrough } } } else { return copyType(originalType); } } return new QualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT, NULL_POSS); }
Example #14
Source File: SourceElementNotifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected char[][] getInterfaceNames(TypeDeclaration typeDeclaration) { char[][] interfaceNames = null; int superInterfacesLength = 0; TypeReference[] superInterfaces = typeDeclaration.superInterfaces; if (superInterfaces != null) { superInterfacesLength = superInterfaces.length; interfaceNames = new char[superInterfacesLength][]; } else { if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { // see PR 3442 QualifiedAllocationExpression alloc = typeDeclaration.allocation; if (alloc != null && alloc.type != null) { superInterfaces = new TypeReference[] { alloc.type}; superInterfacesLength = 1; interfaceNames = new char[1][]; } } } if (superInterfaces != null) { for (int i = 0; i < superInterfacesLength; i++) { interfaceNames[i] = CharOperation.concatWith(superInterfaces[i].getParameterizedTypeName(), '.'); } } return interfaceNames; }
Example #15
Source File: ClassScope.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private ReferenceBinding findSupertype(TypeReference typeReference) { CompilationUnitScope unitScope = compilationUnitScope(); LookupEnvironment env = unitScope.environment; try { env.missingClassFileLocation = typeReference; typeReference.aboutToResolve(this); // allows us to trap completion & selection nodes unitScope.recordQualifiedReference(typeReference.getTypeName()); this.superTypeReference = typeReference; ReferenceBinding superType = (ReferenceBinding) typeReference.resolveSuperType(this); return superType; } catch (AbortCompilation e) { SourceTypeBinding sourceType = this.referenceContext.binding; if (sourceType.superInterfaces == null) sourceType.setSuperInterfaces(Binding.NO_SUPERINTERFACES); // be more resilient for hierarchies (144976) e.updateContext(typeReference, referenceCompilationUnit().compilationResult); throw e; } finally { env.missingClassFileLocation = null; this.superTypeReference = null; } }
Example #16
Source File: TypeConverter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected TypeParameter createTypeParameter(char[] typeParameterName, char[][] typeParameterBounds, int start, int end) { TypeParameter parameter = new TypeParameter(); parameter.name = typeParameterName; parameter.sourceStart = start; parameter.sourceEnd = end; if (typeParameterBounds != null) { int length = typeParameterBounds.length; if (length > 0) { parameter.type = createTypeReference(typeParameterBounds[0], start, end); if (length > 1) { parameter.bounds = new TypeReference[length-1]; for (int i = 1; i < length; i++) { TypeReference bound = createTypeReference(typeParameterBounds[i], start, end); bound.bits |= ASTNode.IsSuperType; parameter.bounds[i-1] = bound; } } } } return parameter; }
Example #17
Source File: CompletionElementNotifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected char[][] getTypeParameterBounds(TypeParameter typeParameter) { TypeReference firstBound = typeParameter.type; TypeReference[] otherBounds = typeParameter.bounds; char[][] typeParameterBounds = null; if (firstBound != null) { if (otherBounds != null) { int otherBoundsLength = otherBounds.length; char[][] boundNames = new char[otherBoundsLength+1][]; int boundCount = 0; if (!CompletionUnitStructureRequestor.hasEmptyName(firstBound, this.assistNode)) { boundNames[boundCount++] = CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.'); } for (int j = 0; j < otherBoundsLength; j++) { TypeReference otherBound = otherBounds[j]; if (!CompletionUnitStructureRequestor.hasEmptyName(otherBound, this.assistNode)) { boundNames[boundCount++] = CharOperation.concatWith(otherBound.getParameterizedTypeName(), '.'); } } if (boundCount == 0) { boundNames = CharOperation.NO_CHAR_CHAR; } else if (boundCount < otherBoundsLength + 1){ System.arraycopy(boundNames, 0, boundNames = new char[boundCount][], 0, boundCount); } typeParameterBounds = boundNames; } else { if (!CompletionUnitStructureRequestor.hasEmptyName(firstBound, this.assistNode)) { typeParameterBounds = new char[][] { CharOperation.concatWith(firstBound.getParameterizedTypeName(), '.')}; } else { typeParameterBounds = CharOperation.NO_CHAR_CHAR; } } } else { typeParameterBounds = CharOperation.NO_CHAR_CHAR; } return typeParameterBounds; }
Example #18
Source File: ExceptionHandlingFlowContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private ASTNode getExceptionType(int index) { if (this.exceptionToCatchBlockMap == null) { return this.catchArguments[index].type; } int catchBlock = this.exceptionToCatchBlockMap[index]; ASTNode node = this.catchArguments[catchBlock].type; if (node instanceof UnionTypeReference) { TypeReference[] typeRefs = ((UnionTypeReference)node).typeReferences; for (int i = 0, len = typeRefs.length; i < len; i++) { TypeReference typeRef = typeRefs[i]; if (TypeBinding.equalsEquals(typeRef.resolvedType, this.handledExceptions[index])) return typeRef; } } return node; }
Example #19
Source File: SelectionOnFieldType.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public SelectionOnFieldType(TypeReference type) { super(); this.sourceStart = type.sourceStart; this.sourceEnd = type.sourceEnd; this.type = type; this.name = CharOperation.NO_CHAR; }
Example #20
Source File: EclipseJavaUtilListSetSingularizer.java From EasyMPermission with MIT License | 5 votes |
void generateSingularMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { 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, false)); FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L); thisDotField.receiver = new ThisReference(0, 0); MessageSend thisDotFieldDotAdd = new MessageSend(); thisDotFieldDotAdd.arguments = new Expression[] {new SingleNameReference(data.getSingularName(), 0L)}; thisDotFieldDotAdd.receiver = thisDotField; thisDotFieldDotAdd.selector = "add".toCharArray(); statements.add(thisDotFieldDotAdd); if (returnStatement != null) statements.add(returnStatement); md.statements = statements.toArray(new Statement[statements.size()]); TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType); Argument param = new Argument(data.getSingularName(), 0, paramType, 0); md.arguments = new Argument[] {param}; md.returnType = returnType; md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray(); data.setGeneratedByRecursive(md); injectMethod(builderType, md); }
Example #21
Source File: EclipseJavaUtilListSetSingularizer.java From EasyMPermission with MIT License | 5 votes |
void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { 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, false)); 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 = "addAll".toCharArray(); statements.add(thisDotFieldDotAddAll); if (returnStatement != null) statements.add(returnStatement); md.statements = statements.toArray(new Statement[statements.size()]); TypeReference paramType = new QualifiedTypeReference(TypeConstants.JAVA_UTIL_COLLECTION, 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("addAll", new String(data.getPluralName())).toCharArray(); data.setGeneratedByRecursive(md); injectMethod(builderType, md); }
Example #22
Source File: SelectionParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void attachOrphanCompletionNode(){ if (this.isOrphanCompletionNode){ ASTNode orphan = this.assistNode; this.isOrphanCompletionNode = false; /* if in context of a type, then persists the identifier into a fake field return type */ if (this.currentElement instanceof RecoveredType){ RecoveredType recoveredType = (RecoveredType)this.currentElement; /* filter out cases where scanner is still inside type header */ if (recoveredType.foundOpeningBrace) { /* generate a pseudo field with a completion on type reference */ if (orphan instanceof TypeReference){ this.currentElement = this.currentElement.add(new SelectionOnFieldType((TypeReference)orphan), 0); return; } } } if (orphan instanceof Expression) { buildMoreCompletionContext((Expression)orphan); } else { if (lastIndexOfElement(K_LAMBDA_EXPRESSION_DELIMITER) < 0) { // lambdas are recovered up to the containing expression statement and will carry along the assist node anyways. Statement statement = (Statement) orphan; this.currentElement = this.currentElement.add(statement, 0); } } if (!isIndirectlyInsideLambdaExpression()) this.currentToken = 0; // given we are not on an eof, we do not want side effects caused by looked-ahead token } }
Example #23
Source File: EclipseJavaUtilListSetSingularizer.java From EasyMPermission with MIT License | 5 votes |
@Override public void generateMethods(SingularData data, EclipseNode builderType, boolean fluent, boolean chain) { if (useGuavaInstead(builderType)) { guavaListSetSingularizer.generateMethods(data, builderType, fluent, chain); return; } TypeReference returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0); Statement returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null; generateSingularMethod(returnType, returnStatement, data, builderType, fluent); returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0); returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null; generatePluralMethod(returnType, returnStatement, data, builderType, fluent); }
Example #24
Source File: EclipseSingularsRecipes.java From EasyMPermission with MIT License | 5 votes |
public SingularData(EclipseNode annotation, char[] singularName, char[] pluralName, List<TypeReference> typeArgs, String targetFqn, EclipseSingularizer singularizer, ASTNode source) { this.annotation = annotation; this.singularName = singularName; this.pluralName = pluralName; this.typeArgs = typeArgs; this.targetFqn = targetFqn; this.singularizer = singularizer; this.source = source; }
Example #25
Source File: HandleEqualsAndHashCode.java From EasyMPermission with MIT License | 5 votes |
public TypeReference generateQualifiedTypeRef(ASTNode source, char[]... varNames) { int pS = source.sourceStart, pE = source.sourceEnd; long p = (long)pS << 32 | pE; TypeReference ref; long[] poss = Eclipse.poss(source, varNames.length); if (varNames.length > 1) ref = new QualifiedTypeReference(varNames, poss); else ref = new SingleTypeReference(varNames[0], p); setGeneratedBy(ref, source); return ref; }
Example #26
Source File: DefaultBindingResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
synchronized IBinding resolveReference(MemberRef ref) { org.eclipse.jdt.internal.compiler.ast.Expression expression = (org.eclipse.jdt.internal.compiler.ast.Expression) this.newAstToOldAst.get(ref); if (expression instanceof TypeReference) { return getTypeBinding(expression.resolvedType); } else if (expression instanceof JavadocFieldReference) { JavadocFieldReference fieldRef = (JavadocFieldReference) expression; if (fieldRef.methodBinding != null) { return getMethodBinding(fieldRef.methodBinding); } return getVariableBinding(fieldRef.binding); } return null; }
Example #27
Source File: HandleEqualsAndHashCode.java From EasyMPermission with MIT License | 5 votes |
public LocalDeclaration createLocalDeclaration(ASTNode source, char[] dollarFieldName, TypeReference type, Expression initializer) { int pS = source.sourceStart, pE = source.sourceEnd; LocalDeclaration tempVar = new LocalDeclaration(dollarFieldName, pS, pE); setGeneratedBy(tempVar, source); tempVar.initialization = initializer; tempVar.type = type; tempVar.type.sourceStart = pS; tempVar.type.sourceEnd = pE; setGeneratedBy(tempVar.type, source); tempVar.modifiers = Modifier.FINAL; return tempVar; }
Example #28
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 #29
Source File: EclipseHandlerUtil.java From EasyMPermission with MIT License | 5 votes |
/** * Create an annotation of the given name, and is marked as being generated by the given source. */ public static MarkerAnnotation makeMarkerAnnotation(char[][] name, ASTNode source) { long pos = (long)source.sourceStart << 32 | source.sourceEnd; TypeReference typeRef = new QualifiedTypeReference(name, new long[] {pos, pos, pos}); setGeneratedBy(typeRef, source); MarkerAnnotation ann = new MarkerAnnotation(typeRef, (int)(pos >> 32)); ann.declarationSourceEnd = ann.sourceEnd = ann.statementEnd = (int)pos; setGeneratedBy(ann, source); return ann; }
Example #30
Source File: PatchVal.java From EasyMPermission with MIT License | 5 votes |
public static boolean couldBeVal(TypeReference ref) { if (ref instanceof SingleTypeReference) { char[] token = ((SingleTypeReference)ref).token; return matches("val", token); } if (ref instanceof QualifiedTypeReference) { char[][] tokens = ((QualifiedTypeReference)ref).tokens; if (tokens == null || tokens.length != 2) return false; return matches("lombok", tokens[0]) && matches("val", tokens[1]); } return false; }