List of usage examples for org.eclipse.jdt.core JavaCore newVariableEntry
public static IClasspathEntry newVariableEntry(IPath variablePath, IPath variableSourceAttachmentPath, IPath variableSourceAttachmentRootPath, IAccessRule[] accessRules, IClasspathAttribute[] extraAttributes, boolean isExported)
CPE_VARIABLE
for the given path. From source file:at.bestsolution.javafx.ide.jdt.internal.jdt.CPListElement.java
License:Open Source License
private IClasspathEntry newClasspathEntry() { IClasspathAttribute[] extraAttributes = getClasspathAttributes(); switch (fEntryKind) { case IClasspathEntry.CPE_SOURCE: IPath[] inclusionPattern = (IPath[]) getAttribute(INCLUSION); IPath[] exclusionPattern = (IPath[]) getAttribute(EXCLUSION); IPath outputLocation = (IPath) getAttribute(OUTPUT); return JavaCore.newSourceEntry(fPath, inclusionPattern, exclusionPattern, outputLocation, extraAttributes);//from w w w . ja va 2 s . c o m case IClasspathEntry.CPE_LIBRARY: { IPath attach = (IPath) getAttribute(SOURCEATTACHMENT); IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES); return JavaCore.newLibraryEntry(fPath, attach, null, accesRules, extraAttributes, isExported()); } case IClasspathEntry.CPE_PROJECT: { IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES); boolean combineAccessRules = ((Boolean) getAttribute(COMBINE_ACCESSRULES)).booleanValue(); return JavaCore.newProjectEntry(fPath, accesRules, combineAccessRules, extraAttributes, isExported()); } case IClasspathEntry.CPE_CONTAINER: { IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES); return JavaCore.newContainerEntry(fPath, accesRules, extraAttributes, isExported()); } case IClasspathEntry.CPE_VARIABLE: { IPath varAttach = (IPath) getAttribute(SOURCEATTACHMENT); IAccessRule[] accesRules = (IAccessRule[]) getAttribute(ACCESSRULES); return JavaCore.newVariableEntry(fPath, varAttach, null, accesRules, extraAttributes, isExported()); } default: return null; } }
From source file:io.sarl.eclipse.util.JavaClasspathParser.java
License:Apache License
/** * Decodes one XML element with the XML stream. * * @param element/*from w ww . j av a 2s .co m*/ * - the considered element * @param projectName * - the name of project containing the .classpath file * @param projectRootAbsoluteFullPath * - he path to project containing the .classpath file * @param unknownElements * - map of unknown elements * @return the set of CLasspath ENtries extracted from the considered element */ @SuppressWarnings({ "checkstyle:npathcomplexity", "checkstyle:cyclomaticcomplexity" }) public static IClasspathEntry elementDecode(Element element, String projectName, IPath projectRootAbsoluteFullPath, Map<IPath, UnknownXmlElements> unknownElements) { final IPath projectPath = projectRootAbsoluteFullPath; final NamedNodeMap attributes = element.getAttributes(); final NodeList children = element.getChildNodes(); final boolean[] foundChildren = new boolean[children.getLength()]; final String kindAttr = removeAttribute(ClasspathEntry.TAG_KIND, attributes); final String pathAttr = removeAttribute(ClasspathEntry.TAG_PATH, attributes); // ensure path is absolute IPath path = new Path(pathAttr); final int kind = kindFromString(kindAttr); if (kind != IClasspathEntry.CPE_VARIABLE && kind != IClasspathEntry.CPE_CONTAINER && !path.isAbsolute()) { if (!(path.segmentCount() > 0 && path.segment(0).equals(ClasspathEntry.DOT_DOT))) { path = projectPath.append(path); } } // source attachment info (optional) IPath sourceAttachmentPath = element.hasAttribute(ClasspathEntry.TAG_SOURCEPATH) ? new Path(removeAttribute(ClasspathEntry.TAG_SOURCEPATH, attributes)) : null; if (kind != IClasspathEntry.CPE_VARIABLE && sourceAttachmentPath != null && !sourceAttachmentPath.isAbsolute()) { sourceAttachmentPath = projectPath.append(sourceAttachmentPath); } final IPath sourceAttachmentRootPath = element.hasAttribute(ClasspathEntry.TAG_ROOTPATH) ? new Path(removeAttribute(ClasspathEntry.TAG_ROOTPATH, attributes)) : null; // exported flag (optional) final boolean isExported = removeAttribute(ClasspathEntry.TAG_EXPORTED, attributes).equals("true"); //$NON-NLS-1$ // inclusion patterns (optional) IPath[] inclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_INCLUDING); if (inclusionPatterns == null) { inclusionPatterns = ClasspathEntry.INCLUDE_ALL; } // exclusion patterns (optional) IPath[] exclusionPatterns = decodePatterns(attributes, ClasspathEntry.TAG_EXCLUDING); if (exclusionPatterns == null) { exclusionPatterns = ClasspathEntry.EXCLUDE_NONE; } // access rules (optional) NodeList attributeList = getChildAttributes(ClasspathEntry.TAG_ACCESS_RULES, children, foundChildren); IAccessRule[] accessRules = decodeAccessRules(attributeList); // backward compatibility if (accessRules == null) { accessRules = getAccessRules(inclusionPatterns, exclusionPatterns); } // combine access rules (optional) final boolean combineAccessRestrictions = !removeAttribute(ClasspathEntry.TAG_COMBINE_ACCESS_RULES, attributes).equals("false"); //$NON-NLS-1$ // extra attributes (optional) attributeList = getChildAttributes(ClasspathEntry.TAG_ATTRIBUTES, children, foundChildren); final IClasspathAttribute[] extraAttributes = decodeExtraAttributes(attributeList); // custom output location final IPath outputLocation = element.hasAttribute(ClasspathEntry.TAG_OUTPUT) ? projectPath.append(removeAttribute(ClasspathEntry.TAG_OUTPUT, attributes)) : null; String[] unknownAttributes = null; ArrayList<String> unknownChildren = null; if (unknownElements != null) { // unknown attributes final int unknownAttributeLength = attributes.getLength(); if (unknownAttributeLength != 0) { unknownAttributes = new String[unknownAttributeLength * 2]; for (int i = 0; i < unknownAttributeLength; i++) { final Node attribute = attributes.item(i); unknownAttributes[i * 2] = attribute.getNodeName(); unknownAttributes[i * 2 + 1] = attribute.getNodeValue(); } } // unknown children for (int i = 0, length = foundChildren.length; i < length; i++) { if (!foundChildren[i]) { final Node node = children.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) { continue; } if (unknownChildren == null) { unknownChildren = new ArrayList<>(); } final StringBuffer buffer = new StringBuffer(); decodeUnknownNode(node, buffer); unknownChildren.add(buffer.toString()); } } } // recreate the CP entry IClasspathEntry entry = null; switch (kind) { case IClasspathEntry.CPE_PROJECT: /* * IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, ClasspathEntry.INCLUDE_ALL, // inclusion patterns * ClasspathEntry.EXCLUDE_NONE, // exclusion patterns null, // source attachment null, // source attachment root null, // specific output * folder */ entry = new ClasspathEntry(IPackageFragmentRoot.K_SOURCE, IClasspathEntry.CPE_PROJECT, path, ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, isExported, accessRules, combineAccessRestrictions, extraAttributes); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules, extraAttributes, isExported); break; case IClasspathEntry.CPE_SOURCE: // must be an entry in this project or specify another project final String projSegment = path.segment(0); if (projSegment != null && projSegment.equals(projectName)) { // this project entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes); } else { if (path.segmentCount() == 1) { // another project entry = JavaCore.newProjectEntry(path, accessRules, combineAccessRestrictions, extraAttributes, isExported); } else { // an invalid source folder entry = JavaCore.newSourceEntry(path, inclusionPatterns, exclusionPatterns, outputLocation, extraAttributes); } } break; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.newVariableEntry(path, sourceAttachmentPath, sourceAttachmentRootPath, accessRules, extraAttributes, isExported); break; case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(path, accessRules, extraAttributes, isExported); break; case ClasspathEntry.K_OUTPUT: if (!path.isAbsolute()) { return null; } /* * ClasspathEntry.EXCLUDE_NONE, null, // source attachment null, // source attachment root null, // custom output location false, null, // * no access rules false, // no accessible files to combine */ entry = new ClasspathEntry(ClasspathEntry.K_OUTPUT, IClasspathEntry.CPE_LIBRARY, path, ClasspathEntry.INCLUDE_ALL, ClasspathEntry.EXCLUDE_NONE, null, null, null, false, null, false, ClasspathEntry.NO_EXTRA_ATTRIBUTES); break; default: throw new AssertionFailedException(Messages.bind(Messages.classpath_unknownKind, kindAttr)); } if (unknownAttributes != null || unknownChildren != null) { final UnknownXmlElements unknownXmlElements = new UnknownXmlElements(); unknownXmlElements.attributes = unknownAttributes; unknownXmlElements.children = unknownChildren; if (unknownElements != null) { unknownElements.put(path, unknownXmlElements); } } return entry; }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Firstly, add library to the Java build path if it's not there already, * then mark the entry as being on the aspect path * @param project//from w w w . j av a 2 s . co m * @param path */ private static void addAttribute(IProject project, String jarPath, int eKind, IClasspathAttribute attribute) { IJavaProject jp = JavaCore.create(project); try { IClasspathEntry[] cp = jp.getRawClasspath(); int cpIndex = getIndexInBuildPathEntry(cp, jarPath); if (cpIndex >= 0) { // already on classpath // add attribute to classpath entry // if it doesn't already exist IClasspathEntry pathAdd = cp[cpIndex]; // only add attribute if this element is not already on the path if (isAspectPathAttribute(attribute) ? !isOnAspectpath(pathAdd) : !isOnInpath(pathAdd)) { IClasspathAttribute[] attributes = pathAdd.getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length + 1]; System.arraycopy(attributes, 0, newattrib, 0, attributes.length); newattrib[attributes.length] = attribute; switch (pathAdd.getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: pathAdd = JavaCore.newLibraryEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_VARIABLE: pathAdd = JavaCore.newVariableEntry(pathAdd.getPath(), pathAdd.getSourceAttachmentPath(), pathAdd.getSourceAttachmentRootPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_CONTAINER: pathAdd = JavaCore.newContainerEntry(pathAdd.getPath(), pathAdd.getAccessRules(), newattrib, pathAdd.isExported()); break; case IClasspathEntry.CPE_PROJECT: pathAdd = JavaCore.newProjectEntry(pathAdd.getPath(), pathAdd.getAccessRules(), true, newattrib, pathAdd.isExported()); break; } cp[cpIndex] = pathAdd; jp.setRawClasspath(cp, null); } } else { addEntryToJavaBuildPath(jp, attribute, jarPath, eKind); } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
private static void addAttribute(IJavaProject jp, IClasspathEntry entry, IClasspathAttribute attr) { try {/*from w w w . ja va 2 s . c o m*/ IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if (cp[i].equals(entry)) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length + 1]; System.arraycopy(attributes, 0, newattrib, 0, attributes.length); newattrib[attributes.length] = attr; switch (cp[i].getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: cp[i] = JavaCore.newLibraryEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_VARIABLE: cp[i] = JavaCore.newVariableEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_CONTAINER: cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_PROJECT: cp[i] = JavaCore.newProjectEntry(cp[i].getPath(), cp[i].getAccessRules(), true, newattrib, cp[i].isExported()); break; } } } jp.setRawClasspath(cp, null); } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
public static void removeAttribute(IJavaProject jp, IClasspathEntry entry, IClasspathAttribute attr) { try {/*from w w w. jav a2s .c o m*/ IClasspathEntry[] cp = jp.getRawClasspath(); for (int i = 0; i < cp.length; i++) { if (cp[i].equals(entry)) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length - 1]; int count = 0; for (int j = 0; j < attributes.length; j++) { if (!attributes[j].getName().equals(attr.getName())) { newattrib[count++] = attributes[j]; } } switch (cp[i].getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: cp[i] = JavaCore.newLibraryEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_VARIABLE: cp[i] = JavaCore.newVariableEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_CONTAINER: cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_PROJECT: cp[i] = JavaCore.newProjectEntry(cp[i].getPath(), cp[i].getAccessRules(), true, newattrib, cp[i].isExported()); break; } } } jp.setRawClasspath(cp, null); } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
/** * Remove all occurrences of an attribute * @param javaProject/*from ww w . j a va 2s.c om*/ * @param attribute */ private static void removeAttribute(IJavaProject javaProject, IClasspathAttribute attribute) { try { IClasspathEntry[] cp = javaProject.getRawClasspath(); boolean changed = false; for (int i = 0; i < cp.length; i++) { IClasspathAttribute[] attributes = cp[i].getExtraAttributes(); boolean found = false; for (int j = 0; !found && (j < attributes.length); j++) { if (attributes[j].getName().equals(attribute.getName())) { found = true; } } if (found) { changed = true; IClasspathAttribute[] newattrib = new IClasspathAttribute[attributes.length - 1]; int count = 0; for (int j = 0; j < attributes.length; j++) { if (!attributes[j].getName().equals(attribute.getName())) { newattrib[count++] = attributes[j]; } } switch (cp[i].getEntryKind()) { case IClasspathEntry.CPE_LIBRARY: cp[i] = JavaCore.newLibraryEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_VARIABLE: cp[i] = JavaCore.newVariableEntry(cp[i].getPath(), cp[i].getSourceAttachmentPath(), cp[i].getSourceAttachmentRootPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_CONTAINER: cp[i] = JavaCore.newContainerEntry(cp[i].getPath(), cp[i].getAccessRules(), newattrib, cp[i].isExported()); break; case IClasspathEntry.CPE_PROJECT: cp[i] = JavaCore.newProjectEntry(cp[i].getPath(), cp[i].getAccessRules(), true, newattrib, cp[i].isExported()); break; } } } if (changed) { javaProject.setRawClasspath(cp, null); } } catch (JavaModelException e) { } }
From source file:org.eclipse.ajdt.core.AspectJCorePreferences.java
License:Open Source License
private static void addEntryToJavaBuildPath(IJavaProject jp, IClasspathAttribute attribute, String path, int eKind) { IClasspathAttribute[] attributes = new IClasspathAttribute[] { attribute }; try {//ww w.ja v a 2 s . com IClasspathEntry[] originalCP = jp.getRawClasspath(); IClasspathEntry[] newCP = new IClasspathEntry[originalCP.length + 1]; IClasspathEntry cp = null; if (eKind == IClasspathEntry.CPE_LIBRARY) { cp = JavaCore.newLibraryEntry(new Path(path), null, null, new IAccessRule[0], attributes, false); } else if (eKind == IClasspathEntry.CPE_VARIABLE) { cp = JavaCore.newVariableEntry(new Path(path), null, null, new IAccessRule[0], attributes, false); } else if (eKind == IClasspathEntry.CPE_CONTAINER) { cp = JavaCore.newContainerEntry(new Path(path), null, attributes, false); } else if (eKind == IClasspathEntry.CPE_PROJECT) { cp = JavaCore.newProjectEntry(new Path(path), null, true, attributes, false); } // Update the raw classpath with the new entry. if (cp != null) { System.arraycopy(originalCP, 0, newCP, 0, originalCP.length); newCP[originalCP.length] = cp; jp.setRawClasspath(newCP, new NullProgressMonitor()); } } catch (JavaModelException e) { } catch (NumberFormatException e) { } }
From source file:org.eclipse.birt.report.designer.internal.ui.ide.adapters.IDECPListElement.java
License:Open Source License
private IClasspathEntry newClasspathEntry() { IClasspathAttribute[] extraAttributes = new IClasspathAttribute[0]; switch (fEntryKind) { case IClasspathEntry.CPE_SOURCE: return JavaCore.newSourceEntry(fPath, null, null, null, extraAttributes); case IClasspathEntry.CPE_LIBRARY: { return JavaCore.newLibraryEntry(fPath, null, null, null, extraAttributes, isExported()); }/* ww w .j a va 2s . co m*/ case IClasspathEntry.CPE_PROJECT: { return JavaCore.newProjectEntry(fPath, null, false, extraAttributes, isExported()); } case IClasspathEntry.CPE_CONTAINER: { return JavaCore.newContainerEntry(fPath, null, extraAttributes, isExported()); } case IClasspathEntry.CPE_VARIABLE: { return JavaCore.newVariableEntry(fPath, null, null, null, extraAttributes, isExported()); } default: return null; } }
From source file:org.eclipse.che.plugin.maven.server.core.classpath.ClasspathEntryHelper.java
License:Open Source License
public IClasspathEntry toClasspathEntry() { Map<String, String> attributes = new HashMap<String, String>(this.attributes); if (artifactKey != null) { attributes.put(ClasspathManager.GROUP_ID_ATTRIBUTE, artifactKey.getGroupId()); attributes.put(ClasspathManager.ARTIFACT_ID_ATTRIBUTE, artifactKey.getArtifactId()); attributes.put(ClasspathManager.VERSION_ATTRIBUTE, artifactKey.getVersion()); attributes.put(ClasspathManager.PACKAGING_ATTRIBUTE, artifactKey.getPackaging()); if (artifactKey.getClassifier() != null) { attributes.put(ClasspathManager.CLASSIFIER_ATTRIBUTE, artifactKey.getClassifier()); }//from ww w .j av a 2 s . c o m } IClasspathAttribute[] attributesArray = new IClasspathAttribute[attributes.size()]; int attributeIndex = 0; for (Map.Entry<String, String> attribute : attributes.entrySet()) { attributesArray[attributeIndex++] = JavaCore.newClasspathAttribute(attribute.getKey(), attribute.getValue()); } IAccessRule[] accessRulesArray = accessRules.toArray(new IAccessRule[accessRules.size()]); IClasspathEntry entry; switch (kind) { case IClasspathEntry.CPE_CONTAINER: entry = JavaCore.newContainerEntry(path, // accessRulesArray, // attributesArray, // exported); break; case IClasspathEntry.CPE_LIBRARY: entry = JavaCore.newLibraryEntry(path, // sourcePath, // sourceRootPath, // accessRulesArray, // attributesArray, // exported); break; case IClasspathEntry.CPE_SOURCE: entry = JavaCore.newSourceEntry(path, // getInclusionPatterns(), // getExclusionPatterns(), // outputLocation, // attributesArray); break; case IClasspathEntry.CPE_PROJECT: entry = JavaCore.newProjectEntry(path, // accessRulesArray, // combineAccessRules, // attributesArray, // exported); break; case IClasspathEntry.CPE_VARIABLE: entry = JavaCore.newVariableEntry(path, // sourcePath, // sourceRootPath, // accessRulesArray, // attributesArray, // exported); break; default: throw new IllegalArgumentException("Unsupported IClasspathEntry kind=" + kind); //$NON-NLS-1$ } return entry; }
From source file:org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil.java
License:Open Source License
public static IClasspathEntry modifyDependencyPath(IClasspathEntry entry, IPath dependencyPath) { IClasspathEntry newEntry = null;// ww w .jav a 2 s .c om IClasspathAttribute[] newAttributes = modifyDependencyPath(entry.getExtraAttributes(), dependencyPath); switch (entry.getEntryKind()) { case IClasspathEntry.CPE_CONTAINER: newEntry = JavaCore.newContainerEntry(entry.getPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_LIBRARY: newEntry = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_VARIABLE: newEntry = JavaCore.newVariableEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_PROJECT: newEntry = JavaCore.newProjectEntry(entry.getPath(), entry.getAccessRules(), entry.combineAccessRules(), newAttributes, entry.isExported()); break; case IClasspathEntry.CPE_SOURCE: newEntry = JavaCore.newSourceEntry(entry.getPath(), entry.getInclusionPatterns(), entry.getExclusionPatterns(), entry.getOutputLocation(), newAttributes); break; } return newEntry; }