List of usage examples for org.eclipse.jdt.core JavaCore getOption
public static String getOption(String optionName)
From source file:JavaSourceViewerConfiguration.java
License:Open Source License
@Override public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { IJavaProject project = getProject(); final int tabWidth = CodeFormatterUtil.getTabWidth(project); final int indentWidth = CodeFormatterUtil.getIndentWidth(project); boolean allowTabs = tabWidth <= indentWidth; String indentMode;//ww w. j a v a2s .c om if (project == null) indentMode = JavaCore.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR); else indentMode = project.getOption(DefaultCodeFormatterConstants.FORMATTER_TAB_CHAR, true); boolean useSpaces = JavaCore.SPACE.equals(indentMode) || DefaultCodeFormatterConstants.MIXED.equals(indentMode); Assert.isLegal(allowTabs || useSpaces); if (!allowTabs) { char[] spaces = new char[indentWidth]; Arrays.fill(spaces, ' '); return new String[] { new String(spaces), "" }; //$NON-NLS-1$ } else if (!useSpaces) return getIndentPrefixesForTab(tabWidth); else return getIndentPrefixesForSpaces(tabWidth); }
From source file:com.ebmwebsourcing.petals.services.jsr181.v11.Jsr181ProvidePage11.java
License:Open Source License
@Override public boolean validate() { // Case: WSDL first String errorMsg = null;/* w ww . j ava 2 s . c om*/ if (this.wsdlFirst) { if (StringUtils.isEmpty(this.wsdlUriAsString)) { errorMsg = "You must specify a WSDL URI."; } else { int errorCode = 0; try { // Check the URI URI uri = UriAndUrlHelper.urlToUri(this.wsdlUriAsString); errorCode = 1; // Validate the WSDL WsdlUtils.INSTANCE.parse(this.wsdlUriAsString); errorCode = 2; // Display its content InputStream stream = uri.toURL().openStream(); ByteArrayOutputStream os = new ByteArrayOutputStream(); IoUtils.copyStream(stream, os); this.styledText.setText(os.toString()); } catch (Exception e) { if (errorCode == 0) errorMsg = "The WSDL location is not a valid URI."; else if (errorCode == 1) errorMsg = "The WSDL cannot be parsed and appears to be invalid."; else { errorMsg = "An unexpected error occurred during the validation in the JSR-181 wizard. Check the logs for more details."; PetalsJsr181Plugin.log(e, IStatus.ERROR); } } } } // Case: new Java class else if (StringUtils.isEmpty(this.classToGenerate)) { errorMsg = "You must specify the name of the class to generate."; } else { IStatus status = JavaConventions.validateJavaTypeName(this.classToGenerate, JavaCore.getOption(JavaCore.COMPILER_SOURCE), JavaCore.getOption(JavaCore.COMPILER_COMPLIANCE)); if (status.getSeverity() != IStatus.ERROR) { if (this.classToGenerate.indexOf('.') < 0) { errorMsg = "The use of the default package is now allowed."; } else if (!status.isOK()) { errorMsg = status.getMessage() + "."; } } else { errorMsg = status.getMessage() + "."; } } updateStatus(errorMsg); return errorMsg == null; }
From source file:com.facebook.nuclide.shim.EclipseJavaProjectShim.java
License:Open Source License
@Override public String getOption(String optionName, boolean inheritJavaCoreOptions) { if (optionName.equals(JavaCore.COMPILER_SOURCE) || optionName.equals(JavaCore.COMPILER_COMPLIANCE)) { return "1.8"; }/*from ww w . ja v a2s . co m*/ return JavaCore.getOption(optionName); }
From source file:com.google.gdt.eclipse.core.JavaUtilities.java
License:Open Source License
public static IStatus validateMethodName(String methodName) { String complianceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance"); String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.source"); IStatus nameStatus = JavaConventions.validateMethodName(methodName, sourceLevel, complianceLevel); if (!nameStatus.isOK()) { return nameStatus; }//from w ww. j av a2 s . c om // The JavaConventions class doesn't seem to be flagging method names with // an uppercase first character, so we need to check it ourselves. if (!Character.isLowerCase(methodName.charAt(0))) { return StatusUtilities.newWarningStatus("Method name should start with a lowercase letter.", CorePlugin.PLUGIN_ID); } return StatusUtilities.OK_STATUS; }
From source file:com.google.gdt.eclipse.designer.gxt.databinding.wizards.autobindings.GxtDatabindingProvider.java
License:Open Source License
public String performSubstitutions(String code, ImportsManager imports) throws Exception { // bean class, field, name, field access String beanClassName = m_beanClass.getName().replace('$', '.'); String beanClassShortName = ClassUtils.getShortClassName(beanClassName); String fieldPrefix = JavaCore.getOption(JavaCore.CODEASSIST_FIELD_PREFIXES); String fieldName = fieldPrefix + StringUtils.uncapitalize(beanClassShortName); ////w w w. j a v a 2 s . co m Collection<String> importList = Sets.newHashSet(); // final List<PropertyAdapter> properties = Lists.newArrayList(); Display.getDefault().syncExec(new Runnable() { public void run() { m_packageName = m_firstPage.getPackageFragment().getElementName(); CollectionUtils.addAll(properties, m_propertiesViewer.getCheckedElements()); } }); // if (!ClassUtils.getPackageName(beanClassName).equals(m_packageName)) { importList.add(beanClassName); } beanClassName = beanClassShortName; // code = StringUtils.replace(code, "%BeanClass%", beanClassName); // if (ReflectionUtils.getConstructorBySignature(m_beanClass, "<init>()") == null) { code = StringUtils.replace(code, "%BeanField%", fieldName); } else { code = StringUtils.replace(code, "%BeanField%", fieldName + " = new " + beanClassName + "()"); } // IPreferenceStore preferences = ToolkitProvider.DESCRIPTION.getPreferences(); String accessPrefix = preferences.getBoolean(FieldUniqueVariableSupport.P_PREFIX_THIS) ? "this." : ""; String beanFieldAccess = accessPrefix + fieldName; // code = StringUtils.replace(code, "%BeanFieldAccess%", beanFieldAccess); code = StringUtils.replace(code, "%BeanName%", StringUtils.capitalize(beanClassShortName)); // boolean useGenerics = CoreUtils.useGenerics(m_javaProject); // StringBuffer fieldsCode = new StringBuffer(); StringBuffer widgetsCode = new StringBuffer(); StringBuffer bindingsCode = new StringBuffer(); // for (Iterator<PropertyAdapter> I = properties.iterator(); I.hasNext();) { PropertyAdapter property = I.next(); Object[] editorData = m_propertyToEditor.get(property); GxtWidgetDescriptor widgetDescriptor = (GxtWidgetDescriptor) editorData[0]; // String propertyName = property.getName(); String widgetClassName = ClassUtils.getShortClassName(widgetDescriptor.getWidgetClass()); String widgetFieldName = fieldPrefix + propertyName + widgetClassName; String widgetFieldAccess = accessPrefix + widgetFieldName; // if (useGenerics && widgetDescriptor.isGeneric()) { widgetClassName += "<" + convertTypes(property.getType().getName()) + ">"; } // fieldsCode.append("\r\nfield\r\n\tprivate " + widgetClassName + " " + widgetFieldName + ";"); // widgetsCode.append("\t\t" + widgetFieldName + " = new " + widgetClassName + "();\r\n"); widgetsCode.append("\t\t" + widgetFieldAccess + ".setFieldLabel(\"" + StringUtils.capitalize(propertyName) + "\");\r\n"); widgetsCode.append("\t\t" + accessPrefix + "m_formPanel.add(" + widgetFieldAccess + ", new FormData(\"100%\"));\r\n"); widgetsCode.append("\t\t//"); // importList.add(widgetDescriptor.getBindingClass()); bindingsCode.append("\t\tm_formBinding.addFieldBinding(new " + ClassUtils.getShortClassName(widgetDescriptor.getBindingClass()) + "(" + widgetFieldAccess + ",\"" + propertyName + "\"));\r\n"); // importList.add(widgetDescriptor.getWidgetClass()); // if (I.hasNext()) { fieldsCode.append("\r\n"); widgetsCode.append("\r\n"); } } // bindingsCode.append("\t\t//\r\n"); bindingsCode.append("\t\tm_formBinding.bind(" + beanFieldAccess + ");"); // replace template patterns code = StringUtils.replace(code, "%WidgetFields%", fieldsCode.toString()); code = StringUtils.replace(code, "%Widgets%", widgetsCode.toString()); code = StringUtils.replace(code, "%Bindings%", bindingsCode.toString()); // add imports for (String qualifiedTypeName : importList) { imports.addImport(qualifiedTypeName); } // return code; }
From source file:com.google.gdt.eclipse.suite.wizards.NewWebAppProjectWizardPage.java
License:Open Source License
private void validatePageAndSetCompletionStatus() { IStatus status;//from ww w .ja v a 2 s . c o m boolean pageComplete = false; try { // Project name cannot be blank if (getProjectName().length() == 0) { setMessage("Enter a name for the project"); return; } // Verify that project name is valid status = ResourcesPlugin.getWorkspace().validateName(getProjectName(), IResource.PROJECT); if (!validateFromStatus(status)) { return; } // Make sure project doesn't already exist in workspace if (existingProjectNames.contains(getProjectName())) { setMessage("A project with this name already exists.", ERROR); return; } // Output directory cannot be blank if (getOutputDirectory().length() == 0) { setMessage("Enter the output directory"); return; } // If the user wants to use a custom output directory, // verify that the directory exists if (outDirCustomButton.getSelection()) { File outDir = new Path(getOutputDirectory()).toFile(); if (!outDir.isDirectory()) { setMessage("The output directory does not exist", ERROR); return; } } // Make sure resource with project's name doesn't already exist in output // directory IPath outPath = new Path(getOutputDirectory()); if (outDirWorkspaceButton.getSelection()) { if (outPath.toFile().exists()) { setMessage("A resource with the project name already exists in the workspace root", ERROR); return; } } // Make sure output directory doesn't already contain an Eclipse project if (outDirCustomButton.getSelection()) { outPath = outPath.append(IProjectDescription.DESCRIPTION_FILE_NAME); if (outPath.toFile().exists()) { setMessage("The output directory already contains a project file", ERROR); return; } } // Package name cannot be blank if (getPackage().length() == 0) { setMessage("Enter a package name"); return; } String complianceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance"); String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.source"); // Verify that package name is valid status = JavaConventions.validatePackageName(getPackage(), complianceLevel, sourceLevel); if (!validateFromStatus(status)) { return; } // If we are using GWT then an SDK must be selected if (useGwtCheckbox.getSelection()) { IStatus gwtRuntimeValidationStatus; GWTRuntime selectedGwtRuntime = getSelectedGwtSdk(); if (selectedGwtRuntime == null) { setMessage("Please configure a GWT SDK.", ERROR); return; } else if (!(gwtRuntimeValidationStatus = selectedGwtRuntime.validate()).isOK()) { setMessage("The selected GWT SDK is not valid: " + gwtRuntimeValidationStatus.getMessage(), ERROR); return; } } pageComplete = true; setMessage(null); } finally { setPageComplete(pageComplete); } }
From source file:com.google.gwt.eclipse.core.modules.ModuleUtils.java
License:Open Source License
/** * Validates a simple module name. The name should be a camel-cased valid Java identifier. * * @param simpleName the simple module name * @return a status object with code <code>IStatus.OK</code> if the given name is valid, otherwise * a status object indicating what is wrong with the name *//*from w w w .j av a 2 s .c o m*/ public static IStatus validateSimpleModuleName(String simpleName) { String complianceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance"); String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.source"); // Make sure that the simple name does not have any dots in it. We need // to do this validation before passing the simpleName to JavaConventions, // because validateTypeName accepts both simple and fully-qualified type // names. if (simpleName.indexOf('.') != -1) { return Util.newErrorStatus("Module name should not contain dots."); } // Validate the module name according to Java type name conventions IStatus nameStatus = JavaConventions.validateJavaTypeName(simpleName, complianceLevel, sourceLevel); if (nameStatus.matches(IStatus.ERROR)) { return Util.newErrorStatus("The module name is invalid"); } return Status.OK_STATUS; }
From source file:com.google.gwt.eclipse.core.util.Util.java
License:Open Source License
public static boolean isValidMethodName(String methodName) { String complianceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance"); String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.source"); return JavaConventions.validateMethodName(methodName, sourceLevel, complianceLevel).isOK(); }
From source file:com.google.gwt.eclipse.core.util.Util.java
License:Open Source License
public static boolean isValidTypeName(String typeName) { String complianceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance"); String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.source"); return JavaConventions.validateJavaTypeName(typeName, sourceLevel, complianceLevel).isOK(); }
From source file:com.google.gwt.eclipse.core.util.Util.java
License:Open Source License
public static IStatus validatePackageName(String packageName) { if (packageName.length() > 0) { String sourceLevel = JavaCore.getOption("org.eclipse.jdt.core.compiler.compliance"); String compliance = JavaCore.getOption("org.eclipse.jdt.core.compiler.source"); return JavaConventions.validatePackageName(packageName, sourceLevel, compliance); }//from w w w . ja v a 2s . c o m return newWarningStatus(NewWizardMessages.NewTypeWizardPage_warning_DefaultPackageDiscouraged); }