org.eclipse.jdt.internal.compiler.env.ICompilationUnit Java Examples

The following examples show how to use org.eclipse.jdt.internal.compiler.env.ICompilationUnit. 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: CompilationUtils.java    From steady with Apache License 2.0 6 votes vote down vote up
/**
 * <p>compileSource.</p>
 *
 * @param source a {@link java.lang.String} object.
 * @return a {@link ch.uzh.ifi.seal.changedistiller.ast.java.JavaCompilation} object.
 */
public static JavaCompilation compileSource(String source) {

	//Compiler Options
    CompilerOptions options = getDefaultCompilerOptions();

    //CommentRecorder
    Parser parser = createCommentRecorderParser(options);

    //Create Compilation Unit from Source
    ICompilationUnit cu = createCompilationunit(source, "");

    //Compilation Result
    CompilationResult compilationResult = createDefaultCompilationResult(cu, options);

    return new JavaCompilation(parser.parse(cu, compilationResult), parser.scanner);
}
 
Example #2
Source File: CompilerJdt.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public int compile(Classpath namingEnvironment, Compiler compiler) throws IOException {
  processSources();

  if (aptstate != null) {
    staleOutputs.addAll(aptstate.writtenOutputs);
    aptstate = null;
  }

  if (!compileQueue.isEmpty()) {
    ICompilationUnit[] compilationUnits = compileQueue.values().toArray(new ICompilationUnit[compileQueue.size()]);
    compiler.compile(compilationUnits);
  }

  persistAnnotationProcessingState(compiler, null);

  deleteStaleOutputs();

  return compileQueue.size();
}
 
Example #3
Source File: CompilerJdt.java    From takari-lifecycle with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * This loop handles the incremental compilation of classes in the compileQueue. Regular apt rounds may occur in this loop, but the apt final round will not.
 * 
 * This loop will be called once after the apt final round is processed to compile all effected types. All prior error/warn/info messages, referenced types, generated outputs and other per-input
 * information tracked by in build context are ignored when a type is recompiled.
 */
private void incrementalCompilationLoop(Classpath namingEnvironment, Compiler compiler, AnnotationProcessorManager aptmanager) throws IOException {
  while (!compileQueue.isEmpty() || !staleOutputs.isEmpty()) {
    processedQueue.clear();
    processedQueue.addAll(compileQueue.keySet());

    // All prior error/warn/info messages, referenced types, generated outputs and other per-input information tracked by in build context are wiped away within.
    processSources();

    // invoke the compiler
    ICompilationUnit[] compilationUnits = compileQueue.values().toArray(new ICompilationUnit[compileQueue.size()]);
    compileQueue.clear();
    compiler.compile(compilationUnits);
    namingEnvironment.reset();

    if (aptmanager != null) {
      aptmanager.incrementalIterationReset();
    }

    deleteStaleOutputs(); // delete stale outputs and enqueue affected sources

    enqueueAffectedSources();
  }
}
 
Example #4
Source File: JavaSearchNameEnvironment.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public JavaSearchNameEnvironment(IJavaProject javaProject, org.eclipse.jdt.core.ICompilationUnit[] copies) {
	computeClasspathLocations(javaProject.getProject().getWorkspace().getRoot(), (JavaProject) javaProject);
	try {
		int length = copies == null ? 0 : copies.length;
		this.workingCopies = new HashMap(length);
		if (copies != null) {
			for (int i = 0; i < length; i++) {
				org.eclipse.jdt.core.ICompilationUnit workingCopy = copies[i];
				IPackageDeclaration[] pkgs = workingCopy.getPackageDeclarations();
				String pkg = pkgs.length > 0 ? pkgs[0].getElementName() : ""; //$NON-NLS-1$
				String cuName = workingCopy.getElementName();
				String mainTypeName = Util.getNameWithoutJavaLikeExtension(cuName);
				String qualifiedMainTypeName = pkg.length() == 0 ? mainTypeName : pkg.replace('.', '/') + '/' + mainTypeName;
				this.workingCopies.put(qualifiedMainTypeName, workingCopy);
			}
		}
	} catch (JavaModelException e) {
		// working copy doesn't exist: cannot happen
	}
}
 
Example #5
Source File: ExtractAnnotations.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private boolean addSources(List<ICompilationUnit> sourceUnits, File file) throws IOException {
    if (file.isDirectory()) {
        File[] files = file.listFiles();
        if (files != null) {
            for (File sub : files) {
                addSources(sourceUnits, sub);
            }

        }

    } else if (file.getPath().endsWith(DOT_JAVA) && file.isFile()) {
        char[] contents = Util.getFileCharContent(file, encoding);
        ICompilationUnit unit = new CompilationUnit(contents, file.getPath(), encoding);
        return sourceUnits.add(unit);
    }
    return false;
}
 
Example #6
Source File: AbstractDOMBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see IDOMFactory#createCompilationUnit(String, String)
 */
public IDOMCompilationUnit createCompilationUnit(ICompilationUnit compilationUnit) {
	if (this.fAbort) {
		return null;
	}
	this.fNode.normalize(this);
	return (IDOMCompilationUnit)this.fNode;
}
 
Example #7
Source File: SelectionParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public CompilationUnitDeclaration parse(ICompilationUnit sourceUnit, CompilationResult compilationResult, int start, int end) {

	if (end == -1) return super.parse(sourceUnit, compilationResult, start, end);

	this.selectionStart = start;
	this.selectionEnd = end;
	SelectionScanner selectionScanner = (SelectionScanner)this.scanner;
	selectionScanner.selectionIdentifier = null;
	selectionScanner.selectionStart = start;
	selectionScanner.selectionEnd = end;
	return super.parse(sourceUnit, compilationResult, -1, -1/*parse without reseting the scanner*/);
}
 
Example #8
Source File: SourceIndexer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	ISourceType sourceType = sourceTypes[0];
	while (sourceType.getEnclosingType() != null)
		sourceType = sourceType.getEnclosingType();
	SourceTypeElementInfo elementInfo = (SourceTypeElementInfo) sourceType;
	IType type = elementInfo.getHandle();
	ICompilationUnit sourceUnit = (ICompilationUnit) type.getCompilationUnit();
	accept(sourceUnit, accessRestriction);		
}
 
Example #9
Source File: CompilationUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
   * Returns the generated {@link JavaCompilation} from the file identified by the given filename.
   *
   * @param _filename
   *            of the file to compile
   * @return the compilation of the file
   */
  public static JavaCompilation compileFile(String _filename) {
  	JavaCompilation jc = null;
try {
	final String src = FileUtil.readFile(_filename);
	final CompilerOptions options = getDefaultCompilerOptions();
       final Parser parser = createCommentRecorderParser(options);
       final ICompilationUnit cu = createCompilationunit(src, _filename);
       final CompilationResult compilationResult = createDefaultCompilationResult(cu, options);
       jc = new JavaCompilation(parser.parse(cu, compilationResult), parser.scanner);
} catch (IOException e) {
	log.error(e);
}
return jc;
  }
 
Example #10
Source File: HierarchyBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public HierarchyBuilder(TypeHierarchy hierarchy) throws JavaModelException {

		this.hierarchy = hierarchy;
		JavaProject project = (JavaProject) hierarchy.javaProject();

		IType focusType = hierarchy.getType();
		org.eclipse.jdt.core.ICompilationUnit unitToLookInside = focusType == null ? null : focusType.getCompilationUnit();
		org.eclipse.jdt.core.ICompilationUnit[] workingCopies = this.hierarchy.workingCopies;
		org.eclipse.jdt.core.ICompilationUnit[] unitsToLookInside;
		if (unitToLookInside != null) {
			int wcLength = workingCopies == null ? 0 : workingCopies.length;
			if (wcLength == 0) {
				unitsToLookInside = new org.eclipse.jdt.core.ICompilationUnit[] {unitToLookInside};
			} else {
				unitsToLookInside = new org.eclipse.jdt.core.ICompilationUnit[wcLength+1];
				unitsToLookInside[0] = unitToLookInside;
				System.arraycopy(workingCopies, 0, unitsToLookInside, 1, wcLength);
			}
		} else {
			unitsToLookInside = workingCopies;
		}
		if (project != null) {
			SearchableEnvironment searchableEnvironment = project.newSearchableNameEnvironment(unitsToLookInside);
			this.nameLookup = searchableEnvironment.nameLookup;
			this.hierarchyResolver =
				new HierarchyResolver(
					searchableEnvironment,
					project.getOptions(true),
					this,
					new DefaultProblemFactory());
		}
		this.infoToHandle = new HashMap(5);
		this.focusQualifiedName = focusType == null ? null : focusType.getFullyQualifiedName();
	}
 
Example #11
Source File: HierarchyBuilder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Create an ICompilationUnit info from the given compilation unit on disk.
 */
protected ICompilationUnit createCompilationUnitFromPath(Openable handle, IFile file) {
	final char[] elementName = handle.getElementName().toCharArray();
	return new ResourceCompilationUnit(file, file.getLocationURI()) {
		public char[] getFileName() {
			return elementName;
		}
	};
}
 
Example #12
Source File: HierarchyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add additional source types
 * @param sourceTypes
 * @param packageBinding
 */
public void accept(ISourceType[] sourceTypes, PackageBinding packageBinding, AccessRestriction accessRestriction) {
	IProgressMonitor progressMonitor = this.builder.hierarchy.progressMonitor;
	if (progressMonitor != null && progressMonitor.isCanceled())
		throw new OperationCanceledException();

	// find most enclosing type first (needed when explicit askForType(...) is done
	// with a member type (e.g. p.A$B))
	ISourceType sourceType = sourceTypes[0];
	while (sourceType.getEnclosingType() != null)
		sourceType = sourceType.getEnclosingType();

	// build corresponding compilation unit
	CompilationResult result = new CompilationResult(sourceType.getFileName(), 1, 1, this.options.maxProblemsPerUnit);
	CompilationUnitDeclaration unit =
		SourceTypeConverter.buildCompilationUnit(
			new ISourceType[] {sourceType}, // ignore secondary types, to improve laziness
			SourceTypeConverter.MEMBER_TYPE | (this.lookupEnvironment.globalOptions.sourceLevel >= ClassFileConstants.JDK1_8 ? SourceTypeConverter.METHOD : 0), // need member types
			// no need for field initialization
			this.lookupEnvironment.problemReporter,
			result);

	// build bindings
	if (unit != null) {
		try {
			this.lookupEnvironment.buildTypeBindings(unit, accessRestriction);

			org.eclipse.jdt.core.ICompilationUnit cu = ((SourceTypeElementInfo)sourceType).getHandle().getCompilationUnit();
			rememberAllTypes(unit, cu, false);

			this.lookupEnvironment.completeTypeBindings(unit, true/*build constructor only*/);
		} catch (AbortCompilation e) {
			// missing 'java.lang' package: ignore
		}
	}
}
 
Example #13
Source File: SearchableEnvironment.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a SearchableEnvironment on the given project
 */
public SearchableEnvironment(JavaProject project, org.eclipse.jdt.core.ICompilationUnit[] workingCopies) throws JavaModelException {
	this.project = project;
	this.checkAccessRestrictions =
		!JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
		|| !JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true));
	this.workingCopies = workingCopies;
	this.nameLookup = project.newNameLookup(workingCopies);
}
 
Example #14
Source File: SearchableEnvironmentRequestor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructs a SearchableEnvironmentRequestor that wraps the
 * given SearchRequestor.  The requestor will not accept types in
 * the <code>unitToSkip</code>.
 */
public SearchableEnvironmentRequestor(ISearchRequestor requestor, ICompilationUnit unitToSkip, IJavaProject project, NameLookup nameLookup) {
	this.requestor = requestor;
	this.unitToSkip= unitToSkip;
	this.project= project;
	this.nameLookup = nameLookup;
	this.checkAccessRestrictions =
		!JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
		|| !JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true));
}
 
Example #15
Source File: HierarchyResolver.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Add an additional compilation unit.
 * @param sourceUnit
 */
public void accept(ICompilationUnit sourceUnit, AccessRestriction accessRestriction) {
	//System.out.println("Cannot accept compilation units inside the HierarchyResolver.");
	this.lookupEnvironment.problemReporter.abortDueToInternalError(
		new StringBuffer(Messages.accept_cannot)
			.append(sourceUnit.getFileName())
			.toString());
}
 
Example #16
Source File: CodeSnippetParsingUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ASTNode[] parseClassBodyDeclarations(
		char[] source,
		int offset,
		int length,
		Map settings,
		boolean recordParsingInformation,
		boolean enabledStatementRecovery) {
	if (source == null) {
		throw new IllegalArgumentException();
	}
	CompilerOptions compilerOptions = new CompilerOptions(settings);
	compilerOptions.ignoreMethodBodies = this.ignoreMethodBodies;
	final ProblemReporter problemReporter = new ProblemReporter(
				DefaultErrorHandlingPolicies.proceedWithAllProblems(),
				compilerOptions,
				new DefaultProblemFactory(Locale.getDefault()));

	CommentRecorderParser parser = new CommentRecorderParser(problemReporter, false);
	parser.setMethodsFullRecovery(false);
	parser.setStatementsRecovery(enabledStatementRecovery);

	ICompilationUnit sourceUnit =
		new CompilationUnit(
			source,
			"", //$NON-NLS-1$
			compilerOptions.defaultEncoding);

	CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, compilerOptions.maxProblemsPerUnit);
	final CompilationUnitDeclaration compilationUnitDeclaration = new CompilationUnitDeclaration(problemReporter, compilationResult, source.length);
	ASTNode[] result = parser.parseClassBodyDeclarations(source, offset, length, compilationUnitDeclaration);

	if (recordParsingInformation) {
		this.recordedParsingInformation = getRecordedParsingInformation(compilationResult, compilationUnitDeclaration.comments);
	}
	return result;
}
 
Example #17
Source File: CodeSnippetParsingUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
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 #18
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public void startLoggingSource(CompilationResult compilationResult) {
	if ((this.tagBits & Logger.XML) != 0) {
		ICompilationUnit compilationUnit = compilationResult.compilationUnit;
		if (compilationUnit != null) {
  				char[] fileName = compilationUnit.getFileName();
  				File f = new File(new String(fileName));
  				if (fileName != null) {
  					this.parameters.put(Logger.PATH, f.getAbsolutePath());
  				}
  				char[][] packageName = compilationResult.packageName;
  				if (packageName != null) {
  					this.parameters.put(
  							Logger.PACKAGE,
  							new String(CharOperation.concatWith(packageName, File.separatorChar)));
  				}
  				CompilationUnit unit = (CompilationUnit) compilationUnit;
  				String destinationPath = unit.destinationPath;
			if (destinationPath == null) {
				destinationPath = this.main.destinationPath;
			}
			if (destinationPath != null && destinationPath != NONE) {
				if (File.separatorChar == '/') {
					this.parameters.put(Logger.OUTPUT, destinationPath);
				} else {
					this.parameters.put(Logger.OUTPUT, destinationPath.replace('/', File.separatorChar));
				}
			}
		}
		printTag(Logger.SOURCE, this.parameters, true, false);
	}
}
 
Example #19
Source File: Main.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public String extractDestinationPathFromSourceFile(CompilationResult result) {
	ICompilationUnit compilationUnit = result.compilationUnit;
	if (compilationUnit != null) {
		char[] fileName = compilationUnit.getFileName();
		int lastIndex = CharOperation.lastIndexOf(java.io.File.separatorChar, fileName);
		if (lastIndex != -1) {
			final String outputPathName = new String(fileName, 0, lastIndex);
			final File output = new File(outputPathName);
			if (output.exists() && output.isDirectory()) {
				return outputPathName;
			}
		}
	}
	return System.getProperty("user.dir"); //$NON-NLS-1$
}
 
Example #20
Source File: CompilationResult.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public CompilationResult(ICompilationUnit compilationUnit, int unitIndex, int totalUnitsKnown, int maxProblemPerUnit){
	this.fileName = compilationUnit.getFileName();
	this.compilationUnit = compilationUnit;
	this.unitIndex = unitIndex;
	this.totalUnitsKnown = totalUnitsKnown;
	this.maxProblemPerUnit = maxProblemPerUnit;
}
 
Example #21
Source File: CompilerJdt.java    From takari-lifecycle with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public int compile(Classpath namingEnvironment, Compiler compiler) throws IOException {
  AnnotationProcessorManager aptmanager = (AnnotationProcessorManager) compiler.annotationProcessorManager;

  if (aptmanager != null) {
    // suppress APT lastRound during incremental compile loop
    aptmanager.suppressLastRound(true);
  }

  // incremental compilation loop
  // keep calling the compiler while there are sources in the queue
  incrementalCompilationLoop(namingEnvironment, compiler, aptmanager);

  // run apt last round iff doing annotation processing and ran regular apt rounds
  if (aptmanager != null && aptstate == null) {
    // tell apt manager we are running APT lastRound
    aptmanager.suppressRegularRounds(true);
    aptmanager.suppressLastRound(false);

    // even if a class was processed it would need recompiled once types are generated.
    processedQueue.clear();

    // trick the compiler to run APT without any source or binary types
    compiler.referenceBindings = new ReferenceBinding[0];
    compiler.compile(new ICompilationUnit[0]);
    namingEnvironment.reset();
    aptmanager.incrementalIterationReset();
    deleteStaleOutputs();

    enqueueAffectedSources();
    // all apt rounds are now suppressed.
    aptmanager.suppressLastRound(true);
    // compile class that rely on apt completing
    incrementalCompilationLoop(namingEnvironment, compiler, aptmanager);
  }

  persistAnnotationProcessingState(compiler, aptstate);

  return processedSources.size();
}
 
Example #22
Source File: EclipseJavaCompiler.java    From kogito-runtimes with Apache License 2.0 5 votes vote down vote up
private void dumpUnits( ICompilationUnit[] compilationUnits, ResourceReader reader ) {
    for (ICompilationUnit unit : compilationUnits) {
        String name = ( (CompilationUnit) unit ).fileName;
        String source = new String( reader.getBytes( name ) );
        try {
            IoUtils.write( new java.io.File(name.replace( '/', '.' )), reader.getBytes( name ) );
        } catch (IOException e) {
            throw new RuntimeException( e );
        }
    }
}
 
Example #23
Source File: ExtractAnnotationsDriver.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
private static Pair<Collection<CompilationUnitDeclaration>, INameEnvironment> parseSources(
        @NonNull List<File> sourcePaths,
        @NonNull List<String> classpath,
        @NonNull String encoding,
        long languageLevel)
        throws IOException {
    List<ICompilationUnit> sourceUnits = Lists.newArrayListWithExpectedSize(100);

    for (File source : gatherJavaSources(sourcePaths)) {
        char[] contents = Util.getFileCharContent(source, encoding);
        ICompilationUnit unit = new CompilationUnit(contents, source.getPath(), encoding);
        sourceUnits.add(unit);
    }

    Map<ICompilationUnit, CompilationUnitDeclaration> outputMap = Maps.newHashMapWithExpectedSize(
            sourceUnits.size());

    CompilerOptions options = EcjParser.createCompilerOptions();
    options.docCommentSupport = true; // So I can find @hide

    // Note: We can *not* set options.ignoreMethodBodies=true because it disables
    // type attribution!

    options.sourceLevel = languageLevel;
    options.complianceLevel = options.sourceLevel;
    // We don't generate code, but just in case the parser consults this flag
    // and makes sure that it's not greater than the source level:
    options.targetJDK = options.sourceLevel;
    options.originalComplianceLevel = options.sourceLevel;
    options.originalSourceLevel = options.sourceLevel;
    options.inlineJsrBytecode = true; // >= 1.5

    INameEnvironment environment = EcjParser.parse(options, sourceUnits, classpath,
            outputMap, null);
    Collection<CompilationUnitDeclaration> parsedUnits = outputMap.values();
    return Pair.of(parsedUnits, environment);
}
 
Example #24
Source File: BaseProcessingEnvImpl.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public BaseProcessingEnvImpl() {
	_addedUnits = new ArrayList<ICompilationUnit>();
	_addedClassFiles = new ArrayList<ReferenceBinding>();
	_deletedUnits = new ArrayList<ICompilationUnit>();
	_elementUtils = new ElementsImpl(this);
	_typeUtils = new TypesImpl(this);
	_factory = new Factory(this);
	_errorRaised = false;
}
 
Example #25
Source File: EcjParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void dispose(@NonNull JavaContext context,
        @NonNull Node compilationUnit) {
    if (mSourceUnits != null && mCompiled != null) {
        ICompilationUnit sourceUnit = mSourceUnits.get(context.file);
        if (sourceUnit != null) {
            mSourceUnits.remove(context.file);
            mCompiled.remove(sourceUnit);
        }
    }
}
 
Example #26
Source File: EcjParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
public NonGeneratingCompiler(INameEnvironment environment, IErrorHandlingPolicy policy,
        CompilerOptions options, ICompilerRequestor requestor,
        IProblemFactory problemFactory,
        Map<ICompilationUnit, CompilationUnitDeclaration> units) {
    super(environment, policy, options, requestor, problemFactory, null, null);
    mUnits = units;
}
 
Example #27
Source File: CompletionResultRequestor.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
public CompletionResultRequestor(ISearchRequestor requestor, ICompilationUnit unitToSkip, IJavaProject project, NameLookup nameLookup) {
	this.requestor = requestor;
	this.unitToSkip= unitToSkip;
	this.project= project;
	this.nameLookup = nameLookup;
	this.checkAccessRestrictions =
		!JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, true))
		|| !JavaCore.IGNORE.equals(project.getOption(JavaCore.COMPILER_PB_DISCOURAGED_REFERENCE, true));
}
 
Example #28
Source File: SelectionParser.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public CompilationUnitDeclaration dietParse(ICompilationUnit sourceUnit, CompilationResult compilationResult, int start, int end) {

	this.selectionStart = start;
	this.selectionEnd = end;
	SelectionScanner selectionScanner = (SelectionScanner)this.scanner;
	selectionScanner.selectionIdentifier = null;
	selectionScanner.selectionStart = start;
	selectionScanner.selectionEnd = end;
	return this.dietParse(sourceUnit, compilationResult);
}
 
Example #29
Source File: EcjParser.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected synchronized void addCompilationUnit(ICompilationUnit sourceUnit,
        CompilationUnitDeclaration parsedUnit) {
    super.addCompilationUnit(sourceUnit, parsedUnit);
    mUnits.put(sourceUnit, parsedUnit);
}
 
Example #30
Source File: CompilationUtils.java    From steady with Apache License 2.0 4 votes vote down vote up
private static CompilationResult createDefaultCompilationResult(ICompilationUnit cu, CompilerOptions options) {
    CompilationResult compilationResult = new CompilationResult(cu, 0, 0, options.maxProblemsPerUnit);
    return compilationResult;
}