List of usage examples for org.eclipse.jdt.core IJavaProject getElementName
String getElementName();
From source file:org.codehaus.groovy.eclipse.refactoring.core.extract.ExtractGroovyConstantRefactoring.java
License:Apache License
private ExtractConstantDescriptor createRefactoringDescriptor() { final Map<String, String> arguments = new HashMap<String, String>(); String project = null;/*from ww w.j a v a 2 s . c om*/ IJavaProject javaProject = getCu().getJavaProject(); if (javaProject != null) project = javaProject.getElementName(); int flags = JavaRefactoringDescriptor.JAR_REFACTORING | JavaRefactoringDescriptor.JAR_SOURCE_ATTACHMENT; flags |= RefactoringDescriptor.STRUCTURAL_CHANGE; String expression = createExpressionText(); final String description = Messages.format( RefactoringCoreMessages.ExtractConstantRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(constantName)); final String header = Messages.format( RefactoringCoreMessages.ExtractConstantRefactoring_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(constantName), BasicElementLabels.getJavaCodeString(expression) }); final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_constant_name_pattern, BasicElementLabels.getJavaElementName(constantName))); comment.addSetting( Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_constant_expression_pattern, BasicElementLabels.getJavaCodeString(expression))); String visibility = ""; if ("".equals(visibility)) //$NON-NLS-1$ visibility = RefactoringCoreMessages.ExtractConstantRefactoring_default_visibility; comment.addSetting( Messages.format(RefactoringCoreMessages.ExtractConstantRefactoring_visibility_pattern, visibility)); if (getReplaceAllOccurrences()) { comment.addSetting(RefactoringCoreMessages.ExtractConstantRefactoring_replace_occurrences); } if (getQualifyReferencesWithDeclaringClassName()) { comment.addSetting(RefactoringCoreMessages.ExtractConstantRefactoring_qualify_references); } arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, getCu())); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, constantName); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(start).toString() + " " + new Integer(length).toString()); //$NON-NLS-1$ arguments.put("replace", Boolean.valueOf(getReplaceAllOccurrences()).toString()); arguments.put("qualify", Boolean.valueOf(getQualifyReferencesWithDeclaringClassName()).toString()); arguments.put("visibility", new Integer(JdtFlags.getVisibilityCode("")).toString()); ExtractConstantDescriptor descriptor = RefactoringSignatureDescriptorFactory .createExtractConstantDescriptor(project, description, comment.asString(), arguments, flags); return descriptor; }
From source file:org.codehaus.groovy.eclipse.refactoring.core.extract.ExtractGroovyLocalRefactoring.java
License:Apache License
/** * @return// w ww . ja v a2s . c om */ private ExtractLocalDescriptor createRefactoringDescriptor() { final Map<String, String> arguments = new HashMap<String, String>(); String project = null; IJavaProject javaProject = unit.getJavaProject(); if (javaProject != null) project = javaProject.getElementName(); final String description = Messages.format( RefactoringCoreMessages.ExtractTempRefactoring_descriptor_description_short, BasicElementLabels.getJavaElementName(localName)); final String expression = getTextAt(getSelectedFragment().getStart(), getSelectedFragment().getEnd()); final String header = Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(localName), BasicElementLabels.getJavaCodeString(expression) }); final JDTRefactoringDescriptorComment comment = new JDTRefactoringDescriptorComment(project, this, header); comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_name_pattern, BasicElementLabels.getJavaElementName(localName))); comment.addSetting(Messages.format(RefactoringCoreMessages.ExtractTempRefactoring_expression_pattern, BasicElementLabels.getJavaCodeString(expression))); if (replaceAllOccurrences) comment.addSetting(RefactoringCoreMessages.ExtractTempRefactoring_replace_occurrences); final ExtractLocalDescriptor descriptor = RefactoringSignatureDescriptorFactory .createExtractLocalDescriptor(project, description, comment.asString(), arguments, RefactoringDescriptor.NONE); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_INPUT, JavaRefactoringDescriptorUtil.elementToHandle(project, unit)); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_NAME, localName); arguments.put(JavaRefactoringDescriptorUtil.ATTRIBUTE_SELECTION, new Integer(start).toString() + " " + new Integer(length).toString()); //$NON-NLS-1$ arguments.put(ATTRIBUTE_REPLACE, Boolean.valueOf(replaceAllOccurrences).toString()); return descriptor; }
From source file:org.codehaus.groovy.eclipse.wizards.NewClassWizardPage.java
License:Apache License
@Override protected IStatus typeNameChanged() { StatusInfo status = (StatusInfo) super.typeNameChanged(); IPackageFragment pack = getPackageFragment(); if (pack == null) { return status; }//from ww w . java 2s.c o m IJavaProject project = pack.getJavaProject(); try { if (!project.getProject().hasNature(GroovyNature.GROOVY_NATURE)) { status.setWarning(project.getElementName() + " is not a groovy project. Groovy Nature will be added to project upon completion."); } } catch (CoreException e) { status.setError("Exception when accessing project natures for " + project.getElementName()); } String typeName = getTypeNameWithoutParameters(); // must not exist as a .groovy file if (!isEnclosingTypeSelected() && (status.getSeverity() < IStatus.ERROR)) { if (pack != null) { IType type = null; try { type = project.findType(pack.getElementName(), typeName); } catch (JavaModelException e) { // can ignore } if (type != null && type.getPackageFragment().equals(pack)) { status.setError(NewWizardMessages.NewTypeWizardPage_error_TypeNameExists); } } } // lastly, check exclusion filters to see if Groovy files are allowed in // the source folder if (status.getSeverity() < IStatus.ERROR) { try { ClasspathEntry entry = (ClasspathEntry) ((IPackageFragmentRoot) pack.getParent()) .getRawClasspathEntry(); if (entry != null) { char[][] inclusionPatterns = entry.fullInclusionPatternChars(); char[][] exclusionPatterns = entry.fullExclusionPatternChars(); if (Util.isExcluded(pack.getResource().getFullPath().append(getCompilationUnitName(typeName)), inclusionPatterns, exclusionPatterns, false)) { status.setError( "Cannot create Groovy type because of exclusion patterns on the source folder."); } } } catch (JavaModelException e) { status.setError(e.getLocalizedMessage()); GroovyCore.logException("Exception inside new Groovy class wizard", e); } } return status; }
From source file:org.dev.toos.constcode.model.ConstModelSet.java
License:Apache License
/**?*/ public static boolean existConstModel(IJavaProject javaProject) { String projectName = javaProject.getElementName(); return modeBeanMap.containsKey(projectName); }
From source file:org.dev.toos.constcode.model.ConstModelSet.java
License:Apache License
/**?*/ public static ConstModel getConstModel(IJavaProject javaProject) { String projectName = javaProject.getElementName(); return modeBeanMap.get(projectName); }
From source file:org.dev.toos.constcode.model.ConstModelSet.java
License:Apache License
/**?*/ public static void refresh(IProgressMonitor monitor) { activateModel = null;//from w ww .j av a 2 s. c o m /* 1.??projectsxml * 1.1. * 1.2.? * 2. */ // HashMap<String, ConstModel> oldModeMap = new HashMap<String, ConstModel>(modeBeanMap); Message.updateTask(monitor, "scanning projects...", 3, 1); // IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); if (projects != null) { for (int i = 0; i < projects.length; i++) { IProject pro = projects[i]; Message.updateTask(monitor, "scanning projects(" + pro.getName() + "?)", projects.length, i); if (pro.isOpen() == false) continue; if (pro.exists() == false) continue; IJavaProject javaProject = JavaCore.create(pro); if (javaProject == null || javaProject.exists() == false) continue; //?Javacore-codes.xml? try { IJavaElement[] javaElements = javaProject.getChildren(); if (javaElements == null) continue; oldModeMap.remove(javaProject.getElementName()); if (existConstModel(javaProject) == true) getConstModel(javaProject).refresh(monitor);// else newConstModel(javaProject, monitor).refresh(monitor);// } catch (Exception e) { Message.errorInfo("Refresh Job", e); } } } // for (ConstModel constModel : getModeBeanList()) if (constModel.getGroups().size() == 0) oldModeMap.put(constModel.getProjectName(), constModel); for (Entry<String, ConstModel> ent : oldModeMap.entrySet()) ConstModelSet.removeModel(ent.getValue().getProject()); // Message.updateTask(monitor, "activate current Project...", 3, 2); if (getModeBeanList().size() != 0) { String projectName = null; IProject currentProject = ResourcesPlugin.getWorkspace().getRoot().getProject(); if (currentProject != null) { ConstModel currentModel = modeBeanMap.get(currentProject.getName()); if (currentModel != null) projectName = currentModel.getProjectName(); } if (projectName == null) projectName = getModeBeanList().get(0).getProjectName(); activateModel(projectName); } // Message.updateTask(monitor, "process callBack function...", 3, 3); }
From source file:org.dev.toos.constcode.model.ConstModelSet.java
License:Apache License
public static void removeModel(IJavaProject javaProject) { modeBeanList.remove(modeBeanMap.remove(javaProject.getElementName())); }
From source file:org.deved.antlride.jdt.launch.AntlrAbstractJavaLauncher.java
License:Open Source License
protected void generateCode(IProgressMonitor monitor, AntlrBuildUnit unit, IJavaProject javaProject, String[] classpath, IPath src) throws CoreException, InterruptedException { ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION); ILaunchConfigurationWorkingCopy cgwc = type.newInstance(null, "Generating Code for " + unit.getGrammar().getElementName()); cgwc.setAttribute(ATTR_PROJECT_NAME, javaProject.getElementName()); cgwc.setAttribute(ATTR_MAIN_TYPE_NAME, "org.antlr.Tool"); cgwc.setAttribute(ATTR_DEFAULT_CLASSPATH, false); cgwc.setAttribute(ATTR_CLASSPATH, Arrays.asList(classpath)); // program arguments StringBuilder programArgs = new StringBuilder(); programArgs.append("-verbose "); programArgs.append("-debug "); programArgs.append("-o "); programArgs.append(safeArg(src.toOSString())); programArgs.append(" "); IGrammar grammar = unit.getGrammar(); if (grammar.isParserGrammar()) { String lexerGrammarName = grammar.getOption("tokenVocab"); IPath lexerFile = unit.getAbsoluteLibraryPath().append(lexerGrammarName).addFileExtension("g"); programArgs.append(safeArg(lexerFile.toOSString())).append(" "); }/*from w ww . jav a2 s .c o m*/ programArgs.append(safeArg(unit.getAbsolutePath().toOSString())); cgwc.setAttribute(ATTR_PROGRAM_ARGUMENTS, programArgs.toString()); // create and run the launch configuration ILaunchConfiguration config = cgwc.doSave(); ILaunch launch = config.launch(ILaunchManager.RUN_MODE, monitor); while (!launch.isTerminated()) { Thread.sleep(500L); } // delete the configuration config.delete(); int exitValue = launch.getProcesses()[0].getExitValue(); if (exitValue != 0) { throw new CoreException(new Status(IStatus.ERROR, AntlrJDT.PLUGIN_ID, "Code generation fails")); } }
From source file:org.deved.antlride.jdt.launch.AntlrAbstractJavaLauncher.java
License:Open Source License
protected void compile(IProgressMonitor monitor, AntlrBuildUnit unit, IJavaProject javaProject, IRuntimeClasspathEntry[] classpath, IPath compilerPath, IPath src, IPath classes) throws CoreException, InterruptedException { ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION); ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, "Compiling " + unit.getGrammar().getElementName()); workingCopy.setAttribute(ATTR_PROJECT_NAME, javaProject.getElementName()); workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, "org.eclipse.jdt.internal.compiler.batch.Main"); workingCopy.setAttribute(ATTR_DEFAULT_CLASSPATH, false); IRuntimeClasspathEntry compilerEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(compilerPath); compilerEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); workingCopy.setAttribute(ATTR_CLASSPATH, Arrays.asList(compilerEntry.getMemento())); StringBuilder compilerArgs = new StringBuilder(); compilerArgs.append("-showversion "); compilerArgs.append("-cp "); for (IRuntimeClasspathEntry rcp : classpath) { compilerArgs.append(safeArg(rcp.getLocation())); compilerArgs.append(File.pathSeparator); }//from ww w .j av a2 s.c om compilerArgs.setLength(compilerArgs.length() - 1); String sourceLevel = "-" + javaProject.getOption(JavaCore.COMPILER_COMPLIANCE, true); compilerArgs.append(" -nowarn "); compilerArgs.append(sourceLevel); compilerArgs.append(" -d "); compilerArgs.append(safeArg(classes.toOSString())); compilerArgs.append(" "); compilerArgs.append(safeArg(src.toOSString())); workingCopy.setAttribute(ATTR_PROGRAM_ARGUMENTS, compilerArgs.toString()); // create and run the launch configuration ILaunchConfiguration config = workingCopy.doSave(); ILaunch launch = config.launch(ILaunchManager.RUN_MODE, monitor); while (!launch.isTerminated()) { Thread.sleep(500L); } // delete the configuration config.delete(); int exitValue = launch.getProcesses()[0].getExitValue(); if (exitValue != 0) { throw new CoreException(new Status(IStatus.ERROR, AntlrJDT.PLUGIN_ID, "Compilation fails")); } }
From source file:org.deved.antlride.jdt.launch.AntlrJavaLauncher.java
License:Open Source License
private int run(IProgressMonitor monitor, AntlrBuildUnit unit, AntlrTestCase test, IJavaProject javaProject, IRuntimeClasspathEntry[] classpath, IPath src, IPath classes) throws CoreException, InterruptedException { ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); ILaunchConfigurationType type = manager.getLaunchConfigurationType(ID_JAVA_APPLICATION); ILaunchConfigurationWorkingCopy workingCopy = type.newInstance(null, new StringBuilder(test.getRule()).append(" ").append(test.getName()).toString()); workingCopy.setAttribute(ATTR_PROJECT_NAME, javaProject.getElementName()); workingCopy.setAttribute(ATTR_MAIN_TYPE_NAME, "org.deved.antlride.runtime.LaunchParser"); workingCopy.setAttribute(ATTR_DEFAULT_CLASSPATH, false); IPath runtimePath = AntlrDeployer.RUNTIME_LOCATION; IRuntimeClasspathEntry runtimeEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(runtimePath); runtimeEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); IRuntimeClasspathEntry classesEntry = JavaRuntime.newArchiveRuntimeClasspathEntry(classes); classesEntry.setClasspathProperty(IRuntimeClasspathEntry.USER_CLASSES); classesEntry.setSourceAttachmentRootPath(src); String[] cp = new String[classpath.length + 2]; cp[0] = runtimeEntry.getMemento();/*from w w w. j a v a 2 s . c o m*/ cp[1] = classesEntry.getMemento(); for (int i = 0; i < classpath.length; i++) { cp[i + 2] = classpath[i].getMemento(); } workingCopy.setAttribute(ATTR_CLASSPATH, Arrays.asList(cp)); IGrammar grammar = unit.getGrammar(); String grammarName = grammar.getElementName(); String lexerPackage = getLexerJavaPackage(grammar); StringBuilder lexerClass = new StringBuilder(lexerPackage); String parserPackage = getParserJavaPackage(grammar); StringBuilder parserClass = new StringBuilder(parserPackage).append(grammarName); if (grammar.isCombinedGrammar()) { lexerClass.append(grammarName).append("Lexer"); parserClass.append("Parser"); } else { // it can only be a parser grammar lexerClass.append(grammar.getOption("tokenVocab")); } int port = findFreePort(); StringBuilder programArgs = new StringBuilder(); programArgs.append("-port").append(" ").append(port).append(" "); programArgs.append("-testCase").append(" ").append(safeArg(test.getPath().toOSString())).append(" "); programArgs.append("-lexer").append(" ").append(lexerClass).append(" "); programArgs.append("-parser").append(" ").append(parserClass).append(" "); programArgs.append("-ruleName").append(" ").append(test.getRule()); // programArgs.append("").append(" ").append(); // programArgs.append("").append(" ").append(); // programArgs.append("").append(" ").append(); // programArgs.append("").append(" ").append(); // programArgs.append("").append(" ").append(); workingCopy.setAttribute(ATTR_PROGRAM_ARGUMENTS, programArgs.toString()); // create and run the launch configuration ILaunchConfiguration config = workingCopy.doSave(); config.launch(ILaunchManager.RUN_MODE, monitor); // delete the configuration config.delete(); return port; }