org.eclipse.jdt.internal.compiler.ast.ASTNode Java Examples
The following examples show how to use
org.eclipse.jdt.internal.compiler.ast.ASTNode.
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: FinallyFlowContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected void recordNullReference(LocalVariableBinding local, ASTNode expression, int checkType) { if (this.nullCount == 0) { this.nullLocals = new LocalVariableBinding[5]; this.nullReferences = new ASTNode[5]; this.nullCheckTypes = new int[5]; } else if (this.nullCount == this.nullLocals.length) { int newLength = this.nullCount * 2; System.arraycopy(this.nullLocals, 0, this.nullLocals = new LocalVariableBinding[newLength], 0, this.nullCount); System.arraycopy(this.nullReferences, 0, this.nullReferences = new ASTNode[newLength], 0, this.nullCount); System.arraycopy(this.nullCheckTypes, 0, this.nullCheckTypes = new int[newLength], 0, this.nullCount); } this.nullLocals[this.nullCount] = local; this.nullReferences[this.nullCount] = expression; this.nullCheckTypes[this.nullCount++] = checkType; }
Example #2
Source File: MethodBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Compute the tagbits for standard annotations. For source types, these could require * lazily resolving corresponding annotation nodes, in case of forward references. * @see org.eclipse.jdt.internal.compiler.lookup.Binding#getAnnotationTagBits() */ public long getAnnotationTagBits() { MethodBinding originalMethod = original(); if ((originalMethod.tagBits & TagBits.AnnotationResolved) == 0 && originalMethod.declaringClass instanceof SourceTypeBinding) { ClassScope scope = ((SourceTypeBinding) originalMethod.declaringClass).scope; if (scope != null) { TypeDeclaration typeDecl = scope.referenceContext; AbstractMethodDeclaration methodDecl = typeDecl.declarationOf(originalMethod); if (methodDecl != null) ASTNode.resolveAnnotations(methodDecl.scope, methodDecl.annotations, originalMethod); CompilerOptions options = scope.compilerOptions(); if (options.isAnnotationBasedNullAnalysisEnabled) { boolean isJdk18 = options.sourceLevel >= ClassFileConstants.JDK1_8; long nullDefaultBits = isJdk18 ? this.defaultNullness : this.tagBits & (TagBits.AnnotationNonNullByDefault|TagBits.AnnotationNullUnspecifiedByDefault); if (nullDefaultBits != 0 && this.declaringClass instanceof SourceTypeBinding) { SourceTypeBinding declaringSourceType = (SourceTypeBinding) this.declaringClass; if (declaringSourceType.checkRedundantNullnessDefaultOne(methodDecl, methodDecl.annotations, nullDefaultBits, isJdk18)) { declaringSourceType.checkRedundantNullnessDefaultRecurse(methodDecl, methodDecl.annotations, nullDefaultBits, isJdk18); } } } } } return originalMethod.tagBits; }
Example #3
Source File: SourceTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * @see org.eclipse.jdt.internal.compiler.lookup.Binding#initializeDeprecatedAnnotationTagBits() */ public void initializeDeprecatedAnnotationTagBits() { if (!isPrototype()) { this.prototype.initializeDeprecatedAnnotationTagBits(); return; } if ((this.tagBits & TagBits.DeprecatedAnnotationResolved) == 0) { TypeDeclaration typeDecl = this.scope.referenceContext; boolean old = typeDecl.staticInitializerScope.insideTypeAnnotation; try { typeDecl.staticInitializerScope.insideTypeAnnotation = true; ASTNode.resolveDeprecatedAnnotations(typeDecl.staticInitializerScope, typeDecl.annotations, this); this.tagBits |= TagBits.DeprecatedAnnotationResolved; } finally { typeDecl.staticInitializerScope.insideTypeAnnotation = old; } if ((this.tagBits & TagBits.AnnotationDeprecated) != 0) { this.modifiers |= ClassFileConstants.AccDeprecated; } } }
Example #4
Source File: ConstructorPattern.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static int encodeExtraFlags(int extraFlags) { int encodedExtraFlags = 0; if ((extraFlags & ExtraFlags.ParameterTypesStoredAsSignature) != 0) { encodedExtraFlags |= ASTNode.Bit28; } if ((extraFlags & ExtraFlags.IsLocalType) != 0) { encodedExtraFlags |= ASTNode.Bit29; } if ((extraFlags & ExtraFlags.IsMemberType) != 0) { encodedExtraFlags |= ASTNode.Bit30; } if ((extraFlags & ExtraFlags.HasNonPrivateStaticMemberTypes) != 0) { encodedExtraFlags |= ASTNode.Bit31; } return encodedExtraFlags; }
Example #5
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 #6
Source File: PatchExtensionMethod.java From EasyMPermission with MIT License | 6 votes |
private static NameReference createNameRef(TypeBinding typeBinding, ASTNode source) { long p = ((long) source.sourceStart << 32) | source.sourceEnd; char[] pkg = typeBinding.qualifiedPackageName(); char[] basename = typeBinding.qualifiedSourceName(); StringBuilder sb = new StringBuilder(); if (pkg != null) sb.append(pkg); if (sb.length() > 0) sb.append("."); sb.append(basename); String tName = sb.toString(); if (tName.indexOf('.') == -1) { return new SingleNameReference(basename, p); } else { char[][] sources; String[] in = tName.split("\\."); sources = new char[in.length][]; for (int i = 0; i < in.length; i++) sources[i] = in[i].toCharArray(); long[] poss = new long[in.length]; Arrays.fill(poss, p); return new QualifiedNameReference(sources, poss, source.sourceStart, source.sourceEnd); } }
Example #7
Source File: JavaStatementPostfixContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public JavaStatementPostfixContext( TemplateContextType type, IDocument document, int offset, int length, ICompilationUnit compilationUnit, ASTNode currentNode, ASTNode parentNode) { super(type, document, offset, length, compilationUnit); this.nodeRegions = new HashMap<>(); this.currentCompletionNode = currentNode; nodeRegions.put(currentNode, calculateNodeRegion(currentNode)); this.currentCompletionNodeParent = parentNode; nodeRegions.put(parentNode, calculateNodeRegion(parentNode)); this.selectedNode = currentNode; outOfRangeOffsets = new HashMap<>(); }
Example #8
Source File: AssistParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * If the given ast node is inside an explicit constructor call * then wrap it with a fake constructor call. * Returns the wrapped completion node or the completion node itself. */ protected ASTNode wrapWithExplicitConstructorCallIfNeeded(ASTNode ast) { int selector; if (ast != null && topKnownElementKind(ASSIST_PARSER) == K_SELECTOR && ast instanceof Expression && (((selector = topKnownElementInfo(ASSIST_PARSER)) == THIS_CONSTRUCTOR) || (selector == SUPER_CONSTRUCTOR))) { ExplicitConstructorCall call = new ExplicitConstructorCall( (selector == THIS_CONSTRUCTOR) ? ExplicitConstructorCall.This : ExplicitConstructorCall.Super ); call.arguments = new Expression[] {(Expression)ast}; call.sourceStart = ast.sourceStart; call.sourceEnd = ast.sourceEnd; return call; } else { return ast; } }
Example #9
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 #10
Source File: SourceTypeBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected boolean checkRedundantNullnessDefaultOne(ASTNode location, Annotation[] annotations, long nullBits, boolean isJdk18) { if (!isPrototype()) throw new IllegalStateException(); int thisDefault = getNullDefault(); if (thisDefault != NO_NULL_DEFAULT) { boolean isRedundant = isJdk18 ? thisDefault == nullBits : (nullBits & TagBits.AnnotationNonNullByDefault) != 0; if (isRedundant) { this.scope.problemReporter().nullDefaultAnnotationIsRedundant(location, annotations, this); } return false; // different default means inner default is not redundant -> we're done } return true; }
Example #11
Source File: InternalCompletionContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
protected void setExtendedData( ITypeRoot typeRoot, CompilationUnitDeclaration compilationUnitDeclaration, LookupEnvironment lookupEnvironment, Scope scope, ASTNode astNode, ASTNode astNodeParent, WorkingCopyOwner owner, CompletionParser parser) { this.isExtended = true; this.extendedContext = new InternalExtendedCompletionContext( this, typeRoot, compilationUnitDeclaration, lookupEnvironment, scope, astNode, astNodeParent, owner, parser); }
Example #12
Source File: SourceElementNotifier.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private int sourceEnd(TypeDeclaration typeDeclaration) { if ((typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { QualifiedAllocationExpression allocation = typeDeclaration.allocation; if (allocation.enumConstant != null) // case of enum constant body return allocation.enumConstant.sourceEnd; return allocation.type.sourceEnd; } else { return typeDeclaration.sourceEnd; } }
Example #13
Source File: MethodBinding.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * @return the annotations for each of the method parameters or <code>null></code> * if there's no parameter or no annotation at all. */ public AnnotationBinding[][] getParameterAnnotations() { int length; if ((length = this.parameters.length) == 0) { return null; } MethodBinding originalMethod = original(); AnnotationHolder holder = originalMethod.declaringClass.retrieveAnnotationHolder(originalMethod, true); AnnotationBinding[][] allParameterAnnotations = holder == null ? null : holder.getParameterAnnotations(); if (allParameterAnnotations == null && (this.tagBits & TagBits.HasParameterAnnotations) != 0) { allParameterAnnotations = new AnnotationBinding[length][]; // forward reference to method, where param annotations have not yet been associated to method if (this.declaringClass instanceof SourceTypeBinding) { SourceTypeBinding sourceType = (SourceTypeBinding) this.declaringClass; if (sourceType.scope != null) { AbstractMethodDeclaration methodDecl = sourceType.scope.referenceType().declarationOf(this); for (int i = 0; i < length; i++) { Argument argument = methodDecl.arguments[i]; if (argument.annotations != null) { ASTNode.resolveAnnotations(methodDecl.scope, argument.annotations, argument.binding); allParameterAnnotations[i] = argument.binding.getAnnotations(); } else { allParameterAnnotations[i] = Binding.NO_ANNOTATIONS; } } } else { for (int i = 0; i < length; i++) { allParameterAnnotations[i] = Binding.NO_ANNOTATIONS; } } } else { for (int i = 0; i < length; i++) { allParameterAnnotations[i] = Binding.NO_ANNOTATIONS; } } setParameterAnnotations(allParameterAnnotations); } return allParameterAnnotations; }
Example #14
Source File: OrLocator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException { PatternLocator closestPattern = null; int level = IMPOSSIBLE_MATCH; for (int i = 0, length = this.patternLocators.length; i < length; i++) { PatternLocator patternLocator = this.patternLocators[i]; int newLevel = patternLocator.referenceType() == 0 ? IMPOSSIBLE_MATCH : patternLocator.resolveLevel(reference); if (newLevel > level) { closestPattern = patternLocator; if (newLevel == ACCURATE_MATCH) break; level = newLevel; } } if (closestPattern != null) closestPattern.matchReportReference(reference, element, localElement, otherElements, elementBinding, accuracy, locator); }
Example #15
Source File: JavaStatementPostfixContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected String resolveNodeToTypeString(ASTNode node) { Binding b = resolveNodeToBinding(node); if (b != null) { return new String(b.readableName()); } return OBJECT_SIGNATURE; }
Example #16
Source File: AbortCompilation.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void updateContext(ASTNode astNode, CompilationResult unitResult) { if (this.problem == null) return; if (this.problem.getSourceStart() != 0 || this.problem.getSourceEnd() != 0) return; this.problem.setSourceStart(astNode.sourceStart()); this.problem.setSourceEnd(astNode.sourceEnd()); int[] lineEnds = unitResult.getLineSeparatorPositions(); this.problem.setSourceLineNumber(Util.getLineNumber(astNode.sourceStart(), lineEnds, 0, lineEnds.length-1)); this.compilationResult = unitResult; }
Example #17
Source File: InferenceContext18.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private void acceptPendingPolyArguments(BoundSet acceptedResult, TypeBinding[] parameterTypes, boolean isVarArgs) { if (acceptedResult == null || this.invocationArguments == null) return; Substitution substitution = getResultSubstitution(acceptedResult); for (int i = 0; i < this.invocationArguments.length; i++) { TypeBinding targetType = getParameter(parameterTypes, i, isVarArgs); if (!targetType.isProperType(true)) targetType = Scope.substitute(substitution, targetType); Expression expression = this.invocationArguments[i]; if (expression instanceof Invocation) { Invocation invocation = (Invocation) expression; if (!this.innerPolies.contains(invocation)) { MethodBinding method = invocation.binding(targetType, true, this.scope); if (method instanceof ParameterizedGenericMethodBinding) { ParameterizedGenericMethodBinding previousBinding = (ParameterizedGenericMethodBinding) method; InferenceContext18 innerCtx = invocation.getInferenceContext(previousBinding); if (innerCtx != null) { // we have a non-poly generic invocation, which needs inference but is not connected via innerPolis. // Finish that inner inference now (incl. binding updates): MethodBinding innerBinding = innerCtx.inferInvocationType(invocation, previousBinding); if (!innerBinding.isValidBinding()) { innerCtx.reportInvalidInvocation(invocation, innerBinding); } if (invocation.updateBindings(innerBinding, targetType)) { // only if we are actually improving anything ASTNode.resolvePolyExpressionArguments(invocation, innerBinding, this.scope); } } } else if(method instanceof ParameterizedMethodBinding){ expression.checkAgainstFinalTargetType(targetType, this.scope); } } else { expression.setExpectedType(targetType); } } else { expression.checkAgainstFinalTargetType(targetType, this.scope); } } }
Example #18
Source File: RecoveredField.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public RecoveredElement add(TypeDeclaration typeDeclaration, int bracketBalanceValue) { if (this.alreadyCompletedFieldInitialization || ((typeDeclaration.bits & ASTNode.IsAnonymousType) == 0) || (this.fieldDeclaration.declarationSourceEnd != 0 && typeDeclaration.sourceStart > this.fieldDeclaration.declarationSourceEnd)) { return super.add(typeDeclaration, bracketBalanceValue); } else { // Prepare anonymous type list if (this.anonymousTypes == null) { this.anonymousTypes = new RecoveredType[5]; this.anonymousTypeCount = 0; } else { if (this.anonymousTypeCount == this.anonymousTypes.length) { System.arraycopy( this.anonymousTypes, 0, (this.anonymousTypes = new RecoveredType[2 * this.anonymousTypeCount]), 0, this.anonymousTypeCount); } } // Store type declaration as an anonymous type RecoveredType element = new RecoveredType(typeDeclaration, this, bracketBalanceValue); this.anonymousTypes[this.anonymousTypeCount++] = element; return element; } }
Example #19
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 #20
Source File: JavaStatementPostfixContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Calculates the beginning position of a given {@link ASTNode} * @param node * @return */ protected int getNodeBegin(ASTNode node) { if (node instanceof NameReference) { return ((NameReference) node).sourceStart; } else if (node instanceof FieldReference) { return ((FieldReference) node).receiver.sourceStart; } else if (node instanceof MessageSend) { return ((MessageSend) node).receiver.sourceStart; } return node.sourceStart; }
Example #21
Source File: HandleBuilder.java From EasyMPermission with MIT License | 5 votes |
public void generateBuilderFields(EclipseNode builderType, List<BuilderFieldData> builderFields, ASTNode source) { List<EclipseNode> existing = new ArrayList<EclipseNode>(); for (EclipseNode child : builderType.down()) { if (child.getKind() == Kind.FIELD) existing.add(child); } top: for (BuilderFieldData bfd : builderFields) { if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) { bfd.createdFields.addAll(bfd.singularData.getSingularizer().generateFields(bfd.singularData, builderType)); } else { for (EclipseNode exists : existing) { char[] n = ((FieldDeclaration) exists.get()).name; if (Arrays.equals(n, bfd.name)) { bfd.createdFields.add(exists); continue top; } } FieldDeclaration fd = new FieldDeclaration(bfd.name, 0, 0); fd.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; fd.modifiers = ClassFileConstants.AccPrivate; fd.type = copyType(bfd.type); fd.traverse(new SetGeneratedByVisitor(source), (MethodScope) null); bfd.createdFields.add(injectFieldAndMarkGenerated(builderType, fd)); } } }
Example #22
Source File: SwitchFlowContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public SwitchFlowContext(FlowContext parent, ASTNode associatedNode, BranchLabel breakLabel, boolean isPreTest) { super(parent, associatedNode); this.breakLabel = breakLabel; if (isPreTest && parent.conditionalLevel > -1) { this.conditionalLevel++; } }
Example #23
Source File: FlowContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public FlowContext(FlowContext parent, ASTNode associatedNode) { this.parent = parent; this.associatedNode = associatedNode; if (parent != null) { if ((parent.tagBits & (FlowContext.DEFER_NULL_DIAGNOSTIC | FlowContext.PREEMPT_NULL_DIAGNOSTIC)) != 0) { this.tagBits |= FlowContext.DEFER_NULL_DIAGNOSTIC; } this.initsOnFinally = parent.initsOnFinally; this.conditionalLevel = parent.conditionalLevel; this.nullCheckedFieldReferences = parent.nullCheckedFieldReferences; // re-use list if there is one } }
Example #24
Source File: EclipseHandlerUtil.java From EasyMPermission with MIT License | 5 votes |
public static Annotation[] copyAnnotations(ASTNode source, Annotation[]... allAnnotations) { List<Annotation> result = null; for (Annotation[] annotations : allAnnotations) { if (annotations != null) { for (Annotation annotation : annotations) { if (result == null) result = new ArrayList<Annotation>(); result.add(copyAnnotation(annotation, source)); } } } return result == null ? null : result.toArray(new Annotation[0]); }
Example #25
Source File: TypeAnnotationCodeStream.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void multianewarray( TypeReference typeReference, TypeBinding typeBinding, int dimensions, ArrayAllocationExpression allocationExpression) { if (typeReference != null && (typeReference.bits & ASTNode.HasTypeAnnotations) != 0) { addAnnotationContext(typeReference, this.position, AnnotationTargetTypeConstants.NEW, allocationExpression); } super.multianewarray(typeReference, typeBinding, dimensions, allocationExpression); }
Example #26
Source File: RecoveredType.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public String toString(int tab) { StringBuffer result = new StringBuffer(tabString(tab)); result.append("Recovered type:\n"); //$NON-NLS-1$ if ((this.typeDeclaration.bits & ASTNode.IsAnonymousType) != 0) { result.append(tabString(tab)); result.append(" "); //$NON-NLS-1$ } this.typeDeclaration.print(tab + 1, result); if (this.annotations != null) { for (int i = 0; i < this.annotationCount; i++) { result.append("\n"); //$NON-NLS-1$ result.append(this.annotations[i].toString(tab + 1)); } } if (this.memberTypes != null) { for (int i = 0; i < this.memberTypeCount; i++) { result.append("\n"); //$NON-NLS-1$ result.append(this.memberTypes[i].toString(tab + 1)); } } if (this.fields != null) { for (int i = 0; i < this.fieldCount; i++) { result.append("\n"); //$NON-NLS-1$ result.append(this.fields[i].toString(tab + 1)); } } if (this.methods != null) { for (int i = 0; i < this.methodCount; i++) { result.append("\n"); //$NON-NLS-1$ result.append(this.methods[i].toString(tab + 1)); } } return result.toString(); }
Example #27
Source File: JavaStatementPostfixContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private Expression createExpression(String expr) { ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setKind(ASTParser.K_EXPRESSION); parser.setResolveBindings(true); parser.setSource(expr.toCharArray()); org.eclipse.jdt.core.dom.ASTNode astNode = parser.createAST(new NullProgressMonitor()); return (Expression) astNode; }
Example #28
Source File: EclipseHandlerUtil.java From EasyMPermission with MIT License | 5 votes |
/** * Inserts a method into an existing type. The type must represent a {@code TypeDeclaration}. */ public static EclipseNode injectMethod(EclipseNode type, AbstractMethodDeclaration method) { method.annotations = addSuppressWarningsAll(type, method, method.annotations); method.annotations = addGenerated(type, method, method.annotations); TypeDeclaration parent = (TypeDeclaration) type.get(); if (parent.methods == null) { parent.methods = new AbstractMethodDeclaration[1]; parent.methods[0] = method; } else { if (method instanceof ConstructorDeclaration) { for (int i = 0 ; i < parent.methods.length ; i++) { if (parent.methods[i] instanceof ConstructorDeclaration && (parent.methods[i].bits & ASTNode.IsDefaultConstructor) != 0) { EclipseNode tossMe = type.getNodeFor(parent.methods[i]); AbstractMethodDeclaration[] withoutGeneratedConstructor = new AbstractMethodDeclaration[parent.methods.length - 1]; System.arraycopy(parent.methods, 0, withoutGeneratedConstructor, 0, i); System.arraycopy(parent.methods, i + 1, withoutGeneratedConstructor, i, parent.methods.length - i - 1); parent.methods = withoutGeneratedConstructor; if (tossMe != null) tossMe.up().removeChild(tossMe); break; } } } //We insert the method in the last position of the methods registered to the type //When changing this behavior, this may trigger issue #155 and #377 AbstractMethodDeclaration[] newArray = new AbstractMethodDeclaration[parent.methods.length + 1]; System.arraycopy(parent.methods, 0, newArray, 0, parent.methods.length); newArray[parent.methods.length] = method; parent.methods = newArray; } return type.add(method, Kind.METHOD); }
Example #29
Source File: EclipseHandlerUtil.java From EasyMPermission with MIT License | 5 votes |
public static Annotation[] addSuppressWarningsAll(EclipseNode node, ASTNode source, Annotation[] originalAnnotationArray) { Annotation[] anns = addAnnotation(source, originalAnnotationArray, TypeConstants.JAVA_LANG_SUPPRESSWARNINGS, new StringLiteral(ALL, 0, 0, 0)); if (Boolean.TRUE.equals(node.getAst().readConfiguration(ConfigurationKeys.ADD_FINDBUGS_SUPPRESSWARNINGS_ANNOTATIONS))) { MemberValuePair mvp = new MemberValuePair(JUSTIFICATION, 0, 0, new StringLiteral(GENERATED_CODE, 0, 0, 0)); anns = addAnnotation(source, anns, EDU_UMD_CS_FINDBUGS_ANNOTATIONS_SUPPRESSFBWARNINGS, mvp); } return anns; }
Example #30
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; }