List of usage examples for org.eclipse.jdt.core JavaCore VERSION_1_7
String VERSION_1_7
To view the source code for org.eclipse.jdt.core JavaCore VERSION_1_7.
Click Source Link
From source file:boa.datagen.scm.AbstractCommit.java
License:Apache License
private Builder processChangeFile(String path, boolean parse, Writer astWriter, String revKey, String keyDelim) {/* ww w . ja va 2 s . c o m*/ final ChangedFile.Builder fb = ChangedFile.newBuilder(); fb.setName(path); fb.setKind(FileKind.OTHER); final String lowerPath = path.toLowerCase(); if (lowerPath.endsWith(".txt")) fb.setKind(FileKind.TEXT); else if (lowerPath.endsWith(".xml")) fb.setKind(FileKind.XML); else if (lowerPath.endsWith(".jar") || lowerPath.endsWith(".class")) fb.setKind(FileKind.BINARY); else if (lowerPath.endsWith(".java") && parse) { final String content = getFileContents(path); fb.setKind(FileKind.SOURCE_JAVA_JLS2); if (!parseJavaFile(path, fb, content, JavaCore.VERSION_1_4, AST.JLS2, false, astWriter, revKey + keyDelim + path)) { if (debug) System.err.println("Found JLS2 parse error in: revision " + id + ": file " + path); fb.setKind(FileKind.SOURCE_JAVA_JLS3); if (!parseJavaFile(path, fb, content, JavaCore.VERSION_1_5, AST.JLS3, false, astWriter, revKey + keyDelim + path)) { if (debug) System.err.println("Found JLS3 parse error in: revision " + id + ": file " + path); fb.setKind(FileKind.SOURCE_JAVA_JLS4); if (!parseJavaFile(path, fb, content, JavaCore.VERSION_1_7, AST.JLS4, false, astWriter, revKey + keyDelim + path)) { if (debug) System.err.println("Found JLS4 parse error in: revision " + id + ": file " + path); //fb.setContent(content); fb.setKind(FileKind.SOURCE_JAVA_ERROR); try { astWriter.append(new Text(revKey + keyDelim + fb.getName()), new BytesWritable(ASTRoot.newBuilder().build().toByteArray())); } catch (IOException e) { e.printStackTrace(); } } else if (debug) System.err.println("Accepted JLS4: revision " + id + ": file " + path); } else if (debug) System.err.println("Accepted JLS3: revision " + id + ": file " + path); } else if (debug) System.err.println("Accepted JLS2: revision " + id + ": file " + path); } fb.setKey(revKey); return fb; }
From source file:boa.datagen.scm.AbstractCommit.java
License:Apache License
protected ChangedFile.Builder processChangeFile(final String path, final boolean attemptParse) { final ChangedFile.Builder fb = ChangedFile.newBuilder(); fb.setName(path);//from www .ja va 2 s.c o m fb.setKind(FileKind.OTHER); final String lowerPath = path.toLowerCase(); if (lowerPath.endsWith(".txt")) fb.setKind(FileKind.TEXT); else if (lowerPath.endsWith(".xml")) fb.setKind(FileKind.XML); else if (lowerPath.endsWith(".jar") || lowerPath.endsWith(".class")) fb.setKind(FileKind.BINARY); else if (lowerPath.endsWith(".java") && attemptParse) { final String content = getFileContents(path); fb.setKind(FileKind.SOURCE_JAVA_JLS2); if (!parseJavaFile(path, fb, content, JavaCore.VERSION_1_4, AST.JLS2, false, null, null)) { if (debug) System.err.println("Found JLS2 parse error in: revision " + id + ": file " + path); fb.setKind(FileKind.SOURCE_JAVA_JLS3); if (!parseJavaFile(path, fb, content, JavaCore.VERSION_1_5, AST.JLS3, false, null, null)) { if (debug) System.err.println("Found JLS3 parse error in: revision " + id + ": file " + path); fb.setKind(FileKind.SOURCE_JAVA_JLS4); if (!parseJavaFile(path, fb, content, JavaCore.VERSION_1_7, AST.JLS4, false, null, null)) { if (debug) System.err.println("Found JLS4 parse error in: revision " + id + ": file " + path); //fb.setContent(content); fb.setKind(FileKind.SOURCE_JAVA_ERROR); } else if (debug) System.err.println("Accepted JLS4: revision " + id + ": file " + path); } else if (debug) System.err.println("Accepted JLS3: revision " + id + ": file " + path); } else if (debug) System.err.println("Accepted JLS2: revision " + id + ": file " + path); } return fb; }
From source file:br.uff.ic.gems.resources.ast.ASTExtractor.java
public void parser() throws IOException { ASTParser parser = ASTParser.newParser(AST.JLS3); File file = new File(filePath); String stringFile = FileUtils.readFileToString(file); parser.setSource(stringFile.toCharArray()); parser.setKind(ASTParser.K_COMPILATION_UNIT); //Setting options Map options;//from w ww.j av a2s . c o m options = JavaCore.getOptions(); options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7); options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7); parser.setCompilerOptions(options); final CompilationUnit cu = (CompilationUnit) parser.createAST(null); Visitor visitor = new Visitor(cu); cu.accept(visitor); List<Comment> commentList = cu.getCommentList(); for (Comment comment : commentList) { comment.accept(visitor); } languageConstructs = visitor.getLanguageConstructs(); }
From source file:com.android.ide.eclipse.adt.internal.build.builders.ResourceManagerBuilder.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from w w w . jav a 2s . c o m*/ protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { // Get the project. final IProject project = getProject(); IJavaProject javaProject = JavaCore.create(project); // Clear the project of the generic markers removeMarkersFromContainer(project, AdtConstants.MARKER_ADT); // check for existing target marker, in which case we abort. // (this means: no SDK, no target, or unresolvable target.) try { abortOnBadSetup(javaProject, null); } catch (AbortBuildException e) { return null; } // Check the compiler compliance level, displaying the error message // since this is the first builder. Pair<Integer, String> result = ProjectHelper.checkCompilerCompliance(project); String errorMessage = null; switch (result.getFirst().intValue()) { case ProjectHelper.COMPILER_COMPLIANCE_LEVEL: errorMessage = Messages.Requires_Compiler_Compliance_s; break; case ProjectHelper.COMPILER_COMPLIANCE_SOURCE: errorMessage = Messages.Requires_Source_Compatibility_s; break; case ProjectHelper.COMPILER_COMPLIANCE_CODEGEN_TARGET: errorMessage = Messages.Requires_Class_Compatibility_s; break; } if (errorMessage != null) { errorMessage = String.format(errorMessage, result.getSecond() == null ? "(no value)" : result.getSecond()); if (JavaCore.VERSION_1_7.equals(result.getSecond())) { // If the user is trying to target 1.7 but compiling with something older, // the error message can be a bit misleading; instead point them in the // direction of updating the project's build target. Sdk currentSdk = Sdk.getCurrent(); if (currentSdk != null) { IAndroidTarget target = currentSdk.getTarget(project.getProject()); if (target != null && target.getVersion().getApiLevel() < 19) { errorMessage = "Using 1.7 requires compiling with Android 4.4 " + "(KitKat); currently using " + target.getVersion(); } ProjectState projectState = Sdk.getProjectState(project); if (projectState != null) { BuildToolInfo buildToolInfo = projectState.getBuildToolInfo(); if (buildToolInfo == null) { buildToolInfo = currentSdk.getLatestBuildTool(); } if (buildToolInfo != null && buildToolInfo.getRevision().getMajor() < 19) { errorMessage = "Using 1.7 requires using Android Build Tools " + "version 19 or later; currently using " + buildToolInfo.getRevision(); } } } } markProject(AdtConstants.MARKER_ADT, errorMessage, IMarker.SEVERITY_ERROR); AdtPlugin.printErrorToConsole(project, errorMessage); return null; } // Check that the SDK directory has been setup. String osSdkFolder = AdtPlugin.getOsSdkFolder(); if (osSdkFolder == null || osSdkFolder.length() == 0) { AdtPlugin.printErrorToConsole(project, Messages.No_SDK_Setup_Error); markProject(AdtConstants.MARKER_ADT, Messages.No_SDK_Setup_Error, IMarker.SEVERITY_ERROR); return null; } // check the 'gen' source folder is present boolean hasGenSrcFolder = false; // whether the project has a 'gen' source folder setup IClasspathEntry[] classpaths = javaProject.readRawClasspath(); if (classpaths != null) { for (IClasspathEntry e : classpaths) { if (e.getEntryKind() == IClasspathEntry.CPE_SOURCE) { IPath path = e.getPath(); if (path.segmentCount() == 2 && path.segment(1).equals(SdkConstants.FD_GEN_SOURCES)) { hasGenSrcFolder = true; break; } } } } boolean genFolderPresent = false; // whether the gen folder actually exists IResource resource = project.findMember(SdkConstants.FD_GEN_SOURCES); genFolderPresent = resource != null && resource.exists(); if (hasGenSrcFolder == false && genFolderPresent) { // No source folder setup for 'gen' in the project, but there's already a // 'gen' resource (file or folder). String message; if (resource.getType() == IResource.FOLDER) { // folder exists already! This is an error. If the folder had been created // by the NewProjectWizard, it'd be a source folder. message = String.format( "%1$s already exists but is not a source folder. Convert to a source folder or rename it.", resource.getFullPath().toString()); } else { // resource exists but is not a folder. message = String.format( "Resource %1$s is in the way. ADT needs a source folder called 'gen' to work. Rename or delete resource.", resource.getFullPath().toString()); } AdtPlugin.printErrorToConsole(project, message); markProject(AdtConstants.MARKER_ADT, message, IMarker.SEVERITY_ERROR); return null; } else if (hasGenSrcFolder == false || genFolderPresent == false) { // either there is no 'gen' source folder in the project (older SDK), // or the folder does not exist (was deleted, or was a fresh svn checkout maybe.) // In case we are migrating from an older SDK, we go through the current source // folders and delete the generated Java files. List<IPath> sourceFolders = BaseProjectHelper.getSourceClasspaths(javaProject); IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); for (IPath path : sourceFolders) { IResource member = root.findMember(path); if (member != null) { removeDerivedResources(member, monitor); } } // create the new source folder, if needed IFolder genFolder = project.getFolder(SdkConstants.FD_GEN_SOURCES); if (genFolderPresent == false) { AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, project, "Creating 'gen' source folder for generated Java files"); genFolder.create(true /* force */, true /* local */, new SubProgressMonitor(monitor, 10)); } // add it to the source folder list, if needed only (or it will throw) if (hasGenSrcFolder == false) { IClasspathEntry[] entries = javaProject.getRawClasspath(); entries = ProjectHelper.addEntryToClasspath(entries, JavaCore.newSourceEntry(genFolder.getFullPath())); javaProject.setRawClasspath(entries, new SubProgressMonitor(monitor, 10)); } // refresh specifically the gen folder first, as it may break the build // if it doesn't arrive in time then refresh the whole project as usual. genFolder.refreshLocal(IResource.DEPTH_ZERO, new SubProgressMonitor(monitor, 10)); project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 10)); // it seems like doing this fails to properly rebuild the project. the Java builder // running right after this builder will not see the gen folder, and will not be // restarted after this build. Therefore in this particular case, we start another // build asynchronously so that it's rebuilt after this build. launchJob(new Job("rebuild") { @Override protected IStatus run(IProgressMonitor m) { try { project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, m); return Status.OK_STATUS; } catch (CoreException e) { return e.getStatus(); } } }); } // convert older projects which use bin as the eclipse output folder into projects // using bin/classes IFolder androidOutput = BaseProjectHelper.getAndroidOutputFolder(project); IFolder javaOutput = BaseProjectHelper.getJavaOutputFolder(project); if (androidOutput.exists() == false || javaOutput == null || javaOutput.getParent().equals(androidOutput) == false) { // get what we want as the new java output. IFolder newJavaOutput = androidOutput.getFolder(SdkConstants.FD_CLASSES_OUTPUT); if (androidOutput.exists() == false) { androidOutput.create(true /*force*/, true /*local*/, monitor); } if (newJavaOutput.exists() == false) { newJavaOutput.create(true /*force*/, true /*local*/, monitor); } // set the java output to this project. javaProject.setOutputLocation(newJavaOutput.getFullPath(), monitor); // need to do a full build. Can't build while we're already building, so launch a // job to build it right after this build launchJob(new Job("rebuild") { @Override protected IStatus run(IProgressMonitor jobMonitor) { try { project.build(IncrementalProjectBuilder.CLEAN_BUILD, jobMonitor); return Status.OK_STATUS; } catch (CoreException e) { return e.getStatus(); } } }); } // check that we have bin/res/ IFolder binResFolder = androidOutput.getFolder(SdkConstants.FD_RESOURCES); if (binResFolder.exists() == false) { binResFolder.create(true /* force */, true /* local */, new SubProgressMonitor(monitor, 10)); project.refreshLocal(IResource.DEPTH_ONE, new SubProgressMonitor(monitor, 10)); } // Check the preference to be sure we are supposed to refresh // the folders. if (AdtPrefs.getPrefs().getBuildForceResResfresh()) { AdtPlugin.printBuildToConsole(BuildVerbosity.VERBOSE, project, Messages.Refreshing_Res); // refresh the res folder. IFolder resFolder = project.getFolder(AdtConstants.WS_RESOURCES); resFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor); // Also refresh the assets folder to make sure the ApkBuilder // will now it's changed and will force a new resource packaging. IFolder assetsFolder = project.getFolder(AdtConstants.WS_ASSETS); assetsFolder.refreshLocal(IResource.DEPTH_INFINITE, monitor); } return null; }
From source file:com.android.ide.eclipse.adt.internal.project.ProjectHelper.java
License:Open Source License
/** * Checks a Java project compiler level option against a list of supported versions. * @param optionValue the Compiler level option. * @return true if the option value is supported. *//* w w w. j av a 2 s. c om*/ private static boolean checkCompliance(@NonNull IJavaProject project, String optionValue) { for (String s : AdtConstants.COMPILER_COMPLIANCE) { if (s != null && s.equals(optionValue)) { return true; } } if (JavaCore.VERSION_1_7.equals(optionValue)) { // Requires API 19 and buildTools 19 Sdk currentSdk = Sdk.getCurrent(); if (currentSdk != null) { IProject p = project.getProject(); IAndroidTarget target = currentSdk.getTarget(p); if (target == null || target.getVersion().getApiLevel() < 19) { return false; } ProjectState projectState = Sdk.getProjectState(p); if (projectState != null) { BuildToolInfo buildToolInfo = projectState.getBuildToolInfo(); if (buildToolInfo == null) { buildToolInfo = currentSdk.getLatestBuildTool(); } if (buildToolInfo == null || buildToolInfo.getRevision().getMajor() < 19) { return false; } } return true; } } return false; }
From source file:com.android.ide.eclipse.adt.internal.wizards.exportgradle.BuildFileCreator.java
License:Open Source License
/** * Outputs the beginning of an Android task in the build file. *//*from w w w . java 2s.com*/ private void startAndroidTask(ProjectState projectState) { int buildApi = projectState.getTarget().getVersion().getApiLevel(); String toolsVersion = projectState.getTarget().getBuildToolInfo().getRevision().toString(); mBuildFile.append("android {\n"); //$NON-NLS-1$ mBuildFile.append(" compileSdkVersion " + buildApi + "\n"); //$NON-NLS-1$ mBuildFile.append(" buildToolsVersion \"" + toolsVersion + "\"\n"); //$NON-NLS-1$ mBuildFile.append("\n"); //$NON-NLS-1$ try { IJavaProject javaProject = BaseProjectHelper.getJavaProject(projectState.getProject()); // otherwise we check source compatibility String source = javaProject.getOption(JavaCore.COMPILER_SOURCE, true); if (JavaCore.VERSION_1_7.equals(source)) { mBuildFile.append(" compileOptions {\n" + //$NON-NLS-1$ " sourceCompatibility JavaVersion.VERSION_1_7\n" + //$NON-NLS-1$ " targetCompatibility JavaVersion.VERSION_1_7\n" + //$NON-NLS-1$ " }\n" + //$NON-NLS-1$ "\n"); //$NON-NLS-1$ } } catch (CoreException e) { // Ignore compliance level, go with default } }
From source file:com.codenvy.ide.ext.java.BaseTest.java
License:Open Source License
public BaseTest() { options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7); options.put(JavaCore.CORE_ENCODING, "UTF-8"); options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7); options.put(CompilerOptions.OPTION_TargetPlatform, JavaCore.VERSION_1_7); options.put(AssistOptions.OPTION_PerformVisibilityCheck, AssistOptions.ENABLED); options.put(CompilerOptions.OPTION_ReportUnusedLocal, CompilerOptions.WARNING); options.put(CompilerOptions.OPTION_TaskTags, CompilerOptions.WARNING); options.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); options.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.DISABLED); options.put(JavaCore.COMPILER_TASK_TAGS, "TODO,FIXME,XXX"); options.put(JavaCore.COMPILER_PB_UNUSED_PARAMETER_INCLUDE_DOC_COMMENT_REFERENCE, JavaCore.ENABLED); options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); options.put(CompilerOptions.OPTION_Process_Annotations, JavaCore.DISABLED); }
From source file:com.crispico.flower.mp.codesync.code.java.adapter.JavaFileModelAdapter.java
License:Open Source License
/** * Creates a new compilation unit from the file's content. */// www. j a va2s . c o m @Override protected Object createFileInfo(Object file) { ASTParser parser = ASTParser.newParser(AST.JLS4); Map options = new HashMap<>(JavaCore.getOptions()); options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7); parser.setCompilerOptions(options); boolean fileExists = EditorPlugin.getInstance().getFileAccessController().exists(file); char[] initialContent = fileExists ? getFileContent(file) : new char[0]; parser.setSource(initialContent); CompilationUnit astRoot = (CompilationUnit) parser.createAST(null); astRoot.recordModifications(); return astRoot; }
From source file:com.gwtplatform.plugin.wizard.NewPresenterWizardPage.java
License:Apache License
protected IStatus placeChanged() { StatusInfo status = new StatusInfo(); if (isPlace.isEnabled() && isPlace.getSelection()) { // Token/*from w w w .j a v a 2 s . c om*/ if (tokenName.getText().isEmpty()) { status.setError("Enter the token's name (fully.qualified.NameTokens#name)"); return status; } String parent = ""; String token = ""; if (!tokenName.getText().contains("#")) { parent = tokenName.getText(); } else { String[] split = tokenName.getText().split("#"); parent = split[0]; if (split.length > 1) { token = split[1]; } } try { IType type = getJavaProject().findType(parent); if (type == null || !type.exists()) { status.setError(parent + " doesn't exist"); return status; } if (type.isBinary()) { status.setError(parent + " is a Binary class"); return status; } if (token.isEmpty()) { status.setError("You must enter the token name (fully.qualified.NameTokens#name)"); return status; } char start = token.toCharArray()[0]; if (start >= 48 && start <= 57) { status.setError("Token name must not start by a number"); return status; } for (char c : token.toCharArray()) { // [a-z][0-9]! if (!((c >= 97 && c <= 122) || (c >= 48 && c <= 57) || c == 33)) { status.setError("Token name must contain only lower-case letters, numbers and !"); return status; } } IField field = type.getField(token); if (field.exists()) { status.setError("The token " + token + " already exists."); return status; } } catch (JavaModelException e) { status.setError("An unexpected error has happened. Close the wizard and retry."); return status; } // Annotation if (!annotation.getText().isEmpty()) { try { IType type = getJavaProject().findType(annotation.getText()); if (type == null || !type.exists()) { // New type, we will try to create the annotation IStatus nameStatus = JavaConventions.validateJavaTypeName(annotation.getText(), JavaCore.VERSION_1_6, JavaCore.VERSION_1_7); if (nameStatus.getCode() != IStatus.OK && nameStatus.getCode() != IStatus.WARNING) { status.setError(annotation.getText() + " is not a valid type name."); return status; } } else { // Existing type, just reuse it if (!type.isAnnotation()) { status.setError(annotation.getText() + " isn't an Annotation"); return status; } } } catch (JavaModelException e) { status.setError("An unexpected error has happened. Close the wizard and retry."); return status; } } // Gatekeeper if (!gatekeeper.getText().isEmpty()) { try { IType type = getJavaProject().findType(gatekeeper.getText()); if (type == null || !type.exists()) { status.setError(gatekeeper.getText() + " doesn't exist"); return status; } ITypeHierarchy hierarchy = type.newSupertypeHierarchy(new NullProgressMonitor()); IType[] interfaces = hierarchy.getAllInterfaces(); boolean isGateKeeper = false; for (IType inter : interfaces) { if (inter.getFullyQualifiedName('.') .equals("com.gwtplatform.mvp.client.proxy.Gatekeeper")) { isGateKeeper = true; break; } } if (!isGateKeeper) { status.setError(gatekeeper.getText() + " doesn't implement GateKeeper"); return status; } } catch (JavaModelException e) { status.setError("An unexpected error has happened. Close the wizard and retry."); return status; } } } return status; }
From source file:com.siteview.mde.internal.core.builders.BuildErrorReporter.java
License:Open Source License
private String findMatchingEE(String srcCompatibility, String clsCompatibility, boolean ee) { String executionEnv = null;/* w ww . jav a 2 s . co m*/ String complaince = null; if (JavaCore.VERSION_1_1.equals(srcCompatibility) && JavaCore.VERSION_1_1.equals(clsCompatibility)) { executionEnv = JRE_1_1; complaince = JavaCore.VERSION_1_1; } else if (JavaCore.VERSION_1_2.equals(srcCompatibility) && JavaCore.VERSION_1_1.equals(clsCompatibility)) { executionEnv = J2SE_1_2; complaince = JavaCore.VERSION_1_2; } else if (JavaCore.VERSION_1_3.equals(srcCompatibility) && JavaCore.VERSION_1_1.equals(clsCompatibility)) { executionEnv = J2SE_1_3; complaince = JavaCore.VERSION_1_3; } else if (JavaCore.VERSION_1_3.equals(srcCompatibility) && JavaCore.VERSION_1_2.equals(clsCompatibility)) { executionEnv = J2SE_1_4; complaince = JavaCore.VERSION_1_4; } else if (JavaCore.VERSION_1_5.equals(srcCompatibility) && JavaCore.VERSION_1_5.equals(clsCompatibility)) { executionEnv = J2SE_1_5; complaince = JavaCore.VERSION_1_5; } else if (JavaCore.VERSION_1_6.equals(srcCompatibility) && JavaCore.VERSION_1_6.equals(clsCompatibility)) { executionEnv = JavaSE_1_6; complaince = JavaCore.VERSION_1_6; } else if (JavaCore.VERSION_1_7.equals(srcCompatibility) && JavaCore.VERSION_1_7.equals(clsCompatibility)) { executionEnv = JavaSE_1_7; complaince = JavaCore.VERSION_1_7; } if (ee) { return executionEnv; } return complaince; }