List of usage examples for org.eclipse.jdt.internal.core LocalVariable LocalVariable
public LocalVariable(JavaElement parent, String name, int declarationSourceStart, int declarationSourceEnd, int nameStart, int nameEnd, String typeSignature, org.eclipse.jdt.internal.compiler.ast.Annotation[] astAnnotations, int flags, boolean isParameter)
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.MatchLocator.java
License:Open Source License
/** * Create an handle for a local variable declaration (may be a local variable or type parameter). *///from w w w. j ava 2 s.c o m protected IJavaElement createHandle(AbstractVariableDeclaration variableDeclaration, IJavaElement parent) { switch (variableDeclaration.getKind()) { case AbstractVariableDeclaration.LOCAL_VARIABLE: if (variableDeclaration.type.resolvedType != null) { return new LocalVariable((JavaElement) parent, new String(variableDeclaration.name), variableDeclaration.declarationSourceStart, variableDeclaration.declarationSourceEnd, variableDeclaration.sourceStart, variableDeclaration.sourceEnd, new String(variableDeclaration.type.resolvedType.signature()), variableDeclaration.annotations, variableDeclaration.modifiers, false); } break; case AbstractVariableDeclaration.PARAMETER: if (variableDeclaration.type.resolvedType != null) { return new LocalVariable((JavaElement) parent, new String(variableDeclaration.name), variableDeclaration.declarationSourceStart, variableDeclaration.declarationSourceEnd, variableDeclaration.sourceStart, variableDeclaration.sourceEnd, new String(variableDeclaration.type.resolvedType.signature()), variableDeclaration.annotations, variableDeclaration.modifiers, true); } break; case AbstractVariableDeclaration.TYPE_PARAMETER: return new org.eclipse.jdt.internal.core.TypeParameter((JavaElement) parent, new String(variableDeclaration.name)); } return null; }
From source file:org.eclipse.ajdt.core.javaelements.IntertypeElement.java
License:Open Source License
protected Object createElementInfo() { IntertypeElementInfo info = new IntertypeElementInfo(); IProject project = this.getJavaProject().getProject(); IProgramElement ipe = AJProjectModelFactory.getInstance().getModelForProject(project) .javaElementToProgramElement(this); if (ipe != IHierarchy.NO_STRUCTURE) { // this way of creating the element info does not contain proper source locations for the name and target type info.setAJExtraInfo(ipe.getExtraInfo()); info.setName(name.toCharArray()); info.setAJKind(ipe.getKind());//from w w w . j a v a 2 s. c o m info.setAJModifiers(ipe.getModifiers()); info.setFlags(ipe.getRawModifiers()); info.setDeclaredModifiers(info.getModifiers()); info.setAJAccessibility(ipe.getAccessibility()); ISourceLocation sourceLocation = ipe.getSourceLocation(); info.setSourceRangeStart(sourceLocation.getOffset()); info.setNameSourceStart(sourceLocation.getOffset()); // This is wrong info.setNameSourceEnd(sourceLocation.getOffset() + ipe.getName().length()); // also wrong info.setConstructor(info.getAJKind() == IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR); char[][] argumentNames = CoreUtils.listStringsToCharArrays(ipe.getParameterNames()); char[][] argumentTypeNames = CoreUtils.listCharsToCharArrays(ipe.getParameterTypes()); if (argumentNames.length == 0 && argumentTypeNames.length > 0) { // argument names not found. likely coming from binary class file w/p source attachment // generate argument names argumentNames = new char[argumentTypeNames.length][]; for (int i = 0; i < argumentNames.length; i++) { argumentNames[i] = ("arg" + i).toCharArray(); } } info.setArgumentNames(argumentNames); info.setArgumentTypeNames(argumentTypeNames); info.setReturnType(ipe.getCorrespondingType(false).toCharArray()); info.setQualifiedReturnType(ipe.getCorrespondingType(true).toCharArray()); info.setTypeParameters(createTypeParameters(project)); if (argumentNames != null && argumentNames.length > 0) { ILocalVariable[] arguments = new ILocalVariable[argumentNames.length]; for (int i = 0; i < argumentNames.length; i++) { arguments[i] = new LocalVariable(this, String.valueOf(argumentNames[i]), // sloc is not correct, but it is close enough sourceLocation.getOffset(), sourceLocation.getOffset() + 1, sourceLocation.getOffset(), sourceLocation.getOffset() + 1, String.valueOf(argumentTypeNames[i]), new Annotation[0], Flags.AccDefault, true); } info.setArguments(arguments); } } else { // no successful build yet, we don't know the contents info.setName(name.toCharArray()); info.setAJKind(IProgramElement.Kind.ERROR); info.setAJModifiers(Collections.<Modifiers>emptyList()); } return info; }
From source file:org.eclipse.ajdt.core.parserbridge.AJCompilationUnitStructureRequestor.java
License:Open Source License
private ILocalVariable[] createMethodParameters(JavaElement handle, String[] parameterTypes, char[][] argumentNames, int reasonableOffset) { if (argumentNames == null) { return null; }/*from ww w.java 2 s . c o m*/ if (argumentNames.length == 0) { return LocalVariable.NO_LOCAL_VARIABLES; } LocalVariable[] result = new LocalVariable[argumentNames.length]; for (int i = 0; i < argumentNames.length; i++) { // we don't know the slocs, so just make something up that is vaguely reasonable result[i] = new LocalVariable(handle, String.valueOf(argumentNames[i]), reasonableOffset, reasonableOffset + 1, reasonableOffset, reasonableOffset + 1, parameterTypes[i], new org.eclipse.jdt.internal.compiler.ast.Annotation[0], Flags.AccDefault, true); } return result; }
From source file:org.eclipse.ajdt.core.tests.refactoring.RenameLocalRefactoringTests.java
License:Open Source License
private void performRefactoringAndUndo(String oldVariableName, String newVariableName, String[] packNames, String[] cuNames, String[] initialContents, String[] finalContents) throws Exception { ICompilationUnit[] origUnits = createUnits(packNames, cuNames, initialContents); RenameJavaElementDescriptor descriptor = RefactoringSignatureDescriptorFactory .createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_LOCAL_VARIABLE); descriptor.setNewName(newVariableName); int start = initialContents[0].indexOf(oldVariableName); int end = start + oldVariableName.length() - 1; ILocalVariable var = new LocalVariable((JavaElement) getFirstMethod(origUnits[0]), oldVariableName, start, end, start, end, "I", new Annotation[0], 0, false); descriptor.setJavaElement(var); descriptor.setUpdateReferences(true); Refactoring refactoring = createRefactoring(descriptor); RefactoringStatus result = performRefactoring(refactoring, true, true); result = ignoreKnownErrors(result);//from w w w . j ava 2 s.com assertTrue("Refactoring produced an error: " + result, result.isOK()); assertContents(origUnits, finalContents); // undo assertTrue("anythingToUndo", RefactoringCore.getUndoManager().anythingToUndo()); assertTrue("! anythingToRedo", !RefactoringCore.getUndoManager().anythingToRedo()); RefactoringCore.getUndoManager().performUndo(null, new NullProgressMonitor()); assertContents(origUnits, initialContents); // redo assertTrue("! anythingToUndo", !RefactoringCore.getUndoManager().anythingToUndo()); assertTrue("anythingToRedo", RefactoringCore.getUndoManager().anythingToRedo()); RefactoringCore.getUndoManager().performRedo(null, new NullProgressMonitor()); assertContents(origUnits, finalContents); }
From source file:org.eclipse.contribution.weaving.jdt.tests.refactoring.RefactoringHooksTests.java
License:Apache License
private RefactoringStatus checkRenameLocalRefactoring(String unitName) throws CoreException { String source = "package p; \n class Something { \nvoid f() { int x = 9 + 8; } }"; ICompilationUnit unit = createCompilationUnitAndPackage("p", unitName, source, project); String toRefactor = "x"; int start = source.indexOf(toRefactor); int end = start; RenameLocalVariableProcessor refactoring = new RenameLocalVariableProcessor(new LocalVariable( extractFirstMethod(unit), toRefactor, start, end, start, end, "I", new Annotation[0], 0, false)); refactoring.setNewElementName("other"); RefactoringStatus status = refactoring.checkInitialConditions(monitor); assertTrue("Refactoring returns with messages.\n" + status, status.isOK()); CheckConditionsContext context = new CheckConditionsContext(); ResourceChangeChecker checker = new ResourceChangeChecker(); context.add(checker);//from ww w. jav a2s. co m status = refactoring.checkFinalConditions(new NullProgressMonitor(), context); assertTrue("Refactoring returns with messages.\n" + status, status.isOK()); return status; }
From source file:org.eclipse.recommenders.rcp.utils.JdtUtils.java
License:Open Source License
public static ILocalVariable createUnresolvedLocaVariable(final VariableBinding compilerBinding, final JavaElement parent) { requireNonNull(compilerBinding);//from w ww . j a v a 2 s . co m requireNonNull(parent); final String name = new String(compilerBinding.name); final String type = new String(compilerBinding.type.signature()); return new LocalVariable(parent, name, 0, 0, 0, 0, type, null, compilerBinding.modifiers, compilerBinding.isParameter()); }
From source file:org.eclipse.recommenders.utils.rcp.JdtUtils.java
License:Open Source License
public static ILocalVariable createUnresolvedLocaVariable(final VariableBinding compilerBinding, final JavaElement parent) { ensureIsNotNull(compilerBinding);//from w ww . j a v a2s. c o m ensureIsNotNull(parent); final String name = new String(compilerBinding.name); final String type = new String(compilerBinding.type.signature()); return new LocalVariable(parent, name, 0, 0, 0, 0, type, null, compilerBinding.modifiers, compilerBinding.isParameter()); }