Java Code Examples for org.eclipse.jdt.core.dom.AST#JLS8

The following examples show how to use org.eclipse.jdt.core.dom.AST#JLS8 . 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: JavaASTUtil.java    From compiler with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
public static ASTParser buildParser(FileKind fileKind) {
	int astLevel = -1;
	String compliance = null;
	switch (fileKind) {
	case SOURCE_JAVA_JLS2:
		astLevel = AST.JLS2;
		compliance = JavaCore.VERSION_1_4;
		break;
	case SOURCE_JAVA_JLS3:
		astLevel = AST.JLS3;
		compliance = JavaCore.VERSION_1_5;
		break;
	case SOURCE_JAVA_JLS4:
		astLevel = AST.JLS4;
		compliance = JavaCore.VERSION_1_7;
		break;
	case SOURCE_JAVA_JLS8:
		astLevel = AST.JLS8;
		compliance = JavaCore.VERSION_1_8;
		break;
	default:
		break;
	}
	if (compliance != null) {
		ASTParser parser = ASTParser.newParser(astLevel);
		parser.setKind(ASTParser.K_COMPILATION_UNIT);

		final Map<?, ?> options = JavaCore.getOptions();
		JavaCore.setComplianceOptions(compliance, options);
		parser.setCompilerOptions(options);
		return parser;
	}
	return null;
}
 
Example 2
Source File: ImportReferencesCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(MethodDeclaration node) {
	if (!isAffected(node)) {
		return false;
	}
	doVisitNode(node.getJavadoc());

	doVisitChildren(node.modifiers());
	doVisitChildren(node.typeParameters());

	if (!node.isConstructor()) {
		doVisitNode(node.getReturnType2());
	}
	// name not visited
	
	int apiLevel= node.getAST().apiLevel();
	if (apiLevel >= AST.JLS8) {
		doVisitNode(node.getReceiverType());
	}
	// receiverQualifier not visited:
	//   Enclosing class names cannot be shadowed by an import (qualification is always redundant).
	doVisitChildren(node.parameters());
	if (apiLevel >= AST.JLS8) {
		doVisitChildren(node.extraDimensions());
		doVisitChildren(node.thrownExceptionTypes());
	} else {
		Iterator<Name> iter= getThrownExceptions(node).iterator();
		while (iter.hasNext()) {
			typeRefFound(iter.next());
		}
	}
	if (!fSkipMethodBodies) {
		doVisitNode(node.getBody());
	}
	return false;
}
 
Example 3
Source File: CompilationUnitSorter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @deprecated marking deprecated as it is using deprecated code
 */
private static void checkASTLevel(int level) {
    switch (level) {
    case AST.JLS2 :
    case AST.JLS3 :
    case AST.JLS4 :
    case AST.JLS8 :
        break;
    default :
        throw new IllegalArgumentException();
    }
}
 
Example 4
Source File: Java8BaseTest.java    From compiler with Apache License 2.0 4 votes vote down vote up
private static void setJava8() {
	astLevel = AST.JLS8;
	javaVersion = JavaCore.VERSION_1_8;
	visitor = new JavaVisitor("");
}
 
Example 5
Source File: ImportReferencesCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void visitAnnotations(AnnotatableType node) {
	if (node.getAST().apiLevel() >= AST.JLS8) {
		doVisitChildren(node.annotations());
	}
}
 
Example 6
Source File: ReconcileContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns a resolved AST with {@link AST#JLS8 JLS8} level.
 * It is created from the current state of the working copy.
 * Creates one if none exists yet.
 * Returns <code>null</code> if the current state of the working copy
 * doesn't allow the AST to be created (e.g. if the working copy's content
 * cannot be parsed).
 * <p>
 * If the AST level requested during reconciling is not {@link AST#JLS8}
 * or if binding resolutions was not requested, then a different AST is created.
 * Note that this AST does not become the current AST and it is only valid for
 * the requestor.
 * </p>
 *
 * @return the AST created from the current state of the working copy,
 *   or <code>null</code> if none could be created
 * @exception JavaModelException  if the contents of the working copy
 *		cannot be accessed. Reasons include:
 * <ul>
 * <li> The working copy does not exist (ELEMENT_DOES_NOT_EXIST)</li>
 * </ul>
 * @since 3.10
 */
public org.eclipse.jdt.core.dom.CompilationUnit getAST8() throws JavaModelException {
	if (this.operation.astLevel != AST.JLS8 || !this.operation.resolveBindings) {
		// create AST (optionally resolving bindings)
		ASTParser parser = ASTParser.newParser(AST.JLS8);
		parser.setCompilerOptions(this.workingCopy.getJavaProject().getOptions(true));
		if (JavaProject.hasJavaNature(this.workingCopy.getJavaProject().getProject()))
			parser.setResolveBindings(true);
		parser.setStatementsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_STATEMENTS_RECOVERY) != 0);
		parser.setBindingsRecovery((this.operation.reconcileFlags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0);
		parser.setSource(this.workingCopy);
		parser.setIgnoreMethodBodies((this.operation.reconcileFlags & ICompilationUnit.IGNORE_METHOD_BODIES) != 0);
		return (org.eclipse.jdt.core.dom.CompilationUnit) parser.createAST(this.operation.progressMonitor);
	}
	return this.operation.makeConsistent(this.workingCopy);
}
 
Example 7
Source File: JavaFileParser.java    From buck with Apache License 2.0 4 votes vote down vote up
public static JavaFileParser createJavaFileParser(JavacLanguageLevelOptions options) {
  String javaVersion = Objects.requireNonNull(javaVersionMap.get(options.getSourceLevel()));
  return new JavaFileParser(AST.JLS8, javaVersion);
}