org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration Java Examples
The following examples show how to use
org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.
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: ProcessTaskManager.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public ProcessTaskManager(Compiler compiler) { this.compiler = compiler; this.unitIndex = 0; this.currentIndex = 0; this.availableIndex = 0; this.size = PROCESSED_QUEUE_SIZE; this.sleepCount = 0; // 0 is no one, +1 is the processing thread & -1 is the writing/main thread this.units = new CompilationUnitDeclaration[this.size]; synchronized (this) { this.processingThread = new Thread(this, "Compiler Processing Task"); //$NON-NLS-1$ this.processingThread.setDaemon(true); this.processingThread.start(); } }
Example #2
Source File: DebugSnapshotStore.java From EasyMPermission with MIT License | 6 votes |
public void log(CompilationUnitDeclaration owner, String message, Object... params) { if (GLOBAL_DSS_DISABLE_SWITCH) return; DebugSnapshot snapshot = new DebugSnapshot(owner, -1, message, params); List<DebugSnapshot> list; synchronized (map) { list = map.get(owner); if (list == null) { list = new ArrayList<DebugSnapshot>(); map.put(owner, list); list.add(snapshot); } else if (!list.isEmpty()) { list.add(snapshot); } else { // An empty list is an indicator that we no longer care about that particular CUD. } } }
Example #3
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 6 votes |
@Override public void process(CompilationUnitDeclaration unit, int unitNumber) { mCurrentUnit = lookupEnvironment.unitBeingCompleted = unit; parser.getMethodBodies(unit); if (unit.scope != null) { unit.scope.faultInTypes(); unit.scope.verifyMethods(lookupEnvironment.methodVerifier()); } unit.resolve(); unit.analyseCode(); // This is where we differ from super: DON'T call generateCode(). // Sadly we can't just set ignoreMethodBodies=true to have the same effect, // since that would also skip the analyseCode call, which we DO, want: // unit.generateCode(); if (options.produceReferenceInfo && unit.scope != null) { unit.scope.storeDependencyInfo(); } unit.finalizeProblems(); unit.compilationResult.totalUnitsKnown = totalUnits; lookupEnvironment.unitBeingCompleted = null; }
Example #4
Source File: RoundEnvImpl.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public RoundEnvImpl(CompilationUnitDeclaration[] units, ReferenceBinding[] binaryTypeBindings, boolean isLastRound, BaseProcessingEnvImpl env) { _processingEnv = env; _isLastRound = isLastRound; _units = units; _factory = _processingEnv.getFactory(); // Discover the annotations that will be passed to Processor.process() AnnotationDiscoveryVisitor visitor = new AnnotationDiscoveryVisitor(_processingEnv); if (_units != null) { for (CompilationUnitDeclaration unit : _units) { unit.scope.suppressImportErrors = true; unit.traverse(visitor, unit.scope); unit.scope.suppressImportErrors = false; } } _annoToUnit = visitor._annoToElement; if (binaryTypeBindings != null) collectAnnotations(binaryTypeBindings); _binaryTypes = binaryTypeBindings; }
Example #5
Source File: PatchExtensionMethod.java From EasyMPermission with MIT License | 6 votes |
private static List<MethodBinding> getApplicableExtensionMethodsDefinedInProvider(EclipseNode typeNode, ReferenceBinding extensionMethodProviderBinding, TypeBinding receiverType) { List<MethodBinding> extensionMethods = new ArrayList<MethodBinding>(); CompilationUnitScope cuScope = ((CompilationUnitDeclaration) typeNode.top().get()).scope; for (MethodBinding method : extensionMethodProviderBinding.methods()) { if (!method.isStatic()) continue; if (!method.isPublic()) continue; if (method.parameters == null || method.parameters.length == 0) continue; TypeBinding firstArgType = method.parameters[0]; if (receiverType.isProvablyDistinct(firstArgType) && !receiverType.isCompatibleWith(firstArgType.erasure())) continue; TypeBinding[] argumentTypes = Arrays.copyOfRange(method.parameters, 1, method.parameters.length); if ((receiverType instanceof ReferenceBinding) && ((ReferenceBinding) receiverType).getExactMethod(method.selector, argumentTypes, cuScope) != null) continue; extensionMethods.add(method); } return extensionMethods; }
Example #6
Source File: AppCompiler.java From actframework with Apache License 2.0 | 6 votes |
public void compile(Collection<Source> sources) { Timer timer = metric.startTimer("act:classload:compile:_all"); int len = sources.size(); ICompilationUnit[] compilationUnits = new ICompilationUnit[len]; int i = 0; for (Source source: sources) { compilationUnits[i++] = source.compilationUnit(); } IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitOnFirstError(); IProblemFactory problemFactory = new DefaultProblemFactory(Locale.ENGLISH); org.eclipse.jdt.internal.compiler.Compiler jdtCompiler = new Compiler( nameEnv, policy, compilerOptions, requestor, problemFactory) { @Override protected void handleInternalException(Throwable e, CompilationUnitDeclaration ud, CompilationResult result) { } }; jdtCompiler.compile(compilationUnits); timer.stop(); }
Example #7
Source File: CompilationUnitResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void reportBinding(Object key, ASTRequestor astRequestor, WorkingCopyOwner owner, CompilationUnitDeclaration unit) { BindingKeyResolver keyResolver = (BindingKeyResolver) key; Binding compilerBinding = keyResolver.getCompilerBinding(); if (compilerBinding != null) { DefaultBindingResolver resolver = new DefaultBindingResolver(unit.scope, owner, this.bindingTables, false, this.fromJavaProject); AnnotationBinding annotationBinding = keyResolver.getAnnotationBinding(); IBinding binding; if (annotationBinding != null) { binding = resolver.getAnnotationInstance(annotationBinding); } else { binding = resolver.getBinding(compilerBinding); } if (binding != null) astRequestor.acceptBinding(keyResolver.getKey(), binding); } }
Example #8
Source File: InternalExtendedCompletionContext.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public InternalExtendedCompletionContext( InternalCompletionContext completionContext, ITypeRoot typeRoot, CompilationUnitDeclaration compilationUnitDeclaration, LookupEnvironment lookupEnvironment, Scope assistScope, ASTNode assistNode, ASTNode assistNodeParent, WorkingCopyOwner owner, CompletionParser parser) { this.completionContext = completionContext; this.typeRoot = typeRoot; this.compilationUnitDeclaration = compilationUnitDeclaration; this.lookupEnvironment = lookupEnvironment; this.assistScope = assistScope; this.assistNode = assistNode; this.assistNodeParent = assistNodeParent; this.owner = owner; this.parser = parser; }
Example #9
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 #10
Source File: HandleBuilder.java From EasyMPermission with MIT License | 6 votes |
public MethodDeclaration generateBuilderMethod(String builderMethodName, String builderClassName, EclipseNode type, TypeParameter[] typeParams, ASTNode source) { int pS = source.sourceStart, pE = source.sourceEnd; long p = (long) pS << 32 | pE; MethodDeclaration out = new MethodDeclaration( ((CompilationUnitDeclaration) type.top().get()).compilationResult); out.selector = builderMethodName.toCharArray(); out.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic; out.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; out.returnType = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); out.typeParameters = copyTypeParams(typeParams, source); AllocationExpression invoke = new AllocationExpression(); invoke.type = namePlusTypeParamsToTypeReference(builderClassName.toCharArray(), typeParams, p); out.statements = new Statement[] {new ReturnStatement(invoke, pS, pE)}; out.traverse(new SetGeneratedByVisitor(source), ((TypeDeclaration) type.get()).scope); return out; }
Example #11
Source File: EclipseNode.java From EasyMPermission with MIT License | 5 votes |
/** {@inheritDoc} */ @Override protected boolean calculateIsStructurallySignificant(ASTNode parent) { if (node instanceof TypeDeclaration) return true; if (node instanceof AbstractMethodDeclaration) return true; if (node instanceof FieldDeclaration) return true; if (node instanceof LocalDeclaration) return true; if (node instanceof CompilationUnitDeclaration) return true; return false; }
Example #12
Source File: SourceIndexer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Called prior to the unit being resolved. Reduce the parse tree where possible. */ private void reduceParseTree(CompilationUnitDeclaration unit) { // remove statements from methods that have no functional interface types. TypeDeclaration[] types = unit.types; for (int i = 0, l = types == null ? 0 : types.length; i < l; i++) purgeMethodStatements(types[i]); }
Example #13
Source File: AssistParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Parse the block statements inside the given method declaration and try to complete at the * cursor location. */ public void parseBlockStatements(AbstractMethodDeclaration md, CompilationUnitDeclaration unit) { if (md instanceof MethodDeclaration) { parseBlockStatements((MethodDeclaration) md, unit); } else if (md instanceof ConstructorDeclaration) { parseBlockStatements((ConstructorDeclaration) md, unit); } }
Example #14
Source File: CompilationUnitProblemFinder.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
/** * Add additional source types */ public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) { // ensure to jump back to toplevel type for first one (could be a member) while (sourceTypes[0].getEnclosingType() != null) { sourceTypes[0] = sourceTypes[0].getEnclosingType(); } CompilationResult result = new CompilationResult(sourceTypes[0].getFileName(), 1, 1, this.options.maxProblemsPerUnit); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=305259, build the compilation unit in its own sand box. final long savedComplianceLevel = this.options.complianceLevel; final long savedSourceLevel = this.options.sourceLevel; try { IJavaProject project = ((SourceTypeElementInfo) sourceTypes[0]).getHandle().getJavaProject(); this.options.complianceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_COMPLIANCE, true)); this.options.sourceLevel = CompilerOptions.versionToJdkLevel(project.getOption(JavaCore.COMPILER_SOURCE, true)); // need to hold onto this CompilationUnitDeclaration unit = SourceTypeConverter.buildCompilationUnit( sourceTypes,//sourceTypes[0] is always toplevel here SourceTypeConverter.FIELD_AND_METHOD // need field and methods | SourceTypeConverter.MEMBER_TYPE // need member types | SourceTypeConverter.FIELD_INITIALIZATION, // need field initialization this.lookupEnvironment.problemReporter, result); if (unit != null) { this.lookupEnvironment.buildTypeBindings(unit, accessRestriction); this.lookupEnvironment.completeTypeBindings(unit); } } finally { this.options.complianceLevel = savedComplianceLevel; this.options.sourceLevel = savedSourceLevel; } }
Example #15
Source File: CompilationUnitResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public CompilationUnitDeclaration resolve( CompilationUnitDeclaration unit, org.eclipse.jdt.internal.compiler.env.ICompilationUnit sourceUnit, boolean verifyMethods, boolean analyzeCode, boolean generateCode) { return resolve( unit, sourceUnit, null/*no node searcher*/, verifyMethods, analyzeCode, generateCode); }
Example #16
Source File: EcjParser.java From javaide with GNU General Public License v3.0 | 5 votes |
@Override public Node parseJava(@NonNull JavaContext context) { String code = context.getContents(); if (code == null) { return null; } CompilationUnitDeclaration unit = getParsedUnit(context, code); try { EcjTreeConverter converter = new EcjTreeConverter(); converter.visit(code, unit); List<? extends Node> nodes = converter.getAll(); if (nodes != null) { // There could be more than one node when there are errors; pick out the // compilation unit node for (Node node : nodes) { if (node instanceof lombok.ast.CompilationUnit) { return node; } } } return null; } catch (Throwable t) { mClient.log(t, "Failed converting ECJ parse tree to Lombok for file %1$s", context.file.getPath()); return null; } }
Example #17
Source File: DefaultCodeFormatter.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private TextEdit formatCompilationUnit(String source, int indentationLevel, String lineSeparator, IRegion[] regions, boolean includeComments) { CompilationUnitDeclaration compilationUnitDeclaration = this.codeSnippetParsingUtil.parseCompilationUnit(source.toCharArray(), getDefaultCompilerOptions(), true); if (lineSeparator != null) { this.preferences.line_separator = lineSeparator; } else { this.preferences.line_separator = Util.LINE_SEPARATOR; } this.preferences.initial_indentation_level = indentationLevel; this.newCodeFormatter = new CodeFormatterVisitor(this.preferences, this.options, regions, this.codeSnippetParsingUtil, includeComments); return this.newCodeFormatter.format(source, compilationUnitDeclaration); }
Example #18
Source File: Extractor.java From javaide with GNU General Public License v3.0 | 5 votes |
private void analyze(CompilationUnitDeclaration unit) { if (processedFiles.contains(unit)) { // The code to process all roots seems to hit some of the same classes // repeatedly... so filter these out manually return; } processedFiles.add(unit); AnnotationVisitor visitor = new AnnotationVisitor(); unit.traverse(visitor, unit.scope); }
Example #19
Source File: EclipseASTVisitor.java From EasyMPermission with MIT License | 5 votes |
public void visitCompilationUnit(EclipseNode node, CompilationUnitDeclaration unit) { out.println("---------------------------------------------------------"); out.println(node.isCompleteParse() ? "COMPLETE" : "incomplete"); print("<CUD %s%s%s>", node.getFileName(), isGenerated(unit) ? " (GENERATED)" : "", position(node)); indent++; }
Example #20
Source File: CommentRecorderParser.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
protected CompilationUnitDeclaration endParse(int act) { CompilationUnitDeclaration unit = super.endParse(act); if (unit.comments == null) { pushOnCommentsStack(0, this.scanner.commentPtr); unit.comments = getCommentsPositions(); } return unit; }
Example #21
Source File: CompilationUnitResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public static CompilationUnit convert( CompilationUnitDeclaration compilationUnitDeclaration, char[] source, int apiLevel, Map options, boolean needToResolveBindings, WorkingCopyOwner owner, DefaultBindingResolver.BindingTables bindingTables, int flags, IProgressMonitor monitor, boolean fromJavaProject) { BindingResolver resolver = null; AST ast = AST.newAST(apiLevel); ast.setDefaultNodeFlag(ASTNode.ORIGINAL); CompilationUnit compilationUnit = null; ASTConverter converter = new ASTConverter(options, needToResolveBindings, monitor); if (needToResolveBindings) { resolver = new DefaultBindingResolver(compilationUnitDeclaration.scope, owner, bindingTables, (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0, fromJavaProject); ast.setFlag(flags | AST.RESOLVED_BINDINGS); } else { resolver = new BindingResolver(); ast.setFlag(flags); } ast.setBindingResolver(resolver); converter.setAST(ast); compilationUnit = converter.convert(compilationUnitDeclaration, source); compilationUnit.setLineEndTable(compilationUnitDeclaration.compilationResult.getLineSeparatorPositions()); ast.setDefaultNodeFlag(0); ast.setOriginalModificationCount(ast.modificationCount()); return compilationUnit; }
Example #22
Source File: CompilationUtils.java From steady with Apache License 2.0 | 5 votes |
/** * <p>findMethod.</p> * * @param cu a {@link org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration} object. * @param methodName a {@link java.lang.String} object. * @return a {@link org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration} object. */ public static AbstractMethodDeclaration findMethod(CompilationUnitDeclaration cu, String methodName) { for (TypeDeclaration type : cu.types) { for (AbstractMethodDeclaration method : type.methods) { if (String.valueOf(method.selector).equals(methodName)) { return method; } } } return null; }
Example #23
Source File: LookupEnvironment.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void completeTypeBindings(CompilationUnitDeclaration parsedUnit, boolean buildFieldsAndMethods) { if (parsedUnit.scope == null) return; // parsing errors were too severe (this.unitBeingCompleted = parsedUnit).scope.checkAndSetImports(); parsedUnit.scope.connectTypeHierarchy(); parsedUnit.scope.checkParameterizedTypes(); if (buildFieldsAndMethods) parsedUnit.scope.buildFieldsAndMethods(); this.unitBeingCompleted = null; }
Example #24
Source File: CodeSnippetParsingUtil.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public Expression parseExpression(char[] source, int offset, int length, Map settings, boolean recordParsingInformation) { if (source == null) { throw new IllegalArgumentException(); } CompilerOptions compilerOptions = new CompilerOptions(settings); // in this case we don't want to ignore method bodies since we are parsing only an expression final ProblemReporter problemReporter = new ProblemReporter( DefaultErrorHandlingPolicies.proceedWithAllProblems(), compilerOptions, new DefaultProblemFactory(Locale.getDefault())); CommentRecorderParser parser = new CommentRecorderParser(problemReporter, false); ICompilationUnit sourceUnit = new CompilationUnit( source, "", //$NON-NLS-1$ compilerOptions.defaultEncoding); CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, compilerOptions.maxProblemsPerUnit); CompilationUnitDeclaration unit = new CompilationUnitDeclaration(problemReporter, compilationResult, source.length); Expression result = parser.parseExpression(source, offset, length, unit, true /* record line separators */); if (recordParsingInformation) { this.recordedParsingInformation = getRecordedParsingInformation(compilationResult, unit.comments); } return result; }
Example #25
Source File: LookupEnvironment.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void buildTypeBindings(CompilationUnitDeclaration unit, AccessRestriction accessRestriction) { CompilationUnitScope scope = new CompilationUnitScope(unit, this); scope.buildTypeBindings(accessRestriction); int unitsLength = this.units.length; if (++this.lastUnitIndex >= unitsLength) System.arraycopy(this.units, 0, this.units = new CompilationUnitDeclaration[2 * unitsLength], 0, unitsLength); this.units[this.lastUnitIndex] = unit; }
Example #26
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 #27
Source File: HandleUtilityClass.java From EasyMPermission with MIT License | 5 votes |
private void createPrivateDefaultConstructor(EclipseNode typeNode, EclipseNode sourceNode) { ASTNode source = sourceNode.get(); TypeDeclaration typeDeclaration = ((TypeDeclaration) typeNode.get()); long p = (long) source.sourceStart << 32 | source.sourceEnd; ConstructorDeclaration constructor = new ConstructorDeclaration(((CompilationUnitDeclaration) typeNode.top().get()).compilationResult); constructor.modifiers = ClassFileConstants.AccPrivate; constructor.selector = typeDeclaration.name; constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper); constructor.constructorCall.sourceStart = source.sourceStart; constructor.constructorCall.sourceEnd = source.sourceEnd; constructor.thrownExceptions = null; constructor.typeParameters = null; constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart; constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd; constructor.arguments = null; AllocationExpression exception = new AllocationExpression(); setGeneratedBy(exception, source); long[] ps = new long[JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION.length]; Arrays.fill(ps, p); exception.type = new QualifiedTypeReference(JAVA_LANG_UNSUPPORTED_OPERATION_EXCEPTION, ps); setGeneratedBy(exception.type, source); exception.arguments = new Expression[] { new StringLiteral(UNSUPPORTED_MESSAGE, source.sourceStart, source.sourceEnd, 0) }; setGeneratedBy(exception.arguments[0], source); ThrowStatement throwStatement = new ThrowStatement(exception, source.sourceStart, source.sourceEnd); setGeneratedBy(throwStatement, source); constructor.statements = new Statement[] {throwStatement}; injectMethod(typeNode, constructor); }
Example #28
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 #29
Source File: EclipseGuavaSingularizer.java From EasyMPermission with MIT License | 5 votes |
void generatePluralMethod(TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) { boolean mapMode = isMap(); 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)); 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 = (mapMode ? "putAll" : "addAll").toCharArray(); statements.add(thisDotFieldDotAddAll); if (returnStatement != null) statements.add(returnStatement); md.statements = statements.toArray(new Statement[statements.size()]); TypeReference paramType; if (mapMode) { paramType = new QualifiedTypeReference(JAVA_UTIL_MAP, NULL_POSS); paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs()); } else { paramType = new QualifiedTypeReference(TypeConstants.JAVA_LANG_ITERABLE, 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(mapMode ? "putAll" : "addAll", new String(data.getPluralName())).toCharArray(); data.setGeneratedByRecursive(md); injectMethod(builderType, md); }
Example #30
Source File: CompilationUnitResolver.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
public void removeUnresolvedBindings(CompilationUnitDeclaration compilationUnitDeclaration) { final org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] types = compilationUnitDeclaration.types; if (types != null) { for (int i = 0, max = types.length; i < max; i++) { removeUnresolvedBindings(types[i]); } } }